You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2013/05/30 18:35:15 UTC
svn commit: r1487920 - in /tomee/tomee/trunk/container/openejb-core/src:
main/java/org/apache/openejb/config/ main/java/org/apache/openejb/testing/
test/java/org/apache/openejb/testing/ test/resources/
Author: rmannibucau
Date: Thu May 30 16:35:15 2013
New Revision: 1487920
URL: http://svn.apache.org/r1487920
Log:
OPENEJB-2029 Openejb for app composer
Added:
tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/testing/AppComposerOpenejbConfigTest.java
tomee/tomee/trunk/container/openejb-core/src/test/resources/custom-openejb.xml
Modified:
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java
Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java?rev=1487920&r1=1487919&r2=1487920&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java (original)
+++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java Thu May 30 16:35:15 2013
@@ -432,21 +432,14 @@ public class ConfigurationFactory implem
}
}
- /**
- * Main loop that gets executed when OpenEJB starts up Reads config files and produces the basic "AST" the assembler needs to actually build the contianer system
- * <p/>
- * This method is called by the Assembler once at startup.
- *
- * @return OpenEjbConfiguration
- * @throws OpenEJBException
- */
- @Override
- public OpenEjbConfiguration getOpenEjbConfiguration() throws OpenEJBException {
+ public OpenEjbConfiguration getOpenEjbConfiguration(final Openejb providedConf) throws OpenEJBException {
if (sys != null) {
return sys;
}
- if (configLocation != null) {
+ if (providedConf != null) {
+ openejb = providedConf;
+ } else if (configLocation != null) {
openejb = JaxbOpenejb.readConfig(configLocation);
} else {
openejb = JaxbOpenejb.createOpenejb();
@@ -569,6 +562,19 @@ public class ConfigurationFactory implem
return finished;
}
+ /**
+ * Main loop that gets executed when OpenEJB starts up Reads config files and produces the basic "AST" the assembler needs to actually build the contianer system
+ * <p/>
+ * This method is called by the Assembler once at startup.
+ *
+ * @return OpenEjbConfiguration
+ * @throws OpenEJBException
+ */
+ @Override
+ public OpenEjbConfiguration getOpenEjbConfiguration() throws OpenEJBException {
+ return getOpenEjbConfiguration(null);
+ }
+
private List<File> getDeclaredApps() {
// make a copy of the list because we update it
final List<Deployments> deployments = new ArrayList<Deployments>();
Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java?rev=1487920&r1=1487919&r2=1487920&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java (original)
+++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java Thu May 30 16:35:15 2013
@@ -24,6 +24,7 @@ import org.apache.openejb.OpenEJBRuntime
import org.apache.openejb.OpenEjbContainer;
import org.apache.openejb.assembler.classic.AppInfo;
import org.apache.openejb.assembler.classic.Assembler;
+import org.apache.openejb.assembler.classic.OpenEjbConfiguration;
import org.apache.openejb.assembler.classic.WebAppBuilder;
import org.apache.openejb.cdi.ScopeHelper;
import org.apache.openejb.config.AppModule;
@@ -33,6 +34,8 @@ import org.apache.openejb.config.Deploym
import org.apache.openejb.config.EjbModule;
import org.apache.openejb.config.PersistenceModule;
import org.apache.openejb.config.WebModule;
+import org.apache.openejb.config.sys.JaxbOpenejb;
+import org.apache.openejb.config.sys.Openejb;
import org.apache.openejb.core.LocalInitialContextFactory;
import org.apache.openejb.core.Operation;
import org.apache.openejb.core.ThreadContext;
@@ -67,6 +70,7 @@ import org.apache.xbean.finder.IAnnotati
import org.apache.xbean.finder.ResourceFinder;
import org.apache.xbean.finder.archive.Archive;
import org.apache.xbean.finder.archive.ClassesArchive;
+import org.xml.sax.InputSource;
import javax.enterprise.context.ConversationScoped;
import javax.enterprise.context.RequestScoped;
@@ -129,11 +133,24 @@ public final class ApplicationComposers
final List<Throwable> errors = new ArrayList<Throwable>();
final List<Method> configs = new ArrayList<Method>();
- configs.addAll(testClassFinder.findAnnotatedMethods(Configuration.class));
+ final List<Method> annotatedConfigurationMethods = testClassFinder.findAnnotatedMethods(Configuration.class);
+ configs.addAll(annotatedConfigurationMethods);
configs.addAll(testClassFinder.findAnnotatedMethods(org.apache.openejb.junit.Configuration.class));
- if (configs.size() > 1) {
- final String gripe = "Test class should have no more than one @Configuration method";
- errors.add(new Exception(gripe));
+ {
+ int nbProp = 0;
+ int nbOpenejb = 0;
+ for (final Method m : annotatedConfigurationMethods) {
+ final Class<?> type = m.getReturnType();
+ if (Openejb.class.isAssignableFrom(type) || String.class.equals(type)) {
+ nbOpenejb++;
+ } else if (Properties.class.isAssignableFrom(type)) {
+ nbProp++;
+ } // else not supported?
+ }
+ if (nbProp > 1 || nbOpenejb > 1) {
+ final String gripe = "Test class should have no more than one @Configuration method by type (Openejb/String or Properties)";
+ errors.add(new Exception(gripe));
+ }
}
if (testClassFinder.findAnnotatedMethods(org.apache.openejb.junit.MockInjector.class).size()
@@ -141,14 +158,6 @@ public final class ApplicationComposers
errors.add(new Exception("Test class should have no more than one @MockInjector method"));
}
- for (final Method method : configs) {
- final Class<?> type = method.getReturnType();
- if (!Properties.class.isAssignableFrom(type)) {
- final String gripe = "@Configuration method must return " + Properties.class.getName();
- errors.add(new Exception(gripe));
- }
- }
-
final List<Method> components = new ArrayList<Method>();
components.addAll(testClassFinder.findAnnotatedMethods(Component.class));
components.addAll(testClassFinder.findAnnotatedMethods(org.apache.openejb.junit.Component.class));
@@ -270,6 +279,7 @@ public final class ApplicationComposers
configuration.setProperty("logging.level.OpenEJB.server.http", "FINE");
}
+ Openejb openejb = null;
final List<Method> configs = new ArrayList<Method>();
configs.addAll(testClassFinder.findAnnotatedMethods(Configuration.class));
configs.addAll(testClassFinder.findAnnotatedMethods(org.apache.openejb.junit.Configuration.class));
@@ -278,6 +288,14 @@ public final class ApplicationComposers
if (o instanceof Properties) {
final Properties properties = (Properties) o;
configuration.putAll(properties);
+ } else if (Openejb.class.isInstance(o)) {
+ openejb = Openejb.class.cast(o);
+ } else if (String.class.isInstance(o)) {
+ final URL url = Thread.currentThread().getContextClassLoader().getResource(String.class.cast(o));
+ if (url ==null) {
+ throw new IllegalArgumentException(o.toString() + " not found");
+ }
+ openejb = JaxbOpenejb.readConfig(new InputSource(url.openStream()));
}
}
@@ -556,7 +574,13 @@ public final class ApplicationComposers
assembler = new Assembler();
SystemInstance.get().setComponent(Assembler.class, assembler);
- assembler.buildContainerSystem(config.getOpenEjbConfiguration());
+ final OpenEjbConfiguration openEjbConfiguration;
+ if (openejb != null) {
+ openEjbConfiguration = config.getOpenEjbConfiguration(openejb);
+ } else {
+ openEjbConfiguration = config.getOpenEjbConfiguration();
+ }
+ assembler.buildContainerSystem(openEjbConfiguration);
if ("true".equals(configuration.getProperty(OpenEjbContainer.OPENEJB_EMBEDDED_REMOTABLE, "false"))
|| (annotation != null || annotationOld != null)) {
Added: tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/testing/AppComposerOpenejbConfigTest.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/testing/AppComposerOpenejbConfigTest.java?rev=1487920&view=auto
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/testing/AppComposerOpenejbConfigTest.java (added)
+++ tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/testing/AppComposerOpenejbConfigTest.java Thu May 30 16:35:15 2013
@@ -0,0 +1,48 @@
+/*
+ * 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.testing;
+
+import org.apache.openejb.jee.EjbJar;
+import org.apache.openejb.junit.ApplicationComposer;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+
+import static org.junit.Assert.assertNotNull;
+
+@RunWith(ApplicationComposer.class)
+public class AppComposerOpenejbConfigTest {
+ @Configuration
+ public String openejbXmlPath() {
+ return "custom-openejb.xml";
+ }
+
+ @Module
+ public EjbJar empty() {
+ return new EjbJar();
+ }
+
+ @AppResource
+ private Context ctx;
+
+ @Test
+ public void checkDsIsHere() throws NamingException {
+ assertNotNull(ctx.lookup("openejb:Resource/app-composer"));
+ }
+}
Added: tomee/tomee/trunk/container/openejb-core/src/test/resources/custom-openejb.xml
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/test/resources/custom-openejb.xml?rev=1487920&view=auto
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/test/resources/custom-openejb.xml (added)
+++ tomee/tomee/trunk/container/openejb-core/src/test/resources/custom-openejb.xml Thu May 30 16:35:15 2013
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<openejb>
+ <Resource id="app-composer" type="DataSource" />
+</openejb>
\ No newline at end of file