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/11/30 21:37:08 UTC

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

vmassol     2003/11/30 12:37:08

  Modified:    framework/src/java/share/org/apache/cactus
                        ServletTestCase.java JspTestCase.java
               framework/src/java/share/org/apache/cactus/internal/client
                        WebClientTestCaseDelegate.java
                        ClientTestCaseDelegate.java
               framework/src/java/j2ee13/org/apache/cactus
                        FilterTestCase.java
  Added:       framework/src/java/share/org/apache/cactus
                        AbstractCactusTestCase.java
               framework/src/java/share/org/apache/cactus/internal/client
                        AbstractClientTestCaseDelegate.java
  Log:
  Factored common Cactus test case extension code (XXXTestCase classes).
  
  Revision  Changes    Path
  1.18      +19 -148   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.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- ServletTestCase.java	19 Oct 2003 18:06:47 -0000	1.17
  +++ ServletTestCase.java	30 Nov 2003 20:37:07 -0000	1.18
  @@ -60,10 +60,9 @@
   import javax.servlet.http.HttpSession;
   
   import junit.framework.Test;
  -import junit.framework.TestCase;
   
  -import org.apache.cactus.configuration.ConfigurationInitializer;
   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;
  @@ -77,21 +76,9 @@
    *
    * @version $Id$
    */
  -public class ServletTestCase extends TestCase
  +public class ServletTestCase extends AbstractCactusTestCase
   {
       /**
  -     * As this class is the first one loaded on the client side, we ensure
  -     * that the Cactus configuration has been initialized. In the future,
  -     * this block will be removed as all initialization will be done in Cactus
  -     * test suites. However, as we still support using Cactus TestCase classes
  -     * we don't a proper initialization hook and thus we need this hack.
  -     */
  -    static
  -    {
  -        ConfigurationInitializer.initialize();
  -    }
  -
  -    /**
        * Valid <code>HttpServletRequest</code> object that you can access from
        * the <code>testXXX()</code>, <code>setUp</code> and
        * <code>tearDown()</code> methods. If you try to access it from either the
  @@ -128,104 +115,52 @@
       public ServletConfigWrapper config;
   
       /**
  -     * Delegate that provides all client side Cactus related test case logic. 
  -     * We are using a delegate in order to hide non public API to the users 
  -     * and thus to be able to easily change the implementation.
  -     */
  -    private WebClientTestCaseDelegate clientDelegate;
  -
  -    /**
  -     * Delegate that provides all server side Cactus related test case logic. 
  -     * We are using a delegate in order to hide non public API to the users 
  -     * and thus to be able to easily change the implementation.
  -     */
  -    private ServerTestCaseDelegate serverDelegate;
  -
  -    /**
  -     * Default constructor defined in order to allow creating Test Case
  -     * without needing to define constructor (new feature in JUnit 3.8.1).
  -     * Should only be used with JUnit 3.8.1 or greater. 
  -     * 
  -     * @since 1.5 
  +     * @see AbstractCactusTestCase#AbstractCactusTestCase()
        */
       public ServletTestCase()
       {
  -        init(null);
  +        super();
       }
   
       /**
  -     * Constructs a JUnit test case with the given name.
  -     *
  -     * @param theName the name of the test case
  +     * @see AbstractCactusTestCase#AbstractCactusTestCase(String)
        */
       public ServletTestCase(String theName)
       {
           super(theName);
  -        init(null);
       }
   
       /**
  -     * Wraps a pure JUnit Test Case in a Cactus Test Case.
  -     *  
  -     * @param theName the name of the test
  -     * @param theTest the Test Case class to wrap
  -     * @since 1.5
  +     * @see AbstractCactusTestCase#AbstractCactusTestCase(String, Test)
        */
       public ServletTestCase(String theName, Test theTest)
       {
  -        super(theName);
  -        init(theTest);
  -    }
  -
  -    /**
  -     * Initializations common to all constructors.
  -     *  
  -     * @param theTest a pure JUnit Test that Cactus will wrap
  -     */
  -    void init(Test theTest)
  -    {
  -        setClientDelegate(new WebClientTestCaseDelegate(
  -            this, theTest, new ServletConfiguration()));        
  -        setServerDelegate(new ServerTestCaseDelegate(this, theTest));
  -    }
  -
  -    /**
  -     * @param theDelegate the client test case delegate
  -     */
  -    void setClientDelegate(WebClientTestCaseDelegate theDelegate)
  -    {
  -        this.clientDelegate = theDelegate;
  -    }
  -
  -    /**
  -     * @param theDelegate the client test case delegate
  -     */
  -    void setServerDelegate(ServerTestCaseDelegate theDelegate)
  -    {
  -        this.serverDelegate = theDelegate;
  +        super(theName, theTest);
       }
   
       /**
  -     * @return the client test case delegate
  +     * @see AbstractCactusTestCase#createClientTestCaseDelegate(Test)
        */
  -    WebClientTestCaseDelegate getClientDelegate()
  +    protected ClientTestCaseDelegate createClientTestCaseDelegate(
  +        Test theTest)
       {
  -        return this.clientDelegate;
  +        return new WebClientTestCaseDelegate(
  +            this, theTest, new ServletConfiguration());
       }
   
       /**
  -     * @return the server test case delegate
  +     * @see AbstractCactusTestCase#createServerTestCaseDelegate(Test)
        */
  -    private ServerTestCaseDelegate getServerDelegate()
  +    protected ServerTestCaseDelegate createServerTestCaseDelegate(
  +        Test theTest)
       {
  -        return this.serverDelegate;
  +        return new ServerTestCaseDelegate(this, theTest);
       }
   
       /**
  -     * @return true if this test class has been instanciated on the server
  -     *         side or false otherwise 
  +     * @see AbstractCactusTestCase#isServerSide()
        */
  -    private boolean isServerSide()
  +    protected boolean isServerSide()
       {
           boolean result = false;
           
  @@ -236,68 +171,4 @@
           return result;
       }
   
  -    /**
  -     * 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.
  -     *
  -     * @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();            
  -        }
  -
  -        // Catch the exception just to have a chance to log it
  -        try
  -        {
  -            runCactusTest();
  -        }
  -        catch (Throwable t)
  -        {
  -            if (!isServerSide())
  -            {
  -                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
  -     */
  -    protected void runCactusTest() 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();            
  -            }
  -        }
  -        else
  -        {
  -            getClientDelegate().runTest();
  -        }
  -    }
   }
  
  
  
  1.15      +23 -39    jakarta-cactus/framework/src/java/share/org/apache/cactus/JspTestCase.java
  
  Index: JspTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/JspTestCase.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- JspTestCase.java	19 Oct 2003 18:06:47 -0000	1.14
  +++ JspTestCase.java	30 Nov 2003 20:37:07 -0000	1.15
  @@ -60,8 +60,8 @@
   
   import junit.framework.Test;
   
  -import org.apache.cactus.configuration.ConfigurationInitializer;
   import org.apache.cactus.configuration.JspConfiguration;
  +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.PageContextWrapper;
  @@ -78,18 +78,6 @@
   public class JspTestCase extends ServletTestCase
   {
       /**
  -     * As this class is the first one loaded on the client side, we ensure
  -     * that the Cactus configuration has been initialized. In the future,
  -     * this block will be removed as all initialization will be done in Cactus
  -     * test suites. However, as we still support using Cactus TestCase classes
  -     * we don't a proper initialization hook and thus we need this hack.
  -     */
  -    static
  -    {
  -        ConfigurationInitializer.initialize();
  -    }
  -
  -    /**
        * Valid <code>PageContext</code> object that you can access from
        * the <code>testXXX()</code>, <code>setUp</code> and
        * <code>tearDown()</code> methods. If you try to access it from either the
  @@ -108,23 +96,7 @@
       public JspWriter out;
   
       /**
  -     * Initializations common to all constructors.
  -     *  
  -     * @param theTest a pure JUnit Test that Cactus will wrap
  -     */
  -    void init(Test theTest)
  -    {
  -        setClientDelegate(new WebClientTestCaseDelegate(
  -            this, theTest, new JspConfiguration()));        
  -        setServerDelegate(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).
  -     * Should only be used with JUnit 3.8.1 or greater. 
  -     * 
  -     * @since 1.5 
  +     * @see AbstractCactusTestCase#AbstractCactusTestCase()
        */
       public JspTestCase()
       {
  @@ -132,9 +104,7 @@
       }
   
       /**
  -     * Constructs a JUnit test case with the given name.
  -     *
  -     * @param theName the name of the test case
  +     * @see AbstractCactusTestCase#AbstractCactusTestCase(String)
        */
       public JspTestCase(String theName)
       {
  @@ -142,15 +112,29 @@
       }
   
       /**
  -     * Wraps a pure JUnit Test Case in a Cactus Test Case.
  -     *  
  -     * @param theName the name of the test
  -     * @param theTest the Test Case class to wrap
  -     * @since 1.5
  +     * @see AbstractCactusTestCase#AbstractCactusTestCase(String, Test)
        */
       public JspTestCase(String theName, Test theTest)
       {
           super(theName, theTest);
       }
   
  +    /**
  +     * @see AbstractCactusTestCase#createClientTestCaseDelegate(Test)
  +     */
  +    protected ClientTestCaseDelegate createClientTestCaseDelegate(
  +            Test theTest)
  +    {
  +        return new WebClientTestCaseDelegate(this, theTest, 
  +            new JspConfiguration());
  +    }
  +
  +    /**
  +     * @see AbstractCactusTestCase#createServerTestCaseDelegate(Test)
  +     */
  +    protected ServerTestCaseDelegate createServerTestCaseDelegate(
  +            Test theTest)
  +    {
  +        return new ServerTestCaseDelegate(this, theTest);
  +    }
   }
  
  
  
  1.1                  jakarta-cactus/framework/src/java/share/org/apache/cactus/AbstractCactusTestCase.java
  
  Index: AbstractCactusTestCase.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;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  
  import org.apache.cactus.configuration.ConfigurationInitializer;
  import org.apache.cactus.internal.client.ClientTestCaseDelegate;
  import org.apache.cactus.internal.server.ServerTestCaseDelegate;
  
  /**
   * Base class for all Cactus test case extensions.
   * 
   * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
   *
   * @version $Id: AbstractCactusTestCase.java,v 1.1 2003/11/30 20:37:07 vmassol Exp $
   * @since 1.6 
   */
  public abstract class AbstractCactusTestCase extends TestCase
  {
      /**
       * As this class is the first one loaded on the client side, we ensure
       * that the Cactus configuration has been initialized. In the future,
       * this block will be removed as all initialization will be done in Cactus
       * test suites. However, as we still support using Cactus TestCase classes
       * we don't have a proper initialization hook and thus we need this hack.
       */
      static
      {
          ConfigurationInitializer.initialize();
      }
  
      /**
       * Delegate that provides all client side Cactus related test case logic. 
       * We are using a delegate in order to hide non public API to the users 
       * and thus to be able to easily change the implementation.
       */
      private ClientTestCaseDelegate clientDelegate;
  
      /**
       * Delegate that provides all server side Cactus related test case logic. 
       * We are using a delegate in order to hide non public API to the users 
       * and thus to be able to easily change the implementation.
       */
      private ServerTestCaseDelegate serverDelegate;
  
      /**
       * Default constructor defined in order to allow creating Test Case
       * without needing to define constructor (new feature in JUnit 3.8.1).
       * Should only be used with JUnit 3.8.1 or greater. 
       */
      public AbstractCactusTestCase()
      {
          init(null);
      }
  
      /**
       * Constructs a JUnit test case with the given name.
       *
       * @param theName the name of the test case
       */
      public AbstractCactusTestCase(String theName)
      {
          super(theName);
          init(null);
      }
  
      /**
       * Wraps a pure JUnit Test Case in a Cactus Test Case.
       *  
       * @param theName the name of the test
       * @param theTest the Test Case class to wrap
       */
      public AbstractCactusTestCase(String theName, Test theTest)
      {
          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
       */
      void setClientDelegate(ClientTestCaseDelegate theDelegate)
      {
          this.clientDelegate = theDelegate;
      }
  
      /**
       * @param theDelegate the client test case delegate
       */
      void setServerDelegate(ServerTestCaseDelegate theDelegate)
      {
          this.serverDelegate = theDelegate;
      }
  
      /**
       * @return the client test case delegate
       */
      ClientTestCaseDelegate getClientDelegate()
      {
          return this.clientDelegate;
      }
  
      /**
       * @return the server test case delegate
       */
      private ServerTestCaseDelegate getServerDelegate()
      {
          return this.serverDelegate;
      }
      
      /**
       * Initializations common to all constructors.
       *  
       * @param theTest a pure JUnit Test that Cactus will wrap
       */
      void init(Test theTest)
      {
          setClientDelegate(createClientTestCaseDelegate(theTest));
          setServerDelegate(createServerTestCaseDelegate(theTest));
      }
  
      /**
       * @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.
       *
       * @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();            
          }
  
          // Catch the exception just to have a chance to log it
          try
          {
              runCactusTest();
          }
          catch (Throwable t)
          {
              if (!isServerSide())
              {
                  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
       */
      protected void runCactusTest() 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();            
              }
          }
          else
          {
              getClientDelegate().runTest();
          }
      }
  }
  
  
  
  1.4       +2 -2      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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- WebClientTestCaseDelegate.java	2 Nov 2003 23:41:43 -0000	1.3
  +++ WebClientTestCaseDelegate.java	30 Nov 2003 20:37:08 -0000	1.4
  @@ -82,7 +82,7 @@
    *
    * @version $Id$
    */
  -public class WebClientTestCaseDelegate extends ClientTestCaseDelegate
  +public class WebClientTestCaseDelegate extends AbstractClientTestCaseDelegate
   {
       /**
        * @param theDelegatedTest the test we are delegating for
  
  
  
  1.5       +15 -349   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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ClientTestCaseDelegate.java	2 Nov 2003 23:41:43 -0000	1.4
  +++ ClientTestCaseDelegate.java	30 Nov 2003 20:37:08 -0000	1.5
  @@ -56,25 +56,13 @@
    */
   package org.apache.cactus.internal.client;
   
  -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.Request;
  -import org.apache.cactus.configuration.Configuration;
  -import org.apache.cactus.util.JUnitVersionHelper;
   import org.apache.commons.logging.Log;
  -import org.apache.commons.logging.LogFactory;
   
   /**
  - * Delegate class that provides useful methods for the Cactus  
  - * <code>XXXTestCase</code> classes. All the methods provided are independent
  - * of any communication protocol between client side and server side (HTTP, 
  - * JMS, etc). Subclasses will define additional behaviour that depends on the 
  - * protocol.
  + * Provides useful methods for the Cactus <code>XXXTestCase</code> classes.
  + * All the methods provided are independent of any communication protocol 
  + * between client side and server side (HTTP, JMS, etc). Subclasses will 
  + * define additional behaviour that depends on the protocol.
    *  
    * It provides the ability to run common code before each test on the client 
    * side (note that calling common tear down code is delegated to child classes 
  @@ -84,354 +72,32 @@
    * initialisation code (a pity this is not provided in JUnit). It can be 
    * useful to start an embedded server for example. Note: In the future this
    * should be refatored and provided using a custom JUnit TestSuite.
  - *
  + * 
    * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
    *
    * @version $Id$
    */
  -public class ClientTestCaseDelegate extends Assert
  +public interface ClientTestCaseDelegate
   {
       /**
  -     * The prefix of a test method.
  -     */
  -    protected static final String TEST_METHOD_PREFIX = "test";
  -
  -    /**
  -     * The prefix of a begin test method.
  -     */
  -    protected static final String BEGIN_METHOD_PREFIX = "begin";
  -
  -    /**
  -     * The prefix of an end test method.
  -     */
  -    protected static final String END_METHOD_PREFIX = "end";
  -
  -    /**
  -     * The name of the method that is called before each test on the client
  -     * side (if it exists).
  -     */
  -    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";
  -
  -    /**
  -     * The logger (only used on the client side).
  -     */
  -    private Log logger;
  -
  -    /**
  -     * The Cactus configuration.
  -     */
  -    private Configuration configuration;
  -
  -    /**
  -     * Pure JUnit Test Case that we are wrapping (if any)
  -     */
  -    private Test wrappedTest;
  -
  -    /**
  -     * The test we are delegating for.
  -     */
  -    private Test delegatedTest;   
  -    
  -    /**
  -     * @param theDelegatedTest the test we are delegating for
  -     * @param theWrappedTest the test being wrapped by this delegate (or null 
  -     *        if none)
  -     * @param theConfiguration the configuration to use 
  -     */
  -    public ClientTestCaseDelegate(Test theDelegatedTest, 
  -        Test theWrappedTest, Configuration theConfiguration)
  -    {        
  -        if (theDelegatedTest == null)
  -        {
  -            throw new IllegalStateException(
  -                "The test object passed must not be null");
  -        }
  -
  -        setDelegatedTest(theDelegatedTest); 
  -        setWrappedTest(theWrappedTest);
  -        setConfiguration(theConfiguration);               
  -    }
  -
  -    /**
  -     * @param theWrappedTest the pure JUnit test that we need to wrap 
  -     */
  -    public void setWrappedTest(Test theWrappedTest)
  -    {
  -        this.wrappedTest = theWrappedTest;
  -    }
  -
  -    /**
  -     * @param theDelegatedTest the test we are delegating for
  -     */
  -    public void setDelegatedTest(Test theDelegatedTest)
  -    {
  -        this.delegatedTest = theDelegatedTest;
  -    }
  -
  -    /**
  -     * @return the wrapped JUnit test
  -     */
  -    public Test getWrappedTest()
  -    {
  -        return this.wrappedTest;
  -    }
  -
  -    /**
  -     * @return the test we are delegating for
  -     */
  -    public Test getDelegatedTest()
  -    {
  -        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
        *         subclasses to perform logging.
        */
  -    public final Log getLogger()
  -    {
  -        return this.logger;
  -    }
  -
  -    /**
  -     * @param theLogger the logger to use 
  -     */
  -    protected void setLogger(Log theLogger)
  -    {
  -        this.logger = theLogger;
  -    }
  +    Log getLogger();
       
       /**
  -     * @return the Cactus configuration
     */
  -    public Configuration getConfiguration()
  -    {
  -        return this.configuration;
  -    }
  -
  -    /**
  -     * Sets the Cactus configuration
  -     * 
     * @param theConfiguration the Cactus configuration
     */
  -    public void setConfiguration(Configuration theConfiguration)
  -    {
  -        this.configuration = theConfiguration;
  -    }
  -   
  -    /**
  -     * @return the name of the test method to call without the
  -     *         TEST_METHOD_PREFIX prefix
  -     */
  -    private String getBaseMethodName()
  -    {
  -        // Sanity check
  -        if (!getCurrentTestName().startsWith(TEST_METHOD_PREFIX))
  -        {
  -            throw new RuntimeException("bad name ["
  -                + getCurrentTestName()
  -                + "]. It should start with ["
  -                + TEST_METHOD_PREFIX + "].");
  -        }
  -
  -        return getCurrentTestName().substring(
  -            TEST_METHOD_PREFIX.length());
  -    }
  -
  -    /**
  -     * @return the name of the test begin method to call that initialize the
  -     *         test by initializing the <code>WebRequest</code> object
  -     *         for the test case.
  -     */
  -    protected String getBeginMethodName()
  -    {
  -        return BEGIN_METHOD_PREFIX + getBaseMethodName();
  -    }
  -
  -    /**
  -     * @return the name of the test end method to call when the test has been
  -     *         run on the server. It can be used to verify returned headers,
  -     *         cookies, ...
  -     */
  -    protected String getEndMethodName()
  -    {
  -        return END_METHOD_PREFIX + getBaseMethodName();
  -    }
  -
  -    /**
        * Perform client side initializations before each test, such as
        * re-initializating the logger and printing some logging information.
        */
  -    public void runBareInit()
  -    {
  -        // We make sure we reinitialize The logger with the name of the
  -        // current extending class so that log statements will contain the
  -        // actual class name (that's why the logged instance is not static).
  -        this.logger = LogFactory.getLog(this.getClass());
  -
  -        // Mark beginning of test on client side
  -        getLogger().debug("------------- Test: " 
  -            + this.getCurrentTestName());        
  -    }
  -
  -    /**
  -     * Call a begin method which takes Cactus WebRequest as parameter
  -     *
  -     * @param theRequest the request object which will contain data that will
  -     *        be used to connect to the Cactus server side redirectors.
  -     * @param theMethodName the name of the begin method to call
  -     * @exception Throwable any error that occurred when calling the method
  -     */
  -    private void callGenericBeginMethod(Request theRequest, 
  -        String theMethodName) throws Throwable
  -    {
  -        // 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 = getTest().getClass().getMethods();
  -
  -        for (int i = 0; i < methods.length; i++)
  -        {
  -            if (methods[i].getName().equals(theMethodName))
  -            {
  -                // Check return type
  -                if (!methods[i].getReturnType().getName().equals("void"))
  -                {
  -                    fail("The method [" + methods[i].getName()
  -                        + "] should return void and not ["
  -                        + methods[i].getReturnType().getName() + "]");
  -                }
  -
  -                // Check if method is public
  -                if (!Modifier.isPublic(methods[i].getModifiers()))
  -                {
  -                    fail("Method [" + methods[i].getName()
  -                        + "] should be declared public");
  -                }
  -
  -                // Check parameters
  -                Class[] parameters = methods[i].getParameterTypes();
  -
  -                if (parameters.length != 1)
  -                {
  -                    fail("The method [" + methods[i].getName()
  -                        + "] must accept a single parameter implementing "
  -                        + "interface [" + Request.class.getName() + "], "
  -                        + "but " + parameters.length
  -                        + " parameters were found");
  -                }
  -                else if (!Request.class.isAssignableFrom(parameters[0]))
  -                {
  -                    fail("The method [" + methods[i].getName()
  -                        + "] must accept a single parameter implementing "
  -                        + "interface [" + Request.class.getName() + "], "
  -                        + "but found a [" + parameters[0].getName() + "] "
  -                        + "parameter instead");
  -                }
  -
  -                try
  -                {
  -                    methods[i].invoke(getTest(), new Object[] {theRequest});
  -
  -                    break;
  -                }
  -                catch (InvocationTargetException e)
  -                {
  -                    e.fillInStackTrace();
  -                    throw e.getTargetException();
  -                }
  -                catch (IllegalAccessException e)
  -                {
  -                    e.fillInStackTrace();
  -                    throw e;
  -                }
  -            }
  -        }
  -    }
  -
  -    /**
  -     * 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 callClientGlobalBegin(Request theRequest) throws Throwable
  -    {
  -        callGenericBeginMethod(theRequest, CLIENT_GLOBAL_BEGIN_METHOD);
  -    }
  +    void runBareInit();
   
       /**
  -     * Call the test case begin method.
  +     * Runs a test case. This method is overriden from the JUnit
  +     * <code>TestCase</code> class in order to seamlessly call the
  +     * Cactus redirection servlet.
        *
  -     * @param theRequest the request object to pass to the begin method.
  -     * @exception Throwable any error that occurred when calling the begin
  -     *            method for the current test case.
  -     */
  -    public void callBeginMethod(Request theRequest) throws Throwable
  -    {
  -        callGenericBeginMethod(theRequest, getBeginMethodName());
  -    }
  -
  -    /**
  -     * @see #getCurrentTestName()
  -     * @deprecated Use {@link #getCurrentTestName()} instead
  -     */
  -    protected String getCurrentTestMethod()
  -    {
  -        return getCurrentTestName();
  -    }
  -
  -    /**
  -     * @return the name of the current test case being executed (it corresponds
  -     *         to the name of the test method with the "test" prefix removed.
  -     *         For example, for "testSomeTestOk" would return "someTestOk".
  -     */
  -    protected String getCurrentTestName()
  -    {
  -        return JUnitVersionHelper.getTestCaseName(getDelegatedTest());        
  -    }
  -
  -    /**
  -     * @return The wrapped test name, if any (null otherwise).
  -     */
  -    public String getWrappedTestName()
  -    {
  -        if (isWrappingATest())
  -        {
  -            return getWrappedTest().getClass().getName();
  -        }
  -        return null;
  -    }
  -
  -    /**
  -     * @return whether this test case wraps another
  +     * @exception Throwable if any error happens during the execution of
  +     *            the test
        */
  -    public boolean isWrappingATest()
  -    {
  -        return (getWrappedTest() != null);
  -    }
  +    void runTest() throws Throwable;    
   }
  
  
  
  1.1                  jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/client/AbstractClientTestCaseDelegate.java
  
  Index: AbstractClientTestCaseDelegate.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-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.internal.client;
  
  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.Request;
  import org.apache.cactus.configuration.Configuration;
  import org.apache.cactus.util.JUnitVersionHelper;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  /**
   * Delegate class that provides useful methods for the Cactus  
   * <code>XXXTestCase</code> classes. All the methods provided are independent
   * of any communication protocol between client side and server side (HTTP, 
   * JMS, etc). Subclasses will define additional behaviour that depends on the 
   * protocol.
   *  
   * It provides the ability to run common code before each test on the client 
   * side (note that calling common tear down code is delegated to child classes 
   * as the method signature depends on the protocol used).
   *
   * In addition it provides the ability to execute some one time (per-JVM)
   * initialisation code (a pity this is not provided in JUnit). It can be 
   * useful to start an embedded server for example. Note: In the future this
   * should be refatored and provided using a custom JUnit TestSuite.
   *
   * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
   *
   * @version $Id: AbstractClientTestCaseDelegate.java,v 1.1 2003/11/30 20:37:08 vmassol Exp $
   */
  public abstract class AbstractClientTestCaseDelegate 
      extends Assert implements ClientTestCaseDelegate
  {
      /**
       * The prefix of a test method.
       */
      protected static final String TEST_METHOD_PREFIX = "test";
  
      /**
       * The prefix of a begin test method.
       */
      protected static final String BEGIN_METHOD_PREFIX = "begin";
  
      /**
       * The prefix of an end test method.
       */
      protected static final String END_METHOD_PREFIX = "end";
  
      /**
       * The name of the method that is called before each test on the client
       * side (if it exists).
       */
      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";
  
      /**
       * The logger (only used on the client side).
       */
      private Log logger;
  
      /**
       * The Cactus configuration.
       */
      private Configuration configuration;
  
      /**
       * Pure JUnit Test Case that we are wrapping (if any)
       */
      private Test wrappedTest;
  
      /**
       * The test we are delegating for.
       */
      private Test delegatedTest;   
      
      /**
       * @param theDelegatedTest the test we are delegating for
       * @param theWrappedTest the test being wrapped by this delegate (or null 
       *        if none)
       * @param theConfiguration the configuration to use 
       */
      public AbstractClientTestCaseDelegate(Test theDelegatedTest, 
          Test theWrappedTest, Configuration theConfiguration)
      {        
          if (theDelegatedTest == null)
          {
              throw new IllegalStateException(
                  "The test object passed must not be null");
          }
  
          setDelegatedTest(theDelegatedTest); 
          setWrappedTest(theWrappedTest);
          setConfiguration(theConfiguration);               
      }
  
      /**
       * @param theWrappedTest the pure JUnit test that we need to wrap 
       */
      public void setWrappedTest(Test theWrappedTest)
      {
          this.wrappedTest = theWrappedTest;
      }
  
      /**
       * @param theDelegatedTest the test we are delegating for
       */
      public void setDelegatedTest(Test theDelegatedTest)
      {
          this.delegatedTest = theDelegatedTest;
      }
  
      /**
       * @return the wrapped JUnit test
       */
      public Test getWrappedTest()
      {
          return this.wrappedTest;
      }
  
      /**
       * @return the test we are delegating for
       */
      public Test getDelegatedTest()
      {
          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
       *         subclasses to perform logging.
       */
      public final Log getLogger()
      {
          return this.logger;
      }
  
      /**
       * @param theLogger the logger to use 
       */
      protected void setLogger(Log theLogger)
      {
          this.logger = theLogger;
      }
      
      /**
       * @return the Cactus configuration
     */
      public Configuration getConfiguration()
      {
          return this.configuration;
      }
  
      /**
       * Sets the Cactus configuration
       * 
     * @param theConfiguration the Cactus configuration
     */
      public void setConfiguration(Configuration theConfiguration)
      {
          this.configuration = theConfiguration;
      }
     
      /**
       * @return the name of the test method to call without the
       *         TEST_METHOD_PREFIX prefix
       */
      private String getBaseMethodName()
      {
          // Sanity check
          if (!getCurrentTestName().startsWith(TEST_METHOD_PREFIX))
          {
              throw new RuntimeException("bad name ["
                  + getCurrentTestName()
                  + "]. It should start with ["
                  + TEST_METHOD_PREFIX + "].");
          }
  
          return getCurrentTestName().substring(
              TEST_METHOD_PREFIX.length());
      }
  
      /**
       * @return the name of the test begin method to call that initialize the
       *         test by initializing the <code>WebRequest</code> object
       *         for the test case.
       */
      protected String getBeginMethodName()
      {
          return BEGIN_METHOD_PREFIX + getBaseMethodName();
      }
  
      /**
       * @return the name of the test end method to call when the test has been
       *         run on the server. It can be used to verify returned headers,
       *         cookies, ...
       */
      protected String getEndMethodName()
      {
          return END_METHOD_PREFIX + getBaseMethodName();
      }
  
      /**
       * Perform client side initializations before each test, such as
       * re-initializating the logger and printing some logging information.
       */
      public void runBareInit()
      {
          // We make sure we reinitialize The logger with the name of the
          // current extending class so that log statements will contain the
          // actual class name (that's why the logged instance is not static).
          this.logger = LogFactory.getLog(this.getClass());
  
          // Mark beginning of test on client side
          getLogger().debug("------------- Test: " 
              + this.getCurrentTestName());        
      }
  
      /**
       * Call a begin method which takes Cactus WebRequest as parameter
       *
       * @param theRequest the request object which will contain data that will
       *        be used to connect to the Cactus server side redirectors.
       * @param theMethodName the name of the begin method to call
       * @exception Throwable any error that occurred when calling the method
       */
      private void callGenericBeginMethod(Request theRequest, 
          String theMethodName) throws Throwable
      {
          // 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 = getTest().getClass().getMethods();
  
          for (int i = 0; i < methods.length; i++)
          {
              if (methods[i].getName().equals(theMethodName))
              {
                  // Check return type
                  if (!methods[i].getReturnType().getName().equals("void"))
                  {
                      fail("The method [" + methods[i].getName()
                          + "] should return void and not ["
                          + methods[i].getReturnType().getName() + "]");
                  }
  
                  // Check if method is public
                  if (!Modifier.isPublic(methods[i].getModifiers()))
                  {
                      fail("Method [" + methods[i].getName()
                          + "] should be declared public");
                  }
  
                  // Check parameters
                  Class[] parameters = methods[i].getParameterTypes();
  
                  if (parameters.length != 1)
                  {
                      fail("The method [" + methods[i].getName()
                          + "] must accept a single parameter implementing "
                          + "interface [" + Request.class.getName() + "], "
                          + "but " + parameters.length
                          + " parameters were found");
                  }
                  else if (!Request.class.isAssignableFrom(parameters[0]))
                  {
                      fail("The method [" + methods[i].getName()
                          + "] must accept a single parameter implementing "
                          + "interface [" + Request.class.getName() + "], "
                          + "but found a [" + parameters[0].getName() + "] "
                          + "parameter instead");
                  }
  
                  try
                  {
                      methods[i].invoke(getTest(), new Object[] {theRequest});
  
                      break;
                  }
                  catch (InvocationTargetException e)
                  {
                      e.fillInStackTrace();
                      throw e.getTargetException();
                  }
                  catch (IllegalAccessException e)
                  {
                      e.fillInStackTrace();
                      throw e;
                  }
              }
          }
      }
  
      /**
       * 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 callClientGlobalBegin(Request theRequest) throws Throwable
      {
          callGenericBeginMethod(theRequest, CLIENT_GLOBAL_BEGIN_METHOD);
      }
  
      /**
       * Call the test case begin method.
       *
       * @param theRequest the request object to pass to the begin method.
       * @exception Throwable any error that occurred when calling the begin
       *            method for the current test case.
       */
      public void callBeginMethod(Request theRequest) throws Throwable
      {
          callGenericBeginMethod(theRequest, getBeginMethodName());
      }
  
      /**
       * @see #getCurrentTestName()
       * @deprecated Use {@link #getCurrentTestName()} instead
       */
      protected String getCurrentTestMethod()
      {
          return getCurrentTestName();
      }
  
      /**
       * @return the name of the current test case being executed (it corresponds
       *         to the name of the test method with the "test" prefix removed.
       *         For example, for "testSomeTestOk" would return "someTestOk".
       */
      protected String getCurrentTestName()
      {
          return JUnitVersionHelper.getTestCaseName(getDelegatedTest());        
      }
  
      /**
       * @return The wrapped test name, if any (null otherwise).
       */
      public String getWrappedTestName()
      {
          if (isWrappingATest())
          {
              return getWrappedTest().getClass().getName();
          }
          return null;
      }
  
      /**
       * @return whether this test case wraps another
       */
      public boolean isWrappingATest()
      {
          return (getWrappedTest() != null);
      }
  }
  
  
  
  1.20      +19 -151   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.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- FilterTestCase.java	19 Oct 2003 18:06:47 -0000	1.19
  +++ FilterTestCase.java	30 Nov 2003 20:37:08 -0000	1.20
  @@ -60,10 +60,9 @@
   import javax.servlet.http.HttpServletResponse;
   
   import junit.framework.Test;
  -import junit.framework.TestCase;
   
  -import org.apache.cactus.configuration.ConfigurationInitializer;
   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;
  @@ -77,23 +76,9 @@
    *
    * @version $Id$
    */
  -public class FilterTestCase extends TestCase
  +public class FilterTestCase extends AbstractCactusTestCase
   {
       /**
  -     * As this class is the first one loaded on the client side, we ensure
  -     * that the Cactus configuration has been initialized. In the future,
  -     * this block will be removed as all initialization will be done in Cactus
  -     * test suites. However, as we still support using Cactus TestCase classes
  -     * we don't a proper initialization hook and thus we need this hack.
  -     */
  -    static
  -    {
  -        ConfigurationInitializer.initialize();
  -    }
  -
  -    // TODO: Find a way to factorize FilterTestCase and ServletTestCase
  -
  -    /**
        * Valid <code>HttpServletRequest</code> object that you can access from
        * the <code>testXXX()</code>, <code>setUp</code> and
        * <code>tearDown()</code> methods. If you try to access it from either the
  @@ -130,104 +115,52 @@
       public FilterChain filterChain;
   
       /**
  -     * Delegate that provides all client side Cactus related test case logic. 
  -     * We are using a delegate in order to hide non public API to the users 
  -     * and thus to be able to easily change the implementation.
  -     */
  -    private WebClientTestCaseDelegate clientDelegate;
  -
  -    /**
  -     * Delegate that provides all server side Cactus related test case logic. 
  -     * We are using a delegate in order to hide non public API to the users 
  -     * and thus to be able to easily change the implementation.
  -     */
  -    private ServerTestCaseDelegate serverDelegate;
  -
  -    /**
  -     * Default constructor defined in order to allow creating Test Case
  -     * without needing to define constructor (new feature in JUnit 3.8.1).
  -     * Should only be used with JUnit 3.8.1 or greater. 
  -     * 
  -     * @since 1.5 
  +     * @see AbstractCactusTestCase#AbstractCactusTestCase()
        */
       public FilterTestCase()
       {
  -        init(null);
  +        super();
       }
   
       /**
  -     * Constructs a JUnit test case with the given name.
  -     *
  -     * @param theName the name of the test case
  +     * @see AbstractCactusTestCase#AbstractCactusTestCase(String)
        */
       public FilterTestCase(String theName)
       {
           super(theName);
  -        init(null);
       }
   
       /**
  -     * Wraps a pure JUnit Test Case in a Cactus Test Case.
  -     *  
  -     * @param theName the name of the test
  -     * @param theTest the Test Case class to wrap
  -     * @since 1.5
  +     * @see AbstractCactusTestCase#AbstractCactusTestCase(String, Test)
        */
       public FilterTestCase(String theName, Test theTest)
       {
  -        super(theName);
  -        init(theTest);
  -    }
  -
  -    /**
  -     * Initializations common to all constructors.
  -     *  
  -     * @param theTest a pure JUnit Test that Cactus will wrap
  -     */
  -    void init(Test theTest)
  -    {
  -        setClientDelegate(new WebClientTestCaseDelegate(
  -            this, theTest, new FilterConfiguration()));        
  -        setServerDelegate(new ServerTestCaseDelegate(this, theTest));
  -    }
  -
  -    /**
  -     * @param theDelegate the client test case delegate
  -     */
  -    void setClientDelegate(WebClientTestCaseDelegate theDelegate)
  -    {
  -        this.clientDelegate = theDelegate;
  -    }
  -
  -    /**
  -     * @param theDelegate the client test case delegate
  -     */
  -    void setServerDelegate(ServerTestCaseDelegate theDelegate)
  -    {
  -        this.serverDelegate = theDelegate;
  +        super(theName, theTest);
       }
   
       /**
  -     * @return the client test case delegate
  +     * @see AbstractCactusTestCase#createClientTestCaseDelegate(Test)
        */
  -    WebClientTestCaseDelegate getClientDelegate()
  +    protected ClientTestCaseDelegate createClientTestCaseDelegate(
  +            Test theTest)
       {
  -        return this.clientDelegate;
  +        return new WebClientTestCaseDelegate(this, theTest, 
  +            new FilterConfiguration());
       }
   
       /**
  -     * @return the server test case delegate
  +     * @see AbstractCactusTestCase#createServerTestCaseDelegate(Test)
        */
  -    private ServerTestCaseDelegate getServerDelegate()
  +    protected ServerTestCaseDelegate createServerTestCaseDelegate(
  +            Test theTest)
       {
  -        return this.serverDelegate;
  +        return new ServerTestCaseDelegate(this, theTest);
       }
   
       /**
  -     * @return true if this test class has been instanciated on the server
  -     *         side or false otherwise 
  +     * @see AbstractCactusTestCase#isServerSide()
        */
  -    private boolean isServerSide()
  +    protected boolean isServerSide()
       {
           boolean result = false;
           
  @@ -236,70 +169,5 @@
               result = true;                    
           }
           return result;
  -    }
  -
  -    /**
  -     * 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.
  -     *
  -     * @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();            
  -        }
  -
  -        // Catch the exception just to have a chance to log it
  -        try
  -        {
  -            runCactusTest();
  -        }
  -        catch (Throwable t)
  -        {
  -            if (!isServerSide())
  -            {
  -                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
  -     */
  -    protected void runCactusTest() 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();            
  -            }
  -        }
  -        else
  -        {
  -            getClientDelegate().runTest();
  -        }
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cactus-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: cactus-dev-help@jakarta.apache.org