vmassol 01/04/14 08:47:31
Modified: cactus/src/framework/share/org/apache/commons/cactus
ServletTestCase.java
cactus/src/framework/share/org/apache/commons/cactus/server
JspTestCaller.java ServletTestCaller.java
cactus/src/sample/share/org/apache/commons/cactus/sample/unit
TestServletTestCase3.java
Removed: cactus/src/framework/share/org/apache/commons/cactus/server
CallerHelper.java
Log:
Made the methods setUp() and tearDown() protected on the server side so that it is
consistent with JUnit.
Revision Changes Path
1.2 +49 -0
jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/ServletTestCase.java
Index: ServletTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/ServletTestCase.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ServletTestCase.java 2001/04/09 11:52:36 1.1
+++ ServletTestCase.java 2001/04/14 15:47:30 1.2
@@ -340,4 +340,53 @@
//connection.disconnect();
}
+ /**
+ * Run the test that was specified in the constructor on the server side,
+ * calling <code>setUp()</code> and <code>tearDown()</code>.
+ */
+ public void runBareServerTest() throws Throwable
+ {
+ setUp();
+ try {
+ runServerTest();
+ }
+ finally {
+ tearDown();
+ }
+ }
+
+ /**
+ * Run the test that was specified in the constructor on the server side,
+ */
+ protected 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 = getClass().getMethod(currentTestMethod, new
Class[0]);
+ } catch (NoSuchMethodException e) {
+ fail("Method [" + currentTestMethod +
+ "()] does not exist for class [" +
+ this.getClass().getName() + "].");
+ }
+ if (runMethod != null && !Modifier.isPublic(runMethod.getModifiers()))
{
+ fail("Method [" + currentTestMethod + "()] should be public");
+ }
+
+ try {
+ runMethod.invoke(this, new Class[0]);
+ }
+ catch (InvocationTargetException e) {
+ e.fillInStackTrace();
+ throw e.getTargetException();
+ }
+ catch (IllegalAccessException e) {
+ e.fillInStackTrace();
+ throw e;
+ }
+ }
+
}
1.2 +1 -22
jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/server/JspTestCaller.java
Index: JspTestCaller.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/server/JspTestCaller.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JspTestCaller.java 2001/04/09 11:52:37 1.1
+++ JspTestCaller.java 2001/04/14 15:47:30 1.2
@@ -144,29 +144,8 @@
}
- // Call the setUp() method
- CallerHelper.callSetUpMethod(testInstance);
-
- // Get the method to call
- Method method;
- try {
- method = testClass.getMethod(theMethod, new Class[0]);
- } catch (Exception e) {
- throw new ServletException("Method " + theMethod + "() does not exist
for class [" + theClassName + "].", e);
- }
-
// Call the test method
- try {
- method.invoke(testInstance, null);
- } catch (IllegalAccessException e) {
- throw new ServletException("Illegal access", e);
- } catch (InvocationTargetException e) {
- throw e.getTargetException();
- }
-
- // Call the tearDown() method
- CallerHelper.callTearDownMethod(testInstance);
-
+ testInstance.runBareServerTest();
}
/**
1.2 +1 -21
jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/server/ServletTestCaller.java
Index: ServletTestCaller.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/server/ServletTestCaller.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ServletTestCaller.java 2001/04/09 11:52:37 1.1
+++ ServletTestCaller.java 2001/04/14 15:47:30 1.2
@@ -135,28 +135,8 @@
}
- // Call the setUp() method
- CallerHelper.callSetUpMethod(testInstance);
-
- // Get the method to call
- Method method;
- try {
- method = testClass.getMethod(theMethod, new Class[0]);
- } catch (Exception e) {
- throw new ServletException("Method " + theMethod + "() does not exist
for class [" + theClassName + "].", e);
- }
-
// Call the test method
- try {
- method.invoke(testInstance, null);
- } catch (IllegalAccessException e) {
- throw new ServletException("Illegal access", e);
- } catch (InvocationTargetException e) {
- throw e.getTargetException();
- }
-
- // Call the tearDown() method
- CallerHelper.callTearDownMethod(testInstance);
+ testInstance.runBareServerTest();
}
1.2 +2 -2
jakarta-commons/cactus/src/sample/share/org/apache/commons/cactus/sample/unit/TestServletTestCase3.java
Index: TestServletTestCase3.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/cactus/src/sample/share/org/apache/commons/cactus/sample/unit/TestServletTestCase3.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestServletTestCase3.java 2001/04/09 11:52:39 1.1
+++ TestServletTestCase3.java 2001/04/14 15:47:31 1.2
@@ -115,7 +115,7 @@
* Put a value in the session to verify that this method is called prior
* to the test, and that it can access servlet implicit objects.
*/
- public void setUp()
+ protected void setUp()
{
session.putValue("setUpFlag", "a setUp test flag");
}
@@ -135,7 +135,7 @@
* Set an HTTP response header to verify that this method is called after
* the test, and that it can access servlet implicit objects.
*/
- public void tearDown()
+ protected void tearDown()
{
response.setHeader("teardownheader", "tear down header");
}