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 2002/01/27 18:23:18 UTC

cvs commit: jakarta-cactus/src/test/share/org/apache/cactus TestAbstractTestCase_InterceptorTestCase.java

vmassol     02/01/27 09:23:18

  Modified:    src/framework/share/org/apache/cactus AbstractTestCase.java
               src/framework/share/org/apache/cactus/client/authentication
                        BasicAuthentication.java
               src/sample/share/org/apache/cactus/sample/unit
                        TestServletTestCase1_InterceptorServletTestCase.java
               src/test/share/org/apache/cactus
                        TestAbstractTestCase_InterceptorTestCase.java
  Log:
  audit fix
  
  Revision  Changes    Path
  1.21      +86 -46    jakarta-cactus/src/framework/share/org/apache/cactus/AbstractTestCase.java
  
  Index: AbstractTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/src/framework/share/org/apache/cactus/AbstractTestCase.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- AbstractTestCase.java	13 Jan 2002 15:07:08 -0000	1.20
  +++ AbstractTestCase.java	27 Jan 2002 17:23:18 -0000	1.21
  @@ -76,7 +76,7 @@
    *
    * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
    *
  - * @version $Id: AbstractTestCase.java,v 1.20 2002/01/13 15:07:08 vmassol Exp $
  + * @version $Id: AbstractTestCase.java,v 1.21 2002/01/27 17:23:18 vmassol Exp $
    */
   public abstract class AbstractTestCase extends TestCase
   {
  @@ -107,7 +107,7 @@
        * <code>tearDown()</code> method, as well as from <code>beginXXX()</code>
        * and <code>endXXX()</code> methods.
        */
  -    public String currentTestMethod;
  +    private String currentTestMethod;
   
       /**
        * The logger (only used on the client side).
  @@ -122,7 +122,7 @@
       public AbstractTestCase(String theName)
       {
           super(theName);
  -        this.currentTestMethod = JUnitVersionHelper.getTestCaseName(this);
  +        this.setCurrentTestMethod(JUnitVersionHelper.getTestCaseName(this));
       }
   
       /**
  @@ -141,12 +141,14 @@
       private String getBaseMethodName()
       {
           // Sanity check
  -        if (!this.currentTestMethod.startsWith(TEST_METHOD_PREFIX)) {
  -            throw new RuntimeException("bad name [" + this.currentTestMethod +
  -                "]. It should start with [" + TEST_METHOD_PREFIX + "].");
  +        if (!this.getCurrentTestMethod().startsWith(TEST_METHOD_PREFIX)) {
  +            throw new RuntimeException("bad name [" +
  +                this.getCurrentTestMethod() + "]. It should start with [" +
  +                TEST_METHOD_PREFIX + "].");
           }
   
  -        return this.currentTestMethod.substring(TEST_METHOD_PREFIX.length());
  +        return this.getCurrentTestMethod().substring(
  +            TEST_METHOD_PREFIX.length());
       }
   
       /**
  @@ -174,6 +176,8 @@
        *
        * @param theRequest the <code>WebRequest</code> object to
        *                   pass to the begin method.
  +     * @throws Throwable any error that occurred when calling the begin method
  +     *         for the current test case.
        */
       protected void callBeginMethod(WebRequest theRequest)
           throws Throwable
  @@ -242,6 +246,8 @@
        *        to open the connection to the redirection servlet. The response
        *        codes, headers, cookies can be checked using the get methods of
        *        this object.
  +     * @throws Throwable any error that occurred when calling the end method
  +     *         for the current test case.
        */
       protected void callEndMethod(WebRequest theRequest,
           HttpURLConnection theConnection) throws Throwable
  @@ -306,7 +312,7 @@
                   // Has a method to call already been found ?
                   if (methodToCall != null) {
                       fail("There can only be one end method per test case. " +
  -                        "Test case [" + this.currentTestMethod +
  +                        "Test case [" + this.getCurrentTestMethod() +
                            "] has two at least !");
                   }
   
  @@ -338,6 +344,10 @@
        * that we don't need the HttpUnit jar for users who are not using
        * the HttpUnit endXXX() signature).
        *
  +     * @param theConnection the HTTP connection that was used when connecting
  +     *        to the server side and which now contains the returned HTTP
  +     *        response that we will pass to HttpUnit so that it can construt
  +     *        a <code>com.meterware.httpunit.WebResponse</code> object.
        * @return a HttpUnit <code>WebResponse</code> object
        */
       private Object createHttpUnitWebResponse(HttpURLConnection theConnection)
  @@ -382,7 +392,7 @@
               LogService.getInstance().getLog(this.getClass().getName());
   
           // Mark beginning of test on client side
  -        getLogger().debug("------------- Test: " + this.currentTestMethod);
  +        getLogger().debug("------------- Test: " + this.getCurrentTestMethod());
   
           // Catch the exception just to have a chance to log it
           try {
  @@ -398,6 +408,9 @@
        * Runs a test case. This method is overriden from the JUnit
        * <code>TestCase</code> class in order to seamlessly call the
        * Cactus redirection servlet.
  +     *
  +     * @throws Throwable any error that occurred when calling the test method
  +     *         for the current test case.
        */
       protected abstract void runTest() throws Throwable;
   
  @@ -408,6 +421,8 @@
        *
        * @param theHttpClient the HTTP client class to use to connect to the
        *                      proxy redirector.
  +     * @throws Throwable any error that occurred when calling the test method
  +     *         for the current test case.
        */
       protected void runGenericTest(AbstractHttpClient theHttpClient)
           throws Throwable
  @@ -424,8 +439,8 @@
           // a file, ...
           request.addParameter(ServiceDefinition.CLASS_NAME_PARAM,
               this.getClass().getName(), WebRequest.GET_METHOD);
  -        request.addParameter(ServiceDefinition.METHOD_NAME_PARAM, this.currentTestMethod,
  -            WebRequest.GET_METHOD);
  +        request.addParameter(ServiceDefinition.METHOD_NAME_PARAM,
  +            this.getCurrentTestMethod(), WebRequest.GET_METHOD);
           request.addParameter(ServiceDefinition.AUTOSESSION_NAME_PARAM,
               new Boolean(request.getAutomaticSession()).toString(),
               WebRequest.GET_METHOD);
  @@ -451,10 +466,13 @@
       // 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,
  +    /**
  +     * Run the test that was specified in the constructor on the server side,
        * calling <code>setUp()</code> and <code>tearDown()</code>.
  -	 */
  +     *
  +     * @throws 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
  @@ -473,42 +491,64 @@
           finally {
               tearDown();
           }
  -	}
  +    }
   
  -	/**
  -	 * Run the test that was specified in the constructor 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.currentTestMethod,
  +    /**
  +     * Run the test that was specified in the constructor on the server side.
  +     *
  +     * @throws 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.currentTestMethod +
  +        } 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.currentTestMethod + "()] 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;
  -		}
  -	}
  +        }
  +        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;
  +    }
  +
  +    /**
  +     * @param theCurrentTestMethod the name of the current test case.
  +     */
  +    private void setCurrentTestMethod(String theCurrentTestMethod)
  +    {
  +        this.currentTestMethod = theCurrentTestMethod;
  +    }
   
   }
  
  
  
  1.2       +30 -26    jakarta-cactus/src/framework/share/org/apache/cactus/client/authentication/BasicAuthentication.java
  
  Index: BasicAuthentication.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/src/framework/share/org/apache/cactus/client/authentication/BasicAuthentication.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BasicAuthentication.java	13 Jan 2002 21:21:17 -0000	1.1
  +++ BasicAuthentication.java	27 Jan 2002 17:23:18 -0000	1.2
  @@ -90,13 +90,16 @@
           String illegalChars = "()<>@,;:\\\"/[]?={} \t";
           StringCharacterIterator iter = new StringCharacterIterator(userid);
           
  -        for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) {
  +        for (char c = iter.first(); c != CharacterIterator.DONE;
  +        	c = iter.next()) {
  +
               if ((illegalChars.indexOf(c) != -1) || 
                   ((c >=0 ) && (c <= 31)) || 
                   (c == 127)) {
                   
                   // Bad userid! Go to your room!
  -                throw new IllegalArgumentException("Given userid contains illegal characters.");
  +                throw new IllegalArgumentException(
  +                    "Given userid contains illegal characters.");
               }
           }
       }
  @@ -137,7 +140,8 @@
                   }
                   
                   // Bad password! Go to your room!
  -                throw new IllegalArgumentException("Given password contains illegal characters.");
  +                throw new IllegalArgumentException(
  +                    "Given password contains illegal characters.");
               }
           }
       }
  @@ -153,36 +157,39 @@
           // see setUserId and setPassword for details of token and TEXT
   
           String basicCookie = userid + ":" + password;
  -        String basicCredentials = "Basic " + new String(base64Encode(basicCookie.getBytes()));
  +        String basicCredentials = "Basic " +
  +            new String(base64Encode(basicCookie.getBytes()));
           
           connection.setRequestProperty("Authorization", basicCredentials);
       }
   
  -    // Base64 code - is there common code somewhere I should be using???
  -    
       /**
  -    * Provides encoding of raw bytes to base64-encoded characters, and
  -    * decoding of base64 characters to raw bytes.
  -    *
  -    * @author Kevin Kelley (kelley@iguana.ruralnet.net)
  -    * @version 1.0
  -    * @date 06 August 1998
  -    */    
  +     * Provides encoding of raw bytes to base64-encoded characters, and
  +     * decoding of base64 characters to raw bytes.
  +     */
   
  -    static private char[] alphabet =
  +    private static char[] alphabet =
           "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".toCharArray();
      
  -    //
  -    // lookup table for converting base64 characters to value in range 0..63
  -    //
  -    static private byte[] codes = new byte[256];
  +    /**
  +     * Lookup table for converting base64 characters to value in range 0..63
  +     */
  +    private static byte[] codes = new byte[256];
       
       static 
       {
  -        for (int i=0; i<256; i++) codes[i] = -1;
  -        for (int i = 'A'; i <= 'Z'; i++) codes[i] = (byte)( i - 'A');
  -        for (int i = 'a'; i <= 'z'; i++) codes[i] = (byte)(26 + i - 'a');
  -        for (int i = '0'; i <= '9'; i++) codes[i] = (byte)(52 + i - '0');
  +        for (int i=0; i<256; i++) {
  +            codes[i] = -1;
  +        }
  +        for (int i = 'A'; i <= 'Z'; i++) {
  +            codes[i] = (byte)( i - 'A');
  +        }
  +        for (int i = 'a'; i <= 'z'; i++) {
  +            codes[i] = (byte)(26 + i - 'a');
  +        }
  +        for (int i = '0'; i <= '9'; i++) {
  +            codes[i] = (byte)(52 + i - '0');
  +        }
           codes['+'] = 62;
           codes['/'] = 63;
       }
  @@ -194,7 +201,7 @@
        * @param data the array of bytes to encode
        * @return base64-coded character array.
        */
  -    static private char[] base64Encode(byte[] data)
  +    private static char[] base64Encode(byte[] data)
       {
           char[] out = new char[((data.length + 2) / 3) * 4];
           
  @@ -238,6 +245,3 @@
           return out;
       }
   }
  -
  -
  -
  
  
  
  1.9       +5 -5      jakarta-cactus/src/sample/share/org/apache/cactus/sample/unit/TestServletTestCase1_InterceptorServletTestCase.java
  
  Index: TestServletTestCase1_InterceptorServletTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/src/sample/share/org/apache/cactus/sample/unit/TestServletTestCase1_InterceptorServletTestCase.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- TestServletTestCase1_InterceptorServletTestCase.java	13 Jan 2002 15:31:40 -0000	1.8
  +++ TestServletTestCase1_InterceptorServletTestCase.java	27 Jan 2002 17:23:18 -0000	1.9
  @@ -66,10 +66,10 @@
    *
    * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
    *
  - * @version $Id: TestServletTestCase1_InterceptorServletTestCase.java,v 1.8 2002/01/13 15:31:40 vmassol Exp $
  + * @version $Id: TestServletTestCase1_InterceptorServletTestCase.java,v 1.9 2002/01/27 17:23:18 vmassol Exp $
    * @see TestServletTestCase1
    */
  -public class TestServletTestCase1_InterceptorServletTestCase 
  +public class TestServletTestCase1_InterceptorServletTestCase
       extends ServletTestCase
   {
       /**
  @@ -94,7 +94,7 @@
               // If the test case is "testAssertionFailedError" and the exception
               // is of type AssertionFailedError and contains the text
               // "test assertion failed error", then the test is ok.
  -            if (this.currentTestMethod.equals("testAssertionFailedError")) {
  +            if (this.getCurrentTestMethod().equals("testAssertionFailedError")) {
                   if (e.instanceOf(AssertionFailedError.class)) {
                       assertEquals("test assertion failed error", e.getMessage());
                       return;
  @@ -108,7 +108,7 @@
               // TestServletTestCaseHelper1_ExceptionNotSerializable
               // and contains the text "test non serializable exception", then
               // the test is ok.
  -            if (this.currentTestMethod.equals("testExceptionNotSerializable")) {
  +            if (this.getCurrentTestMethod().equals("testExceptionNotSerializable")) {
                   if (e.instanceOf(
                       TestServletTestCase1_ExceptionNotSerializable.class)) {
   
  @@ -122,7 +122,7 @@
               // is of type TestServletTestCaseHelper1_ExceptionSerializable
               // and contains the text "test serializable exception", then
               // the test is ok.
  -            if (this.currentTestMethod.equals("testExceptionSerializable")) {
  +            if (this.getCurrentTestMethod().equals("testExceptionSerializable")) {
                   assert(e.instanceOf(
                       TestServletTestCase1_ExceptionSerializable.class));
   
  
  
  
  1.12      +13 -13    jakarta-cactus/src/test/share/org/apache/cactus/TestAbstractTestCase_InterceptorTestCase.java
  
  Index: TestAbstractTestCase_InterceptorTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/src/test/share/org/apache/cactus/TestAbstractTestCase_InterceptorTestCase.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- TestAbstractTestCase_InterceptorTestCase.java	13 Jan 2002 15:33:54 -0000	1.11
  +++ TestAbstractTestCase_InterceptorTestCase.java	27 Jan 2002 17:23:18 -0000	1.12
  @@ -68,7 +68,7 @@
    *
    * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
    *
  - * @version $Id: TestAbstractTestCase_InterceptorTestCase.java,v 1.11 2002/01/13 15:33:54 vmassol Exp $
  + * @version $Id: TestAbstractTestCase_InterceptorTestCase.java,v 1.12 2002/01/27 17:23:18 vmassol Exp $
    */
   public class TestAbstractTestCase_InterceptorTestCase
       extends AbstractTestCase
  @@ -124,7 +124,7 @@
               // 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 (this.currentTestMethod.equals("testBeginMethodBadReturnType")) {
  +            if (this.getCurrentTestMethod().equals("testBeginMethodBadReturnType")) {
                   assertEquals("The begin method " +
                       "[beginBeginMethodBadReturnType] should return void and " +
                       "not [java.lang.String]", e.getMessage());
  @@ -133,7 +133,7 @@
   
               // Test that when a begin method for a given test is not declared
               // public a <code>AssertionFailedError</code> exception is returned.
  -            if (this.currentTestMethod.equals("testBeginMethodNotPublic")) {
  +            if (this.getCurrentTestMethod().equals("testBeginMethodNotPublic")) {
                   assertEquals("Method [beginBeginMethodNotPublic] should be " +
                       "declared public", e.getMessage());
                   return;
  @@ -142,7 +142,7 @@
               // Test that when a begin method for a given test has the wrong
               // type of parameters, a <code>AssertionFailedError</code> exception
               // is returned.
  -            if (this.currentTestMethod.equals("testBeginMethodBadParamType")) {
  +            if (this.getCurrentTestMethod().equals("testBeginMethodBadParamType")) {
                   assertEquals("The begin method " +
                       "[beginBeginMethodBadParamType] must accept a single " +
                       "parameter derived from class " +
  @@ -155,7 +155,7 @@
               // Test that when a begin method for a given test has the wrong
               // number of parameters, a <code>AssertionFailedError</code>
               // exception is returned.
  -            if (this.currentTestMethod.equals("testBeginMethodBadParamNumber")) {
  +            if (this.getCurrentTestMethod().equals("testBeginMethodBadParamNumber")) {
                   assertEquals("The begin method " +
                       "[beginBeginMethodBadParamNumber] must accept a single " +
                       "parameter derived from class " +
  @@ -167,7 +167,7 @@
   
               // Verify that the begin method with a
               // <code>WebRequest</code> parameter is called correctly.
  -            if (this.currentTestMethod.equals("testBeginMethodOK")) {
  +            if (this.getCurrentTestMethod().equals("testBeginMethodOK")) {
                   assertEquals("beginBeginMethodOK", e.getMessage());
                   return;
               }
  @@ -177,7 +177,7 @@
               // 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 (this.currentTestMethod.equals("testEndMethodBadReturnType")) {
  +            if (this.getCurrentTestMethod().equals("testEndMethodBadReturnType")) {
                   assertEquals("The end method " +
                       "[endEndMethodBadReturnType] should return void and " +
                       "not [java.lang.String]", e.getMessage());
  @@ -186,7 +186,7 @@
   
               // Test that when an end method for a given test is not declared
               // public a <code>AssertionFailedError</code> exception is returned.
  -            if (this.currentTestMethod.equals("testEndMethodNotPublic")) {
  +            if (this.getCurrentTestMethod().equals("testEndMethodNotPublic")) {
                   assertEquals("Method [endEndMethodNotPublic] should be " +
                       "declared public", e.getMessage());
                   return;
  @@ -195,7 +195,7 @@
               // Test that when an end method for a given test has the wrong
               // type of parameters, a <code>AssertionFailedError</code> exception
               // is returned.
  -            if (this.currentTestMethod.equals("testEndMethodBadParamType")) {
  +            if (this.getCurrentTestMethod().equals("testEndMethodBadParamType")) {
                   assertEquals("The end method [endEndMethodBadParamType] " +
                       "has a bad parameter of type [java.lang.String]",
                       e.getMessage());
  @@ -205,7 +205,7 @@
               // Test that when an end method for a given test has the wrong
               // number of parameters, a <code>AssertionFailedError</code>
               // exception is returned.
  -            if (this.currentTestMethod.equals("testEndMethodBadParamNumber")) {
  +            if (this.getCurrentTestMethod().equals("testEndMethodBadParamNumber")) {
                   assertEquals("The end method [endEndMethodBadParamNumber] " +
                       "must only have a single parameter", e.getMessage());
                   return;
  @@ -214,7 +214,7 @@
               // Test that the end method is called correctly when it's signature
               // contains a <code>org.apache.cactus.WebResponse</code>
               // parameter.
  -            if (this.currentTestMethod.equals("testEndMethodOK1")) {
  +            if (this.getCurrentTestMethod().equals("testEndMethodOK1")) {
                   assertEquals("endEndMethodOK1", e.getMessage());
                   return;
               }
  @@ -222,7 +222,7 @@
               // Test that the end method is called correctly when it's signature
               // contains a <code>com.meterware.httpunit.WebResponse</code>
               // parameter.
  -            if (this.currentTestMethod.equals("testEndMethodOK2")) {
  +            if (this.getCurrentTestMethod().equals("testEndMethodOK2")) {
                   assertEquals("endEndMethodOK2", e.getMessage());
                   return;
               }
  @@ -230,7 +230,7 @@
               // Test that the deprecated end method with the
               // <code>HttpURLConnection</code> parameter can still be called
               // correctly.
  -            if (this.currentTestMethod.equals("testEndMethodOK3")) {
  +            if (this.getCurrentTestMethod().equals("testEndMethodOK3")) {
                   assertEquals("endEndMethodOK3", e.getMessage());
                   return;
               }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>