vmassol 2003/08/31 07:17:57
Modified: samples/servlet/src/test-cactus/share/org/apache/cactus/sample/unit
TestServerSideExceptions.java
TestTearDownException.java
TestJUnitTestCaseWrapper.java
framework/src/java/share/org/apache/cactus/internal/client
WebClientTestCaseDelegate.java
ClientTestCaseDelegate.java
framework/src/java/share/org/apache/cactus
ServletTestCase.java
framework/src/java/j2ee13/org/apache/cactus
FilterTestCase.java
samples/servlet/src/test-cactus/j2ee13/org/apache/cactus/sample/unit
TestFilterHttpHeaders.java
framework/src/java/share/org/apache/cactus/internal/server
ServerTestCaseDelegate.java
documentation/docs/xdocs changes.xml
Log:
When using the new <code>ServletTestSuite</code> wrapper around pure JUnit test
cases, the <code>setUp()</code> and <code>tearDown()</code> methods were not called.
Revision Changes Path
1.8 +3 -3
jakarta-cactus/samples/servlet/src/test-cactus/share/org/apache/cactus/sample/unit/TestServerSideExceptions.java
Index: TestServerSideExceptions.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/samples/servlet/src/test-cactus/share/org/apache/cactus/sample/unit/TestServerSideExceptions.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- TestServerSideExceptions.java 12 Jul 2003 16:08:11 -0000 1.7
+++ TestServerSideExceptions.java 31 Aug 2003 14:17:57 -0000 1.8
@@ -125,11 +125,11 @@
*
* @exception Throwable on test failure
*/
- protected void runTest() throws Throwable
+ protected void runCactusTest() throws Throwable
{
try
{
- super.runTest();
+ super.runCactusTest();
}
catch (AssertionFailedErrorWrapper e)
{
1.5 +3 -3
jakarta-cactus/samples/servlet/src/test-cactus/share/org/apache/cactus/sample/unit/TestTearDownException.java
Index: TestTearDownException.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/samples/servlet/src/test-cactus/share/org/apache/cactus/sample/unit/TestTearDownException.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TestTearDownException.java 26 May 2003 12:15:13 -0000 1.4
+++ TestTearDownException.java 31 Aug 2003 14:17:57 -0000 1.5
@@ -73,11 +73,11 @@
/**
* Intercepts running test cases to check for normal exceptions.
*/
- protected void runTest()
+ protected void runCactusTest()
{
try
{
- super.runTest();
+ super.runCactusTest();
}
catch (Throwable e)
{
1.5 +15 -4
jakarta-cactus/samples/servlet/src/test-cactus/share/org/apache/cactus/sample/unit/TestJUnitTestCaseWrapper.java
Index: TestJUnitTestCaseWrapper.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/samples/servlet/src/test-cactus/share/org/apache/cactus/sample/unit/TestJUnitTestCaseWrapper.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TestJUnitTestCaseWrapper.java 26 May 2003 12:15:14 -0000 1.4
+++ TestJUnitTestCaseWrapper.java 31 Aug 2003 14:17:57 -0000 1.5
@@ -72,6 +72,16 @@
public class TestJUnitTestCaseWrapper extends TestCase
{
/**
+ * Used to verify that the setUp method does get called.
+ */
+ private boolean isSetUpCalled;
+
+ /**
+ * Used to verify that the testXXX method does get called.
+ */
+ private boolean isTestXXXCalled;
+
+ /**
* Runs this pure JUnit Test Case with Cactus, wrapping it in
* a Servlet Test Case.
*
@@ -92,7 +102,7 @@
*/
public void setUp()
{
- // This test is executed on the server side.
+ this.isSetUpCalled = true;
}
/**
@@ -101,7 +111,8 @@
*/
public void testXXX()
{
- // This test is executed on the server side.
+ assertTrue("setUp() should have been called", this.isSetUpCalled);
+ this.isTestXXXCalled = true;
}
/**
@@ -110,7 +121,7 @@
*/
public void tearDown()
{
- // This test is executed on the server side.
+ assertTrue("testXXX() should have been called", this.isTestXXXCalled);
}
}
1.2 +3 -4
jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/client/WebClientTestCaseDelegate.java
Index: WebClientTestCaseDelegate.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/client/WebClientTestCaseDelegate.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- WebClientTestCaseDelegate.java 12 Jul 2003 19:31:40 -0000 1.1
+++ WebClientTestCaseDelegate.java 31 Aug 2003 14:17:57 -0000 1.2
@@ -119,7 +119,7 @@
Method methodToCall = null;
Object paramObject = null;
- Method[] methods = getWrappedTest().getClass().getMethods();
+ Method[] methods = getTest().getClass().getMethods();
for (int i = 0; i < methods.length; i++)
{
@@ -186,8 +186,7 @@
{
try
{
- methodToCall.invoke(getWrappedTest(),
- new Object[] {paramObject});
+ methodToCall.invoke(getTest(), new Object[] {paramObject});
}
catch (InvocationTargetException e)
{
1.3 +24 -5
jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/client/ClientTestCaseDelegate.java
Index: ClientTestCaseDelegate.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/client/ClientTestCaseDelegate.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ClientTestCaseDelegate.java 14 Jul 2003 10:10:37 -0000 1.2
+++ ClientTestCaseDelegate.java 31 Aug 2003 14:17:57 -0000 1.3
@@ -190,6 +190,26 @@
{
return this.delegatedTest;
}
+
+ /**
+ * @return the test on which we will operate. If there is a wrapped
+ * test then the returned test is the wrapped test. Otherwise we
+ * return the delegated test.
+ */
+ public Test getTest()
+ {
+ Test activeTest;
+ if (getWrappedTest() != null)
+ {
+ activeTest = getWrappedTest();
+ }
+ else
+ {
+ activeTest = getDelegatedTest();
+ }
+ return activeTest;
+ }
+
/**
* @return The logger used by the <code>TestCase</code> class and
@@ -291,7 +311,7 @@
{
// 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 = getWrappedTest().getClass().getMethods();
+ Method[] methods = getTest().getClass().getMethods();
for (int i = 0; i < methods.length; i++)
{
@@ -334,8 +354,7 @@
try
{
- methods[i].invoke(getWrappedTest(),
- new Object[] {theRequest});
+ methods[i].invoke(getTest(), new Object[] {theRequest});
break;
}
@@ -414,6 +433,6 @@
*/
public boolean isWrappingATest()
{
- return getWrappedTest() != getDelegatedTest();
+ return (getWrappedTest() != null);
}
}
1.16 +13 -15
jakarta-cactus/framework/src/java/share/org/apache/cactus/ServletTestCase.java
Index: ServletTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/ServletTestCase.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- ServletTestCase.java 12 Jul 2003 19:31:41 -0000 1.15
+++ ServletTestCase.java 31 Aug 2003 14:17:57 -0000 1.16
@@ -137,7 +137,7 @@
*/
public ServletTestCase()
{
- init(this);
+ init(null);
}
/**
@@ -148,7 +148,7 @@
public ServletTestCase(String theName)
{
super(theName);
- init(this);
+ init(null);
}
/**
@@ -247,8 +247,7 @@
// Catch the exception just to have a chance to log it
try
{
- // Give back control to JUnit
- runTest();
+ runCactusTest();
}
catch (Throwable t)
{
@@ -261,27 +260,26 @@
}
/**
- * Runs a test case. This method is overriden from the JUnit
- * [EMAIL PROTECTED] TestCase} class in order to seamlessly call the
- * Cactus redirector on the client side and the test on the server
- * side.
+ * Runs a Cactus test case.
*
* @exception Throwable if any error happens during the execution of
* the test
*/
- protected void runTest() throws Throwable
+ protected void runCactusTest() throws Throwable
{
if (isServerSide())
{
- setUp();
+ // Note: We cannot delegate this piece of code in the
+ // ServerTestCaseDelegate class as it requires to call
+ // super.runBare()
- try
+ if (getServerDelegate().getWrappedTest() != null)
{
- getServerDelegate().runServerTest();
+ ((TestCase) getServerDelegate().getWrappedTest()).runBare();
}
- finally
+ else
{
- tearDown();
+ super.runBare();
}
}
else
1.18 +13 -15
jakarta-cactus/framework/src/java/j2ee13/org/apache/cactus/FilterTestCase.java
Index: FilterTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/framework/src/java/j2ee13/org/apache/cactus/FilterTestCase.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- FilterTestCase.java 12 Jul 2003 19:40:14 -0000 1.17
+++ FilterTestCase.java 31 Aug 2003 14:17:57 -0000 1.18
@@ -139,7 +139,7 @@
*/
public FilterTestCase()
{
- init(this);
+ init(null);
}
/**
@@ -150,7 +150,7 @@
public FilterTestCase(String theName)
{
super(theName);
- init(this);
+ init(null);
}
/**
@@ -249,8 +249,7 @@
// Catch the exception just to have a chance to log it
try
{
- // Give back control to JUnit
- runTest();
+ runCactusTest();
}
catch (Throwable t)
{
@@ -263,27 +262,26 @@
}
/**
- * Runs a test case. This method is overriden from the JUnit
- * [EMAIL PROTECTED] TestCase} class in order to seamlessly call the
- * Cactus redirector on the client side and the test on the server
- * side.
+ * Runs a Cactus test case.
*
* @exception Throwable if any error happens during the execution of
* the test
*/
- protected void runTest() throws Throwable
+ protected void runCactusTest() throws Throwable
{
if (isServerSide())
{
- setUp();
+ // Note: We cannot delegate this piece of code in the
+ // ServerTestCaseDelegate class as it requires to call
+ // super.runBare()
- try
+ if (getServerDelegate().getWrappedTest() != null)
{
- getServerDelegate().runServerTest();
+ ((TestCase) getServerDelegate().getWrappedTest()).runBare();
}
- finally
+ else
{
- tearDown();
+ super.runBare();
}
}
else
1.4 +3 -3
jakarta-cactus/samples/servlet/src/test-cactus/j2ee13/org/apache/cactus/sample/unit/TestFilterHttpHeaders.java
Index: TestFilterHttpHeaders.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/samples/servlet/src/test-cactus/j2ee13/org/apache/cactus/sample/unit/TestFilterHttpHeaders.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TestFilterHttpHeaders.java 17 Mar 2003 19:30:40 -0000 1.3
+++ TestFilterHttpHeaders.java 31 Aug 2003 14:17:57 -0000 1.4
@@ -89,8 +89,8 @@
{
String header1 = theResponse.getHeaderField("xxparevcount");
String header2 = theResponse.getHeaderField("xparevcount");
- assertNotNull("Header should not be null", header1);
- assertNotNull("Header should not be null", header2);
+ assertNotNull("Header 1 should not be null", header1);
+ assertNotNull("Header 2 should not be null", header2);
assertEquals("xxparevcount", header1);
assertEquals("xparevcount", header2);
}
1.3 +1 -59
jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/server/ServerTestCaseDelegate.java
Index: ServerTestCaseDelegate.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/server/ServerTestCaseDelegate.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ServerTestCaseDelegate.java 24 Jul 2003 21:45:04 -0000 1.2
+++ ServerTestCaseDelegate.java 31 Aug 2003 14:17:57 -0000 1.3
@@ -56,14 +56,9 @@
*/
package org.apache.cactus.internal.server;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-
import junit.framework.Assert;
import junit.framework.Test;
-import org.apache.cactus.util.JUnitVersionHelper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -172,57 +167,4 @@
{
this.logger = theLogger;
}
-
- /**
- * Run the test that was specified in the constructor on the server side
- * by executing the testXXX method.
- *
- * @exception Throwable any error that occurred when calling the test method
- * for the current test case, on the server side.
- */
- public void runServerTest() throws Throwable
- {
- Method runMethod = null;
-
- try
- {
- // Use getMethod to get all public inherited
- // methods. getDeclaredMethods returns all
- // methods of this class but excludes the
- // inherited ones.
- runMethod = getWrappedTest().getClass().getMethod(
- JUnitVersionHelper.getTestCaseName(getWrappedTest()),
- new Class[0]);
- }
- catch (NoSuchMethodException e)
- {
- fail("Method ["
- + JUnitVersionHelper.getTestCaseName(getWrappedTest())
- + "()] does not exist for class ["
- + getWrappedTest().getClass().getName() + "].");
- }
-
- if ((runMethod != null) && !Modifier.isPublic(runMethod.getModifiers()))
- {
- fail("Method ["
- + JUnitVersionHelper.getTestCaseName(getWrappedTest())
- + "()] should be public");
- }
-
- try
- {
- runMethod.invoke(getWrappedTest(), new Class[0]);
- }
- catch (InvocationTargetException e)
- {
- e.fillInStackTrace();
- throw e.getTargetException();
- }
- catch (IllegalAccessException e)
- {
- e.fillInStackTrace();
- throw e;
- }
- }
-
}
1.131 +5 -0 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.130
retrieving revision 1.131
diff -u -r1.130 -r1.131
--- changes.xml 29 Aug 2003 17:17:32 -0000 1.130
+++ changes.xml 31 Aug 2003 14:17:57 -0000 1.131
@@ -71,6 +71,11 @@
</release>
<release version="1.5-rc1" date="in CVS">
+ <action dev="VMA" type="fix" due-to="Alexander Ananiev"
due-to-email="[EMAIL PROTECTED]">
+ When using the new <code>ServletTestSuite</code> wrapper around pure
+ JUnit test cases, the <code>setUp()</code> and
+ <code>tearDown()</code> methods were not called.
+ </action>
<action dev="VMA" type="fix" fixes-bug="22794" due-to="Jonathan Kovacs"
due-to-email="[EMAIL PROTECTED]">
In the Ant integration, the <code>cactus.context</code> filter token
was not correctly defined for EAR files. However, it is needed. For
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]