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/02/21 10:30:41 UTC

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

vmassol     2003/02/21 01:30:41

  Modified:    framework/src/java/share/org/apache/cactus/server
                        JspTestCaller.java AbstractWebTestCaller.java
                        ServletTestCaller.java
               framework/src/java/share/org/apache/cactus
                        AbstractTestCase.java AbstractWebTestCase.java
               framework/src/java/j2ee13/org/apache/cactus/server
                        FilterTestCaller.java
  Added:       framework/src/java/share/org/apache/cactus
                        AbstractServerTestCase.java
  Log:
  Refactoring to separate server side extension to JUnit TestCase from client side extensions. In preparation for a new StaticTestCase (more to come).
  
  Revision  Changes    Path
  1.6       +4 -4      jakarta-cactus/framework/src/java/share/org/apache/cactus/server/JspTestCaller.java
  
  Index: JspTestCaller.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/server/JspTestCaller.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- JspTestCaller.java	3 Jan 2003 15:35:45 -0000	1.5
  +++ JspTestCaller.java	21 Feb 2003 09:30:41 -0000	1.6
  @@ -63,7 +63,7 @@
   
   import javax.servlet.http.HttpServletRequest;
   
  -import org.apache.cactus.AbstractTestCase;
  +import org.apache.cactus.AbstractServerTestCase;
   import org.apache.cactus.JspTestCase;
   import org.apache.cactus.ServletURL;
   
  @@ -86,9 +86,9 @@
       }
   
       /**
  -     * @see AbstractWebTestCaller#setTestCaseFields(AbstractTestCase)
  +     * @see AbstractWebTestCaller#setTestCaseFields(AbstractServerTestCase)
        */
  -    protected void setTestCaseFields(AbstractTestCase theTestInstance)
  +    protected void setTestCaseFields(AbstractServerTestCase theTestInstance)
           throws Exception
       {
           JspTestCase jspInstance = (JspTestCase) theTestInstance;
  
  
  
  1.13      +8 -8      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.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- AbstractWebTestCaller.java	3 Jan 2003 15:35:45 -0000	1.12
  +++ AbstractWebTestCaller.java	21 Feb 2003 09:30:41 -0000	1.13
  @@ -63,7 +63,7 @@
   
   import javax.servlet.ServletException;
   
  -import org.apache.cactus.AbstractTestCase;
  +import org.apache.cactus.AbstractServerTestCase;
   import org.apache.cactus.HttpServiceDefinition;
   import org.apache.cactus.ServiceEnumeration;
   import org.apache.cactus.WebTestResult;
  @@ -118,8 +118,8 @@
        * @exception Exception if an errors occurs when setting the implicit
        *            objects
        */
  -    protected abstract void setTestCaseFields(AbstractTestCase theTestCase)
  -        throws Exception;
  +    protected abstract void setTestCaseFields(
  +        AbstractServerTestCase theTestCase) throws Exception;
   
       /**
        * @return a <code>Writer</code> object that will be used to return the
  @@ -142,7 +142,7 @@
           try
           {
               // Create an instance of the test class
  -            AbstractTestCase testInstance = getTestClassInstance(
  +            AbstractServerTestCase testInstance = getTestClassInstance(
                   getTestClassName(), getTestMethodName());
   
               // Set its fields (implicit objects)
  @@ -337,19 +337,19 @@
        *            test fails to be instanciated (for example if some
        *            information is missing from the HTTP request)
        */
  -    protected AbstractTestCase getTestClassInstance(String theClassName, 
  +    protected AbstractServerTestCase getTestClassInstance(String theClassName, 
           String theTestCaseName) throws ServletException
       {
           // Get the class to call and build an instance of it.
           Class testClass = getTestClassClass(theClassName);
  -        AbstractTestCase testInstance = null;
  +        AbstractServerTestCase testInstance = null;
   
           try
           {
               Constructor constructor = testClass.getConstructor(
                   new Class[] {String.class});
   
  -            testInstance = (AbstractTestCase) constructor.newInstance(
  +            testInstance = (AbstractServerTestCase) constructor.newInstance(
                   new Object[] {theTestCaseName});
           }
           catch (Exception e)
  
  
  
  1.6       +4 -4      jakarta-cactus/framework/src/java/share/org/apache/cactus/server/ServletTestCaller.java
  
  Index: ServletTestCaller.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/server/ServletTestCaller.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ServletTestCaller.java	3 Jan 2003 15:35:45 -0000	1.5
  +++ ServletTestCaller.java	21 Feb 2003 09:30:41 -0000	1.6
  @@ -64,7 +64,7 @@
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpSession;
   
  -import org.apache.cactus.AbstractTestCase;
  +import org.apache.cactus.AbstractServerTestCase;
   import org.apache.cactus.ServletTestCase;
   import org.apache.cactus.ServletURL;
   
  @@ -87,9 +87,9 @@
       }
   
       /**
  -     * @see AbstractWebTestCaller#setTestCaseFields(AbstractTestCase)
  +     * @see AbstractWebTestCaller#setTestCaseFields(AbstractServerTestCase)
        */
  -    protected void setTestCaseFields(AbstractTestCase theTestInstance)
  +    protected void setTestCaseFields(AbstractServerTestCase theTestInstance)
           throws Exception
       {
           ServletTestCase servletInstance = (ServletTestCase) theTestInstance;
  
  
  
  1.19      +13 -103   jakarta-cactus/framework/src/java/share/org/apache/cactus/AbstractTestCase.java
  
  Index: AbstractTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/AbstractTestCase.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- AbstractTestCase.java	28 Jan 2003 13:47:31 -0000	1.18
  +++ AbstractTestCase.java	21 Feb 2003 09:30:41 -0000	1.19
  @@ -69,9 +69,8 @@
   import org.apache.commons.logging.LogFactory;
   
   /**
  - * Abstract class that is a thin layer on top of JUnit and that knows about
  - * test cases that are executed on the server side. It also provides the
  - * ability to run common code before each test on the client side (note
  + * Abstract class that is a thin layer on top of JUnit and that provides 
  + * the ability to run common code before each test on the client side (note
    * that calling common tear down code is delegated to extending classes as the
    * method signature depends on the protocol used).
    *
  @@ -117,11 +116,6 @@
       protected static final String CLIENT_GLOBAL_END_METHOD = "end";
   
       /**
  -     * Name of properties file to initialize logging subsystem
  -     */
  -    public static final String LOG_CLIENT_CONFIG = "log_client.properties";
  -
  -    /**
        * Flag used to verify if client initialization has already been performed
        * for the current test suite or not.
        */
  @@ -167,6 +161,14 @@
       }
   
       /**
  +     * @param theLogger the logger to use 
  +     */
  +    protected void setLogger(Log theLogger)
  +    {
  +        this.logger = theLogger;
  +    }
  +    
  +    /**
        * @return the Cactus configuration
     */
       protected Configuration getConfiguration()
       {
  @@ -278,51 +280,7 @@
       protected abstract Configuration createConfiguration();
       
       /**
  -     * Runs a test case. This method is overriden from the JUnit
  -     * <code>TestCase</code> class in order to seamlessly call the
  -     * Cactus redirection servlet.
  -     *
  -     * @exception Throwable any error that occurred when calling the test method
  -     *            for the current test case.
  -     */
  -    protected abstract void runTest() throws Throwable;
  -
  -    // Methods below are only called by the Cactus redirector on the server
  -    // side
  -
  -    /**
  -     * Run the test that was specified in the constructor on the server side,
  -     * calling <code>setUp()</code> and <code>tearDown()</code>.
  -     *
  -     * @exception Throwable any error that occurred when calling the test method
  -     *         for the current test case, on the server side.
  -     */
  -    public void runBareServerTest() throws Throwable
  -    {
  -        // Initialize the logging system. As this class is instanciated both
  -        // on the server side and on the client side, we need to differentiate
  -        // the logging initialisation. This method is only called on the server
  -        // side, so we instanciate the log for server side here.
  -        if (getLogger() == null)
  -        {
  -            this.logger = LogFactory.getLog(this.getClass());
  -        }
  -
  -        setUp();
  -
  -        try
  -        {
  -            runServerTest();
  -        }
  -        finally
  -        {
  -            tearDown();
  -        }
  -    }
  -
  -    /**
  -     * Call a begin method which takes either a Cactus WebResponse parameter
  -     * or a HttpUnit WebResponse object as paramter.
  +     * 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.
  @@ -421,61 +379,13 @@
       }
   
       /**
  -     * Run the test that was specified in the constructor on the server side.
  -     *
  -     * @exception Throwable any error that occurred when calling the test method
  -     *         for the current test case, on the server side.
  -     */
  -    protected void runServerTest() throws Throwable
  -    {
  -        Method runMethod = null;
  -
  -        try
  -        {
  -            // use getMethod to get all public inherited
  -            // methods. getDeclaredMethods returns all
  -            // methods of this class but excludes the
  -            // inherited ones.
  -            runMethod = getClass().getMethod(this.getCurrentTestMethod(), 
  -                new Class[0]);
  -        }
  -        catch (NoSuchMethodException e)
  -        {
  -            fail("Method [" + this.getCurrentTestMethod()
  -                + "()] does not exist for class [" + this.getClass().getName()
  -                + "].");
  -        }
  -
  -        if ((runMethod != null) && !Modifier.isPublic(runMethod.getModifiers()))
  -        {
  -            fail("Method [" + this.getCurrentTestMethod()
  -                + "()] should be public");
  -        }
  -
  -        try
  -        {
  -            runMethod.invoke(this, new Class[0]);
  -        }
  -        catch (InvocationTargetException e)
  -        {
  -            e.fillInStackTrace();
  -            throw e.getTargetException();
  -        }
  -        catch (IllegalAccessException e)
  -        {
  -            e.fillInStackTrace();
  -            throw e;
  -        }
  -    }
  -
  -    /**
        * @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 getCurrentTestMethod()
       {
  -        return currentTestMethod;
  +        return this.currentTestMethod;
       }
   
       /**
  
  
  
  1.14      +2 -2      jakarta-cactus/framework/src/java/share/org/apache/cactus/AbstractWebTestCase.java
  
  Index: AbstractWebTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/AbstractWebTestCase.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- AbstractWebTestCase.java	3 Jan 2003 15:35:47 -0000	1.13
  +++ AbstractWebTestCase.java	21 Feb 2003 09:30:41 -0000	1.14
  @@ -76,7 +76,7 @@
    *
    * @version $Id$
    */
  -public abstract class AbstractWebTestCase extends AbstractTestCase
  +public abstract class AbstractWebTestCase extends AbstractServerTestCase
   {
       /**
        * Constructs a JUnit test case with the given name.
  
  
  
  1.1                  jakarta-cactus/framework/src/java/share/org/apache/cactus/AbstractServerTestCase.java
  
  Index: AbstractServerTestCase.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;
  
  import java.lang.reflect.InvocationTargetException;
  import java.lang.reflect.Method;
  import java.lang.reflect.Modifier;
  
  import org.apache.commons.logging.LogFactory;
  
  /**
   * Abstract test case class that extends {@link AbstractTestCase} by
   * adding generic code to run the tests on the server side.
   *
   * This class is independent of the protocol used to communicate from the
   * Cactus client side and the Cactus server side; it can be HTTP, JMS, etc.
   * Subclasses will define additional behaviour that depends on the protocol.
   *
   * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
   *
   * @version $Id: AbstractServerTestCase.java,v 1.1 2003/02/21 09:30:41 vmassol Exp $
   */
  public abstract class AbstractServerTestCase extends AbstractTestCase
  {
      /**
       * Constructs a JUnit test case with the given name.
       *
       * @param theName the name of the test case
       */
      public AbstractServerTestCase(String theName)
      {
          super(theName);
      }
  
      /**
       * Runs a test case. This method is overriden from the JUnit
       * <code>TestCase</code> class in order to perform different
       * use cases such as seamlessly calling the Cactus Redirector, etc.
       *
       * @exception Throwable any error that occurred when calling the test method
       *            for the current test case.
       */
      protected abstract void runTest() throws Throwable;
  
      /**
       * Run the test that was specified in the constructor on the server side,
       * calling <code>setUp()</code> and <code>tearDown()</code>.
       *
       * @exception Throwable any error that occurred when calling the test method
       *         for the current test case, on the server side.
       */
      public void runBareServerTest() throws Throwable
      {
          // Initialize the logging system. As this class is instanciated both
          // on the server side and on the client side, we need to differentiate
          // the logging initialisation. This method is only called on the server
          // side, so we instanciate the log for server side here.
          if (getLogger() == null)
          {
              setLogger(LogFactory.getLog(this.getClass()));
          }
  
          setUp();
  
          try
          {
              runServerTest();
          }
          finally
          {
              tearDown();
          }
      }
  
      /**
       * Run the test that was specified in the constructor on the server side.
       *
       * @exception Throwable any error that occurred when calling the test method
       *         for the current test case, on the server side.
       */
      protected void runServerTest() throws Throwable
      {
          Method runMethod = null;
  
          try
          {
              // use getMethod to get all public inherited
              // methods. getDeclaredMethods returns all
              // methods of this class but excludes the
              // inherited ones.
              runMethod = getClass().getMethod(this.getCurrentTestMethod(), 
                  new Class[0]);
          }
          catch (NoSuchMethodException e)
          {
              fail("Method [" + this.getCurrentTestMethod()
                  + "()] does not exist for class [" + this.getClass().getName()
                  + "].");
          }
  
          if ((runMethod != null) && !Modifier.isPublic(runMethod.getModifiers()))
          {
              fail("Method [" + this.getCurrentTestMethod()
                  + "()] should be public");
          }
  
          try
          {
              runMethod.invoke(this, new Class[0]);
          }
          catch (InvocationTargetException e)
          {
              e.fillInStackTrace();
              throw e.getTargetException();
          }
          catch (IllegalAccessException e)
          {
              e.fillInStackTrace();
              throw e;
          }
      }
  
  }
  
  
  1.7       +4 -4      jakarta-cactus/framework/src/java/j2ee13/org/apache/cactus/server/FilterTestCaller.java
  
  Index: FilterTestCaller.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/java/j2ee13/org/apache/cactus/server/FilterTestCaller.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- FilterTestCaller.java	3 Jan 2003 15:43:21 -0000	1.6
  +++ FilterTestCaller.java	21 Feb 2003 09:30:41 -0000	1.7
  @@ -63,7 +63,7 @@
   
   import javax.servlet.http.HttpServletRequest;
   
  -import org.apache.cactus.AbstractTestCase;
  +import org.apache.cactus.AbstractServerTestCase;
   import org.apache.cactus.FilterTestCase;
   import org.apache.cactus.ServletURL;
   
  @@ -86,9 +86,9 @@
       }
   
       /**
  -     * @see AbstractWebTestCaller#setTestCaseFields(AbstractTestCase)
  +     * @see AbstractWebTestCaller#setTestCaseFields(AbstractServerTestCase)
        */
  -    protected void setTestCaseFields(AbstractTestCase theTestInstance)
  +    protected void setTestCaseFields(AbstractServerTestCase theTestInstance)
                                 throws Exception
       {
           FilterTestCase filterInstance = (FilterTestCase) theTestInstance;
  
  
  

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