tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r937541 - /tomcat/trunk/test/org/apache/catalina/core/TestNamingContextListener.java
Date Fri, 23 Apr 2010 22:19:12 GMT
Author: markt
Date: Fri Apr 23 22:19:12 2010
New Revision: 937541

URL: http://svn.apache.org/viewvc?rev=937541&view=rev
Log:
Add test case for bug 49132.
Check JNDI is available when ServletContextListeners start

Added:
    tomcat/trunk/test/org/apache/catalina/core/TestNamingContextListener.java   (with props)

Added: tomcat/trunk/test/org/apache/catalina/core/TestNamingContextListener.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/core/TestNamingContextListener.java?rev=937541&view=auto
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/core/TestNamingContextListener.java (added)
+++ tomcat/trunk/test/org/apache/catalina/core/TestNamingContextListener.java Fri Apr 23 22:19:12
2010
@@ -0,0 +1,85 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.catalina.core;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+import org.apache.catalina.LifecycleState;
+import org.apache.catalina.deploy.ContextEnvironment;
+import org.apache.catalina.startup.TomcatBaseTest;
+import org.apache.catalina.startup.Tomcat;
+
+public class TestNamingContextListener extends TomcatBaseTest {
+
+    private static final String JNDI_NAME = "TestName";
+    private static final String JNDI_VALUE= "Test Value";
+
+    /** 
+     * Test JNDI is available to ServletContextListeners.
+     */
+    public void testBug49132() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+        
+        // Must have a real docBase - just use temp
+        org.apache.catalina.Context ctx = 
+            tomcat.addContext("/", System.getProperty("java.io.tmpdir"));
+        
+        // Enable JNDI - it is disabled by default
+        tomcat.enableNaming();
+
+        ContextEnvironment environment = new ContextEnvironment();
+        environment.setType(JNDI_VALUE.getClass().getName());
+        environment.setName(JNDI_NAME);
+        environment.setValue(JNDI_VALUE);
+        ctx.getNamingResources().addEnvironment(environment);
+        
+        ctx.addApplicationListener(Bug49132Listener.class.getName());
+        
+        tomcat.start();
+
+        assertEquals(LifecycleState.STARTED, ctx.getState());
+    }
+
+    public static final class Bug49132Listener implements ServletContextListener {
+
+        @Override
+        public void contextDestroyed(ServletContextEvent sce) {
+            // NOOP
+        }
+
+        @Override
+        public void contextInitialized(ServletContextEvent sce) {
+            javax.naming.Context initCtx;
+            try {
+                initCtx = new InitialContext();
+                javax.naming.Context envCtx =
+                    (javax.naming.Context) initCtx.lookup("java:comp/env");
+                String value = (String) envCtx.lookup(JNDI_NAME);
+                if (!JNDI_VALUE.equals(value)) {
+                    throw new RuntimeException();
+                }
+            } catch (NamingException e) {
+                throw new RuntimeException(e);
+            }
+        }
+    }
+
+}

Propchange: tomcat/trunk/test/org/apache/catalina/core/TestNamingContextListener.java
------------------------------------------------------------------------------
    svn:eol-style = native



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


Mime
View raw message