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 2003/12/06 11:41:30 UTC
cvs commit: jakarta-cactus/framework/src/java/share/org/apache/cactus/server AbstractWebTestCaller.java
vmassol 2003/12/06 02:41:30
Modified: framework/src/java/share/org/apache/cactus
AbstractCactusTestCase.java ServletTestCase.java
framework/src/java/j2ee13/org/apache/cactus
FilterTestCase.java
framework/src/java/share/org/apache/cactus/server
AbstractWebTestCaller.java
Added: framework/src/java/share/org/apache/cactus
CactusTestCase.java
Log:
- Added new Cactus TestCase SPI: runBareServer(). Executed on the server side to start the test.
- Removed the need for a isServerSide() method in Cactus TestCase. WebTestCallers now use the new runBarServer() instead
Revision Changes Path
1.2 +50 -60 jakarta-cactus/framework/src/java/share/org/apache/cactus/AbstractCactusTestCase.java
Index: AbstractCactusTestCase.java
===================================================================
RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/AbstractCactusTestCase.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractCactusTestCase.java 30 Nov 2003 20:37:07 -0000 1.1
+++ AbstractCactusTestCase.java 6 Dec 2003 10:41:30 -0000 1.2
@@ -99,6 +99,32 @@
*/
private ServerTestCaseDelegate serverDelegate;
+ // ----------------------------------------------------------------------
+
+ /**
+ * Create a client side test case delegate.
+ *
+ * @param theTest the JUnit test to wrap or null if there is no test to
+ * wrap
+ * @return the client side test case delegate to use
+ */
+ protected abstract ClientTestCaseDelegate createClientTestCaseDelegate(
+ Test theTest);
+
+ // ----------------------------------------------------------------------
+
+ /**
+ * Create a server side test case delegate.
+ *
+ * @param theTest the JUnit test to wrap or null if there is no test to
+ * wrap
+ * @return the server side test case delegate to use
+ */
+ protected ServerTestCaseDelegate createServerTestCaseDelegate(Test theTest)
+ {
+ return new ServerTestCaseDelegate(this, theTest);
+ }
+
/**
* Default constructor defined in order to allow creating Test Case
* without needing to define constructor (new feature in JUnit 3.8.1).
@@ -131,26 +157,8 @@
super(theName);
init(theTest);
}
-
- /**
- * Create a client side test case delegate.
- *
- * @param theTest the JUnit test to wrap or null if there is no test to
- * wrap
- * @return the client side test case delegate to use
- */
- protected abstract ClientTestCaseDelegate createClientTestCaseDelegate(
- Test theTest);
-
- /**
- * Create a server side test case delegate.
- *
- * @param theTest the JUnit test to wrap or null if there is no test to
- * wrap
- * @return the server side test case delegate to use
- */
- protected abstract ServerTestCaseDelegate createServerTestCaseDelegate(
- Test theTest);
+
+ // ----------------------------------------------------------------------
/**
* @param theDelegate the client test case delegate
@@ -196,73 +204,55 @@
}
/**
- * @return true if this test class has been instanciated on the server
- * side or false otherwise
- */
- protected abstract boolean isServerSide();
-
- /**
* Runs the bare test (either on the client side or on the server side).
* This method is overridden from the JUnit
* {@link TestCase} class in order to prevent the latter to immediatly
* call the <code>setUp()</code> and <code>tearDown()</code> methods
* which, in our case, need to be executed on the server side.
*
+ * @todo change the comment
* @exception Throwable if any exception is thrown during the test. Any
* exception will be displayed by the JUnit Test Runner
*/
public void runBare() throws Throwable
{
- if (isServerSide())
- {
- getServerDelegate().runBareInit();
- }
- else
- {
- getClientDelegate().runBareInit();
- }
+ runBareClient();
+ }
+
+ private void runBareClient() throws Throwable
+ {
+ getClientDelegate().runBareInit();
// Catch the exception just to have a chance to log it
try
{
- runCactusTest();
+ getClientDelegate().runTest();
}
catch (Throwable t)
{
- if (!isServerSide())
- {
- getClientDelegate().getLogger().debug("Exception in test", t);
- }
+ getClientDelegate().getLogger().debug("Exception in test", t);
throw t;
}
}
/**
- * Runs a Cactus test case.
- *
- * @exception Throwable if any error happens during the execution of
- * the test
+ * @see CactusTestCase#runBareServer()
*/
- protected void runCactusTest() throws Throwable
+ public void runBareServer() throws Throwable
{
- if (isServerSide())
- {
- // Note: We cannot delegate this piece of code in the
- // ServerTestCaseDelegate class as it requires to call
- // super.runBare()
-
- if (getServerDelegate().getWrappedTest() != null)
- {
- ((TestCase) getServerDelegate().getWrappedTest()).runBare();
- }
- else
- {
- super.runBare();
- }
+ getServerDelegate().runBareInit();
+
+ // Note: We cannot delegate this piece of code in the
+ // ServerTestCaseDelegate class as it requires to call
+ // super.runBare()
+
+ if (getServerDelegate().getWrappedTest() != null)
+ {
+ ((TestCase) getServerDelegate().getWrappedTest()).runBare();
}
else
{
- getClientDelegate().runTest();
+ super.runBare();
}
}
}
1.19 +3 -27 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.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- ServletTestCase.java 30 Nov 2003 20:37:07 -0000 1.18
+++ ServletTestCase.java 6 Dec 2003 10:41:30 -0000 1.19
@@ -64,7 +64,6 @@
import org.apache.cactus.configuration.ServletConfiguration;
import org.apache.cactus.internal.client.ClientTestCaseDelegate;
import org.apache.cactus.internal.client.WebClientTestCaseDelegate;
-import org.apache.cactus.internal.server.ServerTestCaseDelegate;
import org.apache.cactus.server.ServletConfigWrapper;
/**
@@ -76,7 +75,8 @@
*
* @version $Id$
*/
-public class ServletTestCase extends AbstractCactusTestCase
+public class ServletTestCase
+ extends AbstractCactusTestCase implements CactusTestCase
{
/**
* Valid <code>HttpServletRequest</code> object that you can access from
@@ -147,28 +147,4 @@
return new WebClientTestCaseDelegate(
this, theTest, new ServletConfiguration());
}
-
- /**
- * @see AbstractCactusTestCase#createServerTestCaseDelegate(Test)
- */
- protected ServerTestCaseDelegate createServerTestCaseDelegate(
- Test theTest)
- {
- return new ServerTestCaseDelegate(this, theTest);
- }
-
- /**
- * @see AbstractCactusTestCase#isServerSide()
- */
- protected boolean isServerSide()
- {
- boolean result = false;
-
- if (this.request != null)
- {
- result = true;
- }
- return result;
- }
-
}
1.1 jakarta-cactus/framework/src/java/share/org/apache/cactus/CactusTestCase.java
Index: CactusTestCase.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 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;
/**
* Common interface that must be implemented by all Cactus test cases.
*
* @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
*
* @version $Id: CactusTestCase.java,v 1.1 2003/12/06 10:41:30 vmassol Exp $
*/
public interface CactusTestCase
{
/**
* Executes JUnit tests on the server side. It is the equivalent of
* {@link org.junit.framework.TestCase#runBare()} but run on the server
* side.
*
* @throws Throwable if an error occurred when running the test on the
* server side
*/
void runBareServer() throws Throwable;
}
1.21 +3 -26 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.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- FilterTestCase.java 30 Nov 2003 20:37:08 -0000 1.20
+++ FilterTestCase.java 6 Dec 2003 10:41:30 -0000 1.21
@@ -64,7 +64,6 @@
import org.apache.cactus.configuration.FilterConfiguration;
import org.apache.cactus.internal.client.ClientTestCaseDelegate;
import org.apache.cactus.internal.client.WebClientTestCaseDelegate;
-import org.apache.cactus.internal.server.ServerTestCaseDelegate;
import org.apache.cactus.server.FilterConfigWrapper;
/**
@@ -76,7 +75,8 @@
*
* @version $Id$
*/
-public class FilterTestCase extends AbstractCactusTestCase
+public class FilterTestCase
+ extends AbstractCactusTestCase implements CactusTestCase
{
/**
* Valid <code>HttpServletRequest</code> object that you can access from
@@ -146,28 +146,5 @@
{
return new WebClientTestCaseDelegate(this, theTest,
new FilterConfiguration());
- }
-
- /**
- * @see AbstractCactusTestCase#createServerTestCaseDelegate(Test)
- */
- protected ServerTestCaseDelegate createServerTestCaseDelegate(
- Test theTest)
- {
- return new ServerTestCaseDelegate(this, theTest);
- }
-
- /**
- * @see AbstractCactusTestCase#isServerSide()
- */
- protected boolean isServerSide()
- {
- boolean result = false;
-
- if (this.request != null)
- {
- result = true;
- }
- return result;
}
}
1.25 +11 -2 jakarta-cactus/framework/src/java/share/org/apache/cactus/server/AbstractWebTestCaller.java
Index: AbstractWebTestCaller.java
===================================================================
RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/server/AbstractWebTestCaller.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- AbstractWebTestCaller.java 2 Nov 2003 19:10:50 -0000 1.24
+++ AbstractWebTestCaller.java 6 Dec 2003 10:41:30 -0000 1.25
@@ -66,6 +66,7 @@
import junit.framework.Test;
import junit.framework.TestCase;
+import org.apache.cactus.CactusTestCase;
import org.apache.cactus.HttpServiceDefinition;
import org.apache.cactus.ServiceEnumeration;
import org.apache.cactus.WebTestResult;
@@ -153,7 +154,15 @@
setTestCaseFields(testInstance);
// Call it's method corresponding to the current test case
- testInstance.runBare();
+ if (testInstance instanceof CactusTestCase)
+ {
+ ((CactusTestCase) testInstance).runBareServer();
+
+ }
+ else
+ {
+ testInstance.runBare();
+ }
// Return an instance of <code>WebTestResult</code> with a
// positive result.
---------------------------------------------------------------------
To unsubscribe, e-mail: cactus-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: cactus-dev-help@jakarta.apache.org