Author: markt
Date: Fri Sep 18 12:41:19 2015
New Revision: 1703821

URL: http://svn.apache.org/viewvc?rev=1703821&view=rev
Log:
Fix test broken by fix for BZ 58373

Modified:
    tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java
    tomcat/trunk/test/org/apache/catalina/core/TestStandardContextResources.java

Modified: tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java?rev=1703821&r1=1703820&r2=1703821&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java Fri Sep 18 
12:41:19 2015
@@ -520,6 +520,14 @@ public class Tomcat {
      * @see #addWebapp(String, String)
      */
     public Context addWebapp(Host host, String contextPath, String docBase) {
+        return addWebapp(host,  contextPath, docBase, new ContextConfig());
+    }
+
+    /**
+     * @see #addWebapp(String, String)
+     */
+    public Context addWebapp(Host host, String contextPath, String docBase, 
ContextConfig config) {
+
         silence(host, contextPath);
 
         Context ctx = createContext(host, contextPath);
@@ -528,11 +536,10 @@ public class Tomcat {
         ctx.addLifecycleListener(new DefaultWebXmlListener());
         ctx.setConfigFile(getWebappConfigFile(docBase, contextPath));
 
-        ContextConfig ctxCfg = new ContextConfig();
-        ctx.addLifecycleListener(ctxCfg);
+        ctx.addLifecycleListener(config);
 
         // prevent it from looking ( if it finds one - it'll have dup error )
-        ctxCfg.setDefaultWebXml(noDefaultWebXmlPath());
+        config.setDefaultWebXml(noDefaultWebXmlPath());
 
         if (host == null) {
             getHost().addChild(ctx);

Modified: 
tomcat/trunk/test/org/apache/catalina/core/TestStandardContextResources.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/core/TestStandardContextResources.java?rev=1703821&r1=1703820&r2=1703821&view=diff
==============================================================================
--- 
tomcat/trunk/test/org/apache/catalina/core/TestStandardContextResources.java 
(original)
+++ 
tomcat/trunk/test/org/apache/catalina/core/TestStandardContextResources.java 
Fri Sep 18 12:41:19 2015
@@ -37,9 +37,6 @@ import static org.junit.Assert.assertTru
 import org.junit.Test;
 
 import org.apache.catalina.Context;
-import org.apache.catalina.Lifecycle;
-import org.apache.catalina.LifecycleEvent;
-import org.apache.catalina.LifecycleListener;
 import org.apache.catalina.startup.Constants;
 import org.apache.catalina.startup.ContextConfig;
 import org.apache.catalina.startup.Tomcat;
@@ -131,26 +128,14 @@ public class TestStandardContextResource
     @Test
     public void testResourcesAbsoluteOrdering() throws Exception {
         Tomcat tomcat = getTomcatInstance();
-
         File appDir = new File("test/webapp-fragments");
+
+        AbsoluteOrderContextConfig absoluteOrderConfig = new 
AbsoluteOrderContextConfig();
+
         // app dir is relative to server home
         StandardContext ctx = (StandardContext) tomcat.addWebapp(null, "/test",
-                appDir.getAbsolutePath());
-        LifecycleListener[] listener = ctx.findLifecycleListeners();
-        assertEquals(3,listener.length);
-        assertTrue(listener[1] instanceof ContextConfig);
-        ContextConfig config = new ContextConfig() {
-            @Override
-            protected WebXml createWebXml() {
-                WebXml wxml = new WebXml();
-                wxml.addAbsoluteOrdering("resources");
-                wxml.addAbsoluteOrdering("resources2");
-                return wxml;
-            }
-        };
-        // prevent it from looking ( if it finds one - it'll have dup error )
-        config.setDefaultWebXml(Constants.NoDefaultWebXml);
-        listener[1] = config;
+                appDir.getAbsolutePath(), absoluteOrderConfig);
+
         Tomcat.addServlet(ctx, "getresource", new GetResourceServlet());
         ctx.addServletMapping("/getresource", "getresource");
 
@@ -164,29 +149,18 @@ public class TestStandardContextResource
         assertEquals(Arrays.asList("resources.jar", "resources2.jar"), ctx
                 
.getServletContext().getAttribute(ServletContext.ORDERED_LIBS));
 
-        ctx.stop();
+        tomcat.getHost().removeChild(ctx);
+        tomcat.getHost().stop();
 
-        LifecycleListener[] listener1 = ctx.findLifecycleListeners();
-        // change ordering and reload
-        ContextConfig config1 = new ContextConfig() {
-            @Override
-            protected WebXml createWebXml() {
-                WebXml wxml = new WebXml();
-                wxml.addAbsoluteOrdering("resources2");
-                wxml.addAbsoluteOrdering("resources");
-                return wxml;
-            }
-        };
-        // prevent it from looking ( if it finds one - it'll have dup error )
-        config1.setDefaultWebXml(Constants.NoDefaultWebXml);
-        listener1[1] = config1;
-        // Need to init since context won't call init
-        config1.lifecycleEvent(
-                new LifecycleEvent(ctx, Lifecycle.AFTER_INIT_EVENT, null));
+        // change ordering
+        absoluteOrderConfig.swap();
+
+        ctx = (StandardContext) tomcat.addWebapp(null, "/test",
+                appDir.getAbsolutePath(), absoluteOrderConfig);
         Tomcat.addServlet(ctx, "getresource", new GetResourceServlet());
         ctx.addServletMapping("/getresource", "getresource");
 
-        ctx.start();
+        tomcat.getHost().start();
 
         assertPageContains("/test/getresource?path=/resourceF.jsp",
         "<p>resourceF.jsp in resources2.jar</p>");
@@ -198,6 +172,36 @@ public class TestStandardContextResource
                 
.getServletContext().getAttribute(ServletContext.ORDERED_LIBS));
     }
 
+
+    public static class AbsoluteOrderContextConfig extends ContextConfig {
+
+        private boolean swap = false;
+
+        public AbsoluteOrderContextConfig() {
+            super();
+            // Prevent it from looking (if it finds one - it'll have dup error)
+            setDefaultWebXml(Constants.NoDefaultWebXml);
+        }
+
+        @Override
+        protected WebXml createWebXml() {
+            WebXml wxml = new WebXml();
+            if (swap) {
+                wxml.addAbsoluteOrdering("resources2");
+                wxml.addAbsoluteOrdering("resources");
+            } else {
+                wxml.addAbsoluteOrdering("resources");
+                wxml.addAbsoluteOrdering("resources2");
+            }
+            return wxml;
+        }
+
+        protected void swap() {
+            swap = !swap;
+        }
+    }
+
+
     @Test
     public void testResources2() throws Exception {
         Tomcat tomcat = getTomcatInstance();



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

Reply via email to