vmassol 2002/08/03 11:03:15
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/share/org/apache/cactus/unit
TestAbstractWebTestCase.java
Log:
refactorings : move creation of response objects to a factory class to allow for
different responses (HttpClient WebResponse, Cactus WebResponse and later JMS
responses, etc)
Revision Changes Path
1.37 +2 -2 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.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- changes.xml 31 Jul 2002 21:44:33 -0000 1.36
+++ changes.xml 3 Aug 2002 18:03:15 -0000 1.37
@@ -49,8 +49,8 @@
<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
+ Added support for client side <code>begin(...)</code>
+ and <code>end(...)</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
1.19 +2 -2 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.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- todo.xml 31 Jul 2002 21:44:33 -0000 1.18
+++ todo.xml 3 Aug 2002 18:03:15 -0000 1.19
@@ -33,8 +33,8 @@
<category title="Documentation">
<action>
- Update web site for new <code>clientSetUp()</code> and
- <code>clientTearDown()</code> methods.
+ Update web site for new <code>begin()</code> and <code>end()</code>
+ methods.
</action>
<action assigned-to="Vincent Massol">
Move all documentation to docbook and cocoon2 and generate PDF
1.11 +15 -20
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.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- AbstractTestCase.java 31 Jul 2002 21:44:33 -0000 1.10
+++ AbstractTestCase.java 3 Aug 2002 18:03:15 -0000 1.11
@@ -69,7 +69,7 @@
/**
* Abstract class that is a thin layer on top of JUnit and that knows about
* 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
+ * ability to run common 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
@@ -98,22 +98,16 @@
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.
+ * The name of the method that is called before each test on the client
+ * side (if it exists).
*/
- protected static final String CLIENT_TEARDOWN_METHOD = "clientTearDown";
+ protected static final String CLIENT_GLOBAL_BEGIN_METHOD = "begin";
+
+ /**
+ * The name of the method that is called after each test on the client
+ * side (if it exists).
+ */
+ protected static final String CLIENT_GLOBAL_END_METHOD = "end";
/**
* Name of properties file to initialize logging subsystem
@@ -325,15 +319,16 @@
}
/**
- * Call the client side set up method if it exists.
+ * Call the global begin method. This is the method that is called before
+ * each test if it exists. It is called on the client side only.
*
* @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
+ protected void callClientGlobalBegin(Request theRequest) throws Throwable
{
- callGenericBeginMethod(theRequest, CLIENT_SETUP_METHOD);
+ callGenericBeginMethod(theRequest, CLIENT_GLOBAL_BEGIN_METHOD);
}
/**
1.8 +20 -70
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.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- AbstractWebTestCase.java 31 Jul 2002 21:44:33 -0000 1.7
+++ AbstractWebTestCase.java 3 Aug 2002 18:03:15 -0000 1.8
@@ -60,10 +60,10 @@
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.net.HttpURLConnection;
-import java.net.URLConnection;
import org.apache.cactus.client.AbstractHttpClient;
-import org.apache.cactus.util.ChainedRuntimeException;
+import org.apache.cactus.client.WebResponseObjectFactory;
+import org.apache.cactus.client.ClientException;
/**
* Abstract class for Web Test Cases (i.e. HTTP connection to the server) that
@@ -87,8 +87,8 @@
}
/**
- * Call an end method which takes either a Cactus WebResponse parameter
- * or a HttpUnit WebResponse object as paramter.
+ * Call the global end method. This is the method that is called after
+ * each test if it exists. It is called on the client side only.
*
* @param theRequest the request data that were used to open the
* connection.
@@ -138,36 +138,17 @@
paramObject = theResponse;
- // Is it a Http Unit WebResponse ?
- if (parameters[0].getName().
- equals("com.meterware.httpunit.WebResponse")) {
-
- if (paramObject == null) {
- paramObject = createHttpUnitWebResponse(theConnection);
- }
-
- // Is it a Cactus WebResponse ?
- } else if (parameters[0].getName().
- equals("org.apache.cactus.WebResponse")) {
-
- if (paramObject == null) {
- paramObject = new WebResponse(theRequest,
- theConnection);
+ if (paramObject == null) {
+ try {
+ paramObject =
+ new WebResponseObjectFactory().getResponseObject(
+ parameters[0].getName(), theRequest, theConnection);
+ } catch (ClientException e) {
+ throw new ClientException("The method ["
+ + methods[i].getName()
+ + "] has a bad parameter of type ["
+ + parameters[0].getName() + "]", e);
}
-
- // Is it an old HttpURLConnection (deprecated) ?
- } else if (parameters[0].getName().
- equals("java.net.HttpURLConnection")) {
-
- if (paramObject == null) {
- paramObject = theConnection;
- }
-
- // Else it is an error ...
- } else {
- fail("The method [" + methods[i].getName()
- + "] has a bad parameter of type ["
- + parameters[0].getName() + "]");
}
// Has a method to call already been found ?
@@ -214,11 +195,11 @@
* which case it is created from the HttpURLConnection
* @exception Throwable any error that occurred when calling the method
*/
- protected void callClientTearDown(WebRequest theRequest,
+ protected void callClientGlobalEnd(WebRequest theRequest,
HttpURLConnection theConnection, Object theResponse) throws Throwable
{
- callGenericEndMethod(theRequest, theConnection, CLIENT_TEARDOWN_METHOD,
- theResponse);
+ callGenericEndMethod(theRequest, theConnection,
+ CLIENT_GLOBAL_END_METHOD, theResponse);
}
/**
@@ -242,37 +223,6 @@
}
/**
- * Create a HttpUnit <code>WebResponse</code> object by reflection (so
- * that we don't need the HttpUnit jar for users who are not using
- * the HttpUnit endXXX() signature).
- *
- * @param theConnection the HTTP connection that was used when connecting
- * to the server side and which now contains the returned HTTP
- * response that we will pass to HttpUnit so that it can construt
- * a <code>com.meterware.httpunit.WebResponse</code> object.
- * @return a HttpUnit <code>WebResponse</code> object
- */
- private Object createHttpUnitWebResponse(HttpURLConnection theConnection)
- {
- Object webResponse;
-
- try {
- Class responseClass =
- Class.forName("com.meterware.httpunit.WebResponse");
- Method method = responseClass.getMethod("newResponse",
- new Class[]{URLConnection.class});
- webResponse = method.invoke(null, new Object[]{theConnection});
- } catch (Exception e) {
- throw new ChainedRuntimeException("Error calling "
- + "[public static com.meterware.httpunit.WebResponse "
- + "com.meterware.httpunit.WebResponse.newResponse("
- + "java.net.URLConnection) throws java.io.IOException]", e);
- }
-
- return webResponse;
- }
-
- /**
* Execute the test case begin method, then connect to the server proxy
* redirector (where the test case test method is executed) and then
* executes the test case end method.
@@ -288,7 +238,7 @@
WebRequest request = new WebRequest();
// Call the set up and begin methods to fill the request object
- callClientSetUp(request);
+ callClientGlobalBegin(request);
callBeginMethod(request);
// Run the web test
@@ -298,7 +248,7 @@
Object response = callEndMethod(request, connection);
// call the tear down method
- callClientTearDown(request, connection, response);
+ callClientGlobalEnd(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) ....
1.6 +11 -1
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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- TestAbstractTestCaseInterceptorTestCase.java 31 Jul 2002 21:44:34 -0000
1.5
+++ TestAbstractTestCaseInterceptorTestCase.java 3 Aug 2002 18:03:15 -0000
1.6
@@ -62,6 +62,7 @@
import junit.framework.AssertionFailedError;
import org.apache.cactus.mock.MockHttpURLConnection;
+import org.apache.cactus.client.ClientException;
/**
* Test <code>TestCase</code> class that intercepts all exceptions (and assert
@@ -128,6 +129,15 @@
callEndMethod(request, connection);
} catch (AssertionFailedError e) {
+
+ // Perform asserts
+ if (!verifyBeginMethodsOk(e.getMessage())
+ && !verifyEndMethodsOk(e.getMessage())) {
+
+ throw e;
+ }
+
+ } catch (ClientException e) {
// Perform asserts
if (!verifyBeginMethodsOk(e.getMessage())
1.2 +22 -22
jakarta-cactus/sample-servlet/src/unit/share/org/apache/cactus/unit/TestAbstractWebTestCase.java
Index: TestAbstractWebTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/sample-servlet/src/unit/share/org/apache/cactus/unit/TestAbstractWebTestCase.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestAbstractWebTestCase.java 31 Jul 2002 21:44:34 -0000 1.1
+++ TestAbstractWebTestCase.java 3 Aug 2002 18:03:15 -0000 1.2
@@ -99,54 +99,54 @@
//-------------------------------------------------------------------------
/**
- * true if <code>clientTearDown()</code> has been called.
+ * true if <code>end()</code> has been called.
*/
- private boolean isClientTearDownCalled;
+ private boolean isClientGlobalEndCalled;
/**
- * Verifies that <code>clientTearDown()</code> has been called correctly.
+ * Verifies that <code>end()</code> has been called correctly.
*/
protected void runTest() throws Throwable
{
runGenericTest(new ServletHttpClient());
- if (!this.isClientTearDownCalled) {
- fail("clientTearDown has not been called");
+ if (!this.isClientGlobalEndCalled) {
+ fail("end() 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.
+ * the common <code>begin()</code> method. It also verifies that
+ * <code>begin()</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)
+ public void begin(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.
+ * the common <code>begin()()</code> method. It also verifies that
+ * <code>begin()</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)
+ public void beginGlobalBeginEnd(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.
+ * the common <code>begin()()</code> method. It also verifies that
+ * <code>begin()()</code> is called at all.
*/
- public void testSetUpTearDown() throws Exception
+ public void testGlobalBeginEnd() throws Exception
{
assertEquals("value1", request.getParameter("param1"));
response.getWriter().print("Hello there!");
@@ -154,27 +154,27 @@
/**
* 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.
+ * endXXX() and then again in <code>end()</code>. It also
+ * verifies that <code>end()</code> is called at all.
*
* @param theResponse the response from the server side.
*/
- public void endSetUpTearDown(WebResponse theResponse)
+ public void endGlobalBeginEnd(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.
+ * endXXX() and then again in <code>end()</code>. It also
+ * verifies that <code>end()</code> is called at all.
*
* @param theResponse the response from the server side.
*/
- public void clientTearDown(WebResponse theResponse)
+ public void end(WebResponse theResponse)
{
assertEquals("Hello there!", theResponse.getText());
- this.isClientTearDownCalled = true;
+ this.isClientGlobalEndCalled = true;
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>