vmassol     2003/03/17 11:13:52

  Modified:    framework/src/java/share/org/apache/cactus
                        ServletTestCase.java AbstractWebServerTestCase.java
                        AbstractWebClientTestCase.java
                        AbstractClientTestCase.java
               framework/src/java/share/org/apache/cactus/server
                        AbstractWebTestCaller.java
               documentation/docs/xdocs changes.xml
  Log:
          <action dev="VMA" type="add">
            Allows creating Cactus TestCase without the need for a constructor 
            that takes a String parameter (a default constructor is good enough).
            Obviously, this feature works only with JUnit 3.8.1 (but Cactus
            continues to support JUnit 3.7).
          </action>
  
  Revision  Changes    Path
  1.11      +12 -1     
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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- ServletTestCase.java      23 Feb 2003 18:05:19 -0000      1.10
  +++ ServletTestCase.java      17 Mar 2003 19:13:51 -0000      1.11
  @@ -113,6 +113,17 @@
       public ServletConfigWrapper config;
   
       /**
  +     * 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 
  +     */
  +    public ServletTestCase()
  +    {
  +    }
  +
  +    /**
        * Constructs a JUnit test case with the given name.
        *
        * @param theName the name of the test case
  
  
  
  1.6       +12 -1     
jakarta-cactus/framework/src/java/share/org/apache/cactus/AbstractWebServerTestCase.java
  
  Index: AbstractWebServerTestCase.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/AbstractWebServerTestCase.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AbstractWebServerTestCase.java    23 Feb 2003 18:05:19 -0000      1.5
  +++ AbstractWebServerTestCase.java    17 Mar 2003 19:13:51 -0000      1.6
  @@ -80,6 +80,17 @@
       extends AbstractWebClientTestCase
   {
       /**
  +     * 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 
  +     */
  +    public AbstractWebServerTestCase()
  +    {
  +    }
  +
  +    /**
        * Constructs a JUnit test case with the given name.
        *
        * @param theName the name of the test case
  
  
  
  1.3       +12 -1     
jakarta-cactus/framework/src/java/share/org/apache/cactus/AbstractWebClientTestCase.java
  
  Index: AbstractWebClientTestCase.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/AbstractWebClientTestCase.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractWebClientTestCase.java    23 Feb 2003 18:05:19 -0000      1.2
  +++ AbstractWebClientTestCase.java    17 Mar 2003 19:13:51 -0000      1.3
  @@ -79,6 +79,17 @@
   public abstract class AbstractWebClientTestCase extends AbstractClientTestCase
   {
       /**
  +     * 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 
  +     */
  +    public AbstractWebClientTestCase()
  +    {
  +    }
  +
  +    /**
        * Constructs a JUnit test case with the given name.
        *
        * @param theName the name of the test case
  
  
  
  1.4       +15 -20    
jakarta-cactus/framework/src/java/share/org/apache/cactus/AbstractClientTestCase.java
  
  Index: AbstractClientTestCase.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/AbstractClientTestCase.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AbstractClientTestCase.java       23 Feb 2003 18:05:19 -0000      1.3
  +++ AbstractClientTestCase.java       17 Mar 2003 19:13:51 -0000      1.4
  @@ -123,15 +123,6 @@
       private static boolean isClientInitialized;
   
       /**
  -     * The name of the current test method being executed. This name is valid
  -     * both on the client side and on the server side, meaning you can call it
  -     * from a <code>testXXX()</code>, <code>setUp()</code> or
  -     * <code>tearDown()</code> method, as well as from <code>beginXXX()</code>
  -     * and <code>endXXX()</code> methods.
  -     */
  -    private String currentTestMethod;
  -
  -    /**
        * The logger (only used on the client side).
        */
       private Log logger;
  @@ -146,6 +137,19 @@
        * JUnit Test Case using Cactus.
        */
       private Test wrappedTest;
  +
  +    /**
  +     * 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 
  +     */
  +    public AbstractClientTestCase()
  +    {
  +        super(null);
  +        this.wrappedTest = this;
  +    }
       
       /**
        * Constructs a JUnit test case with the given name.
  @@ -155,7 +159,6 @@
       public AbstractClientTestCase(String theName)
       {
           super(theName);
  -        this.setCurrentTestMethod(JUnitVersionHelper.getTestCaseName(this));
           this.wrappedTest = this;
       }
   
  @@ -415,14 +418,6 @@
        */
       protected String getCurrentTestMethod()
       {
  -        return this.currentTestMethod;
  -    }
  -
  -    /**
  -     * @param theCurrentTestMethod the name of the current test case.
  -     */
  -    private void setCurrentTestMethod(String theCurrentTestMethod)
  -    {
  -        this.currentTestMethod = theCurrentTestMethod;
  +        return JUnitVersionHelper.getTestCaseName(this);
       }
   }
  
  
  
  1.18      +36 -41    
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.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- AbstractWebTestCaller.java        16 Mar 2003 22:26:43 -0000      1.17
  +++ AbstractWebTestCaller.java        17 Mar 2003 19:13:52 -0000      1.18
  @@ -64,6 +64,7 @@
   import javax.servlet.ServletException;
   
   import junit.framework.Test;
  +import junit.framework.TestCase;
   
   import org.apache.cactus.AbstractWebServerTestCase;
   import org.apache.cactus.HttpServiceDefinition;
  @@ -406,17 +407,26 @@
           {
               if (theWrappedClassName == null)
               {
  -                constructor = testClass.getConstructor(
  -                    new Class[] {String.class});
  +                constructor = getTestClassConstructor(testClass); 
   
  -                testInstance = 
  -                    (AbstractWebServerTestCase) constructor.newInstance(
  -                    new Object[] {theTestCaseName});                
  +                if (constructor.getParameterTypes().length == 0)
  +                {
  +                    testInstance = 
  +                        (AbstractWebServerTestCase) constructor.newInstance(
  +                        new Object[0]);
  +                    ((TestCase) testInstance).setName(theTestCaseName);
  +                }
  +                else
  +                {
  +                    testInstance = 
  +                        (AbstractWebServerTestCase) constructor.newInstance(
  +                        new Object[] {theTestCaseName});                
  +                }
               }
               else
               {
                   Class wrappedTestClass = 
  -                    getWrappedTestClassClass(theWrappedClassName);
  +                    getTestClassClass(theWrappedClassName);
                   Constructor wrappedConstructor =
                       wrappedTestClass.getConstructor(
                       new Class[] {String.class});
  @@ -445,50 +455,35 @@
       }
   
       /**
  -     * @param theClassName the name of the test class
  -     * @return the class object the test class to call
  -     * @exception ServletException if the class of the current test case
  -     *            cannot be loaded in memory (i.e. it is not in the
  -     *            classpath)
  +     * @param theTestClass the test class for which we want to find the
  +     *        constructor
  +     * @return the availble constructor for the test class
  +     * @throws NoSuchMethodException if no suitable constructor is found
        */
  -    protected Class getTestClassClass(String theClassName)
  -        throws ServletException
  +    private Constructor getTestClassConstructor(Class theTestClass)
  +        throws NoSuchMethodException
       {
  -        // Get the class to call and build an instance of it.
  -        Class testClass = null;
  -
  -        try
  +        Constructor constructor;
  +        try 
           {
  -            testClass = ClassLoaderUtils.loadClass(theClassName, 
  -                this.getClass());
  +            constructor = theTestClass.getConstructor(
  +                new Class[] {String.class});         
           }
  -        catch (Exception e)
  +        catch (NoSuchMethodException e)
           {
  -            String message = "Error finding class [" + theClassName
  -                + "] using both the Context classloader and the webapp "
  -                + "classloader. Possible causes include:\r\n";
  -
  -            message += ("\t- Your webapp does not include your test " 
  -                + "classes,\r\n");
  -            message += ("\t- The cactus.jar is not located in your " 
  -                + "WEB-INF/lib directory and your Container has not set the " 
  -                + "Context classloader to point to the webapp one");
  -
  -            LOGGER.error(message, e);
  -            throw new ServletException(message, e);
  +            constructor = theTestClass.getConstructor(new Class[0]);
           }
  -
  -        return testClass;
  +        return constructor;        
       }
   
       /**
  -     * @param theWrappedClassName the name of the wrapped test class
  -     * @return the class object to wrapped test class
  -     * @exception ServletException if the class of the wrapped test case
  +     * @param theClassName the name of the test class
  +     * @return the class object the test class to call
  +     * @exception ServletException if the class of the current test case
        *            cannot be loaded in memory (i.e. it is not in the
        *            classpath)
        */
  -    protected Class getWrappedTestClassClass(String theWrappedClassName)
  +    protected Class getTestClassClass(String theClassName)
           throws ServletException
       {
           // Get the class to call and build an instance of it.
  @@ -496,12 +491,12 @@
   
           try
           {
  -            testClass = ClassLoaderUtils.loadClass(theWrappedClassName, 
  +            testClass = ClassLoaderUtils.loadClass(theClassName, 
                   this.getClass());
           }
           catch (Exception e)
           {
  -            String message = "Error finding class [" + theWrappedClassName
  +            String message = "Error finding class [" + theClassName
                   + "] using both the Context classloader and the webapp "
                   + "classloader. Possible causes include:\r\n";
   
  
  
  
  1.86      +6 -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.85
  retrieving revision 1.86
  diff -u -r1.85 -r1.86
  --- changes.xml       14 Mar 2003 15:29:27 -0000      1.85
  +++ changes.xml       17 Mar 2003 19:13:52 -0000      1.86
  @@ -57,6 +57,12 @@
         </devs>
   
         <release version="1.5" date="- in CVS">
  +        <action dev="VMA" type="add">
  +          Allows creating Cactus TestCase without the need for a constructor 
  +          that takes a String parameter (a default constructor is good enough).
  +          Obviously, this feature works only with JUnit 3.8.1 (but Cactus
  +          continues to support JUnit 3.7).
  +        </action>
           <action dev="CML" type="update">
             Update of jars bundled in the Cactus distribution: Commons Logging
             1.0.2, Log4j 1.2.7, HttpClient 2.0alpha3, HttpUnit 1.5 and 
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to