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

remm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/main by this push:
     new cd59ca905e Add test for custom wrapper related classes
cd59ca905e is described below

commit cd59ca905e178372cd23075d7f277d07b0712b1e
Author: remm <r...@apache.org>
AuthorDate: Tue Nov 12 16:48:47 2024 +0100

    Add test for custom wrapper related classes
---
 .../apache/catalina/core/TestStandardContext.java  | 46 ++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/test/org/apache/catalina/core/TestStandardContext.java 
b/test/org/apache/catalina/core/TestStandardContext.java
index 9070963476..97bb169ceb 100644
--- a/test/org/apache/catalina/core/TestStandardContext.java
+++ b/test/org/apache/catalina/core/TestStandardContext.java
@@ -52,6 +52,8 @@ import org.hamcrest.MatcherAssert;
 import org.junit.Assert;
 import org.junit.Test;
 
+import org.apache.catalina.ContainerEvent;
+import org.apache.catalina.ContainerListener;
 import org.apache.catalina.Context;
 import org.apache.catalina.Engine;
 import org.apache.catalina.Host;
@@ -1066,4 +1068,48 @@ public class TestStandardContext extends TomcatBaseTest {
 
         Assert.assertEquals("/engine/hostcontext", result);
     }
+
+    @Test
+    public void testWrapperListeners() throws Exception {
+        // Setup Tomcat instance
+        Tomcat tomcat = getTomcatInstance();
+
+        // No file system docBase required
+        Context ctx = tomcat.addContext("/test", null);
+        
ctx.setWrapperClass("org.apache.catalina.core.TestStandardContext$MyWrapperClass");
+        
ctx.addWrapperLifecycle("org.apache.catalina.core.TestStandardContext$MyWrapperLifecycleListener");
+        
ctx.addWrapperListener("org.apache.catalina.core.TestStandardContext$MyWrapperContainerListener");
+        Wrapper w = Tomcat.addServlet(ctx, "something", 
"org.apache.catalina.core.TestStandardContext$Bug51376Servlet");
+
+        tomcat.start();
+
+        w.addInitParameter("foo", "bar");
+
+        Assert.assertTrue(customWrapperClassOk);
+        Assert.assertTrue(containerListenerOk);
+        Assert.assertTrue(lifecycleListenerOk);
+    }
+
+    private static boolean customWrapperClassOk = false;
+    public static class MyWrapperClass extends StandardWrapper {
+        @Override
+        protected void startInternal() throws LifecycleException {
+            super.startInternal();
+            customWrapperClassOk = true;
+        }
+    }
+    private static boolean containerListenerOk = false;
+    public static class MyWrapperContainerListener implements 
ContainerListener {
+        @Override
+        public void containerEvent(ContainerEvent event) {
+            containerListenerOk = true;
+        }
+    }
+    private static boolean lifecycleListenerOk = false;
+    public static class MyWrapperLifecycleListener implements 
LifecycleListener {
+        @Override
+        public void lifecycleEvent(LifecycleEvent event) {
+            lifecycleListenerOk = true;
+        }
+    }
 }


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

Reply via email to