You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by kk...@apache.org on 2014/02/11 22:51:47 UTC

svn commit: r1567408 - in /tomcat/tc7.0.x/trunk: ./ test/org/apache/catalina/deploy/TestWebXml.java

Author: kkolinko
Date: Tue Feb 11 21:51:47 2014
New Revision: 1567408

URL: http://svn.apache.org/r1567408
Log:
Backport of r1567382, r1567404 from tomcat/trunk:
Followup to r1567148
Expand validation tests for merged web.xml:
add default conf/web.xml into the merged one.

Modified:
    tomcat/tc7.0.x/trunk/   (props changed)
    tomcat/tc7.0.x/trunk/test/org/apache/catalina/deploy/TestWebXml.java

Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
  Merged /tomcat/trunk:r1567382,1567404

Modified: tomcat/tc7.0.x/trunk/test/org/apache/catalina/deploy/TestWebXml.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/catalina/deploy/TestWebXml.java?rev=1567408&r1=1567407&r2=1567408&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/test/org/apache/catalina/deploy/TestWebXml.java (original)
+++ tomcat/tc7.0.x/trunk/test/org/apache/catalina/deploy/TestWebXml.java Tue Feb 11 21:51:47 2014
@@ -16,6 +16,7 @@
  */
 package org.apache.catalina.deploy;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.StringReader;
 import java.util.HashSet;
@@ -30,7 +31,6 @@ import org.apache.tomcat.util.descriptor
 import org.apache.tomcat.util.descriptor.XmlErrorHandler;
 import org.apache.tomcat.util.descriptor.XmlIdentifiers;
 import org.apache.tomcat.util.digester.Digester;
-
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 
@@ -120,27 +120,27 @@ public class TestWebXml {
     }
 
     @Test
-    public void testValidateVerion22() throws IOException, SAXException {
+    public void testValidateVersion22() throws IOException, SAXException {
         doTestValidateVersion("2.2");
     }
 
     @Test
-    public void testValidateVerion23() throws IOException, SAXException {
+    public void testValidateVersion23() throws IOException, SAXException {
         doTestValidateVersion("2.3");
     }
 
     @Test
-    public void testValidateVerion24() throws IOException, SAXException {
+    public void testValidateVersion24() throws IOException, SAXException {
         doTestValidateVersion("2.4");
     }
 
     @Test
-    public void testValidateVerion25() throws IOException, SAXException {
+    public void testValidateVersion25() throws IOException, SAXException {
         doTestValidateVersion("2.5");
     }
 
     @Test
-    public void testValidateVerion30() throws IOException, SAXException {
+    public void testValidateVersion30() throws IOException, SAXException {
         doTestValidateVersion("3.0");
     }
 
@@ -156,12 +156,19 @@ public class TestWebXml {
             webxml.setVersion(version);
         }
 
+        // Merged web.xml that is published as MERGED_WEB_XML context attribute
+        // in the simplest case consists of webapp's web.xml file
+        // plus the default conf/web.xml one.
+        Set<WebXml> defaults = new HashSet<WebXml>();
+        defaults.add(getDefaultWebXmlFragment());
+        webxml.merge(defaults);
+
         Digester digester = DigesterFactory.newDigester(true, true, new WebRuleSet(), true);
 
         XmlErrorHandler handler = new XmlErrorHandler();
         digester.setErrorHandler(handler);
 
-        System.out.print(webxml.toXml() + "\n\n\n");
+        // System.out.print(webxml.toXml() + "\n\n\n");
 
         InputSource is = new InputSource(new StringReader(webxml.toXml()));
         digester.push(new WebXml());
@@ -171,6 +178,33 @@ public class TestWebXml {
         Assert.assertEquals(0, handler.getWarnings().size());
     }
 
+    // A simplified copy of ContextConfig.getDefaultWebXmlFragment().
+    // Assuming that global web.xml exists, host-specific web.xml does not exist.
+    private WebXml getDefaultWebXmlFragment() throws IOException, SAXException {
+        InputSource globalWebXml = new InputSource(new File("conf/web.xml")
+                .getAbsoluteFile().toURI().toString());
+
+        WebXml webXmlDefaultFragment = new WebXml();
+        webXmlDefaultFragment.setOverridable(true);
+        webXmlDefaultFragment.setDistributable(true);
+        webXmlDefaultFragment.setAlwaysAddWelcomeFiles(false);
+
+        Digester digester = DigesterFactory.newDigester(true, true, new WebRuleSet(), true);
+        XmlErrorHandler handler = new XmlErrorHandler();
+        digester.setErrorHandler(handler);
+        digester.push(webXmlDefaultFragment);
+        digester.parse(globalWebXml);
+        Assert.assertEquals(0, handler.getErrors().size());
+        Assert.assertEquals(0, handler.getWarnings().size());
+
+        webXmlDefaultFragment.setReplaceWelcomeFiles(true);
+
+        // Assert that web.xml was parsed and is not empty. Default servlet is known to be there.
+        Assert.assertNotNull(webXmlDefaultFragment.getServlets().get("default"));
+
+        return webXmlDefaultFragment;
+    }
+
     @Test
     public void testLifecycleMethodsWebXml() {
         WebXml webxml = new WebXml();



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