You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2019/09/27 12:20:56 UTC

[tomcat] branch 7.0.x updated: Back-port test changes to take account of LifecycleBase refactoring

This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 7.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/7.0.x by this push:
     new ffa7833  Back-port test changes to take account of LifecycleBase refactoring
ffa7833 is described below

commit ffa7833f0f22f7ea746e1366f771658439f4bac1
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri Sep 27 13:19:58 2019 +0100

    Back-port test changes to take account of LifecycleBase refactoring
---
 .../core/TestStandardContextResources.java         | 82 ++++++++++++----------
 1 file changed, 43 insertions(+), 39 deletions(-)

diff --git a/test/org/apache/catalina/core/TestStandardContextResources.java b/test/org/apache/catalina/core/TestStandardContextResources.java
index eab5797..0485228 100644
--- a/test/org/apache/catalina/core/TestStandardContextResources.java
+++ b/test/org/apache/catalina/core/TestStandardContextResources.java
@@ -36,9 +36,6 @@ import org.junit.Assert;
 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.deploy.WebXml;
 import org.apache.catalina.startup.Constants;
 import org.apache.catalina.startup.ContextConfig;
@@ -131,26 +128,14 @@ public class TestStandardContextResources extends TomcatBaseTest {
     @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();
-        Assert.assertEquals(3,listener.length);
-        Assert.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 TestStandardContextResources extends TomcatBaseTest {
         Assert.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 TestStandardContextResources extends TomcatBaseTest {
                 .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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org