You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-dev@jakarta.apache.org by vm...@apache.org on 2002/07/31 23:44:34 UTC
cvs commit: jakarta-cactus/sample-servlet/src/unit/share/org/apache/cactus/unit TestAbstractWebTestCase.java
vmassol 2002/07/31 14:44:34
Modified: documentation/docs/xdocs changes.xml todo.xml
framework/src/java/share/org/apache/cactus
AbstractTestCase.java AbstractWebTestCase.java
framework/src/test/share/org/apache/cactus
TestAbstractTestCaseInterceptorTestCase.java
sample-servlet/src/unit/j2ee12/org/apache/cactus/unit
TestAll.java
sample-servlet/src/unit/j2ee13/org/apache/cactus/unit
TestAll.java
Added: sample-servlet/src/unit/share/org/apache/cactus/unit
TestAbstractWebTestCase.java
Log:
added support for client side clientSetUp() and clientTearDown() that are called before and after each test on the cactus client side. Still missing the hardest: documentation for the web site (UML diagrams need to be modified, Powerpoints too, etc :-().
Revision Changes Path
1.36 +16 -1 jakarta-cactus/documentation/docs/xdocs/changes.xml
Index: changes.xml
===================================================================
RCS file: /home/cvs/jakarta-cactus/documentation/docs/xdocs/changes.xml,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -r1.35 -r1.36
--- changes.xml 27 Jul 2002 12:41:46 -0000 1.35
+++ changes.xml 31 Jul 2002 21:44:33 -0000 1.36
@@ -47,7 +47,22 @@
<person name="Nicholas Lesiecki" email="ndlesiecki@yahoo.com" id="NDL"/>
</devs>
- <release version="1.4 in CVS">
+ <release version="1.5 in CVS">
+ <action dev="VMA" type="add">
+ Added support for client side <code>clientSetUp(...)</code>
+ and <code>clientTearDown(...)</code> methods. They are called on the
+ client side, before and after every test in the same way as the
+ JUnit <code>setUp()</code> and <code>tearDown()</code> are called
+ before and after each test, but on the server side. <em>Note: web site
+ documentation is not yet up to date</em>.
+ </action>
+ <action dev="VMA" type="add">
+ Added a new <code>CheckPropertiesTask</code> Ant task to check
+ properties in build files.
+ </action>
+ </release>
+
+ <release version="1.4" date="July 29 2002">
<action dev="VMA" type="add">
It is now possible to assert response codes in
<code>endXXX()</code>. For example, you can verify that you servlet
1.18 +4 -12 jakarta-cactus/documentation/docs/xdocs/todo.xml
Index: todo.xml
===================================================================
RCS file: /home/cvs/jakarta-cactus/documentation/docs/xdocs/todo.xml,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- todo.xml 28 Jul 2002 20:50:43 -0000 1.17
+++ todo.xml 31 Jul 2002 21:44:33 -0000 1.18
@@ -32,6 +32,10 @@
<version title="Version 1.5">
<category title="Documentation">
+ <action>
+ Update web site for new <code>clientSetUp()</code> and
+ <code>clientTearDown()</code> methods.
+ </action>
<action assigned-to="Vincent Massol">
Move all documentation to docbook and cocoon2 and generate PDF
containing full Cactus documentation. Note: I still need to find out
@@ -83,18 +87,6 @@
</action>
<action assigned-to="Peter Wong, Jason Robertson, Vincent Massol">
Add support for Form-based authentication.
- </action>
- <action>
- Add methods that are called before and after each test, but on the
- client side (i.e. before the <code>beginXXX()</code> and
- <code>endXXX()</code> methods). They
- would act the same way as <code>setUp()</code> and
- <code>tearDown()</code> but on the client side. They could be
- named <code>init()</code> and <code>destroy()</code>, or maybe we
- should rather rename the existing <code>setUp()</code> and
- <code>tearDown()</code> and have something consistent like :
- <code>setUpClient()</code>, <code>setUpServer()</code>,
- <code>tearDownClient()</code> and <code>tearDownServer()</code> ?
</action>
<action>
Provide support for generating Session cookies and URL Sessions
1.10 +64 -17 jakarta-cactus/framework/src/java/share/org/apache/cactus/AbstractTestCase.java
Index: AbstractTestCase.java
===================================================================
RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/AbstractTestCase.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- AbstractTestCase.java 22 Jul 2002 12:26:04 -0000 1.9
+++ AbstractTestCase.java 31 Jul 2002 21:44:33 -0000 1.10
@@ -68,7 +68,10 @@
/**
* Abstract class that is a thin layer on top of JUnit and that knows about
- * test cases that are executed on the server side. This class is independent
+ * test cases that are executed on the server side. It also provides the
+ * ability to run common set up code before each test on the client side (note
+ * that calling common tear down code is delegated to extending classes as the
+ * method signature depends on the protocol used). This class is independent
* of the protocol used to communicate from the Cactus client side and the
* Cactus server side; it can be HTTP, JMS, etc. Subclasses will define
* additional behaviour that depends on the protocol.
@@ -95,6 +98,24 @@
protected static final String END_METHOD_PREFIX = "end";
/**
+ * The name of the set up method to run on the client side if it exists.
+ * This method is run before each test in the same way as the JUnit
+ * <code>setUp()</code> method is run. The difference is that is that it
+ * is run on the client side whereas <code>setUp()</code> runs on the
+ * server side.
+ */
+ protected static final String CLIENT_SETUP_METHOD = "clientSetUp";
+
+ /**
+ * The name of the tear down method to run on the client side if it exists.
+ * This method is run after each test in the same way as the JUnit
+ * <code>tearDown()</code> method is run. The difference is that is that it
+ * is run on the client side whereas <code>tearDown()</code> runs on the
+ * server side.
+ */
+ protected static final String CLIENT_TEARDOWN_METHOD = "clientTearDown";
+
+ /**
* Name of properties file to initialize logging subsystem
*/
public static final String LOG_CLIENT_CONFIG = "log_client.properties";
@@ -171,11 +192,11 @@
}
/**
- * Runs the bare test sequence. This method is overridden from the
- * JUnit <code>TestCase</code> class in order to prevent the latter
- * to call the <code>setUp()</code> and <code>tearDown()</code> methods
- * which, in our case, need to be ran in the servlet engine by the
- * servlet redirector class.
+ * Runs the bare test.
+ * This method is overridden from the JUnit <code>TestCase</code> class in
+ * order to prevent the latter to call the <code>setUp()</code> and
+ * <code>tearDown()</code> methods which, in our case, need to be ran in
+ * the servlet engine by the servlet redirector class.
*
* @exception Throwable if any exception is thrown during the test. Any
* exception will be displayed by the JUnit Test Runner
@@ -197,7 +218,6 @@
logger.debug("Exception in test", t);
throw t;
}
-
}
/**
@@ -239,23 +259,26 @@
}
/**
- * Call the test case begin method.
+ * Call an end method which takes either a Cactus WebResponse parameter
+ * or a HttpUnit WebResponse object as paramter.
*
- * @param theRequest the request object to pass to the begin method.
- * @exception Throwable any error that occurred when calling the begin
- * method for the current test case.
+ * @param theRequest the request object which will contain data that will
+ * be used to connect to the Cactus server side redirectors.
+ * @param theMethodName the name of the begin method to call
+ * @exception Throwable any error that occurred when calling the method
*/
- protected void callBeginMethod(Request theRequest) throws Throwable
+ private void callGenericBeginMethod(Request theRequest,
+ String theMethodName) throws Throwable
{
// First, verify if a begin method exist. If one is found, verify if
// it has the correct signature. If not, send a warning.
Method[] methods = getClass().getMethods();
for (int i = 0; i < methods.length; i++) {
- if (methods[i].getName().equals(getBeginMethodName())) {
+ if (methods[i].getName().equals(theMethodName)) {
// Check return type
if (!methods[i].getReturnType().getName().equals("void")) {
- fail("The begin method [" + methods[i].getName()
+ fail("The method [" + methods[i].getName()
+ "] should return void and not ["
+ methods[i].getReturnType().getName() + "]");
}
@@ -270,7 +293,7 @@
Class[] parameters = methods[i].getParameterTypes();
if (parameters.length != 1) {
- fail("The begin method [" + methods[i].getName()
+ fail("The method [" + methods[i].getName()
+ "] must accept a single parameter derived from "
+ "class [" + WebRequest.class.getName() + "], "
+ "but " + parameters.length
@@ -279,7 +302,7 @@
} else if (!theRequest.getClass().isAssignableFrom(
parameters[0])) {
- fail("The begin method [" + methods[i].getName()
+ fail("The method [" + methods[i].getName()
+ "] must accept a single parameter derived from "
+ "class [" + theRequest.getClass().getName() + "], "
+ "but found a [" + parameters[0].getName() + "] "
@@ -299,6 +322,30 @@
}
}
+ }
+
+ /**
+ * Call the client side set up method if it exists.
+ *
+ * @param theRequest the request object which will contain data that will
+ * be used to connect to the Cactus server side redirectors.
+ * @exception Throwable any error that occurred when calling the method
+ */
+ protected void callClientSetUp(Request theRequest) throws Throwable
+ {
+ callGenericBeginMethod(theRequest, CLIENT_SETUP_METHOD);
+ }
+
+ /**
+ * Call the test case begin method.
+ *
+ * @param theRequest the request object to pass to the begin method.
+ * @exception Throwable any error that occurred when calling the begin
+ * method for the current test case.
+ */
+ protected void callBeginMethod(Request theRequest) throws Throwable
+ {
+ callGenericBeginMethod(theRequest, getBeginMethodName());
}
/**
1.7 +116 -37 jakarta-cactus/framework/src/java/share/org/apache/cactus/AbstractWebTestCase.java
Index: AbstractWebTestCase.java
===================================================================
RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/AbstractWebTestCase.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- AbstractWebTestCase.java 21 Jul 2002 12:09:16 -0000 1.6
+++ AbstractWebTestCase.java 31 Jul 2002 21:44:33 -0000 1.7
@@ -87,33 +87,36 @@
}
/**
- * Call the test case end method
+ * Call an end method which takes either a Cactus WebResponse parameter
+ * or a HttpUnit WebResponse object as paramter.
*
* @param theRequest the request data that were used to open the
- * connection.
+ * connection.
* @param theConnection the <code>HttpURLConnection</code> that was used
* to open the connection to the redirection servlet. The response
* codes, headers, cookies can be checked using the get methods of
* this object.
+ * @param theMethodName the name of the end method to call
+ * @param theResponse the Response object if it exists. Can be null in
+ * which case it is created from the HttpURLConnection
+ * @return the created WebReponse object (either Cactus or HttpClient)
* @exception Throwable any error that occurred when calling the end method
- * for the current test case.
+ * for the current test case.
*/
- protected void callEndMethod(WebRequest theRequest,
- HttpURLConnection theConnection) throws Throwable
+ private Object callGenericEndMethod(WebRequest theRequest,
+ HttpURLConnection theConnection, String theMethodName,
+ Object theResponse) throws Throwable
{
- // First, verify if an end method exist. If one is found, verify if
- // it has the correct signature. If not, send a warning. Also
- // verify that only one end method is defined for a given test.
Method methodToCall = null;
Object paramObject = null;
Method[] methods = getClass().getMethods();
for (int i = 0; i < methods.length; i++) {
- if (methods[i].getName().equals(getEndMethodName())) {
+ if (methods[i].getName().equals(theMethodName)) {
// Check return type
if (!methods[i].getReturnType().getName().equals("void")) {
- fail("The end method [" + methods[i].getName()
+ fail("The method [" + methods[i].getName()
+ "] should return void and not ["
+ methods[i].getReturnType().getName() + "]");
}
@@ -129,38 +132,48 @@
// Verify only one parameter is defined
if (parameters.length != 1) {
- fail("The end method [" + methods[i].getName()
+ fail("The method [" + methods[i].getName()
+ "] must only have a single parameter");
}
+ paramObject = theResponse;
+
// Is it a Http Unit WebResponse ?
if (parameters[0].getName().
equals("com.meterware.httpunit.WebResponse")) {
- paramObject = createHttpUnitWebResponse(theConnection);
+ if (paramObject == null) {
+ paramObject = createHttpUnitWebResponse(theConnection);
+ }
- // Is it a Cactus WebResponse ?
+ // Is it a Cactus WebResponse ?
} else if (parameters[0].getName().
equals("org.apache.cactus.WebResponse")) {
- paramObject = new WebResponse(theRequest, theConnection);
+ if (paramObject == null) {
+ paramObject = new WebResponse(theRequest,
+ theConnection);
+ }
- // Is it an old HttpURLConnection (deprecated) ?
+ // Is it an old HttpURLConnection (deprecated) ?
} else if (parameters[0].getName().
equals("java.net.HttpURLConnection")) {
- paramObject = theConnection;
+ if (paramObject == null) {
+ paramObject = theConnection;
+ }
- // Else it is an error ...
+ // Else it is an error ...
} else {
- fail("The end method [" + methods[i].getName()
+ fail("The method [" + methods[i].getName()
+ "] has a bad parameter of type ["
+ parameters[0].getName() + "]");
}
// Has a method to call already been found ?
if (methodToCall != null) {
- fail("There can only be one end method per test case. "
+ fail("There can only be one method [" + methods[i].getName()
+ + "] per test case. "
+ "Test case [" + this.getCurrentTestMethod()
+ "] has two at least !");
}
@@ -185,6 +198,47 @@
}
}
+ return paramObject;
+ }
+
+ /**
+ * Call the client tear down up method if it exists.
+ *
+ * @param theRequest the request data that were used to open the
+ * connection.
+ * @param theConnection the <code>HttpURLConnection</code> that was used
+ * to open the connection to the redirection servlet. The response
+ * codes, headers, cookies can be checked using the get methods of
+ * this object.
+ * @param theResponse the Response object if it exists. Can be null in
+ * which case it is created from the HttpURLConnection
+ * @exception Throwable any error that occurred when calling the method
+ */
+ protected void callClientTearDown(WebRequest theRequest,
+ HttpURLConnection theConnection, Object theResponse) throws Throwable
+ {
+ callGenericEndMethod(theRequest, theConnection, CLIENT_TEARDOWN_METHOD,
+ theResponse);
+ }
+
+ /**
+ * Call the test case end method
+ *
+ * @param theRequest the request data that were used to open the
+ * connection.
+ * @param theConnection the <code>HttpURLConnection</code> that was used
+ * to open the connection to the redirection servlet. The response
+ * codes, headers, cookies can be checked using the get methods of
+ * this object.
+ * @return the created WebReponse object (either Cactus or HttpClient)
+ * @exception Throwable any error that occurred when calling the end method
+ * for the current test case.
+ */
+ protected Object callEndMethod(WebRequest theRequest,
+ HttpURLConnection theConnection) throws Throwable
+ {
+ return callGenericEndMethod(
+ theRequest, theConnection, getEndMethodName(), null);
}
/**
@@ -224,47 +278,72 @@
* executes the test case end method.
*
* @param theHttpClient the HTTP client class to use to connect to the
- * proxy redirector.
+ * proxy redirector.
* @exception Throwable any error that occurred when calling the test method
- * for the current test case.
+ * for the current test case.
*/
protected void runGenericTest(AbstractHttpClient theHttpClient)
throws Throwable
{
- // Call the begin method to fill the request object
WebRequest request = new WebRequest();
+
+ // Call the set up and begin methods to fill the request object
+ callClientSetUp(request);
callBeginMethod(request);
+ // Run the web test
+ HttpURLConnection connection = runWebTest(request, theHttpClient);
+
+ // Call the end method
+ Object response = callEndMethod(request, connection);
+
+ // call the tear down method
+ callClientTearDown(request, connection, response);
+
+ // Close the input stream (just in the case the user has not done it
+ // in it's endXXX method (or if he has no endXXX method) ....
+ connection.getInputStream().close();
+ }
+
+ /**
+ * Run the web test by connecting to the server proxy
+ * redirector (where the test case test method is executed).
+ *
+ * @param theRequest the request object which will contain data that will
+ * be used to connect to the Cactus server side redirectors.
+ * @param theHttpClient the HTTP client class to use to connect to the
+ * proxy redirector.
+ * @return the HTTP connection object that was used to call the server side
+ * @exception Throwable any error that occurred when calling the test method
+ * for the current test case.
+ */
+ private HttpURLConnection runWebTest(WebRequest theRequest,
+ AbstractHttpClient theHttpClient) throws Throwable
+ {
// Add the class name, the method name, the URL to simulate and
// automatic session creation flag to the request
// Note: All these pareameters are passed in the URL. This is to allow
// the user to send whatever he wants in the request body. For example
// a file, ...
- request.addParameter(HttpServiceDefinition.CLASS_NAME_PARAM,
+ theRequest.addParameter(HttpServiceDefinition.CLASS_NAME_PARAM,
this.getClass().getName(), WebRequest.GET_METHOD);
- request.addParameter(HttpServiceDefinition.METHOD_NAME_PARAM,
+ theRequest.addParameter(HttpServiceDefinition.METHOD_NAME_PARAM,
this.getCurrentTestMethod(), WebRequest.GET_METHOD);
- request.addParameter(HttpServiceDefinition.AUTOSESSION_NAME_PARAM,
- request.getAutomaticSession() ? "true" : "false",
+ theRequest.addParameter(HttpServiceDefinition.AUTOSESSION_NAME_PARAM,
+ theRequest.getAutomaticSession() ? "true" : "false",
WebRequest.GET_METHOD);
// Add the simulated URL (if one has been defined)
- if (request.getURL() != null) {
- request.getURL().saveToRequest(request);
+ if (theRequest.getURL() != null) {
+ theRequest.getURL().saveToRequest(theRequest);
}
// Open the HTTP connection to the servlet redirector
// and manage errors that could be returned in the
// HTTP response.
- HttpURLConnection connection = theHttpClient.doTest(request);
-
- // Call the end method
- callEndMethod(request, connection);
+ HttpURLConnection connection = theHttpClient.doTest(theRequest);
- // Close the input stream (just in the case the user has not done it
- // in it's endXXX method (or if he has no endXXX method) ....
- connection.getInputStream().close();
+ return connection;
}
-
}
1.5 +7 -7 jakarta-cactus/framework/src/test/share/org/apache/cactus/TestAbstractTestCaseInterceptorTestCase.java
Index: TestAbstractTestCaseInterceptorTestCase.java
===================================================================
RCS file: /home/cvs/jakarta-cactus/framework/src/test/share/org/apache/cactus/TestAbstractTestCaseInterceptorTestCase.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TestAbstractTestCaseInterceptorTestCase.java 21 Jul 2002 12:09:17 -0000 1.4
+++ TestAbstractTestCaseInterceptorTestCase.java 31 Jul 2002 21:44:34 -0000 1.5
@@ -154,7 +154,7 @@
if (this.getCurrentTestMethod().equals(
"testBeginMethodBadReturnType")) {
- assertEquals("The begin method "
+ assertEquals("The method "
+ "[beginBeginMethodBadReturnType] should return void and "
+ "not [java.lang.String]", theMessage);
return true;
@@ -176,7 +176,7 @@
if (this.getCurrentTestMethod().equals(
"testBeginMethodBadParamType")) {
- assertEquals("The begin method "
+ assertEquals("The method "
+ "[beginBeginMethodBadParamType] must accept a single "
+ "parameter derived from class "
+ "[org.apache.cactus.WebRequest], but "
@@ -191,7 +191,7 @@
if (this.getCurrentTestMethod().equals(
"testBeginMethodBadParamNumber")) {
- assertEquals("The begin method "
+ assertEquals("The method "
+ "[beginBeginMethodBadParamNumber] must accept a single "
+ "parameter derived from class "
+ "[org.apache.cactus.WebRequest], but 2 "
@@ -224,7 +224,7 @@
if (this.getCurrentTestMethod().equals(
"testEndMethodBadReturnType")) {
- assertEquals("The end method "
+ assertEquals("The method "
+ "[endEndMethodBadReturnType] should return void and "
+ "not [java.lang.String]", theMessage);
return true;
@@ -244,7 +244,7 @@
if (this.getCurrentTestMethod().equals(
"testEndMethodBadParamType")) {
- assertEquals("The end method [endEndMethodBadParamType] "
+ assertEquals("The method [endEndMethodBadParamType] "
+ "has a bad parameter of type [java.lang.String]",
theMessage);
return true;
@@ -256,7 +256,7 @@
if (this.getCurrentTestMethod().equals(
"testEndMethodBadParamNumber")) {
- assertEquals("The end method [endEndMethodBadParamNumber] "
+ assertEquals("The method [endEndMethodBadParamNumber] "
+ "must only have a single parameter", theMessage);
return true;
}
1.3 +4 -1 jakarta-cactus/sample-servlet/src/unit/j2ee12/org/apache/cactus/unit/TestAll.java
Index: TestAll.java
===================================================================
RCS file: /home/cvs/jakarta-cactus/sample-servlet/src/unit/j2ee12/org/apache/cactus/unit/TestAll.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TestAll.java 10 Apr 2002 00:26:20 -0000 1.2
+++ TestAll.java 31 Jul 2002 21:44:34 -0000 1.3
@@ -99,6 +99,9 @@
// test class for more information on why
suite.addTest(org.apache.cactus.unit.TestServletTestCase_TestResult.suite());
+ // AbstractTestCase related tests
+ suite.addTestSuite(org.apache.cactus.unit.TestAbstractWebTestCase.class);
+
// ServletTestCase related tests
suite.addTest(org.apache.cactus.unit.TestServletTestCase1.suite());
suite.addTest(org.apache.cactus.unit.TestServletTestCase2.suite());
1.3 +4 -1 jakarta-cactus/sample-servlet/src/unit/j2ee13/org/apache/cactus/unit/TestAll.java
Index: TestAll.java
===================================================================
RCS file: /home/cvs/jakarta-cactus/sample-servlet/src/unit/j2ee13/org/apache/cactus/unit/TestAll.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TestAll.java 10 Apr 2002 00:26:20 -0000 1.2
+++ TestAll.java 31 Jul 2002 21:44:34 -0000 1.3
@@ -100,6 +100,9 @@
// test class for more information on why
suite.addTest(org.apache.cactus.unit.TestServletTestCase_TestResult.suite());
+ // AbstractTestCase related tests
+ suite.addTestSuite(org.apache.cactus.unit.TestAbstractWebTestCase.class);
+
// ServletTestCase related tests
suite.addTest(org.apache.cactus.unit.TestServletTestCase1.suite());
suite.addTest(org.apache.cactus.unit.TestServletTestCase2.suite());
1.1 jakarta-cactus/sample-servlet/src/unit/share/org/apache/cactus/unit/TestAbstractWebTestCase.java
Index: TestAbstractWebTestCase.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Cactus", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.cactus.unit;
import org.apache.cactus.ServletTestCase;
import org.apache.cactus.WebRequest;
import org.apache.cactus.WebResponse;
import org.apache.cactus.client.ServletHttpClient;
/**
* Some Cactus unit tests for testing <code>AbstractWebTestCase</code> that
* verifies that the client <code>clientSetUp()</code> and
* <code>clientTearDown()</code> work correctly.
*
* These tests should not really be part of the sample application functional
* tests as they are unit tests for Cactus. However, they are unit tests that
* need a servlet environment running for their execution, so they have been
* package here for convenience. They can also be read by end-users to
* understand how Cactus work.
*
* @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
*
* @version $Id: TestAbstractWebTestCase.java,v 1.1 2002/07/31 21:44:34 vmassol Exp $
*/
public class TestAbstractWebTestCase extends ServletTestCase
{
/**
* Defines the testcase name for JUnit.
*
* @param theName the testcase's name.
*/
public TestAbstractWebTestCase(String theName)
{
super(theName);
}
/**
* Start the tests.
*
* @param theArgs the arguments. Not used
*/
public static void main(String[] theArgs)
{
junit.swingui.TestRunner.main(new String[]{
TestAbstractWebTestCase.class.getName()});
}
//-------------------------------------------------------------------------
/**
* true if <code>clientTearDown()</code> has been called.
*/
private boolean isClientTearDownCalled;
/**
* Verifies that <code>clientTearDown()</code> has been called correctly.
*/
protected void runTest() throws Throwable
{
runGenericTest(new ServletHttpClient());
if (!this.isClientTearDownCalled) {
fail("clientTearDown has not been called");
}
}
/**
* Verify that it is possible to modify the <code>WebRequest</code> in
* the common <code>clientSetUp()</code> method. It also verifies that
* <code>clientSetUp()</code> is called at all.
*
* @param theRequest the request object that serves to initialize the
* HTTP connection to the server redirector.
*/
public void clientSetUp(WebRequest theRequest)
{
theRequest.addParameter("param1", "value1");
}
/**
* Verify that it is possible to modify the <code>WebRequest</code> in
* the common <code>clientSetUp()</code> method. It also verifies that
* <code>clientSetUp()</code> is called at all.
*
* @param theRequest the request object that serves to initialize the
* HTTP connection to the server redirector.
*/
public void beginSetUpTearDown(WebRequest theRequest)
{
assertEquals("value1", theRequest.getParameterGet("param1"));
}
/**
* Verify that it is possible to modify the <code>WebRequest</code> in
* the common <code>clientSetUp()</code> method. It also verifies that
* <code>clientSetUp()</code> is called at all.
*/
public void testSetUpTearDown() throws Exception
{
assertEquals("value1", request.getParameter("param1"));
response.getWriter().print("Hello there!");
}
/**
* Verify that it is possible to read the connection object once in
* endXXX() and then again in <code>clientTearDown()</code>. It also
* verifies that <code>clientTearDown()</code> is called at all.
*
* @param theResponse the response from the server side.
*/
public void endSetUpTearDown(WebResponse theResponse)
{
assertEquals("Hello there!", theResponse.getText());
}
/**
* Verify that it is possible to read the connection object once in
* endXXX() and then again in <code>clientTearDown()</code>. It also
* verifies that <code>clientTearDown()</code> is called at all.
*
* @param theResponse the response from the server side.
*/
public void clientTearDown(WebResponse theResponse)
{
assertEquals("Hello there!", theResponse.getText());
this.isClientTearDownCalled = true;
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>