vmassol     2004/05/11 12:25:14

  Modified:    framework build.xml build.properties.sample
               framework/src/test/share/org/apache/cactus TestAll.java
               framework/src/java/share/org/apache/cactus/server/runner
                        ServletTestRunner.java
  Added:       framework/src/test/share/org/apache/cactus/server/runner
                        TestServletTestRunner.java
  Log:
  fix ServletTestRunner bug (CACTUS-107) + added unit tests so that it doesn't happen 
again...
  
  Revision  Changes    Path
  1.83      +8 -3      jakarta-cactus/framework/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/build.xml,v
  retrieving revision 1.82
  retrieving revision 1.83
  diff -u -r1.82 -r1.83
  --- build.xml 10 Apr 2004 16:10:43 -0000      1.82
  +++ build.xml 11 May 2004 19:25:14 -0000      1.83
  @@ -99,6 +99,7 @@
       <echo>  httpunit.jar = [${httpunit.jar}]</echo>
       <echo>  j2ee.jar = [${j2ee.jar}]</echo>
       <echo>  junit.jar = [${junit.jar}]</echo>
  +    <echo>  mockobjects.jar = [${mockobjects.jar}]</echo>
       <echo>  log4j.jar (optional) = [${log4j.jar}]</echo>
       <echo>  xmlapis.jar (optional) = [${xmlapis.jar}]</echo>
       <echo/>
  @@ -124,6 +125,7 @@
           <available file="${httpunit.jar}"/>
           <available file="${j2ee.jar}"/>
           <available file="${junit.jar}"/>
  +        <available file="${mockobjects.jar}"/>
           <!-- Check for a TraX class instead of the xmlapis.jar file so that
                the build works on JDK 1.4 without needing to define the
                xmlapis.jar property -->
  @@ -209,8 +211,9 @@
           optimize="${optimize}">
         <src path="${src.test.share.dir}"/>
         <classpath>
  -          <path path="${target.classes.java.dir}"/>
  -          <path refid="project.classpath"/>
  +        <path path="${target.classes.java.dir}"/>
  +        <path refid="project.classpath"/>
  +        <pathelement location="${mockobjects.jar}"/>
         </classpath>
       </javac>
   
  @@ -404,6 +407,7 @@
         <pathelement path="${target.classes.test.dir}"/>
         <pathelement location="${clover.jar}"/>
         <pathelement location="${log4j.jar}"/>
  +      <pathelement location="${mockobjects.jar}"/>
         <path refid="project.classpath"/>
       </path>
   
  @@ -416,6 +420,7 @@
         <pathelement path="${target.classes.java.dir}"/>
         <pathelement path="${target.classes.test.dir}"/>
         <pathelement location="${log4j.jar}"/>
  +      <pathelement location="${mockobjects.jar}"/>
         <path refid="project.classpath"/>
       </path>
   
  
  
  
  1.37      +4 -1      jakarta-cactus/framework/build.properties.sample
  
  Index: build.properties.sample
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/build.properties.sample,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- build.properties.sample   12 Apr 2004 10:48:30 -0000      1.36
  +++ build.properties.sample   11 May 2004 19:25:14 -0000      1.37
  @@ -39,6 +39,9 @@
   # The location of the Httpunit jar
   httpunit.jar = ${lib.repo}/httpunit/jars/httpunit-1.5.4.jar
   
  +# The location of the MockObjects jar (needed for our unit tests)
  +mockobjects.jar = ${lib.repo}/mockobjects/jars/mockobjects-core-0.09.jar
  +
   # -----------------------------------------------------------------------------
   # Optional properties
   # -----------------------------------------------------------------------------
  
  
  
  1.1                  
jakarta-cactus/framework/src/test/share/org/apache/cactus/server/runner/TestServletTestRunner.java
  
  Index: TestServletTestRunner.java
  ===================================================================
  /* 
   * ========================================================================
   * 
   * Copyright 2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *   http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   * 
   * ========================================================================
   */
  package org.apache.cactus.server.runner;
  
  import java.io.IOException;
  import java.io.InputStream;
  
  import javax.servlet.ServletConfig;
  import javax.servlet.ServletContext;
  import javax.servlet.ServletException;
  import javax.servlet.UnavailableException;
  
  import com.mockobjects.dynamic.C;
  import com.mockobjects.dynamic.Mock;
  
  import junit.framework.TestCase;
  
  /**
   * Unit tests for [EMAIL PROTECTED] ServletTestRunner}.
   *
   * @version $Id: TestServletTestRunner.java,v 1.1 2004/05/11 19:25:14 vmassol Exp $
   */
  public final class TestServletTestRunner extends TestCase
  {   
      /**
       * Control mock for [EMAIL PROTECTED] ServletConfig}.
       */
      private Mock mockServletConfig;
  
      /**
       * Mock for [EMAIL PROTECTED] ServletConfig}.
       */
      private ServletConfig servletConfig;
  
      /**
       * Control mock for [EMAIL PROTECTED] ServletContext}.
       */
      private Mock mockServletContext;
  
      /**
       * Mock for [EMAIL PROTECTED] ServletContext}.
       */
      private ServletContext servletContext;
      
      /**
       * Object to unit test.
       */
      private ServletTestRunner runner;
  
      /**
       * @see TestCase#setUp()
       */
      protected void setUp()
      {
          mockServletConfig = new Mock(ServletConfig.class);
          servletConfig = (ServletConfig) mockServletConfig.proxy();
  
          mockServletContext = new Mock(ServletContext.class);
          servletContext = (ServletContext) mockServletContext.proxy();
  
          mockServletConfig.matchAndReturn("getServletContext", servletContext);
          mockServletConfig.matchAndReturn("getServletName", "TestServlet");
          mockServletContext.expect("log", C.ANY_ARGS);
          
          runner = new ServletTestRunner();
      }
  
      /**
       * Verify that the [EMAIL PROTECTED] ServletTestRunner#init()} method works when
       * there are no user stylesheet defined.
       * 
       * @throws ServletException in case of error
       */
      public void testInitWhenNoXslStylesheet() throws ServletException
      {
          mockServletConfig.expectAndReturn("getInitParameter", 
              "xsl-stylesheet", null);
  
          runner.init(servletConfig);        
      }
  
      /**
       * Verify that the [EMAIL PROTECTED] ServletTestRunner#init()} method works when
       * there is a user stylesheet defined which points to an invalid
       * file.
       * 
       * @throws ServletException in case of error
       */
      public void testInitWhenXslStylesheetNotFound() throws ServletException
      {
          mockServletConfig.expectAndReturn("getInitParameter", 
              "xsl-stylesheet", "some-stylesheet.xsl");
          mockServletContext.expectAndReturn("getResourceAsStream", C.ANY_ARGS, 
              null);
          
          try
          {
              runner.init(servletConfig);
              fail("Should have thrown an UnavailableException exception");
          }
          catch (UnavailableException expected)
          {
              assertEquals("The initialization parameter 'xsl-stylesheet' does "
                  + "not refer to an existing resource", expected.getMessage());
          }
      }
  
      /**
       * Verify that the [EMAIL PROTECTED] ServletTestRunner#init()} method works when
       * there is a valid user stylesheet defined.
       * 
       * @throws ServletException in case of error
       */
      public void testInitWithXslStylesheet() throws ServletException
      {
          mockServletConfig.expectAndReturn("getInitParameter", 
              "xsl-stylesheet", "some-stylesheet.xsl");
  
          InputStream mockInputStream = new InputStream()
          {
              private int counter = 0;
              
              private static final String CONTENT = ""
                  + "<xsl:stylesheet xmlns:xsl=\""
                  + "http://www.w3.org/1999/XSL/Transform\"; version=\"1.0\">"
                  + "</xsl:stylesheet>";
              
              public int read() throws IOException
              {
                  while (counter < CONTENT.length())
                  {
                      return CONTENT.charAt(counter++);
                  }
                  return -1;
              }
          };
  
          mockServletContext.expectAndReturn("getResourceAsStream", C.ANY_ARGS, 
              mockInputStream);
  
          // Note: There should be no call to log. If there is it means there 
          // has been an error...
  
          runner.init(servletConfig);        
      }
  
  }
  
  
  
  1.23      +5 -2      
jakarta-cactus/framework/src/test/share/org/apache/cactus/TestAll.java
  
  Index: TestAll.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-cactus/framework/src/test/share/org/apache/cactus/TestAll.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- TestAll.java      10 Apr 2004 18:18:58 -0000      1.22
  +++ TestAll.java      11 May 2004 19:25:14 -0000      1.23
  @@ -30,6 +30,7 @@
   import org.apache.cactus.internal.util.TestStringUtil;
   import org.apache.cactus.internal.util.TestTestCaseImplementChecker;
   import org.apache.cactus.internal.util.TestUniqueGenerator;
  +import org.apache.cactus.server.runner.TestServletTestRunner;
   
   import junit.framework.Test;
   import junit.framework.TestSuite;
  @@ -76,7 +77,9 @@
           suite.addTestSuite(TestStringUtil.class);
           suite.addTestSuite(TestTestCaseImplementChecker.class);
           suite.addTestSuite(TestUniqueGenerator.class);
  -        
  +
  +        suite.addTestSuite(TestServletTestRunner.class);
  +                
           return suite;
       }
   }
  
  
  
  1.21      +3 -3      
jakarta-cactus/framework/src/java/share/org/apache/cactus/server/runner/ServletTestRunner.java
  
  Index: ServletTestRunner.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/server/runner/ServletTestRunner.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- ServletTestRunner.java    14 Apr 2004 06:55:34 -0000      1.20
  +++ ServletTestRunner.java    11 May 2004 19:25:14 -0000      1.21
  @@ -130,8 +130,8 @@
               {
                   try
                   {
  -                    Class transformerClass = Class.forName(
  -                        "org.apache.cactus.server.runner.XMLTransformer");
  +                    Class transformerClass = Class.forName("org.apache.cactus."
  +                        + "internal.server.runner.XMLTransformer");
                       Constructor transformerCtor = 
                           transformerClass.getConstructor(
                           new Class[] {InputStream.class});
  
  
  

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

Reply via email to