Author: rmannibucau Date: Mon May 13 07:11:31 2013 New Revision: 1481713 URL: http://svn.apache.org/r1481713 Log: DataSourceTest was testing almost nothing - making it testing what it was designed for + fixing it for remote case
Added: tomee/tomee/trunk/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/datasource/PojoServlet.java Modified: tomee/tomee/trunk/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/datasource/DataSourceTest.java tomee/tomee/trunk/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/contextxml/datasource/context.xml tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java Modified: tomee/tomee/trunk/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/datasource/DataSourceTest.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/datasource/DataSourceTest.java?rev=1481713&r1=1481712&r2=1481713&view=diff ============================================================================== --- tomee/tomee/trunk/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/datasource/DataSourceTest.java (original) +++ tomee/tomee/trunk/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/datasource/DataSourceTest.java Mon May 13 07:11:31 2013 @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.openejb.arquillian.tests.contextxml.datasource; +package org.apache.openejb.arquillian.tests.datasource; import org.apache.ziplock.IO; import org.jboss.arquillian.container.test.api.Deployment; @@ -26,14 +26,6 @@ import org.jboss.shrinkwrap.api.spec.Web import org.junit.Test; import org.junit.runner.RunWith; -import javax.annotation.Resource; -import javax.servlet.ServletException; -import javax.servlet.annotation.WebServlet; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.sql.DataSource; -import java.io.IOException; import java.net.URL; /** @@ -49,7 +41,7 @@ public class DataSourceTest { public static WebArchive createDeployment() { WebArchive archive = ShrinkWrap.create(WebArchive.class, DataSourceTest.class.getSimpleName() + ".war") .addClass(PojoServlet.class) - .addAsWebInfResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/contextxml/datasource/context.xml"), "context.xml"); + .addAsManifestResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/contextxml/datasource/context.xml"), "context.xml"); return archive; } @@ -58,17 +50,4 @@ public class DataSourceTest { public void lookupEnvEntryInjectionShouldSucceed() throws Exception { final String output = IO.readString(new URL(url.toExternalForm() + "test")); } - - @WebServlet("/test") - public static class PojoServlet extends HttpServlet { - - @Resource - private DataSource dataSource; - - @Override - protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - - if (dataSource == null) throw new ServletException(); - } - } } Added: tomee/tomee/trunk/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/datasource/PojoServlet.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/datasource/PojoServlet.java?rev=1481713&view=auto ============================================================================== --- tomee/tomee/trunk/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/datasource/PojoServlet.java (added) +++ tomee/tomee/trunk/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/datasource/PojoServlet.java Mon May 13 07:11:31 2013 @@ -0,0 +1,61 @@ +/* + * 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.openejb.arquillian.tests.datasource; + +import javax.annotation.Resource; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.sql.DataSource; +import java.io.IOException; +import java.sql.Connection; +import java.sql.SQLException; + +import static org.junit.Assert.assertEquals; + +@WebServlet("/test") +public class PojoServlet extends HttpServlet { + + @Resource(name = "jdbc/myDB") + private DataSource dataSource; + + @Override + protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + + if (dataSource == null) throw new ServletException(); + + Connection c = null; + try { + c = dataSource.getConnection(); + if (!"jdbc:hsqldb:mem:foo:myDB".equals(c.getMetaData().getURL())) { + throw new ServletException(); + } + } catch (final SQLException e) { + throw new ServletException(e); + } finally { + try { + if (c != null) { + c.close(); + } + } catch (final SQLException e) { + // no-op + } + } + } +} Modified: tomee/tomee/trunk/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/contextxml/datasource/context.xml URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/contextxml/datasource/context.xml?rev=1481713&r1=1481712&r2=1481713&view=diff ============================================================================== --- tomee/tomee/trunk/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/contextxml/datasource/context.xml (original) +++ tomee/tomee/trunk/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/contextxml/datasource/context.xml Mon May 13 07:11:31 2013 @@ -20,7 +20,7 @@ <Resource name="jdbc/myDB" auth="Container" type="javax.sql.DataSource" username="sa" password="" driverClassName="org.hsqldb.jdbcDriver" - url="jdbc:hsqldb:file:data/hsqldb/hsqldb" + url="jdbc:hsqldb:mem:foo:myDB" maxActive="8" /> </Context> Modified: tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java?rev=1481713&r1=1481712&r2=1481713&view=diff ============================================================================== --- tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java (original) +++ tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java Mon May 13 07:11:31 2013 @@ -1014,10 +1014,17 @@ public class TomcatWebAppBuilder impleme final AppModule appModule = loadApplication(standardContext); if (standardContext.getNamingResources() instanceof OpenEJBNamingResource) { + final Collection<String> importedNames = new ArrayList<String>(); // we can get the same resource twice as in tomcat + // add them to the app as resource final OpenEJBNamingResource nr = (OpenEJBNamingResource) standardContext.getNamingResources(); for (ResourceBase resource : nr.getTomcatResources()) { final String name = resource.getName(); + if (!importedNames.contains(name)) { + importedNames.add(name); + } else { + continue; + } boolean found = false; for (ResourceInfo r : SystemInstance.get().getComponent(OpenEjbConfiguration.class).facilities.resources) {