--- org/apache/naming/resources/TestJndiLookupName.java (revision 0) +++ org/apache/naming/resources/TestJndiLookupName.java (revision 0) @@ -0,0 +1,238 @@ +/* + * 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.naming.resources; + +import java.io.StringReader; + +import org.apache.catalina.deploy.ContextEjb; +import org.apache.catalina.deploy.ContextEnvironment; +import org.apache.catalina.deploy.ContextLocalEjb; +import org.apache.catalina.deploy.ContextResource; +import org.apache.catalina.deploy.ContextResourceEnvRef; +import org.apache.catalina.deploy.ContextService; +import org.apache.catalina.deploy.MessageDestination; +import org.apache.catalina.deploy.MessageDestinationRef; +import org.apache.catalina.deploy.WebXml; +import org.apache.catalina.startup.DigesterFactory; +import org.apache.catalina.startup.TomcatBaseTest; +import org.apache.catalina.startup.WebRuleSet; +import org.apache.tomcat.util.digester.Digester; + +/** + * Unit test for testing lookup name. + * @author Gurkan Erdogdu + * @version $Revision: $ + */ +public class TestJndiLookupName extends TomcatBaseTest { + + private Digester digester; + + public void setUp() throws Exception{ + super.setUp(); + this.digester = DigesterFactory.newDigester(false,false,new WebRuleSet(false)); + } + + /** + * Context Environment + */ + public void testLookupNameForContextEnvironment() throws Exception { + + WebXml webXml = new WebXml(); + webXml.setPublicId("web-app_3_0.xsd"); + + ContextEnvironment env = new ContextEnvironment(); + env.setDescription("My Context Desc"); + env.setName("jndiName"); + env.setLookupName("java:/my/injection"); + + webXml.addEnvEntry(env); + + WebXml parsed = new WebXml(); + this.digester.push(parsed); + //Lets do revers + this.digester.parse(new StringReader(webXml.toXml())); + + ContextEnvironment contextEnv = parsed.getEnvEntries().get("jndiName"); + assertEquals("java:/my/injection", contextEnv.getLookupName()); + } + + /** + * Context Ejb + */ + public void testLookupNameForContextEjb() throws Exception { + + WebXml webXml = new WebXml(); + webXml.setPublicId("web-app_3_0.xsd"); + + ContextEjb ejbRef = new ContextEjb(); + ejbRef.setDescription("My Context Desc"); + ejbRef.setName("jndiName"); + ejbRef.setLookupName("java:/my/injection"); + + webXml.addEjbRef(ejbRef); + + WebXml parsed = new WebXml(); + this.digester.push(parsed); + //Lets do revers + this.digester.parse(new StringReader(webXml.toXml())); + + ContextEjb parsedEjb = parsed.getEjbRefs().get("jndiName"); + assertEquals("java:/my/injection", parsedEjb.getLookupName()); + } + + /** + * Context Local Ejb + */ + public void testLookupNameForContextLocalEjb() throws Exception { + + WebXml webXml = new WebXml(); + webXml.setPublicId("web-app_3_0.xsd"); + + ContextLocalEjb ejbRef = new ContextLocalEjb(); + ejbRef.setDescription("My Context Desc"); + ejbRef.setName("jndiName"); + ejbRef.setLookupName("java:/my/injection"); + + webXml.addEjbLocalRef(ejbRef); + + WebXml parsed = new WebXml(); + this.digester.push(parsed); + //Lets do revers + this.digester.parse(new StringReader(webXml.toXml())); + + ContextLocalEjb parsedEjb = parsed.getEjbLocalRefs().get("jndiName"); + assertEquals("java:/my/injection", parsedEjb.getLookupName()); + } + + /** + * Context Service + */ + public void testLookupNameForContextService() throws Exception { + + WebXml webXml = new WebXml(); + webXml.setPublicId("web-app_3_0.xsd"); + + ContextService serviceRef = new ContextService(); + serviceRef.setDescription("My Context Desc"); + serviceRef.setName("jndiName"); + serviceRef.setLookupName("java:/my/injection"); + + webXml.addServiceRef(serviceRef); + + WebXml parsed = new WebXml(); + this.digester.push(parsed); + //Lets do revers + this.digester.parse(new StringReader(webXml.toXml())); + + ContextService parsedRef = parsed.getServiceRefs().get("jndiName"); + assertEquals("java:/my/injection", parsedRef.getLookupName()); + } + + /** + * Context Resource + */ + public void testLookupNameForContextResource() throws Exception { + + WebXml webXml = new WebXml(); + webXml.setPublicId("web-app_3_0.xsd"); + + ContextResource serviceRef = new ContextResource(); + serviceRef.setDescription("My Context Desc"); + serviceRef.setName("jndiName"); + serviceRef.setLookupName("java:/my/injection"); + + webXml.addResourceRef(serviceRef); + WebXml parsed = new WebXml(); + this.digester.push(parsed); + //Lets do revers + this.digester.parse(new StringReader(webXml.toXml())); + + ContextResource parsedRef = parsed.getResourceRefs().get("jndiName"); + assertEquals("java:/my/injection", parsedRef.getLookupName()); + } + + /** + * Context Resource Env + */ + public void testLookupNameForContextResourceEnv() throws Exception { + + WebXml webXml = new WebXml(); + webXml.setPublicId("web-app_3_0.xsd"); + + ContextResourceEnvRef serviceRef = new ContextResourceEnvRef(); + serviceRef.setDescription("My Context Desc"); + serviceRef.setName("jndiName"); + serviceRef.setLookupName("java:/my/injection"); + + webXml.addResourceEnvRef(serviceRef); + WebXml parsed = new WebXml(); + this.digester.push(parsed); + //Lets do revers + this.digester.parse(new StringReader(webXml.toXml())); + + ContextResourceEnvRef parsedRef = parsed.getResourceEnvRefs().get("jndiName"); + assertEquals("java:/my/injection", parsedRef.getLookupName()); + } + + /** + * Message Destination Ref + */ + public void testLookupNameForMessageDestinationRef() throws Exception { + + WebXml webXml = new WebXml(); + webXml.setPublicId("web-app_3_0.xsd"); + + MessageDestinationRef serviceRef = new MessageDestinationRef(); + serviceRef.setDescription("My Context Desc"); + serviceRef.setName("jndiName"); + serviceRef.setLookupName("java:/my/injection"); + + webXml.addMessageDestinationRef(serviceRef); + WebXml parsed = new WebXml(); + this.digester.push(parsed); + //Lets do revers + this.digester.parse(new StringReader(webXml.toXml())); + + MessageDestinationRef parsedRef = parsed.getMessageDestinationRefs().get("jndiName"); + assertEquals("java:/my/injection", parsedRef.getLookupName()); + } + + /** + * Message Destination + */ + public void testLookupNameForMessageDestination() throws Exception { + + WebXml webXml = new WebXml(); + webXml.setPublicId("web-app_3_0.xsd"); + + MessageDestination serviceRef = new MessageDestination(); + serviceRef.setDescription("My Context Desc"); + serviceRef.setName("jndiName"); + serviceRef.setLookupName("java:/my/injection"); + + webXml.addMessageDestination(serviceRef); + WebXml parsed = new WebXml(); + this.digester.push(parsed); + //Lets do revers + this.digester.parse(new StringReader(webXml.toXml())); + + MessageDestination parsedRef = parsed.getMessageDestinations().get("jndiName"); + assertEquals("java:/my/injection", parsedRef.getLookupName()); + } + + +} + native