Bug 432512 - [enterprise] Introduce generic service provider for tomcat naming resources
diff --git a/build-web/build.xml b/build-web/build.xml
index 782de92..5770275 100644
--- a/build-web/build.xml
+++ b/build-web/build.xml
@@ -10,6 +10,7 @@
<pathelement location="../org.eclipse.virgo.web.enterprise.applistener"/>
<pathelement location="../org.eclipse.virgo.web.enterprise.jsf.support"/>
<pathelement location="../org.eclipse.virgo.web.enterprise.openejb.initialiser"/>
+ <pathelement location="../org.eclipse.virgo.web.enterprise.openejb.tomcat.factory"/>
<pathelement location="../org.eclipse.virgo.web.enterprise.openwebbeans.initialiser"/>
<pathelement location="../org.eclipse.virgo.web.enterprise.services.accessor"/>
<pathelement location="../org.eclipse.virgo.web.enterprise.security"/>
diff --git a/build.versions b/build.versions
index 3e68e9e..a87f63b 100644
--- a/build.versions
+++ b/build.versions
@@ -57,6 +57,9 @@
org.apache.catalina=7.0.35.v201302131125
org.apache.catalina.ha=7.0.35.v201302131607
org.apache.catalina.tribes=7.0.35.v201302140645
+org.apache.juli.extras=7.0.35.v201302120746
+org.apache.tomcat.util=7.0.35.v201302140645
+org.apache.tomcat.api=7.0.35.v201302120746
org.apache.taglibs=1.1.2.v20110517
javax.servlet.jsp=2.2.0.v201112011158
javax.servlet.jsp.jstl=1.2.0.v20110728
diff --git a/org.eclipse.virgo.web.enterprise.appdeployer/src/main/java/org/eclipse/virgo/web/enterprise/openejb/deployer/VirgoDeployerEjb.java b/org.eclipse.virgo.web.enterprise.appdeployer/src/main/java/org/eclipse/virgo/web/enterprise/openejb/deployer/VirgoDeployerEjb.java
index d4d1329..6d8b4e1 100755
--- a/org.eclipse.virgo.web.enterprise.appdeployer/src/main/java/org/eclipse/virgo/web/enterprise/openejb/deployer/VirgoDeployerEjb.java
+++ b/org.eclipse.virgo.web.enterprise.appdeployer/src/main/java/org/eclipse/virgo/web/enterprise/openejb/deployer/VirgoDeployerEjb.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 SAP AG
+ * Copyright (c) 2012 - 2014 SAP AG
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -20,9 +20,6 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -43,7 +40,7 @@
import org.apache.catalina.core.StandardContext;
import org.apache.catalina.deploy.ContextResource;
-import org.apache.catalina.deploy.NamingResources;
+import org.apache.catalina.deploy.ContextResourceEnvRef;
import org.apache.catalina.deploy.ResourceBase;
import org.apache.naming.ContextAccessController;
import org.apache.openejb.AppContext;
@@ -59,17 +56,14 @@
import org.apache.openejb.assembler.classic.PersistenceUnitInfo;
import org.apache.openejb.assembler.classic.WebAppInfo;
import org.apache.openejb.config.AppModule;
-import org.apache.openejb.config.AutoConfig;
import org.apache.openejb.config.ConfigurationFactory;
import org.apache.openejb.config.DeploymentLoader;
import org.apache.openejb.config.DeploymentModule;
import org.apache.openejb.config.DynamicDeployer;
import org.apache.openejb.config.FinderFactory;
-import org.apache.openejb.config.ServiceUtils;
import org.apache.openejb.config.WebModule;
import org.apache.openejb.config.WebappAggregatedArchive;
import org.apache.openejb.config.sys.Resource;
-import org.apache.openejb.config.sys.ServiceProvider;
import org.apache.openejb.loader.SystemInstance;
import org.apache.openejb.util.Contexts;
import org.apache.xbean.finder.AnnotationFinder;
@@ -108,9 +102,8 @@
private static final String META_INF = "META-INF";
private static final String DISABLED_SUFFIX = ".disabled";
private static final String RESOURCES_XML = "resources.xml";
- private static final String PROVIDER = "provider";
private static final String TRANSACTION_TYPE_PROP = "transactionType";
- private static final String STANDARD_CONTEXT_PROPERTY = "CatalinaStandardContext";
+ private static final String STANDARD_CONTEXT_PROPERTY = "standardContext";
private static final String DATA_SOURCE = "DataSource";
private static final String OPENEJB_JDBC_DRIVER = "JdbcDriver";
private static final String TOMCAT_DRIVER_CLASS_NAME = "driverClassName";
@@ -118,11 +111,11 @@
private static final String TOMCAT_JDBC_URL = "url";
private static final String OPENEJB_USERNAME = "UserName";
private static final String TOMCAT_USERNAME = "username";
+ private static final String TOMCAT_PROVIDER_FACTORY = "org.eclipse.virgo.tomcat:ProvidedByTomcat";
private final DeploymentLoader deploymentLoader;
private final ConfigurationFactory configurationFactory;
private final Assembler assembler;
- private List<ServiceProvider> resourceProviders;
private final String webContextPath;
private final ClassLoader servletClassLoader;
private DynamicDeployer dynamicDeployer = null;
@@ -142,13 +135,6 @@
configurationFactory = new ConfigurationFactory();
}
assembler = (Assembler) SystemInstance.get().getComponent(org.apache.openejb.spi.Assembler.class);
-
- try {
- resourceProviders = ServiceUtils
- .getServiceProvidersByServiceType("Resource");
- } catch (OpenEJBException e) {
- resourceProviders = new ArrayList<ServiceProvider>(0);
- }
}
public AppInfo deploy(String loc, StandardContext standardContext) throws OpenEJBException {
@@ -524,88 +510,60 @@
StandardContext standardContext) {
ContextResource[] contextResources = standardContext
.getNamingResources().findResources();
+ ContextResourceEnvRef[] contextEnvResources = standardContext
+ .getNamingResources().findResourceEnvRefs();
- if (contextResources == null) {
- return;
+ if (contextResources != null) {
+ for (ContextResource contextResource : contextResources) {
+ if (!"UserTransaction".equals(contextResource.getName())) {
+ Resource resource = createResource(contextResource,
+ standardContext, appModule.getModuleId());
+ appModule.getResources().add(resource);
+ }
+ }
}
- for (ContextResource contextResource : contextResources) {
- if (isResourceTypeSupported(contextResource)) {
- Resource resource = createResource(contextResource,
- standardContext, appModule.getModuleId());
- appModule.getResources().add(resource);
- }
- }
-
- final Collection<String> tomcatResources = getResourcesNames(standardContext
- .getNamingResources());
- AutoConfig.PROVIDED_RESOURCES.set(tomcatResources);
- AutoConfig.PROVIDED_RESOURCES_PREFIX.set("java:/comp/env/");
+ if (contextEnvResources != null) {
+ for (ContextResourceEnvRef contextEnvResource : contextEnvResources) {
+ if (!"UserTransaction".equals(contextEnvResource.getName())) {
+ Resource resource = createResource(contextEnvResource,
+ standardContext, appModule.getModuleId());
+ appModule.getResources().add(resource);
+ }
+ }
+ }
}
- private Collection<String> getResourcesNames(
- final NamingResources namingResources) {
- final Collection<String> names = new ArrayList<String>();
- final Collection<ResourceBase> tomcatResources = new ArrayList<ResourceBase>();
- tomcatResources.addAll(Arrays.asList(namingResources.findResources()));
- tomcatResources
- .addAll(Arrays.asList(namingResources.findEnvironments()));
- tomcatResources.addAll(Arrays.asList(namingResources
- .findResourceLinks()));
- tomcatResources.addAll(Arrays.asList(namingResources.findServices()));
- tomcatResources.addAll(Arrays.asList(namingResources
- .findResourceEnvRefs()));
-
- for (ResourceBase resource : tomcatResources) {
- String processedResourceName = getResourceNameFromTomcatResource(
- names, resource);
- if (processedResourceName != null) {
- names.add(processedResourceName);
- }
- }
- return names;
- }
-
- private String getResourceNameFromTomcatResource(
- final Collection<String> names, ResourceBase resource) {
- final String name = resource.getName();
- final String mappedName = (String) resource.getProperty("mappedName");
- String processedResourceName = name;
- if (mappedName != null && !mappedName.isEmpty()) {
- processedResourceName = mappedName;
- }
- return processedResourceName;
- }
-
- private Resource createResource(final ContextResource contextResource,
+ private Resource createResource(final ResourceBase resourceBase,
StandardContext standardContext, final String appModuleId) {
- final String id = appModuleId + '/' + contextResource.getName();
- final String type = contextResource.getType();
- String provider = (String) contextResource.getProperty(PROVIDER);
- Resource resource = new Resource(id, type, provider);
- populateResourceProperties(contextResource, resource, standardContext);
+ final String mappedName = (String) resourceBase.getProperty("mappedName");
+ final String id;
+ if (mappedName == null) {
+ id = appModuleId + '/' + resourceBase.getName();
+ } else {
+ id = appModuleId + '/' + mappedName;
+ }
+ final String type = resourceBase.getType();
+ Resource resource = new Resource(id, type, TOMCAT_PROVIDER_FACTORY);
+ populateResourceProperties(resourceBase, resource, standardContext);
return resource;
}
- private void populateResourceProperties(ContextResource contextResource,
+ private void populateResourceProperties(ResourceBase resourceBase,
Resource resource, StandardContext standardContext) {
Properties resProperties = resource.getProperties();
- Iterator<String> ctxResPropertiesItr = contextResource.listProperties();
- boolean isDataSource = contextResource.getType().contains(DATA_SOURCE);
+ resProperties.setProperty("jndiName", resourceBase.getName());
+ resProperties.put(STANDARD_CONTEXT_PROPERTY, standardContext);
+ Iterator<String> ctxResPropertiesItr = resourceBase.listProperties();
+ boolean isDataSource = resourceBase.getType().contains(DATA_SOURCE);
while (ctxResPropertiesItr.hasNext()) {
String key = ctxResPropertiesItr.next();
- if (PROVIDER.equals(key) || key.length() == 0) {
- continue;
- }
- final Object value = contextResource.getProperty(key);
+ final Object value = resourceBase.getProperty(key);
if (isDataSource) {
key = transformKey(key);
}
resProperties.put(key, value);
}
- if (isDataSource) {
- resProperties.put(STANDARD_CONTEXT_PROPERTY, standardContext);
- }
}
private String transformKey(String key) {
@@ -626,30 +584,4 @@
return transformedKey;
}
-
- private boolean isResourceTypeSupported(ContextResource contextResource) {
- String resourceType = contextResource.getType();
- for (ServiceProvider serviceProvider : resourceProviders) {
- if (serviceProvider.getTypes().contains(resourceType)) {
- return true;
- }
- }
-
- String provider = (String) contextResource.getProperty(PROVIDER);
- if (provider == null) {
- return false;
- }
-
- try {
- ServiceProvider serviceProvider = ServiceUtils
- .getServiceProvider(provider);
- if (serviceProvider.getTypes().contains(resourceType)) {
- return true;
- }
- } catch (OpenEJBException e) {
- return false;
- }
-
- return false;
- }
}
diff --git a/org.eclipse.virgo.web.enterprise.openejb.tomcat.factory/.classpath b/org.eclipse.virgo.web.enterprise.openejb.tomcat.factory/.classpath
new file mode 100755
index 0000000..0921b08
--- /dev/null
+++ b/org.eclipse.virgo.web.enterprise.openejb.tomcat.factory/.classpath
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src/test/java"/>
+ <classpathentry kind="src" path="src/test/resources"/>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="src" path="src/main/resources"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="var" path="IVY_CACHE/org.eclipse.virgo.mirrored/org.apache.catalina/7.0.35.v201302131125/org.apache.catalina-7.0.35.v201302131125.jar" sourcepath="/IVY_CACHE/org.eclipse.virgo.mirrored/org.apache.catalina/7.0.35.v201302131125/org.apache.catalina.source-7.0.35.v201302131125.jar"/>
+ <classpathentry kind="var" path="IVY_CACHE/org.eclipse.virgo.mirrored/org.apache.openejb.core/4.5.2.virgo-1/org.apache.openejb.core-4.5.2.virgo-1.jar" sourcepath="/IVY_CACHE/org.eclipse.virgo.mirrored/org.apache.openejb.core/4.0.0.beta-2_v201205260545-virgo-2/org.apache.openejb.core.source-4.0.0.beta-2_v201205260545-virgo-2.jar"/>
+ <classpathentry kind="var" path="IVY_CACHE/org.junit/com.springsource.org.junit/4.7.0/com.springsource.org.junit-4.7.0.jar" sourcepath="/IVY_CACHE/org.junit/com.springsource.org.junit/4.7.0/com.springsource.org.junit-sources-4.7.0.jar"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/org.eclipse.virgo.web.enterprise.openejb.tomcat.factory/.project b/org.eclipse.virgo.web.enterprise.openejb.tomcat.factory/.project
new file mode 100755
index 0000000..85ccce3
--- /dev/null
+++ b/org.eclipse.virgo.web.enterprise.openejb.tomcat.factory/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.virgo.web.enterprise.openejb.tomcat.factory</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/org.eclipse.virgo.web.enterprise.openejb.tomcat.factory/build.properties b/org.eclipse.virgo.web.enterprise.openejb.tomcat.factory/build.properties
new file mode 100755
index 0000000..41eb6ad
--- /dev/null
+++ b/org.eclipse.virgo.web.enterprise.openejb.tomcat.factory/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
diff --git a/org.eclipse.virgo.web.enterprise.openejb.tomcat.factory/build.xml b/org.eclipse.virgo.web.enterprise.openejb.tomcat.factory/build.xml
new file mode 100755
index 0000000..cf8e458
--- /dev/null
+++ b/org.eclipse.virgo.web.enterprise.openejb.tomcat.factory/build.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="org.eclipse.virgo.web.enterprise.openejb.tomcat.factory">
+
+ <property name="findbugs.exclude.file" value="${basedir}/findbugs-exclude.xml"/>
+ <property file="${basedir}/../build.properties"/>
+ <property file="${basedir}/../build.versions"/>
+ <import file="${basedir}/../virgo-build/standard/default.xml"/>
+
+</project>
diff --git a/org.eclipse.virgo.web.enterprise.openejb.tomcat.factory/ivy.xml b/org.eclipse.virgo.web.enterprise.openejb.tomcat.factory/ivy.xml
new file mode 100755
index 0000000..a21baa9
--- /dev/null
+++ b/org.eclipse.virgo.web.enterprise.openejb.tomcat.factory/ivy.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ivy-module xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd" version="2.0">
+
+ <info organisation="${project.organisation}" module="${ant.project.name}"/>
+
+ <configurations>
+ <include file="${virgo.build.dir}/common/default-ivy-configurations.xml"/>
+ </configurations>
+
+ <publications>
+ <artifact name="${ant.project.name}"/>
+ <artifact name="${ant.project.name}-sources" type="src" ext="jar"/>
+ </publications>
+
+ <dependencies>
+ <dependency org="org.eclipse.virgo.mirrored" name="org.apache.openejb.core" rev="${org.apache.openejb.core}" conf="compile->runtime"/>
+ <dependency org="org.eclipse.virgo.mirrored" name="org.apache.catalina" rev="${org.apache.catalina}" conf="compile->runtime"/>
+
+ <!-- Test dependencies -->
+ <dependency org="org.junit" name="com.springsource.org.junit" rev="${org.junit}" conf="test->runtime"/>
+ <dependency org="org.eclipse.virgo.mirrored" name="org.apache.juli.extras" rev="${org.apache.juli.extras}" conf="test->runtime"/>
+ <dependency org="org.eclipse.virgo.mirrored" name="org.apache.tomcat.util" rev="${org.apache.tomcat.util}" conf="test->runtime"/>
+ <dependency org="org.eclipse.virgo.mirrored" name="org.apache.tomcat.api" rev="${org.apache.tomcat.api}" conf="test->runtime"/>
+ <dependency org="org.eclipse.virgo.mirrored" name="org.apache.coyote" rev="${org.apache.coyote}" conf="test->runtime"/>
+ <dependency org="org.eclipse.virgo.mirrored" name="javax.servlet" rev="${javax.servlet}" conf="compile->runtime"/>
+ <dependency org="org.eclipse.virgo.mirrored" name="org.apache.openejb.loader" rev="${org.apache.openejb.loader}" conf="compile->runtime"/>
+ </dependencies>
+
+</ivy-module>
diff --git a/org.eclipse.virgo.web.enterprise.openejb.tomcat.factory/src/main/java/org/eclipse/virgo/web/enterprise/openejb/tomcat/factory/TomcatResourceFactory.java b/org.eclipse.virgo.web.enterprise.openejb.tomcat.factory/src/main/java/org/eclipse/virgo/web/enterprise/openejb/tomcat/factory/TomcatResourceFactory.java
new file mode 100755
index 0000000..4617112
--- /dev/null
+++ b/org.eclipse.virgo.web.enterprise.openejb.tomcat.factory/src/main/java/org/eclipse/virgo/web/enterprise/openejb/tomcat/factory/TomcatResourceFactory.java
@@ -0,0 +1,29 @@
+package org.eclipse.virgo.web.enterprise.openejb.tomcat.factory;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+
+import org.apache.catalina.core.StandardContext;
+
+import org.apache.openejb.util.Logger;
+import org.apache.openejb.util.LogCategory;
+
+public class TomcatResourceFactory {
+ private static final Logger LOGGER = Logger.getInstance(LogCategory.OPENEJB.createChild("tr"), TomcatResourceFactory.class);
+
+ private static final String COMP_ENV_SUBCONTEXT = "comp/env/";
+
+ public static Object create(String jndiName, StandardContext standardContext) throws NamingException {
+ if (standardContext == null) {
+ return null;
+ }
+
+ Context context = standardContext.getNamingContextListener().getNamingContext();
+ try {
+ return context.lookup(COMP_ENV_SUBCONTEXT + jndiName);
+ } catch (NamingException e) {
+ LOGGER.error("Error while looking up " + jndiName, e);
+ throw(e);
+ }
+ }
+}
diff --git a/org.eclipse.virgo.web.enterprise.openejb.tomcat.factory/src/main/resources/META-INF/org.eclipse.virgo.tomcat/service-jar.xml b/org.eclipse.virgo.web.enterprise.openejb.tomcat.factory/src/main/resources/META-INF/org.eclipse.virgo.tomcat/service-jar.xml
new file mode 100755
index 0000000..b240d21
--- /dev/null
+++ b/org.eclipse.virgo.web.enterprise.openejb.tomcat.factory/src/main/resources/META-INF/org.eclipse.virgo.tomcat/service-jar.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+ <ServiceJar>
+ <ServiceProvider
+ id="ProvidedByTomcat"
+ types="javax.sql.DataSource,DataSource,javax.jms.ConnectionFactory,ConnectionFactory,java.lang.Object"
+ service="Resource"
+ class-name="org.eclipse.virgo.web.enterprise.openejb.tomcat.factory.TomcatResourceFactory"
+ factory-name="create"
+ constructor="jndiName, standardContext">
+ jndiName
+ standardContext
+ </ServiceProvider>
+ </ServiceJar>
diff --git a/org.eclipse.virgo.web.enterprise.openejb.tomcat.factory/src/main/resources/about.html b/org.eclipse.virgo.web.enterprise.openejb.tomcat.factory/src/main/resources/about.html
new file mode 100755
index 0000000..c258ef5
--- /dev/null
+++ b/org.eclipse.virgo.web.enterprise.openejb.tomcat.factory/src/main/resources/about.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
+<title>About</title>
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>June 5, 2006</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, "Program" will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party ("Redistributor") and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
+
+</body>
+</html>
\ No newline at end of file
diff --git a/org.eclipse.virgo.web.enterprise.openejb.tomcat.factory/src/test/java/.gitignore b/org.eclipse.virgo.web.enterprise.openejb.tomcat.factory/src/test/java/.gitignore
new file mode 100755
index 0000000..e69de29
--- /dev/null
+++ b/org.eclipse.virgo.web.enterprise.openejb.tomcat.factory/src/test/java/.gitignore
diff --git a/org.eclipse.virgo.web.enterprise.openejb.tomcat.factory/src/test/java/org/eclipse/virgo/web/enterprise/openejb/tomcat/factory/TomcatResourceFactoryTest.java b/org.eclipse.virgo.web.enterprise.openejb.tomcat.factory/src/test/java/org/eclipse/virgo/web/enterprise/openejb/tomcat/factory/TomcatResourceFactoryTest.java
new file mode 100755
index 0000000..faa6d6c
--- /dev/null
+++ b/org.eclipse.virgo.web.enterprise.openejb.tomcat.factory/src/test/java/org/eclipse/virgo/web/enterprise/openejb/tomcat/factory/TomcatResourceFactoryTest.java
@@ -0,0 +1,48 @@
+package org.eclipse.virgo.web.enterprise.openejb.tomcat.factory;
+
+import java.util.Hashtable;
+
+import javax.naming.NamingException;
+
+import junit.framework.Assert;
+
+import org.apache.catalina.core.NamingContextListener;
+import org.apache.catalina.core.StandardContext;
+import org.apache.naming.NamingContext;
+import org.junit.Test;
+
+public class TomcatResourceFactoryTest {
+
+ private static final String name = "testName";
+ private static final String searchName = "comp/env/testName";
+
+ @Test
+ public void testCreate() throws Exception {
+ NamingContext namingContext = new MyNamingContext(null, null);
+ NamingContextListener namingContextListener = new MyNamingContextListener(namingContext);
+ StandardContext standardContext = new StandardContext();
+ standardContext.setNamingContextListener(namingContextListener);
+
+ TomcatResourceFactory.create(name, standardContext);
+ }
+
+ class MyNamingContextListener extends NamingContextListener {
+ public MyNamingContextListener(NamingContext context) {
+ namingContext = context;
+ }
+ }
+
+ class MyNamingContext extends NamingContext {
+
+ public MyNamingContext(Hashtable<String, Object> env, String name)
+ throws NamingException {
+ super(env, name);
+ // TODO Auto-generated constructor stub
+ }
+
+ public Object lookup(String name) {
+ Assert.assertEquals("Wrong lookup name", searchName, name);
+ return null;
+ }
+ }
+}
diff --git a/org.eclipse.virgo.web.enterprise.openejb.tomcat.factory/src/test/resources/.gitignore b/org.eclipse.virgo.web.enterprise.openejb.tomcat.factory/src/test/resources/.gitignore
new file mode 100755
index 0000000..acee03f
--- /dev/null
+++ b/org.eclipse.virgo.web.enterprise.openejb.tomcat.factory/src/test/resources/.gitignore
@@ -0,0 +1,2 @@
+bin
+*.class
diff --git a/org.eclipse.virgo.web.enterprise.openejb.tomcat.factory/template.mf b/org.eclipse.virgo.web.enterprise.openejb.tomcat.factory/template.mf
new file mode 100755
index 0000000..c96066b
--- /dev/null
+++ b/org.eclipse.virgo.web.enterprise.openejb.tomcat.factory/template.mf
@@ -0,0 +1,15 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Virgo Web Enterprise OpenEJB Generic Service Provider
+Bundle-SymbolicName: org.eclipse.virgo.web.enterprise.openejb.tomcat.factory
+Bundle-Version: ${version}
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Import-Template: javax.naming;version="0",
+ org.apache.catalina;version="0",
+ org.apache.catalina.core;version="0"
+Excluded-Imports:
+ org.apache.openejb.util;version="0",
+ org.apache.naming;version="0"
+Excluded-Exports:
+ *
+Fragment-Host: org.apache.openejb.core