You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jg...@apache.org on 2018/01/23 12:35:56 UTC

[2/2] tomee git commit: Honor the ApplicationWide property, and add a test for it

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/e3867f85
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/e3867f85
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/e3867f85

Branch: refs/heads/tomee-1.7.x
Commit: e3867f851e61767c6b910d3c45736a92058a097a
Parents: 6e3f0c6
Author: Jonathan Gallimore <jo...@jrg.me.uk>
Authored: Mon Jan 22 14:23:31 2018 +0000
Committer: Jonathan Gallimore <jo...@jrg.me.uk>
Committed: Mon Jan 22 17:37:07 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/e3867f85/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 4a45a90..228d960 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
@@ -2347,7 +2347,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/e3867f85/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/e3867f85/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 942d181..1410c03 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
@@ -363,12 +363,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/e3867f85/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/e3867f85/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;
+        }
+    }
+
+}