tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject [1/3] tomee git commit: trying to honor java:module even with a faked managed bean test class
Date Wed, 04 Mar 2015 23:41:28 GMT
Repository: tomee
Updated Branches:
  refs/heads/develop aa4cfc355 -> 5a22afaee


trying to honor java:module even with a faked managed bean test class


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/d464d6b0
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/d464d6b0
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/d464d6b0

Branch: refs/heads/develop
Commit: d464d6b047cbe847f421b38335603e5f1217f1df
Parents: aa4cfc3
Author: Romain Manni-Bucau <rmannibucau@apache.org>
Authored: Thu Mar 5 00:29:07 2015 +0100
Committer: Romain Manni-Bucau <rmannibucau@apache.org>
Committed: Thu Mar 5 00:29:07 2015 +0100

----------------------------------------------------------------------
 .../openejb/OpenEJBArchiveProcessor.java        |  4 ++-
 .../openejb/OpenEJBDeployableContainer.java     | 28 ++++++++++++++++++++
 .../openejb/ExceptionInjectionTest.java         |  6 ++---
 .../assembler/classic/EjbJarBuilder.java        |  5 +++-
 .../apache/openejb/core/ivm/ContextHandler.java | 11 ++++++++
 5 files changed, 49 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/d464d6b0/arquillian/arquillian-openejb-embedded-5/src/main/java/org/apache/openejb/arquillian/openejb/OpenEJBArchiveProcessor.java
----------------------------------------------------------------------
diff --git a/arquillian/arquillian-openejb-embedded-5/src/main/java/org/apache/openejb/arquillian/openejb/OpenEJBArchiveProcessor.java
b/arquillian/arquillian-openejb-embedded-5/src/main/java/org/apache/openejb/arquillian/openejb/OpenEJBArchiveProcessor.java
index 1d6c72f..1a75a69 100644
--- a/arquillian/arquillian-openejb-embedded-5/src/main/java/org/apache/openejb/arquillian/openejb/OpenEJBArchiveProcessor.java
+++ b/arquillian/arquillian-openejb-embedded-5/src/main/java/org/apache/openejb/arquillian/openejb/OpenEJBArchiveProcessor.java
@@ -232,7 +232,8 @@ public class OpenEJBArchiveProcessor {
         // add the test as a managed bean to be able to inject into it easily
         final Map<String, Object> testDD;
         if (javaClass != null) {
-            testDD = addTestClassAsManagedBean(javaClass, tempClassLoader, appModule).getAltDDs();
+            final EjbModule testEjbModule = addTestClassAsManagedBean(javaClass, tempClassLoader,
appModule);
+            testDD = testEjbModule.getAltDDs();
         } else {
             testDD = new HashMap<>(); // ignore
         }
@@ -306,6 +307,7 @@ public class OpenEJBArchiveProcessor {
         ejbDeployment.setDeploymentId(ejbName);
         final EjbModule e = new EjbModule(ejbJar, openejbJar);
         e.getProperties().setProperty("openejb.cdi.activated", "false");
+        e.getProperties().setProperty("openejb.test.module", "true");
         e.setBeans(new Beans());
         e.setClassLoader(tempClassLoader);
         appModule.getEjbModules().add(e);

http://git-wip-us.apache.org/repos/asf/tomee/blob/d464d6b0/arquillian/arquillian-openejb-embedded-5/src/main/java/org/apache/openejb/arquillian/openejb/OpenEJBDeployableContainer.java
----------------------------------------------------------------------
diff --git a/arquillian/arquillian-openejb-embedded-5/src/main/java/org/apache/openejb/arquillian/openejb/OpenEJBDeployableContainer.java
b/arquillian/arquillian-openejb-embedded-5/src/main/java/org/apache/openejb/arquillian/openejb/OpenEJBDeployableContainer.java
index bc699ac..0b917cd 100644
--- a/arquillian/arquillian-openejb-embedded-5/src/main/java/org/apache/openejb/arquillian/openejb/OpenEJBDeployableContainer.java
+++ b/arquillian/arquillian-openejb-embedded-5/src/main/java/org/apache/openejb/arquillian/openejb/OpenEJBDeployableContainer.java
@@ -17,6 +17,8 @@
 package org.apache.openejb.arquillian.openejb;
 
 import org.apache.openejb.AppContext;
+import org.apache.openejb.BeanContext;
+import org.apache.openejb.ModuleTestContext;
 import org.apache.openejb.OpenEJB;
 import org.apache.openejb.OpenEJBRuntimeException;
 import org.apache.openejb.OpenEjbContainer;
@@ -35,6 +37,7 @@ import org.apache.openejb.config.DeploymentFilterable;
 import org.apache.openejb.config.WebModule;
 import org.apache.openejb.core.LocalInitialContext;
 import org.apache.openejb.core.LocalInitialContextFactory;
+import org.apache.openejb.jee.sun.BeanCache;
 import org.apache.openejb.loader.IO;
 import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.web.LightweightWebAppBuilder;
@@ -65,6 +68,8 @@ import java.io.ByteArrayInputStream;
 import java.io.Closeable;
 import java.io.IOException;
 import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.concurrent.ConcurrentHashMap;
@@ -219,6 +224,29 @@ public class OpenEJBDeployableContainer implements DeployableContainer<OpenEJBCo
             closeablesProducer.set(cl);
             info = quickDeploy(archive, testClass.get(), cl);
 
+            // try to switch module context jndi to let test use java:module naming
+            // we could put the managed bean in the war but then test class should respect
all the
+            // container rules (CDI) which is not the case with this solution
+            if (archive.getName().endsWith(".war")) {
+                final List<BeanContext> beanContexts = info.appCtx.getBeanContexts();
+                if (beanContexts.size() > 1) {
+                    final Iterator<BeanContext> it = beanContexts.iterator();
+                    while (it.hasNext()) {
+                        final BeanContext next = it.next();
+                        if (ModuleTestContext.class.isInstance(next.getModuleContext()) &&
BeanContext.Comp.class != next.getBeanClass()) {
+                            for (final BeanContext b : beanContexts) {
+                                if (b.getModuleContext() != next.getModuleContext()) {
+                                    ModuleTestContext.class.cast(next.getModuleContext())
+                                            .setModuleJndiContextOverride(b.getModuleContext().getModuleJndiContext());
+                                    break;
+                                }
+                            }
+                            break;
+                        }
+                    }
+                }
+            }
+
             servletContextProducer.set(info.appServletContext);
             sessionProducer.set(info.appSession);
             appInfoProducer.set(info.appInfo);

http://git-wip-us.apache.org/repos/asf/tomee/blob/d464d6b0/arquillian/arquillian-openejb-embedded-5/src/test/java/org/apache/openejb/arquillian/openejb/ExceptionInjectionTest.java
----------------------------------------------------------------------
diff --git a/arquillian/arquillian-openejb-embedded-5/src/test/java/org/apache/openejb/arquillian/openejb/ExceptionInjectionTest.java
b/arquillian/arquillian-openejb-embedded-5/src/test/java/org/apache/openejb/arquillian/openejb/ExceptionInjectionTest.java
index efa6d20..bab0830 100644
--- a/arquillian/arquillian-openejb-embedded-5/src/test/java/org/apache/openejb/arquillian/openejb/ExceptionInjectionTest.java
+++ b/arquillian/arquillian-openejb-embedded-5/src/test/java/org/apache/openejb/arquillian/openejb/ExceptionInjectionTest.java
@@ -16,7 +16,7 @@
  */
 package org.apache.openejb.arquillian.openejb;
 
-import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.exception.WebBeansDeploymentException;
 import org.jboss.arquillian.container.spi.client.container.DeploymentException;
 import org.jboss.arquillian.container.test.api.Deployment;
 import org.jboss.arquillian.container.test.api.ShouldThrowException;
@@ -39,10 +39,10 @@ public class ExceptionInjectionTest {
     private DeploymentException de;
 
     @ArquillianResource
-    private WebBeansConfigurationException owbException;
+    private WebBeansDeploymentException owbException;
 
     @ArquillianResource
-    private javax.enterprise.inject.spi.DeploymentException oejbException;
+    private DeploymentException oejbException;
 
     @Deployment(testable = false)
     @ShouldThrowException(javax.enterprise.inject.spi.DeploymentException.class)

http://git-wip-us.apache.org/repos/asf/tomee/blob/d464d6b0/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarBuilder.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarBuilder.java
b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarBuilder.java
index 68c14a3..0accb01 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarBuilder.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarBuilder.java
@@ -22,6 +22,7 @@ import org.apache.openejb.BeanContext;
 import org.apache.openejb.Container;
 import org.apache.openejb.Injection;
 import org.apache.openejb.ModuleContext;
+import org.apache.openejb.ModuleTestContext;
 import org.apache.openejb.OpenEJBException;
 import org.apache.openejb.util.Messages;
 
@@ -54,7 +55,9 @@ public class EjbJarBuilder {
 
         final HashMap<String, BeanContext> deployments = new HashMap<String, BeanContext>();
 
-        final ModuleContext moduleContext = new ModuleContext(ejbJar.moduleName, ejbJar.moduleUri,
ejbJar.uniqueId, context, moduleJndiContext, classLoader);
+        final ModuleContext moduleContext = !ejbJar.properties.containsKey("openejb.test.module")
?
+                new ModuleContext(ejbJar.moduleName, ejbJar.moduleUri, ejbJar.uniqueId, context,
moduleJndiContext, classLoader) :
+                new ModuleTestContext(ejbJar.moduleName, ejbJar.moduleUri, ejbJar.uniqueId,
context, moduleJndiContext, classLoader);
         moduleContext.getProperties().putAll(ejbJar.properties);
         final InterceptorBindingBuilder interceptorBindingBuilder = new InterceptorBindingBuilder(classLoader,
ejbJar);
 

http://git-wip-us.apache.org/repos/asf/tomee/blob/d464d6b0/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/ContextHandler.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/ContextHandler.java
b/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/ContextHandler.java
index d62c592..b86aa9b 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/ContextHandler.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/ContextHandler.java
@@ -17,6 +17,7 @@
 
 package org.apache.openejb.core.ivm;
 
+import org.apache.openejb.core.ThreadContext;
 import org.apache.openejb.core.ivm.naming.ContextWrapper;
 import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.spi.ContainerSystem;
@@ -80,6 +81,16 @@ public class ContextHandler extends ContextWrapper {
             } catch (final NameNotFoundException nnfe2) {
                 // ignore, let it be thrown
             }
+            try {
+                final ThreadContext threadContext = ThreadContext.getThreadContext();
+                if (threadContext != null) {
+                    return threadContext.getBeanContext()
+                            .getModuleContext().getModuleJndiContext()
+                            .lookup(name);
+                }
+            } catch (final Exception nnfe3) {
+                // ignore, let it be thrown
+            }
             throw nnfe;
         }
     }


Mime
View raw message