Add a test case for global naming resources with embedded
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 4 Feb 2010 23:18:12 +0000 (23:18 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 4 Feb 2010 23:18:12 +0000 (23:18 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@906723 13f79535-47bb-0310-9956-ffa450edef68

test/org/apache/catalina/startup/TestTomcat.java

index 649dc7c..40ae2f5 100644 (file)
@@ -36,6 +36,7 @@ import javax.servlet.http.HttpServletResponse;
 
 import org.apache.catalina.core.StandardContext;
 import org.apache.catalina.deploy.ContextEnvironment;
+import org.apache.catalina.deploy.ContextResourceLink;
 import org.apache.catalina.realm.GenericPrincipal;
 import org.apache.catalina.realm.RealmBase;
 import org.apache.tomcat.util.buf.ByteChunk;
@@ -252,6 +253,41 @@ public class TestTomcat extends TomcatBaseTest {
         assertEquals("Hello, Tomcat User", res.toString());
     }
 
+    /** 
+     * Test for enabling JNDI and using global resources.
+     */
+    public void testEnableNamingGlobal() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+        
+        // Must have a real docBase - just use temp
+        StandardContext ctx = 
+            tomcat.addContext("/", System.getProperty("java.io.tmpdir"));
+        
+        // You can customise the context by calling its API
+        
+        // Enable JNDI - it is disabled by default
+        tomcat.enableNaming();
+
+        ContextEnvironment environment = new ContextEnvironment();
+        environment.setType("java.lang.String");
+        environment.setName("globalTest");
+        environment.setValue("Tomcat User");
+        tomcat.getServer().getGlobalNamingResources().addEnvironment(environment);
+        
+        ContextResourceLink link = new ContextResourceLink();
+        link.setGlobal("globalTest");
+        link.setName(HelloWorldJndi.JNDI_ENV_NAME);
+        ctx.getNamingResources().addResourceLink(link);
+        
+        Tomcat.addServlet(ctx, "jndiServlet", new HelloWorldJndi());
+        ctx.addServletMapping("/", "jndiServlet");
+        
+        tomcat.start();
+        
+        ByteChunk res = getUrl("http://localhost:" + getPort() + "/");
+        assertEquals("Hello, Tomcat User", res.toString());
+    }
+
 
     /**
      * Test for https://issues.apache.org/bugzilla/show_bug.cgi?id=47866