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/08/31 16:38:18 UTC

cvs commit: jakarta-cactus/framework/src/java/j2ee13/org/apache/cactus FilterTestCase.java

vmassol     2003/08/31 07:38:18

  Modified:    framework/src/java/share/org/apache/cactus Tag:
                        CACTUS_15_BRANCH ServletTestCase.java
               framework/src/java/share/org/apache/cactus/internal/server
                        Tag: CACTUS_15_BRANCH ServerTestCaseDelegate.java
               samples/servlet/src/test-cactus/share/org/apache/cactus/sample/unit
                        Tag: CACTUS_15_BRANCH TestServerSideExceptions.java
                        TestTearDownException.java
                        TestJUnitTestCaseWrapper.java
               framework/src/java/share/org/apache/cactus/server Tag:
                        CACTUS_15_BRANCH AbstractWebTestController.java
               samples/servlet/src/test-cactus/j2ee13/org/apache/cactus/sample/unit
                        Tag: CACTUS_15_BRANCH TestFilterHttpHeaders.java
               documentation/docs/xdocs Tag: CACTUS_15_BRANCH changes.xml
               framework/src/java/share/org/apache/cactus/internal/client
                        Tag: CACTUS_15_BRANCH
                        WebClientTestCaseDelegate.java
                        ClientTestCaseDelegate.java
               framework/src/java/j2ee13/org/apache/cactus Tag:
                        CACTUS_15_BRANCH FilterTestCase.java
  Log:
  Merged from CVS HEAD
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.15.2.1  +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.15.2.1
  diff -u -r1.15 -r1.15.2.1
  --- ServletTestCase.java	12 Jul 2003 19:31:41 -0000	1.15
  +++ ServletTestCase.java	31 Aug 2003 14:38:18 -0000	1.15.2.1
  @@ -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
  -     * {@link 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
  
  
  
  No                   revision
  No                   revision
  1.1.2.2   +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.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- ServerTestCaseDelegate.java	9 Aug 2003 14:39:06 -0000	1.1.2.1
  +++ ServerTestCaseDelegate.java	31 Aug 2003 14:38:18 -0000	1.1.2.2
  @@ -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;
  -        }
  -    }
  -
   }
  
  
  
  No                   revision
  No                   revision
  1.7.2.1   +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.7.2.1
  diff -u -r1.7 -r1.7.2.1
  --- TestServerSideExceptions.java	12 Jul 2003 16:08:11 -0000	1.7
  +++ TestServerSideExceptions.java	31 Aug 2003 14:38:18 -0000	1.7.2.1
  @@ -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.4.2.1   +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.4.2.1
  diff -u -r1.4 -r1.4.2.1
  --- TestTearDownException.java	26 May 2003 12:15:13 -0000	1.4
  +++ TestTearDownException.java	31 Aug 2003 14:38:18 -0000	1.4.2.1
  @@ -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.4.2.1   +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.4.2.1
  diff -u -r1.4 -r1.4.2.1
  --- TestJUnitTestCaseWrapper.java	26 May 2003 12:15:14 -0000	1.4
  +++ TestJUnitTestCaseWrapper.java	31 Aug 2003 14:38:18 -0000	1.4.2.1
  @@ -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);
       }
   
   }
  
  
  
  No                   revision
  No                   revision
  1.11.2.1  +2 -2      jakarta-cactus/framework/src/java/share/org/apache/cactus/server/AbstractWebTestController.java
  
  Index: AbstractWebTestController.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/server/AbstractWebTestController.java,v
  retrieving revision 1.11
  retrieving revision 1.11.2.1
  diff -u -r1.11 -r1.11.2.1
  --- AbstractWebTestController.java	26 May 2003 11:45:22 -0000	1.11
  +++ AbstractWebTestController.java	31 Aug 2003 14:38:18 -0000	1.11.2.1
  @@ -119,7 +119,7 @@
   
               AbstractWebTestCaller caller = getTestCaller(webImplicitObjects);
   
  -            // FIXME: will need a factory here real soon...
  +            // TODO: will need a factory here real soon...
               
               ServiceEnumeration service =
                   ServiceEnumeration.valueOf(serviceName);
  
  
  
  No                   revision
  No                   revision
  1.3.4.1   +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.3.4.1
  diff -u -r1.3 -r1.3.4.1
  --- TestFilterHttpHeaders.java	17 Mar 2003 19:30:40 -0000	1.3
  +++ TestFilterHttpHeaders.java	31 Aug 2003 14:38:18 -0000	1.3.4.1
  @@ -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);
          }
  
  
  
  No                   revision
  No                   revision
  1.120.2.5 +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.120.2.4
  retrieving revision 1.120.2.5
  diff -u -r1.120.2.4 -r1.120.2.5
  --- changes.xml	29 Aug 2003 17:27:58 -0000	1.120.2.4
  +++ changes.xml	31 Aug 2003 14:38:18 -0000	1.120.2.5
  @@ -68,6 +68,11 @@
         </devs>
   
         <release version="1.5-rc1" date="in CVS">
  +        <action dev="VMA" type="fix" due-to="Alexander Ananiev" due-to-email="alexander@myarch.com">
  +          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="jdk@jdk.ca">
             In the Ant integration, the <code>cactus.context</code> filter token 
             was not correctly defined for EAR files. However, it is needed. For 
  
  
  
  No                   revision
  No                   revision
  1.1.2.1   +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.1.2.1
  diff -u -r1.1 -r1.1.2.1
  --- WebClientTestCaseDelegate.java	12 Jul 2003 19:31:40 -0000	1.1
  +++ WebClientTestCaseDelegate.java	31 Aug 2003 14:38:18 -0000	1.1.2.1
  @@ -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.2.2.1   +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.2.2.1
  diff -u -r1.2 -r1.2.2.1
  --- ClientTestCaseDelegate.java	14 Jul 2003 10:10:37 -0000	1.2
  +++ ClientTestCaseDelegate.java	31 Aug 2003 14:38:18 -0000	1.2.2.1
  @@ -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);
       }
   }
  
  
  
  No                   revision
  No                   revision
  1.17.2.1  +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.17.2.1
  diff -u -r1.17 -r1.17.2.1
  --- FilterTestCase.java	12 Jul 2003 19:40:14 -0000	1.17
  +++ FilterTestCase.java	31 Aug 2003 14:38:18 -0000	1.17.2.1
  @@ -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
  -     * {@link 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