| Home >> All >> com >> mockobjects >> [ helpers Javadoc ] |
Source code: com/mockobjects/helpers/ServletTestHelper.java
1 package com.mockobjects.helpers; 2 3 import javax.servlet.ServletException; 4 import javax.servlet.http.HttpServlet; 5 import java.io.IOException; 6 7 /** 8 * Sets up mock servlet objects in a common configuration. 9 * HttpSession is attached to request, RequestDispatcher is connected to HttpSession 10 * @see com.mockobjects.servlet.MockHttpServletRequest#setSession 11 * @see com.mockobjects.servlet.MockServletContext#setupGetRequestDispatcher 12 */ 13 public class ServletTestHelper extends AbstractServletTestHelper { 14 private final HttpServlet testSubject; 15 16 public ServletTestHelper(HttpServlet testSubject) { 17 super(); 18 this.testSubject = testSubject; 19 } 20 21 /** 22 * Calls HttpServlet.init passing it the MockServletConfig 23 */ 24 public void testServletInit() throws ServletException { 25 testSubject.init(servletConfig); 26 } 27 28 /** 29 * Calls HttpServlet.service passing it the MockHttpServletRequest & MockHttpServletResponse 30 */ 31 public void testServlet() throws ServletException, IOException { 32 testSubject.service(request, response); 33 } 34 35 public void testDoPost() throws ServletException, IOException { 36 request.setupGetMethod("POST"); 37 testServlet(); 38 } 39 40 public void testDoGet() throws ServletException, IOException { 41 request.setupGetMethod("GET"); 42 testServlet(); 43 } 44 45 }