You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2010/10/04 11:52:03 UTC
svn commit: r1004172 - in /openejb/trunk/openejb3/container/openejb-core: ./
src/main/java/org/apache/openejb/config/
src/main/java/org/apache/openejb/junit/ src/test/java/org/apache/openejb/
src/test/java/org/apache/openejb/core/stateless/
Author: dblevins
Date: Mon Oct 4 09:52:02 2010
New Revision: 1004172
URL: http://svn.apache.org/viewvc?rev=1004172&view=rev
Log:
OPENEJB-1364: @RunWith(ApplicationComposer.class) test runner allows for programmatic creation of apps
Added:
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/junit/
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/junit/ApplicationComposer.java (with props)
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/junit/Configuration.java (with props)
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/junit/Module.java (with props)
Modified:
openejb/trunk/openejb3/container/openejb-core/pom.xml
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/JndiEncInfoBuilder.java
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/DependenceValidationTest.java
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/StatelessContainerTest.java
Modified: openejb/trunk/openejb3/container/openejb-core/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/pom.xml?rev=1004172&r1=1004171&r2=1004172&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/pom.xml (original)
+++ openejb/trunk/openejb3/container/openejb-core/pom.xml Mon Oct 4 09:52:02 2010
@@ -319,6 +319,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>hsqldb</groupId>
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java?rev=1004172&r1=1004171&r2=1004172&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java Mon Oct 4 09:52:02 2010
@@ -2652,24 +2652,34 @@ public class AnnotationDeployer implemen
}
private boolean isKnownLocalBean(Class clazz) {
- DeploymentModule module = getModule();
- if (module instanceof EjbModule) {
- Set<String> localbeans = new HashSet<String>();
- EjbModule ejbModule = (EjbModule) module;
- for (EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) {
- if (bean instanceof SessionBean) {
- if (((SessionBean) bean).getLocalBean() != null) {
- localbeans.add(bean.getEjbClass());
- }
- }
- }
-
- if (localbeans.contains(clazz.getName())) {
- return true;
- }
- }
+ if (clazz.isAnnotation()) return false;
+ if (clazz.isArray()) return false;
+ if (clazz.isEnum()) return false;
+ if (clazz.isInterface()) return false;
+ if (clazz.isPrimitive()) return false;
+ if (Modifier.isAbstract(clazz.getModifiers())) return false;
+ if (Modifier.isFinal(clazz.getModifiers())) return false;
- return false;
+ return true;
+// // This limits @LocalBean references to things in the same module
+// DeploymentModule module = getModule();
+// if (module instanceof EjbModule) {
+// Set<String> localbeans = new HashSet<String>();
+// EjbModule ejbModule = (EjbModule) module;
+// for (EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) {
+// if (bean instanceof SessionBean) {
+// if (((SessionBean) bean).getLocalBean() != null) {
+// localbeans.add(bean.getEjbClass());
+// }
+// }
+// }
+//
+// if (localbeans.contains(clazz.getName())) {
+// return true;
+// }
+// }
+//
+// return false;
}
private boolean isValidEjbInterface(String b, Class clazz, String refName) {
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java?rev=1004172&r1=1004171&r2=1004172&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java Mon Oct 4 09:52:02 2010
@@ -396,7 +396,10 @@ public class ConfigurationFactory implem
}
- return sys;
+ final OpenEjbConfiguration finished = sys;
+ sys = null;
+ openejb = null;
+ return finished;
}
private List<String> getDeclaredApps() {
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/JndiEncInfoBuilder.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/JndiEncInfoBuilder.java?rev=1004172&r1=1004171&r2=1004172&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/JndiEncInfoBuilder.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/JndiEncInfoBuilder.java Mon Oct 4 09:52:02 2010
@@ -406,7 +406,8 @@ public class JndiEncInfoBuilder {
private EnterpriseBeanInfo getInterfaceBeanInfo(String moduleId, String interfaceClassName) {
List<EjbJarInfo> ejbJars = appInfo.ejbJars;
for (EjbJarInfo ejbJar : ejbJars) {
- if (!ejbJar.moduleId.equals(moduleId) && !(moduleId == null && appInfo.ejbJars.size() == 1)) continue;
+ // DMB Not sure why we don't allow @LocalBean references in other modules in the EAR
+// if (!ejbJar.moduleId.equals(moduleId) && !(moduleId == null && appInfo.ejbJars.size() == 1)) continue;
List<EnterpriseBeanInfo> enterpriseBeans = ejbJar.enterpriseBeans;
for (EnterpriseBeanInfo enterpriseBean : enterpriseBeans) {
Added: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/junit/ApplicationComposer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/junit/ApplicationComposer.java?rev=1004172&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/junit/ApplicationComposer.java (added)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/junit/ApplicationComposer.java Mon Oct 4 09:52:02 2010
@@ -0,0 +1,281 @@
+/**
+ * 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.junit;
+
+import org.apache.openejb.BeanContext;
+import org.apache.openejb.InjectionProcessor;
+import org.apache.openejb.assembler.classic.AppInfo;
+import org.apache.openejb.assembler.classic.Assembler;
+import org.apache.openejb.config.AppModule;
+import org.apache.openejb.config.ConfigurationFactory;
+import org.apache.openejb.config.ConnectorModule;
+import org.apache.openejb.config.EjbModule;
+import org.apache.openejb.config.PersistenceModule;
+import org.apache.openejb.core.Operation;
+import org.apache.openejb.core.ThreadContext;
+import org.apache.openejb.core.ivm.naming.InitContextFactory;
+import org.apache.openejb.jee.Application;
+import org.apache.openejb.jee.Beans;
+import org.apache.openejb.jee.Connector;
+import org.apache.openejb.jee.EjbJar;
+import org.apache.openejb.jee.EnterpriseBean;
+import org.apache.openejb.jee.ManagedBean;
+import org.apache.openejb.jee.jpa.unit.Persistence;
+import org.apache.openejb.jee.oejb3.EjbDeployment;
+import org.apache.openejb.jee.oejb3.OpenejbJar;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.spi.ContainerSystem;
+import org.apache.openejb.util.Join;
+import org.junit.rules.MethodRule;
+import org.junit.runners.BlockJUnit4ClassRunner;
+import org.junit.runners.model.FrameworkMethod;
+import org.junit.runners.model.InitializationError;
+import org.junit.runners.model.Statement;
+import org.junit.runners.model.TestClass;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import static org.apache.openejb.config.DeploymentsResolver.DEPLOYMENTS_CLASSPATH_PROPERTY;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ApplicationComposer extends BlockJUnit4ClassRunner {
+
+ private final TestClass testClass;
+
+ public ApplicationComposer(Class<?> klass) throws InitializationError {
+ super(klass);
+ testClass = new TestClass(klass);
+ validate();
+ }
+
+ private void validate() throws InitializationError {
+ List<Throwable> errors = new ArrayList<Throwable>();
+
+ final List<FrameworkMethod> configs = testClass.getAnnotatedMethods(Configuration.class);
+ if (configs.size() > 1) {
+ final String gripe = "Test class should have no more than one @Configuration method";
+ errors.add(new Exception(gripe));
+ }
+
+ for (FrameworkMethod method : configs) {
+ final Class<?> type = method.getMethod().getReturnType();
+ if (!Properties.class.isAssignableFrom(type)) {
+ final String gripe = "@Configuration method must return " + Properties.class.getName();
+ errors.add(new Exception(gripe));
+ }
+ }
+
+ int appModules = 0;
+ int modules = 0;
+ Class[] moduleTypes = {EjbJar.class, EnterpriseBean.class, Persistence.class, Connector.class, Beans.class, Application.class};
+ for (FrameworkMethod method : testClass.getAnnotatedMethods(Module.class)) {
+
+ modules++;
+
+ final Class<?> type = method.getMethod().getReturnType();
+
+ if (Application.class.isAssignableFrom(type)) {
+
+ appModules++;
+
+ } else if (!isValidModuleType(type, moduleTypes)) {
+ final String gripe = "@Module method must return " + Join.join(" or ", moduleTypes).replaceAll("(class|interface) ", "");
+ errors.add(new Exception(gripe));
+ }
+ }
+
+ if (appModules > 1) {
+ final String gripe = "Test class should have no more than one @Module method that returns " + Application.class.getName();
+ errors.add(new Exception(gripe));
+ }
+
+ if (modules < 1) {
+ final String gripe = "Test class should have at least one @Module method";
+ errors.add(new Exception(gripe));
+ }
+
+ if (!errors.isEmpty()) {
+ throw new InitializationError(errors);
+ }
+ }
+
+ private boolean isValidModuleType(Class<?> type, Class[] moduleTypes) {
+ for (Class moduleType : moduleTypes) {
+ if (moduleType.isAssignableFrom(type)) return true;
+ }
+ return false;
+ }
+
+ @Override
+ protected List<MethodRule> rules(Object test) {
+ final List<MethodRule> rules = super.rules(test);
+ rules.add(new MethodRule(){
+ public Statement apply(Statement base, FrameworkMethod method, Object target) {
+ return new DeployApplication(target, base);
+ }
+ });
+ return rules;
+ }
+
+ public class DeployApplication extends Statement {
+
+ // The TestCase instance
+ private final Object testInstance;
+
+ private final Statement next;
+
+ public DeployApplication(Object testInstance, Statement next) {
+ this.testInstance = testInstance;
+ this.next = next;
+ }
+
+ @Override
+ public void evaluate() throws Throwable {
+ final Class<?> javaClass = testClass.getJavaClass();
+ final ClassLoader loader = javaClass.getClassLoader();
+ AppModule appModule = new AppModule(loader, javaClass.getSimpleName());
+
+ // Add the test case as an @ManagedBean
+ {
+ final EjbJar ejbJar = new EjbJar();
+ final OpenejbJar openejbJar = new OpenejbJar();
+ final ManagedBean bean = ejbJar.addEnterpriseBean(new ManagedBean(javaClass));
+
+ final EjbDeployment ejbDeployment = openejbJar.addEjbDeployment(bean);
+ ejbDeployment.setDeploymentId(javaClass.getName());
+
+ appModule.getEjbModules().add(new EjbModule(ejbJar, openejbJar));
+ }
+
+ Application application = null;
+
+ // Invoke the @Module producer methods to build out the AppModule
+ for (FrameworkMethod method : testClass.getAnnotatedMethods(Module.class)) {
+
+ final Object obj = method.invokeExplosively(testInstance);
+
+ if (obj instanceof EjbJar) {
+
+ final EjbJar ejbJar = (EjbJar) obj;
+ appModule.getEjbModules().add(new EjbModule(ejbJar));
+
+ } else if (obj instanceof EnterpriseBean) {
+
+ final EnterpriseBean bean = (EnterpriseBean) obj;
+ final EjbJar ejbJar = new EjbJar();
+ ejbJar.addEnterpriseBean(bean);
+ appModule.getEjbModules().add(new EjbModule(ejbJar));
+
+ } else if (obj instanceof Application) {
+
+ application = (Application) obj;
+
+ } else if (obj instanceof Connector) {
+
+ final Connector connector = (Connector) obj;
+ appModule.getConnectorModules().add(new ConnectorModule(connector));
+
+ } else if (obj instanceof Persistence) {
+
+ final Persistence persistence = (Persistence) obj;
+ appModule.getPersistenceModules().add(new PersistenceModule("", persistence));
+
+ } else if (obj instanceof Beans) {
+
+ final Beans beans = (Beans) obj;
+ final EjbModule ejbModule = new EjbModule(new EjbJar());
+ ejbModule.setBeans(beans);
+ appModule.getEjbModules().add(ejbModule);
+ }
+ }
+
+ // Application is final in AppModule, which is fine, so we'll create a new one and move everything
+ if (application != null) {
+ final AppModule newModule = new AppModule(appModule.getClassLoader(), appModule.getModuleId(), application, false);
+ newModule.getClientModules().addAll(appModule.getClientModules());
+ newModule.getPersistenceModules().addAll(appModule.getPersistenceModules());
+ newModule.getEjbModules().addAll(appModule.getEjbModules());
+ newModule.getConnectorModules().addAll(appModule.getConnectorModules());
+ appModule = newModule;
+ }
+
+ // For the moment we just take the first @Configuration method
+ // maybe later we can add something fancy to allow multiple configurations using a qualifier
+ // as a sort of altDD/altConfig concept. Say for example the altDD prefix might be "foo",
+ // we can then imagine something like this:
+ // @Foo @Configuration public Properties alternateConfig(){...}
+ // @Foo @Module public Properties alternateModule(){...}
+ // anyway, one thing at a time ....
+
+ final Properties configuration = new Properties();
+ configuration.put(DEPLOYMENTS_CLASSPATH_PROPERTY, "false");
+
+ final List<FrameworkMethod> methods = testClass.getAnnotatedMethods(Configuration.class);
+ for (FrameworkMethod method : methods) {
+ final Object o = method.invokeExplosively(testInstance);
+ if (o instanceof Properties) {
+ Properties properties = (Properties) o;
+ configuration.putAll(properties);
+ }
+ break;
+ }
+
+ if (SystemInstance.isInitialized()) SystemInstance.reset();
+
+ SystemInstance.init(configuration);
+
+ try {
+ ConfigurationFactory config = new ConfigurationFactory();
+ config.init(SystemInstance.get().getProperties());
+
+ Assembler assembler = new Assembler();
+ assembler.buildContainerSystem(config.getOpenEjbConfiguration());
+
+ final AppInfo appInfo = config.configureApplication(appModule);
+
+ assembler.createApplication(appInfo);
+
+ try {
+ final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
+ final BeanContext context = containerSystem.getBeanContext(javaClass.getName());
+
+ InjectionProcessor processor = new InjectionProcessor(testInstance, context.getInjections(), context.getJndiContext());
+
+ processor.createInstance();
+
+ System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
+
+ final ThreadContext previous = ThreadContext.enter(new ThreadContext(context, null, Operation.BUSINESS));
+ try {
+ next.evaluate();
+ } finally {
+ ThreadContext.exit(previous);
+ }
+
+ } finally {
+ assembler.destroyApplication(appInfo.path);
+ }
+ } finally {
+ SystemInstance.reset();
+ }
+ }
+ }
+}
Propchange: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/junit/ApplicationComposer.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/junit/Configuration.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/junit/Configuration.java?rev=1004172&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/junit/Configuration.java (added)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/junit/Configuration.java Mon Oct 4 09:52:02 2010
@@ -0,0 +1,27 @@
+/**
+ * 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.junit;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Configuration {
+}
Propchange: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/junit/Configuration.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/junit/Module.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/junit/Module.java?rev=1004172&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/junit/Module.java (added)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/junit/Module.java Mon Oct 4 09:52:02 2010
@@ -0,0 +1,27 @@
+/**
+ * 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.junit;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Module {
+}
Propchange: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/junit/Module.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/DependenceValidationTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/DependenceValidationTest.java?rev=1004172&r1=1004171&r2=1004172&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/DependenceValidationTest.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/DependenceValidationTest.java Mon Oct 4 09:52:02 2010
@@ -54,16 +54,16 @@ public class DependenceValidationTest ex
// Nothing may depend on the Assembler except the config code
String dynamicAssembler = "org.apache.openejb.assembler.dynamic";
- assertNotDependentOn("org.apache.openejb", "org.apache.openejb.assembler.classic", "org.apache.openejb.assembler", "org.apache.openejb.config", "org.apache.openejb.assembler.dynamic", "org.apache.openejb.assembler.classic.cmd", "org.apache.openejb.cdi");
+ assertNotDependentOn("org.apache.openejb", "org.apache.openejb.assembler.classic", "org.apache.openejb.assembler", "org.apache.openejb.config", "org.apache.openejb.assembler.dynamic", "org.apache.openejb.assembler.classic.cmd", "org.apache.openejb.cdi", "org.apache.openejb.junit");
// Nothing may depend on the Dynamic Assembler
assertNotDependentOn("org.apache.openejb", dynamicAssembler);
// Nothing may depend on the JAXB Tree except the Config code
- assertNotDependentOn("org.apache.openejb", "org.apache.openejb.jee", "org.apache.openejb.config", "org.apache.openejb.config.rules", "org.apache.openejb.config.sys", "org.apache.openejb.cdi");
+ assertNotDependentOn("org.apache.openejb", "org.apache.openejb.jee", "org.apache.openejb.config", "org.apache.openejb.config.rules", "org.apache.openejb.config.sys", "org.apache.openejb.cdi", "org.apache.openejb.junit");
// Nothing may depend on the Config code except it's subpackages
- assertNotDependentOn("org.apache.openejb", "org.apache.openejb.config", "org.apache.openejb.config.rules", "org.apache.openejb.config.sys", "org.apache.openejb.assembler","org.apache.openejb.cdi", dynamicAssembler);
+ assertNotDependentOn("org.apache.openejb", "org.apache.openejb.config", "org.apache.openejb.config.rules", "org.apache.openejb.config.sys", "org.apache.openejb.assembler", "org.apache.openejb.cdi", "org.apache.openejb.junit", dynamicAssembler);
// The assembler may not be dependent on the config factory Implementation
assertNotDependentOn("org.apache.openejb.assembler.classic", "org.apache.openejb.config");
Modified: openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/StatelessContainerTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/StatelessContainerTest.java?rev=1004172&r1=1004171&r2=1004172&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/StatelessContainerTest.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/StatelessContainerTest.java Mon Oct 4 09:52:02 2010
@@ -18,42 +18,47 @@
package org.apache.openejb.core.stateless;
import junit.framework.TestCase;
-import org.apache.openejb.assembler.classic.*;
-import org.apache.openejb.assembler.classic.cmd.Info2Properties;
-import org.apache.openejb.config.ConfigurationFactory;
-import org.apache.openejb.core.ivm.naming.InitContextFactory;
-import org.apache.openejb.jee.EjbJar;
import org.apache.openejb.jee.Empty;
import org.apache.openejb.jee.StatelessBean;
+import org.apache.openejb.junit.ApplicationComposer;
+import org.apache.openejb.junit.Configuration;
+import org.apache.openejb.junit.Module;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import javax.ejb.EJB;
import javax.ejb.SessionContext;
-import javax.naming.InitialContext;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.Properties;
import java.util.Stack;
/**
* @version $Revision$ $Date$
*/
+@RunWith(ApplicationComposer.class)
public class StatelessContainerTest extends TestCase {
+ @EJB
+ private WidgetBean localBean;
+
+ @EJB
+ private Widget local;
+
+ @EJB
+ private RemoteWidget remote;
+
+ @Test
public void testPojoStyleBean() throws Exception {
List expected = Arrays.asList(Lifecycle.values());
- InitialContext ctx = new InitialContext();
{
WidgetBean.lifecycle.clear();
- Object object = ctx.lookup("WidgetBeanLocal");
-
- assertTrue("instanceof widget", object instanceof Widget);
-
- Widget widget = (Widget) object;
-
// Do a business method...
- Stack<Lifecycle> lifecycle = widget.getLifecycle();
+ Stack<Lifecycle> lifecycle = local.getLifecycle();
assertNotNull("lifecycle", lifecycle);
assertSame("lifecycle", lifecycle, WidgetBean.lifecycle);
@@ -63,20 +68,13 @@ public class StatelessContainerTest exte
{
WidgetBean.lifecycle.clear();
- Object object = ctx.lookup("WidgetBeanLocalBean");
-
- assertTrue("instanceof widgetbean", object instanceof WidgetBean);
-
- WidgetBean widget = (WidgetBean) object;
-
// Do a business method...
- Stack<Lifecycle> lifecycle = widget.getLifecycle();
+ Stack<Lifecycle> lifecycle = localBean.getLifecycle();
assertNotNull("lifecycle", lifecycle);
assertSame("lifecycle", lifecycle, WidgetBean.lifecycle);
// Check the lifecycle of the bean
List localBeanExpected = new ArrayList();
- localBeanExpected.add(0, Lifecycle.CONSTRUCTOR);
localBeanExpected.addAll(expected);
assertEquals(join("\n", localBeanExpected), join("\n", lifecycle));
}
@@ -84,57 +82,38 @@ public class StatelessContainerTest exte
WidgetBean.lifecycle.clear();
- Object object = ctx.lookup("WidgetBeanRemote");
-
- assertTrue("instanceof widget", object instanceof RemoteWidget);
-
- RemoteWidget remoteWidget = (RemoteWidget) object;
-
// Do a business method...
- Stack<Lifecycle> lifecycle = remoteWidget.getLifecycle();
+ Stack<Lifecycle> lifecycle = remote.getLifecycle();
assertNotNull("lifecycle", lifecycle);
assertNotSame("lifecycle", lifecycle, WidgetBean.lifecycle);
// Check the lifecycle of the bean
assertEquals(join("\n", expected), join("\n", lifecycle));
}
-
- Info2Properties.printLocalConfig();
}
- protected void setUp() throws Exception {
- super.setUp();
-
- System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
-
- ConfigurationFactory config = new ConfigurationFactory();
- Assembler assembler = new Assembler();
+ @Configuration
+ public Properties config() {
+ final Properties properties = new Properties();
+ properties.put("statelessContainer", "new://Container?type=STATELESS");
+ properties.put("statelessContainer.TimeOut", "10");
+ properties.put("statelessContainer.MaxSize", "0");
+ properties.put("statelessContainer.StrictPooling", "false");
- assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
- assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
- assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
-
- // containers
- StatelessSessionContainerInfo statelessContainerInfo = config.configureService(StatelessSessionContainerInfo.class);
- statelessContainerInfo.properties.setProperty("TimeOut", "10");
- statelessContainerInfo.properties.setProperty("MaxSize", "0");
- statelessContainerInfo.properties.setProperty("StrictPooling", "false");
- assembler.createContainer(statelessContainerInfo);
+ return properties;
+ }
- // Setup the descriptor information
+ @Module
+ public StatelessBean app() throws Exception {
- StatelessBean bean = new StatelessBean(WidgetBean.class);
+ final StatelessBean bean = new StatelessBean(WidgetBean.class);
bean.addBusinessLocal(Widget.class.getName());
bean.addBusinessRemote(RemoteWidget.class.getName());
bean.addPostConstruct("init");
bean.addPreDestroy("destroy");
bean.setLocalBean(new Empty());
- EjbJar ejbJar = new EjbJar();
- ejbJar.addEnterpriseBean(bean);
-
- assembler.createApplication(config.configureApplication(ejbJar));
-
+ return bean;
}
private static String join(String delimeter, List items) {