vmassol     2003/09/21 02:05:48

  Modified:    framework/src/test/share/org/apache/cactus
                        TestAbstractTestCase.java
  Added:       framework/src/test/share/org/apache/cactus
                        AbstractTestAbstractTestCase.java
  Removed:     framework/src/test/share/org/apache/cactus
                        TestAbstractTestCaseInterceptorTestCase.java
  Log:
  Renamed TestAbstractTestCaseInterceptorTestCase to AbstractTestAbstractTestCase to 
give a more consistent naming and clearly show that this class is not a test class 
that can be run (it is abstract)
  
  Revision  Changes    Path
  1.11      +2 -3      
jakarta-cactus/framework/src/test/share/org/apache/cactus/TestAbstractTestCase.java
  
  Index: TestAbstractTestCase.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-cactus/framework/src/test/share/org/apache/cactus/TestAbstractTestCase.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- TestAbstractTestCase.java 22 Jun 2003 18:00:27 -0000      1.10
  +++ TestAbstractTestCase.java 21 Sep 2003 09:05:48 -0000      1.11
  @@ -65,8 +65,7 @@
    *
    * @version $Id$
    */
  -public class TestAbstractTestCase
  -    extends TestAbstractTestCaseInterceptorTestCase
  +public class TestAbstractTestCase extends AbstractTestAbstractTestCase
   {
       // Make sure logging is disabled
       static
  
  
  
  1.1                  
jakarta-cactus/framework/src/test/share/org/apache/cactus/AbstractTestAbstractTestCase.java
  
  Index: AbstractTestAbstractTestCase.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 [EMAIL PROTECTED]
   *
   * 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.io.ByteArrayInputStream;
  
  import java.net.URL;
  
  import junit.framework.AssertionFailedError;
  import junit.framework.TestCase;
  
  import org.apache.cactus.client.ClientException;
  import org.apache.cactus.configuration.ServletConfiguration;
  import org.apache.cactus.configuration.WebConfiguration;
  import org.apache.cactus.internal.client.WebClientTestCaseDelegate;
  import org.apache.cactus.mock.MockHttpURLConnection;
  import org.apache.cactus.util.JUnitVersionHelper;
  
  /**
   * Test <code>TestCase</code> class that intercepts all exceptions (and assert
   * them) coming from test case classes that inherits from it. This class is
   * used to unit test the <code>TestAbstractTestCase</code> class.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a>
   *
   * @version $Id: AbstractTestAbstractTestCase.java,v 1.1 2003/09/21 09:05:48 vmassol 
Exp $
   */
  public abstract class AbstractTestAbstractTestCase extends TestCase
  {
      /**
       * Override default method so that configuration checks are not run during
       * these unit tests.
       *
       * @exception Throwable if any exception is thrown during the test. Any
       *            exception will be displayed by the JUnit Test Runner
       * @see AbstractTestCase#runBare()
       */
      public void runBare() throws Throwable
      {
          runTest();
      }
  
      /**
       * Intercepts running test cases to check for normal exceptions.
       *
       * @exception Throwable any error that occurred when calling the test method
       *            for the current test case.
       * @see AbstractTestCase#runTest()
       */
      protected void runTest() throws Throwable
      {
          WebClientTestCaseDelegate delegator = new WebClientTestCaseDelegate(
              this, this, new ServletConfiguration());        
  
          try
          {
              // Call the begin method
              WebRequest request = new WebRequest(
                  (WebConfiguration) delegator.getConfiguration());
  
              delegator.callBeginMethod(request);
  
              // Create a mock HttpURLConnection as it is needed by HttpUnit
              // for creating a WebResponse
              MockHttpURLConnection connection = new MockHttpURLConnection(
                  new URL("http://something";));
  
              // Set the values expected by Http Unit. Note: only the test
              // cases that have an end method with an HttpUnit WebReponse
              // will use the HttpURLConnection.
              connection.setExpectedGetHeaderField("HTTP/1.1 200 OK");
              connection.setExpectedGetInputStream(
                  new ByteArrayInputStream("".getBytes()));
  
              // Create a WebResponse object and call the end method
              delegator.callEndMethod(request, connection);
          }
          catch (AssertionFailedError e)
          {
              // Perform asserts
              if (!verifyBeginMethodsOk(e.getMessage())
                  && !verifyEndMethodsOk(e.getMessage()))
              {
                  throw e;
              }
          }
          catch (ClientException e)
          {
              // Perform asserts
              if (!verifyBeginMethodsOk(e.getMessage())
                  && !verifyEndMethodsOk(e.getMessage()))
              {
                  throw e;
              }
          }
      }
  
      /**
       * @param theTestName the test name to verify
       * @return true if the test name to verify corresponds to the currently
       *         executing test
       */
      private boolean checkName(String theTestName)
      {
          return JUnitVersionHelper.getTestCaseName(this).equals(
              theTestName);
      }
      
      /**
       * Assert begin method tests.
       *
       * @param theMessage the error message from the exception
       * @return false is no test matches
       */
      private boolean verifyBeginMethodsOk(String theMessage)
      {
          // Test that when a begin method for a given test does not have the
          // correct return type (i.e. void), a
          // <code>AssertionFailedError</code> exception is returned.
          if (checkName("testBeginMethodBadReturnType"))
          {
              assertEquals("The method "
                  + "[beginBeginMethodBadReturnType] should return void and "
                  + "not [java.lang.String]", theMessage);
  
              return true;
          }
  
          // Test that when a begin method for a given test is not declared
          // public a <code>AssertionFailedError</code> exception is returned.
          if (checkName("testBeginMethodNotPublic"))
          {
              assertEquals("Method [beginBeginMethodNotPublic] should be "
                  + "declared public", theMessage);
  
              return true;
          }
  
          // Test that when a begin method for a given test has the wrong
          // type of parameters, a <code>AssertionFailedError</code> exception
          // is returned.
          if (checkName("testBeginMethodBadParamType"))
          {
              assertEquals("The method "
                  + "[beginBeginMethodBadParamType] must accept a single "
                  + "parameter derived from class "
                  + "[org.apache.cactus.WebRequest], but "
                  + "found a [java.lang.String] parameter instead", theMessage);
  
              return true;
          }
  
          // Test that when a begin method for a given test has the wrong
          // number of parameters, a <code>AssertionFailedError</code>
          // exception is returned.
          if (checkName("testBeginMethodBadParamNumber"))
          {
              assertEquals("The method "
                  + "[beginBeginMethodBadParamNumber] must accept a single "
                  + "parameter derived from class "
                  + "[org.apache.cactus.WebRequest], but 2 "
                  + "parameters were found", theMessage);
  
              return true;
          }
  
          // Verify that the begin method with a
          // <code>WebRequest</code> parameter is called correctly.
          if (checkName("testBeginMethodOK"))
          {
              assertEquals("beginBeginMethodOK", theMessage);
  
              return true;
          }
  
          return false;
      }
  
      /**
       * Assert end method tests.
       *
       * @param theMessage the error message from the exception
       * @return false is no test matches
       */
      private boolean verifyEndMethodsOk(String theMessage)
      {
          // Test that when an end method for a given test does not have the
          // correct return type (i.e. void), a
          // <code>AssertionFailedError</code> exception is returned.
          if (checkName("testEndMethodBadReturnType"))
          {
              assertEquals("The method "
                  + "[endEndMethodBadReturnType] should return void and "
                  + "not [java.lang.String]", theMessage);
  
              return true;
          }
  
          // Test that when an end method for a given test is not declared
          // public a <code>AssertionFailedError</code> exception is returned.
          if (checkName("testEndMethodNotPublic"))
          {
              assertEquals("Method [endEndMethodNotPublic] should be "
                  + "declared public", theMessage);
  
              return true;
          }
  
          // Test that when an end method for a given test has the wrong
          // type of parameters, a <code>AssertionFailedError</code> exception
          // is returned.
          if (checkName("testEndMethodBadParamType"))
          {
              assertEquals("The method [endEndMethodBadParamType] "
                  + "has a bad parameter of type [java.lang.String]", 
                  theMessage);
  
              return true;
          }
  
          // Test that when an end method for a given test has the wrong
          // number of parameters, a <code>AssertionFailedError</code>
          // exception is returned.
          if (checkName("testEndMethodBadParamNumber"))
          {
              assertEquals("The method [endEndMethodBadParamNumber] "
                  + "must only have a single parameter", theMessage);
  
              return true;
          }
  
          // Test that the end method is called correctly when it's signature
          // contains a <code>org.apache.cactus.WebResponse</code>
          // parameter.
          if (checkName("testEndMethodOK1"))
          {
              assertEquals("endEndMethodOK1", theMessage);
  
              return true;
          }
  
          // Test that the end method is called correctly when it's signature
          // contains a <code>com.meterware.httpunit.WebResponse</code>
          // parameter.
          if (checkName("testEndMethodOK2"))
          {
              assertEquals("endEndMethodOK2", theMessage);
  
              return true;
          }
  
          // Test that the deprecated end method with the
          // <code>HttpURLConnection</code> parameter can still be called
          // correctly.
          if (checkName("testEndMethodOK3"))
          {
              assertEquals("endEndMethodOK3", theMessage);
  
              return true;
          }
  
          return false;
      }
  
  }
  
  
  

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

Reply via email to