jakarta-cactus-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cml...@apache.org
Subject cvs commit: jakarta-cactus/integration/ant/src/test/org/apache/cactus/integration/ant/deployment TestWebXmlMerger.java
Date Tue, 01 Jul 2003 19:24:35 GMT
cmlenz      2003/07/01 12:24:35

  Modified:    integration/ant/src/java/org/apache/cactus/integration/ant/deployment
                        WebXmlTag.java WebXml.java
               integration/ant/src/test/org/apache/cactus/integration/ant/deployment
                        TestWebXmlMerger.java
  Log:
  Add servlet initialization before a potential <load-on-startup> element, so the resulting
XML is valid according to the web-app DTD.
  
  PR: 21237
  
  Revision  Changes    Path
  1.7       +7 -1      jakarta-cactus/integration/ant/src/java/org/apache/cactus/integration/ant/deployment/WebXmlTag.java
  
  Index: WebXmlTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/integration/ant/src/java/org/apache/cactus/integration/ant/deployment/WebXmlTag.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- WebXmlTag.java	10 Jun 2003 13:53:53 -0000	1.6
  +++ WebXmlTag.java	1 Jul 2003 19:24:35 -0000	1.7
  @@ -173,6 +173,12 @@
           new WebXmlTag("servlet-class");
       
       /**
  +     * Element name 'load-on-startup'.
  +     */
  +    public static final WebXmlTag LOAD_ON_STARTUP =
  +        new WebXmlTag("load-on-startup");
  +    
  +    /**
        * Element name 'servlet-mapping'.
        */
       public static final WebXmlTag SERVLET_MAPPING =
  
  
  
  1.9       +12 -2     jakarta-cactus/integration/ant/src/java/org/apache/cactus/integration/ant/deployment/WebXml.java
  
  Index: WebXml.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/integration/ant/src/java/org/apache/cactus/integration/ant/deployment/WebXml.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- WebXml.java	11 Jun 2003 16:18:33 -0000	1.8
  +++ WebXml.java	1 Jul 2003 19:24:35 -0000	1.9
  @@ -1015,7 +1015,17 @@
               createNestedText(WebXmlTag.PARAM_NAME, theParamName));
           initParamElement.appendChild(
               createNestedText(WebXmlTag.PARAM_VALUE, theParamValue));
  -        theElement.appendChild(initParamElement);
  +        Iterator loadOnStartupElements = getNestedElements(theElement,
  +            WebXmlTag.LOAD_ON_STARTUP);
  +        if (loadOnStartupElements.hasNext())
  +        {
  +            theElement.insertBefore(initParamElement,
  +                (Element) loadOnStartupElements.next());
  +        }
  +        else
  +        {
  +            theElement.appendChild(initParamElement);
  +        }
       }
       
       /**
  
  
  
  1.5       +41 -1     jakarta-cactus/integration/ant/src/test/org/apache/cactus/integration/ant/deployment/TestWebXmlMerger.java
  
  Index: TestWebXmlMerger.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/integration/ant/src/test/org/apache/cactus/integration/ant/deployment/TestWebXmlMerger.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestWebXmlMerger.java	10 Jun 2003 09:20:32 -0000	1.4
  +++ TestWebXmlMerger.java	1 Jul 2003 19:24:35 -0000	1.5
  @@ -66,6 +66,7 @@
   import junit.framework.TestCase;
   
   import org.w3c.dom.Document;
  +import org.w3c.dom.Element;
   
   /**
    * Unit tests for {@link WebXmlMerger}.
  @@ -567,6 +568,45 @@
           assertEquals("s3", servletNames.next());
           assertEquals("s4", servletNames.next());
           assertTrue(!servletNames.hasNext());
  +    }
  +
  +    /**
  +     * Verifies that servlet init parameters are added after the load-on-startup
  +     * element of an already existing servlet definition.
  +     * 
  +     * @throws Exception If an unexpected error occurs
  +     */
  +    public void testMergingServletWithInitParamsThatIsAlreadyDefined()
  +        throws Exception
  +    {
  +        String srcXml = "<web-app>".trim()
  +            + "  <servlet>".trim()
  +            + "    <servlet-name>s1</servlet-name>".trim()
  +            + "    <servlet-class>sclass1</servlet-class>".trim()
  +            + "    <load-on-startup>1</load-on-startup>".trim()
  +            + "  </servlet>".trim()
  +            + "</web-app>";
  +        Document srcDoc =
  +            builder.parse(new ByteArrayInputStream(srcXml.getBytes()));
  +        WebXml srcWebXml = new WebXml(srcDoc);
  +        String mergeXml = "<web-app>"
  +            + "  <servlet>".trim()
  +            + "    <servlet-name>s1</servlet-name>".trim()
  +            + "    <servlet-class>sclass1</servlet-class>".trim()
  +            + "    <init-param>".trim()
  +            + "      <param-name>s1param1</param-name>".trim()
  +            + "      <param-value>s1param1value</param-value>".trim()
  +            + "    </init-param>".trim()
  +            + "  </servlet>".trim()
  +            + "</web-app>";
  +        Document mergeDoc =
  +            builder.parse(new ByteArrayInputStream(mergeXml.getBytes()));
  +        WebXml mergeWebXml = new WebXml(mergeDoc);
  +        WebXmlMerger merger = new WebXmlMerger(srcWebXml);
  +        merger.mergeServlets(mergeWebXml);
  +        Element servletElement = srcWebXml.getServlet("s1");
  +        assertEquals("load-on-startup",
  +            ((Element) servletElement.getLastChild()).getTagName());
       }
   
       /**
  
  
  

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


Mime
View raw message