Honor the ApplicationWide property, and add a test for it

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

Branch: refs/heads/fb_tomee8
Commit: b81156161985116f1cc8cc11ce70df6edcc0acc9
Parents: 065654d
Author: Jonathan Gallimore <j...@jrg.me.uk>
Authored: Mon Jan 22 14:23:31 2018 +0000
Committer: Jonathan Gallimore <j...@jrg.me.uk>
Committed: Mon Jan 22 14:23:31 2018 +0000

----------------------------------------------------------------------
 .../openejb/assembler/classic/Assembler.java    |   4 +-
 .../assembler/classic/ContainerInfo.java        |   1 +
 .../apache/openejb/config/AppInfoBuilder.java   |   6 -
 .../apache/openejb/config/ContainerUtils.java   |   6 +
 .../openejb/config/ApplicationWideTest.java     | 116 +++++++++++++++++++
 5 files changed, 126 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/b8115616/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
----------------------------------------------------------------------
diff --git 
a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
 
b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
index 69cfb5f..ac2d080 100644
--- 
a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
+++ 
b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
@@ -2560,7 +2560,9 @@ public class Assembler extends AssemblerTool implements 
org.apache.openejb.spi.A
             }
 
             for (final ContainerInfo containerInfo : appInfo.containers) {
-                removeContainer(containerInfo.id);
+                if (! containerInfo.applicationWide) {
+                    removeContainer(containerInfo.id);
+                }
             }
 
             containerSystem.removeAppContext(appInfo.appId);

http://git-wip-us.apache.org/repos/asf/tomee/blob/b8115616/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ContainerInfo.java
----------------------------------------------------------------------
diff --git 
a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ContainerInfo.java
 
b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ContainerInfo.java
index cb29603..c655598 100644
--- 
a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ContainerInfo.java
+++ 
b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ContainerInfo.java
@@ -19,4 +19,5 @@ package org.apache.openejb.assembler.classic;
 
 public class ContainerInfo extends ServiceInfo {
     public String originAppName; // if define by an app
+    public boolean applicationWide;
 }

http://git-wip-us.apache.org/repos/asf/tomee/blob/b8115616/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java
----------------------------------------------------------------------
diff --git 
a/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java
 
b/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java
index 248c491..0c2264c 100644
--- 
a/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java
+++ 
b/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java
@@ -364,12 +364,6 @@ class AppInfoBuilder {
                 info.resourceAliases.addAll(def.getAliases());
             }
         }
-
-//        for (final Container def : module.getContainers()) {
-//            if (!def.getProperties().containsKey("ApplicationWide")) {
-//                info.containerIds.add(def.getId());
-//            }
-//        }
     }
 
     private void buildAppContainers(final AppModule module, final AppInfo 
info) throws OpenEJBException {

http://git-wip-us.apache.org/repos/asf/tomee/blob/b8115616/container/openejb-core/src/main/java/org/apache/openejb/config/ContainerUtils.java
----------------------------------------------------------------------
diff --git 
a/container/openejb-core/src/main/java/org/apache/openejb/config/ContainerUtils.java
 
b/container/openejb-core/src/main/java/org/apache/openejb/config/ContainerUtils.java
index 09bfd54..ce6eed2 100644
--- 
a/container/openejb-core/src/main/java/org/apache/openejb/config/ContainerUtils.java
+++ 
b/container/openejb-core/src/main/java/org/apache/openejb/config/ContainerUtils.java
@@ -42,6 +42,12 @@ public class ContainerUtils {
 
             final ContainerInfo containerInfo = 
configFactory.createContainerInfo(container);
             containerInfo.originAppName = module.getModuleId();
+
+            final Object applicationWideProperty = 
containerInfo.properties.remove("ApplicationWide");
+            if (applicationWideProperty != null) {
+                containerInfo.applicationWide = 
Boolean.parseBoolean(applicationWideProperty.toString().trim());
+            }
+
             containerInfos.add(containerInfo);
         }
 

http://git-wip-us.apache.org/repos/asf/tomee/blob/b8115616/container/openejb-core/src/test/java/org/apache/openejb/config/ApplicationWideTest.java
----------------------------------------------------------------------
diff --git 
a/container/openejb-core/src/test/java/org/apache/openejb/config/ApplicationWideTest.java
 
b/container/openejb-core/src/test/java/org/apache/openejb/config/ApplicationWideTest.java
new file mode 100644
index 0000000..20669fe
--- /dev/null
+++ 
b/container/openejb-core/src/test/java/org/apache/openejb/config/ApplicationWideTest.java
@@ -0,0 +1,116 @@
+/**
+ * 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.config;
+
+import junit.framework.TestCase;
+import org.apache.openejb.assembler.classic.AppInfo;
+import org.apache.openejb.assembler.classic.Assembler;
+import org.apache.openejb.assembler.classic.SecurityServiceInfo;
+import org.apache.openejb.assembler.classic.TransactionServiceInfo;
+import org.apache.openejb.config.sys.Container;
+import org.apache.openejb.jee.EjbJar;
+import org.apache.openejb.jee.StatelessBean;
+import org.apache.openejb.jee.oejb3.OpenejbJar;
+import org.apache.openejb.spi.ContainerSystem;
+
+import javax.ejb.Stateless;
+
+
+public class ApplicationWideTest extends TestCase {
+
+    public void testShouldCreateAResourceAndNotRemoveOnUndeploy() throws 
Exception {
+        final EjbModule ejbModule = new EjbModule(new EjbJar(), new 
OpenejbJar());
+        final EjbJar ejbJar = ejbModule.getEjbJar();
+        ejbJar.addEnterpriseBean(new StatelessBean(EchoBean.class));
+
+        final AppModule appModule = new AppModule(ejbModule);
+        final Container container = new Container();
+        container.setId("My Container");
+        container.setCtype("STATELESS");
+        container.getProperties().setProperty("ApplicationWide", "true");
+        appModule.getContainers().add(container);
+
+        final ConfigurationFactory config = new ConfigurationFactory();
+        final Assembler assembler = new Assembler();
+        { // setup the system
+            
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
+            
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
+        }
+
+        final AppInfo appInfo = config.configureApplication(appModule);
+        assembler.createApplication(appInfo);
+
+        {
+            final ContainerSystem containerSystem = 
assembler.getContainerSystem();
+            final org.apache.openejb.Container appContainer = 
containerSystem.getContainer(ejbModule.getModuleId() + "/My Container");
+            assertNotNull(appContainer);
+        }
+
+        assembler.destroyApplication(appInfo);
+
+        {
+            final ContainerSystem containerSystem = 
assembler.getContainerSystem();
+            final org.apache.openejb.Container appContainer = 
containerSystem.getContainer(ejbModule.getModuleId() + "/My Container");
+            assertNotNull(appContainer);
+        }
+    }
+
+    public void testShouldCreateAResourceAndRemoveOnUndeploy() throws 
Exception {
+        final EjbModule ejbModule = new EjbModule(new EjbJar(), new 
OpenejbJar());
+        final EjbJar ejbJar = ejbModule.getEjbJar();
+        ejbJar.addEnterpriseBean(new StatelessBean(EchoBean.class));
+
+        final AppModule appModule = new AppModule(ejbModule);
+        final Container container = new Container();
+        container.setId("My Container");
+        container.setCtype("STATELESS");
+        container.getProperties().setProperty("ApplicationWide", "false");
+        appModule.getContainers().add(container);
+
+        final ConfigurationFactory config = new ConfigurationFactory();
+        final Assembler assembler = new Assembler();
+        { // setup the system
+            
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
+            
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
+        }
+
+        final AppInfo appInfo = config.configureApplication(appModule);
+        assembler.createApplication(appInfo);
+
+        {
+            final ContainerSystem containerSystem = 
assembler.getContainerSystem();
+            final org.apache.openejb.Container appContainer = 
containerSystem.getContainer(ejbModule.getModuleId() + "/My Container");
+            assertNotNull(appContainer);
+        }
+
+        assembler.destroyApplication(appInfo);
+
+        {
+            final ContainerSystem containerSystem = 
assembler.getContainerSystem();
+            final org.apache.openejb.Container appContainer = 
containerSystem.getContainer(ejbModule.getModuleId() + "/My Container");
+            assertNull(appContainer);
+        }
+    }
+
+    @Stateless
+    public static class EchoBean {
+        public String echo(final String input) {
+            return input;
+        }
+    }
+
+}

Reply via email to