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 cm...@apache.org on 2003/05/10 14:53:53 UTC

cvs commit: jakarta-cactus/integration/ant/src/test-input/org/apache/cactus/integration/ant test-cactify.xml

cmlenz      2003/05/10 05:53:52

  Modified:    integration/ant/src/test/org/apache/cactus/integration/ant
                        Tag: CACTUS_14_ANT_BRANCH TestCactifyTask.java
               integration/ant/src/test-input/org/apache/cactus/integration/ant
                        Tag: CACTUS_14_ANT_BRANCH test-cactify.xml
  Log:
  Add tests to verify that the redirectors are correctly added to an empty war, depending on whether the input web.xml is without DOCTYPE, with a 2.2 DOCTYPE or a 2.3 DOCTYPE
  (Note: currently these tests require an internet connection because for some reason the DTDs are looked up online. I'll try to fix that ASAP)
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.7   +197 -1    jakarta-cactus/integration/ant/src/test/org/apache/cactus/integration/ant/Attic/TestCactifyTask.java
  
  Index: TestCactifyTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/integration/ant/src/test/org/apache/cactus/integration/ant/Attic/TestCactifyTask.java,v
  retrieving revision 1.1.2.6
  retrieving revision 1.1.2.7
  diff -u -r1.1.2.6 -r1.1.2.7
  --- TestCactifyTask.java	9 May 2003 07:33:58 -0000	1.1.2.6
  +++ TestCactifyTask.java	10 May 2003 12:53:52 -0000	1.1.2.7
  @@ -56,7 +56,17 @@
    */
   package org.apache.cactus.integration.ant;
   
  +import java.io.File;
  +import java.io.IOException;
  +import java.util.Iterator;
  +import java.util.jar.JarFile;
  +
  +import org.apache.cactus.integration.ant.webxml.WebXml;
  +import org.apache.cactus.integration.ant.webxml.WebXmlIo;
   import org.apache.tools.ant.BuildException;
  +import org.xml.sax.EntityResolver;
  +import org.xml.sax.InputSource;
  +import org.xml.sax.SAXException;
   
   /**
    * Unit tests for {@link CactifyTask}.
  @@ -75,6 +85,28 @@
   public final class TestCactifyTask extends AntTestCase
   {
   
  +    // Inner Classes -----------------------------------------------------------
  +
  +    /**
  +     * Entity resolver implementation that simply returns <code>null</code>
  +     * for each request. 
  +     */
  +    private static class NullEntityResolver implements EntityResolver
  +    {
  +
  +        /**
  +         * @see org.xml.sax.EntityResolver#resolveEntity
  +         */
  +        public InputSource resolveEntity(String thePublicId, String theSystemId)
  +            throws SAXException, IOException
  +        {
  +            System.err.println(
  +                "[NULLRESOLVER] resolve public ID " + thePublicId);
  +            return null;
  +        }
  +        
  +    }
  +
       // Constants ---------------------------------------------------------------
   
       /**
  @@ -145,6 +177,170 @@
               assertEquals("You must specify the war file to create!",
                   expected.getMessage());
           }
  +    }
  +
  +    /**
  +     * Tests whether the Cactus test redirectors are correctly added to the 
  +     * descriptor of the cactified WAR. 
  +     * 
  +     * @throws Exception If an unexpected error occurs
  +     */
  +    public void testDefaultRedirectorsNoDoctype() throws Exception
  +    {
  +        executeTestTarget();
  +
  +        File destFile = getProject().resolveFile("work/destfile.war");
  +        JarFile destWar = new JarFile(destFile);
  +        try
  +        {
  +            WebXml webXml = WebXmlIo.parseWebXml(destWar,
  +                new NullEntityResolver());
  +    
  +            assertServletMapping(webXml,
  +                "org.apache.cactus.server.ServletTestRedirector",
  +                "/ServletRedirector");
  +            assertJspMapping(webXml, "/jspRedirector.jsp", "/JspRedirector");
  +    
  +            // As the deployment descriptor in the source WAR doesn't contain a 
  +            // DOCTYPE, it is assumed to be a version 2.2 descriptor. Thus it 
  +            // should not contain a definition of the filter test redirector.
  +            // Assert that.
  +            assertTrue("Filter test redirector should not have been defined",
  +                !webXml.getFilterNames().hasNext());
  +        }
  +        finally
  +        {
  +            destWar.close();
  +        }
  +   }
  +
  +    /**
  +     * Tests whether the Cactus test redirectors are correctly added to the 
  +     * descriptor of the cactified WAR. 
  +     * 
  +     * @throws Exception If an unexpected error occurs
  +     */
  +    public void testDefaultRedirectors22Doctype() throws Exception
  +    {
  +        executeTestTarget();
  +
  +        File destFile = getProject().resolveFile("work/destfile.war");
  +        JarFile destWar = new JarFile(destFile);
  +        try
  +        {
  +            WebXml webXml = WebXmlIo.parseWebXml(destWar,
  +                new NullEntityResolver());
  +
  +            assertServletMapping(webXml,
  +                "org.apache.cactus.server.ServletTestRedirector",
  +                "/ServletRedirector");
  +            assertJspMapping(webXml, "/jspRedirector.jsp", "/JspRedirector");
  +            assertTrue("Filter test redirector should not have been defined",
  +                !webXml.getFilterNames().hasNext());
  +        }
  +        finally
  +        {
  +            destWar.close();
  +        }
  +    }
  +
  +    /**
  +     * Tests whether the Cactus test redirectors are correctly added to the 
  +     * descriptor of the cactified WAR. 
  +     * 
  +     * @throws Exception If an unexpected error occurs
  +     */
  +    public void testDefaultRedirectors23Doctype() throws Exception
  +    {
  +        executeTestTarget();
  +
  +        File destFile = getProject().resolveFile("work/destfile.war");
  +        JarFile destWar = new JarFile(destFile);
  +        try
  +        {
  +            WebXml webXml = WebXmlIo.parseWebXml(destWar,
  +                new NullEntityResolver());
  +            
  +            assertServletMapping(webXml,
  +                "org.apache.cactus.server.ServletTestRedirector",
  +                "/ServletRedirector");
  +            assertJspMapping(webXml, "/jspRedirector.jsp", "/JspRedirector");
  +            assertFilterMapping(webXml,
  +                "org.apache.cactus.server.FilterTestRedirector",
  +                "/FilterRedirector");
  +        }
  +        finally
  +        {
  +            destWar.close();
  +        }
  +    }
  +
  +    // Private Methods ---------------------------------------------------------
  +
  +    /**
  +     * Asserts that a filter of the specified class is defined in the given
  +     * deployment descriptor and mapped to a specific URL-pattern.
  +     * 
  +     * @param theWebXml The deployment descriptor
  +     * @param theFilterClass The name of the filter class
  +     * @param theMapping The URL-pattern that the filter is expected to be
  +     *        mapped to
  +     */
  +    private void assertFilterMapping(WebXml theWebXml, String theFilterClass,
  +        String theMapping)
  +    {
  +        Iterator names = theWebXml.getFilterNamesForClass(theFilterClass);
  +        assertTrue("Definition of " + theFilterClass + " not found",
  +            names.hasNext());
  +        String name = (String) names.next();
  +        Iterator mappings = theWebXml.getFilterMappings(name);
  +        assertTrue("Mapping for " + theFilterClass + " not found",
  +            mappings.hasNext());
  +        assertEquals(theMapping, mappings.next());
  +    }
  +
  +    /**
  +     * Asserts that the specified JSP file is defined in the given deployment
  +     * descriptor and mapped to a specific URL-pattern.
  +     * 
  +     * @param theWebXml The deployment descriptor
  +     * @param theJspFile The JSP file name
  +     * @param theMapping The URL-pattern that the JSP file is expected to be
  +     *        mapped to
  +     */
  +    private void assertJspMapping(WebXml theWebXml, String theJspFile,
  +        String theMapping)
  +    {
  +        Iterator names = theWebXml.getServletNamesForJspFile(theJspFile);
  +        assertTrue("Definition of " + theJspFile + " not found",
  +            names.hasNext());
  +        String name = (String) names.next();
  +        Iterator mappings = theWebXml.getServletMappings(name);
  +        assertTrue("Mapping for " + theJspFile + " not found",
  +            mappings.hasNext());
  +        assertEquals(theMapping, mappings.next());
  +    }
  +
  +    /**
  +     * Asserts that a servlet of the specified class is defined in the given
  +     * deployment descriptor and mapped to a specific URL-pattern.
  +     * 
  +     * @param theWebXml The deployment descriptor
  +     * @param theServletClass The name of servlet class
  +     * @param theMapping The URL-pattern that the servlet is expected to be
  +     *        mapped to
  +     */
  +    private void assertServletMapping(WebXml theWebXml, String theServletClass,
  +        String theMapping)
  +    {
  +        Iterator names = theWebXml.getServletNamesForClass(theServletClass);
  +        assertTrue("Definition of " + theServletClass + " not found",
  +            names.hasNext());
  +        String name = (String) names.next();
  +        Iterator mappings = theWebXml.getServletMappings(name);
  +        assertTrue("Mapping for " + theServletClass + " not found",
  +            mappings.hasNext());
  +        assertEquals(theMapping, mappings.next());
       }
   
   }
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.2   +35 -0     jakarta-cactus/integration/ant/src/test-input/org/apache/cactus/integration/ant/Attic/test-cactify.xml
  
  Index: test-cactify.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/integration/ant/src/test-input/org/apache/cactus/integration/ant/Attic/test-cactify.xml,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- test-cactify.xml	8 May 2003 22:58:25 -0000	1.1.2.1
  +++ test-cactify.xml	10 May 2003 12:53:52 -0000	1.1.2.2
  @@ -2,12 +2,47 @@
   
   <project name="cactify-test" basedir="." default="help">
   
  +  <property name="work.dir" location="${basedir}/work"/>
  +
  +  <target name="setUp">
  +    <mkdir dir="${work.dir}"/>
  +    <xmlcatalog id="j2ee.dtds">
  +      <dtd publicId="-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
  +          location="${basedir}/web-app_2_2.dtd"/>
  +      <dtd publicId="-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
  +          location="${basedir}/web-app_2_3.dtd"/>
  +    </xmlcatalog>
  +  </target>
  +
     <target name="testSrcFileNotSet">
       <cactify destfile="destfile.war"/>
     </target>
   
     <target name="testDestFileNotSet">
       <cactify srcfile="empty.war"/>
  +  </target>
  +
  +  <target name="testDefaultRedirectorsNoDoctype">
  +    <cactify srcfile="empty.war"
  +        destfile="${work.dir}/destfile.war"/>
  +  </target>
  +
  +  <target name="testDefaultRedirectors22Doctype">
  +    <cactify srcfile="empty-2_2.war"
  +        destfile="${work.dir}/destfile.war">
  +      <xmlcatalog refid="j2ee.dtds"/>
  +    </cactify>
  +  </target>
  +
  +  <target name="testDefaultRedirectors23Doctype">
  +    <cactify srcfile="empty-2_3.war"
  +        destfile="${work.dir}/destfile.war">
  +      <xmlcatalog refid="j2ee.dtds"/>
  +    </cactify>
  +  </target>
  +
  +  <target name="tearDown">
  +    <delete dir="${work.dir}"/>
     </target>
   
   </project>
  
  
  

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