TOMEE-2162 check containers defined on the appmodule

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

Branch: refs/heads/fb_tomee8
Commit: d9f3ca8498e1696637eac569f0396b63030703b0
Parents: cf40762
Author: Jonathan Gallimore <j...@jrg.me.uk>
Authored: Wed Jan 10 14:17:20 2018 +0000
Committer: Jonathan Gallimore <j...@jrg.me.uk>
Committed: Wed Jan 10 16:31:55 2018 +0000

----------------------------------------------------------------------
 .../ActivationConfigPropertyOverride.java       | 29 +++++++++++++-
 .../ActivationConfigPropertyOverrideTest.java   | 42 +++++++++++++++++---
 2 files changed, 64 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/d9f3ca84/container/openejb-core/src/main/java/org/apache/openejb/config/ActivationConfigPropertyOverride.java
----------------------------------------------------------------------
diff --git 
a/container/openejb-core/src/main/java/org/apache/openejb/config/ActivationConfigPropertyOverride.java
 
b/container/openejb-core/src/main/java/org/apache/openejb/config/ActivationConfigPropertyOverride.java
index bff7e41..3d9f4c3 100644
--- 
a/container/openejb-core/src/main/java/org/apache/openejb/config/ActivationConfigPropertyOverride.java
+++ 
b/container/openejb-core/src/main/java/org/apache/openejb/config/ActivationConfigPropertyOverride.java
@@ -36,6 +36,7 @@ import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
 import org.apache.openejb.util.PropertyPlaceHolderHelper;
 
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
@@ -94,7 +95,7 @@ public class ActivationConfigPropertyOverride implements 
DynamicDeployer {
                 // now try to use special keys
                 final Properties overrides = new Properties();
 
-                final MdbContainerDetails mdbContainer = 
getMdbContainer(ejbDeployment.getContainerId(), appModule.getModuleId());
+                final MdbContainerDetails mdbContainer = 
getMdbContainer(appModule, ejbDeployment.getContainerId(), 
appModule.getModuleId());
                 if (mdbContainer != null) {
                     
overrides.putAll(ConfigurationFactory.getOverrides(properties, "mdb.container." 
+ mdbContainer.getContainerId() + ".activation", "EnterpriseBean"));
                     
overrides.putAll(ConfigurationFactory.getOverrides(mdbContainer.getProperties(),
 "activation", "EnterpriseBean"));
@@ -143,7 +144,7 @@ public class ActivationConfigPropertyOverride implements 
DynamicDeployer {
         return appModule;
     }
 
-    private MdbContainerDetails getMdbContainer(final String containerId, 
final String moduleId) {
+    private MdbContainerDetails getMdbContainer(final AppModule appModule, 
final String containerId, final String moduleId) {
 
         final ContainerSystem containerSystem = 
SystemInstance.get().getComponent(ContainerSystem.class);
         final ConfigurationFactory configurationFactory = 
SystemInstance.get().getComponent(ConfigurationFactory.class);
@@ -187,6 +188,30 @@ public class ActivationConfigPropertyOverride implements 
DynamicDeployer {
             return containerInfo;
         }
 
+        final MdbContainerDetails moduleContainer = 
findModuleContainer(appModule, configurationFactory, containerId);
+        if (moduleContainer != null) {
+            return moduleContainer;
+        }
+
+        return null;
+    }
+
+    private MdbContainerDetails findModuleContainer(final AppModule appModule, 
final ConfigurationFactory configurationFactory, final String containerId) {
+        // try the containers on the AppModule
+        final Collection<org.apache.openejb.config.sys.Container> containers = 
appModule.getContainers();
+        for (final org.apache.openejb.config.sys.Container appMopduleContainer 
: containers) {
+            if (appMopduleContainer.getId().equals(containerId) || 
appMopduleContainer.getId().equals(appModule.getModuleId() + "/" + 
containerId)) {
+                try {
+                    final ContainerInfo containerInfo = 
configurationFactory.createContainerInfo(appMopduleContainer);
+                    if (containerInfo != null && 
MdbContainerInfo.class.isInstance(containerInfo)) {
+                        return 
convert(MdbContainerInfo.class.cast(containerInfo));
+                    }
+                } catch (OpenEJBException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+
         return null;
     }
 

http://git-wip-us.apache.org/repos/asf/tomee/blob/d9f3ca84/container/openejb-core/src/test/java/org/apache/openejb/config/ActivationConfigPropertyOverrideTest.java
----------------------------------------------------------------------
diff --git 
a/container/openejb-core/src/test/java/org/apache/openejb/config/ActivationConfigPropertyOverrideTest.java
 
b/container/openejb-core/src/test/java/org/apache/openejb/config/ActivationConfigPropertyOverrideTest.java
index a444a16..8dd398d 100755
--- 
a/container/openejb-core/src/test/java/org/apache/openejb/config/ActivationConfigPropertyOverrideTest.java
+++ 
b/container/openejb-core/src/test/java/org/apache/openejb/config/ActivationConfigPropertyOverrideTest.java
@@ -18,11 +18,8 @@ package org.apache.openejb.config;
 
 import org.apache.openejb.OpenEJBException;
 import 
org.apache.openejb.activemq.ActivationContainerOverwriteBothConfigurationTest;
-import org.apache.openejb.assembler.classic.Assembler;
-import org.apache.openejb.assembler.classic.EjbJarInfo;
-import org.apache.openejb.assembler.classic.MessageDrivenBeanInfo;
-import org.apache.openejb.assembler.classic.SecurityServiceInfo;
-import org.apache.openejb.assembler.classic.TransactionServiceInfo;
+import org.apache.openejb.assembler.classic.*;
+import org.apache.openejb.config.sys.Container;
 import org.apache.openejb.core.builder.AppModuleBuilder;
 import org.apache.openejb.core.builder.MdbBuilder;
 import org.apache.openejb.jee.ActivationConfigProperty;
@@ -372,6 +369,41 @@ public class ActivationConfigPropertyOverrideTest{
 
     }
 
+    @Test
+    public void testOverrideFromContainerDefinedInAppModule() throws Exception 
{
+        SystemInstance.reset();
+
+        final Assembler assembler = new Assembler();
+        final ConfigurationFactory config = new ConfigurationFactory();
+        
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
+        
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
+
+        final EjbJar ejbJar = new EjbJar();
+        ejbJar.addEnterpriseBean(new MessageDrivenBean("Yellow", 
Orange.class));
+        ejbJar.addEnterpriseBean(new MessageDrivenBean("Orange", 
Yellow.class));
+
+        final AppModule appModule = new AppModule(new EjbModule(ejbJar));
+        appModule.setModuleId("mymodule");
+
+        final Container container = new Container();
+        container.setId("mycontainer");
+        container.setCtype("MESSAGE");
+        container.getProperties().setProperty("activation.DeliveryActive", 
"false");
+        appModule.getContainers().add(container);
+
+
+        final AppInfo appInfo = config.configureApplication(appModule);
+        assertEquals(1, appInfo.ejbJars.size());
+        final EjbJarInfo ejbJarInfo = appInfo.ejbJars.get(0);
+
+        assertEquals(2, ejbJarInfo.enterpriseBeans.size());
+        final MessageDrivenBeanInfo orange = (MessageDrivenBeanInfo) 
ejbJarInfo.enterpriseBeans.get(0);
+        final MessageDrivenBeanInfo yellow = (MessageDrivenBeanInfo) 
ejbJarInfo.enterpriseBeans.get(1);
+
+        assertEquals("false", 
orange.activationProperties.get("DeliveryActive"));
+        assertEquals("false", 
yellow.activationProperties.get("DeliveryActive"));
+    }
+
 
     @MessageDriven(activationConfig = {
         @javax.ejb.ActivationConfigProperty(propertyName = "maxSessions", 
propertyValue = "7"),

Reply via email to