From: Jeff M. <cus...@us...> - 2003-07-22 10:25:03
|
Update of /cvsroot/mockobjects/mockobjects-java/src/j2ee/1.3/com/mockobjects/helpers In directory sc8-pr-cvs1:/tmp/cvs-serv26232/src/j2ee/1.3/com/mockobjects/helpers Modified Files: AbstractServletTestHelper.java ServletTestHelper.java Log Message: Made AbstractServletTestHelper extends MockObject to allow easier verification Added methods to allow a servlet to be tested with a certain status expectaion Index: AbstractServletTestHelper.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/j2ee/1.3/com/mockobjects/helpers/AbstractServletTestHelper.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- AbstractServletTestHelper.java 14 May 2003 15:17:32 -0000 1.4 +++ AbstractServletTestHelper.java 22 Jul 2003 10:25:00 -0000 1.5 @@ -1,11 +1,12 @@ package com.mockobjects.helpers; import com.mockobjects.servlet.*; +import com.mockobjects.MockObject; /** * $Revision$ */ -public abstract class AbstractServletTestHelper { +public abstract class AbstractServletTestHelper extends MockObject{ protected final MockHttpServletRequest request = new MockHttpServletRequest(); protected final MockHttpServletResponse response = new MockHttpServletResponse(); protected final MockHttpSession httpSession = new MockHttpSession(); Index: ServletTestHelper.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/j2ee/1.3/com/mockobjects/helpers/ServletTestHelper.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ServletTestHelper.java 14 May 2003 15:17:57 -0000 1.2 +++ ServletTestHelper.java 22 Jul 2003 10:25:00 -0000 1.3 @@ -32,14 +32,140 @@ testSubject.service(request, response); } + /** + * Calls the service method on the test subject after setting the HTTP method on the request to POST + * @throws ServletException + * @throws IOException + */ public void testDoPost() throws ServletException, IOException { - request.setupGetMethod("POST"); - testServlet(); + testServletWithMethod("POST"); } + /** + * Calls the service method on the test subject after setting the HTTP method on the request to GET + * @throws ServletException + * @throws IOException + */ public void testDoGet() throws ServletException, IOException { - request.setupGetMethod("GET"); + testServletWithMethod("GET"); + } + + /** + * Calls the service method on the test subject after setting the HTTP method on the request to PUT + * @throws ServletException + * @throws IOException + */ + public void testDoPut() throws ServletException, IOException { + testServletWithMethod("PUT"); + } + + /** + * Calls the service method on the test subject after setting the HTTP method on the request to PUT. + * The expected response status is also set so that it can be verified later. + * @throws ServletException + * @throws IOException + */ + public void testDoPutWithExpectedStatus(int status) throws ServletException, IOException { + testServletWithMethod("PUT", status); + } + + /** + * Calls the service method on the test subject after setting the HTTP method on the request to PUT. + * The expected response status and message are also set so that it can be verified later. + * @throws ServletException + * @throws IOException + */ + public void testDoPutWithExpectedStatus(int status, String message) throws ServletException, IOException { + testServletWithMethod("PUT", status, message); + } + + /** + * Calls the service method on the test subject after setting the HTTP method on the request to PUT + * The response status is set to expect not to be called. + * @throws ServletException + * @throws IOException + */ + public void testDoPutWithExpectedStatusNone() throws ServletException, IOException { + testServletWithMethodAndNoStatus("PUT"); + } + + /** + * Calls the service method on the test subject after setting the HTTP method on the request to GET. + * The expected response status is also set so that it can be verified later. + * @throws ServletException + * @throws IOException + */ + public void testDoGetWithExpectedStatus(int status) throws ServletException, IOException { + testServletWithMethod("GET", status); + } + + /** + * Calls the service method on the test subject after setting the HTTP method on the request to GET. + * The expected response status and message are also set so that it can be verified later. + * @throws ServletException + * @throws IOException + */ + public void testDoGetWithExpectedStatus(int status, String message) throws ServletException, IOException { + testServletWithMethod("GET", status, message); + } + + /** + * Calls the service method on the test subject after setting the HTTP method on the request to GET + * The response status is set to expect not to be called. + * @throws ServletException + * @throws IOException + */ + public void testDoGetWithExpectedStatusNone() throws ServletException, IOException { + testServletWithMethodAndNoStatus("GET"); + } + + /** + * Calls the service method on the test subject after setting the HTTP method on the request to POST. + * The expected response status is also set so that it can be verified later. + * @throws ServletException + * @throws IOException + */ + public void testDoPostWithExpectedStatus(int status) throws ServletException, IOException { + testServletWithMethod("POST", status); + } + + /** + * Calls the service method on the test subject after setting the HTTP method on the request to POST. + * The expected response status and message are also set so that it can be verified later. + * @throws ServletException + * @throws IOException + */ + public void testDoPostWithExpectedStatus(int status, String message) throws ServletException, IOException { + testServletWithMethod("POST", status, message); + } + + /** + * Calls the service method on the test subject after setting the HTTP method on the request to POST + * The response status is set to expect not to be called. + * @throws ServletException + * @throws IOException + */ + public void testDoPostWithExpectedStatusNone() throws ServletException, IOException { + testServletWithMethodAndNoStatus("POST"); + } + + private void testServletWithMethod(final String aMethod) throws ServletException, IOException { + request.setupGetMethod(aMethod); testServlet(); } + private void testServletWithMethod(final String aMethod, int status) throws ServletException, IOException { + response.setExpectedError(status); + testServletWithMethod(aMethod); + } + + private void testServletWithMethod(final String aMethod, int status, String message) throws ServletException, IOException { + response.setExpectedError(status, message); + testServletWithMethod(aMethod); + } + + private void testServletWithMethodAndNoStatus(final String aMethod) throws ServletException, IOException { + response.setExpectedErrorNothing(); + testServletWithMethod(aMethod); + } } |