Author: dblevins
Date: Mon Aug 20 03:02:54 2012
New Revision: 1374901

URL: http://svn.apache.org/viewvc?rev=1374901&view=rev
Log:
TOMEE-385 - Complete application properties scoping
 - Ensure complete propagation of Properties at each level 
 - Ensure inheritance in Options

Added:
    
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/DeploymentContextOptionsTest.java
    
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/DeploymentContextPropertiesTest.java
   (contents, props changed)
      - copied, changed from r1374882, 
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/EjbDeploymentPropertiesTest.java
Removed:
    
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/EjbDeploymentPropertiesTest.java
Modified:
    
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/AppInfo.java
    
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
    
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarBuilder.java
    
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java

Modified: 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/AppInfo.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/AppInfo.java?rev=1374901&r1=1374900&r2=1374901&view=diff
==============================================================================
--- 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/AppInfo.java
 (original)
+++ 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/AppInfo.java
 Mon Aug 20 03:02:54 2012
@@ -26,6 +26,8 @@ import java.util.TreeSet;
  * @version $Rev$ $Date$
  */
 public class AppInfo extends InfoObject {
+    public final Properties properties = new Properties();
+
     public String appId;
     public String path;
     public boolean autoDeploy = true;

Modified: 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java?rev=1374901&r1=1374900&r2=1374901&view=diff
==============================================================================
--- 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
 (original)
+++ 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
 Mon Aug 20 03:02:54 2012
@@ -579,6 +579,7 @@ public class Assembler extends Assembler
             }
 
             final AppContext appContext = new AppContext(appInfo.appId, 
SystemInstance.get(), classLoader, globalJndiContext, appJndiContext, 
appInfo.standaloneModule);
+            appContext.getProperties().putAll(appInfo.properties);
             appContext.getInjections().addAll(injections);
             appContext.getBindings().putAll(globalBindings);
             appContext.getBindings().putAll(appBindings);

Modified: 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarBuilder.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarBuilder.java?rev=1374901&r1=1374900&r2=1374901&view=diff
==============================================================================
--- 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarBuilder.java
 (original)
+++ 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarBuilder.java
 Mon Aug 20 03:02:54 2012
@@ -55,6 +55,7 @@ public class EjbJarBuilder {
         HashMap<String, BeanContext> deployments = new HashMap<String, 
BeanContext>();
 
         ModuleContext moduleContext = new ModuleContext(ejbJar.moduleName, 
ejbJar.moduleUri, ejbJar.uniqueId, context, moduleJndiContext);
+        moduleContext.getProperties().putAll(ejbJar.properties);
         InterceptorBindingBuilder interceptorBindingBuilder = new 
InterceptorBindingBuilder(context.getClassLoader(), ejbJar);
 
         MethodScheduleBuilder methodScheduleBuilder = new 
MethodScheduleBuilder();

Modified: 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java?rev=1374901&r1=1374900&r2=1374901&view=diff
==============================================================================
--- 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java
 (original)
+++ 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java
 Mon Aug 20 03:02:54 2012
@@ -109,6 +109,7 @@ class AppInfoBuilder {
         appInfo.watchedResources.addAll(appModule.getWatchedResources());
         appInfo.mbeans.addAll(appModule.getAdditionalLibMbeans());
         appInfo.jaxRsProviders.addAll(appModule.getJaxRsProviders());
+        appInfo.properties.putAll(appModule.getProperties());
 
         if (appInfo.appId == null) throw new 
IllegalArgumentException("AppInfo.appId cannot be null");
         if (appInfo.path == null) appInfo.path = appInfo.appId;

Added: 
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/DeploymentContextOptionsTest.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/DeploymentContextOptionsTest.java?rev=1374901&view=auto
==============================================================================
--- 
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/DeploymentContextOptionsTest.java
 (added)
+++ 
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/DeploymentContextOptionsTest.java
 Mon Aug 20 03:02:54 2012
@@ -0,0 +1,230 @@
+/*
+ * 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;
+
+import junit.framework.TestCase;
+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.AppModule;
+import org.apache.openejb.config.ConfigurationFactory;
+import org.apache.openejb.config.EjbModule;
+import org.apache.openejb.jee.EjbJar;
+import org.apache.openejb.jee.StatelessBean;
+import org.apache.openejb.jee.oejb3.EjbDeployment;
+import org.apache.openejb.jee.oejb3.OpenejbJar;
+import org.apache.openejb.loader.Options;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.spi.ContainerSystem;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class DeploymentContextOptionsTest extends TestCase {
+    @Override
+    protected void setUp() throws Exception {
+        SystemInstance.reset();
+    }
+
+    public void testBeanContextOptions() throws Exception {
+
+        final ConfigurationFactory config = new ConfigurationFactory();
+        final Assembler assembler = new Assembler();
+
+        {
+            
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
+            
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
+        }
+
+        {
+            // Setup the descriptor information
+            final EjbModule ejbModule = new EjbModule(new EjbJar(), new 
OpenejbJar());
+            final EjbJar ejbJar = ejbModule.getEjbJar();
+            final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
+
+            final StatelessBean statelessBean = ejbJar.addEnterpriseBean(new 
StatelessBean(WidgetBean.class));
+
+            { // Set at BeanContext level
+                final EjbDeployment deployment = 
openejbJar.addEjbDeployment(statelessBean);
+                deployment.getProperties().put("color", "orange");
+            }
+
+            
assembler.createApplication(config.configureApplication(ejbModule));
+        }
+
+
+        final ContainerSystem containerSystem = 
SystemInstance.get().getComponent(ContainerSystem.class);
+        final BeanContext beanContext = 
containerSystem.getBeanContext("WidgetBean");
+
+        assertOption(beanContext.getOptions(), "color", "orange");
+        assertNoOption(beanContext.getModuleContext().getOptions(), "color");
+        
assertNoOption(beanContext.getModuleContext().getAppContext().getOptions(), 
"color");
+    }
+
+    public void testModuleContextOptions() throws Exception {
+
+        final ConfigurationFactory config = new ConfigurationFactory();
+        final Assembler assembler = new Assembler();
+
+        {
+            
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
+            
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
+        }
+
+        {
+            // Setup the descriptor information
+            final EjbModule ejbModule = new EjbModule(new EjbJar(), new 
OpenejbJar());
+
+            final EjbJar ejbJar = ejbModule.getEjbJar();
+            final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
+            openejbJar.getProperties().setProperty("color", "orange");
+
+            ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
+            
assembler.createApplication(config.configureApplication(ejbModule));
+        }
+
+        final ContainerSystem containerSystem = 
SystemInstance.get().getComponent(ContainerSystem.class);
+        final BeanContext beanContext = 
containerSystem.getBeanContext("WidgetBean");
+
+        assertOption(beanContext.getOptions(), "color", "orange");
+        assertOption(beanContext.getModuleContext().getOptions(), "color", 
"orange");
+        
assertNoOption(beanContext.getModuleContext().getAppContext().getOptions(), 
"color");
+    }
+
+    public void testAppContextOptions() throws Exception {
+
+        final ConfigurationFactory config = new ConfigurationFactory();
+        final Assembler assembler = new Assembler();
+
+        {
+            
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
+            
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
+        }
+
+        {
+            // Setup the descriptor information
+            final EjbModule ejbModule = new EjbModule(new EjbJar(), new 
OpenejbJar());
+            final EjbJar ejbJar = ejbModule.getEjbJar();
+            ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
+
+            final AppModule appModule = new AppModule(ejbModule);
+            appModule.getProperties().setProperty("color", "orange");
+
+            
assembler.createApplication(config.configureApplication(appModule));
+        }
+
+        final ContainerSystem containerSystem = 
SystemInstance.get().getComponent(ContainerSystem.class);
+        final BeanContext beanContext = 
containerSystem.getBeanContext("WidgetBean");
+
+        assertOption(beanContext.getOptions(), "color", "orange");
+        assertOption(beanContext.getModuleContext().getOptions(), "color", 
"orange");
+        
assertOption(beanContext.getModuleContext().getAppContext().getOptions(), 
"color", "orange");
+    }
+
+    public void testSystemInstanceOptions() throws Exception {
+
+        SystemInstance.get().setProperty("color", "orange");
+        final ConfigurationFactory config = new ConfigurationFactory();
+        final Assembler assembler = new Assembler();
+
+        {
+            
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
+            
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
+        }
+
+        {
+            // Setup the descriptor information
+            final EjbModule ejbModule = new EjbModule(new EjbJar(), new 
OpenejbJar());
+            final EjbJar ejbJar = ejbModule.getEjbJar();
+            ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
+
+            final AppModule appModule = new AppModule(ejbModule);
+            
assembler.createApplication(config.configureApplication(appModule));
+        }
+
+        final ContainerSystem containerSystem = 
SystemInstance.get().getComponent(ContainerSystem.class);
+        final BeanContext beanContext = 
containerSystem.getBeanContext("WidgetBean");
+
+        assertOption(beanContext.getOptions(), "color", "orange");
+        assertOption(beanContext.getModuleContext().getOptions(), "color", 
"orange");
+        
assertOption(beanContext.getModuleContext().getAppContext().getOptions(), 
"color", "orange");
+        assertOption(SystemInstance.get().getOptions(), "color", "orange");
+    }
+
+
+    public void testAllLevels() throws Exception {
+
+        SystemInstance.get().setProperty("color", "orangeSystem");
+        final ConfigurationFactory config = new ConfigurationFactory();
+        final Assembler assembler = new Assembler();
+
+        {
+            
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
+            
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
+        }
+
+        {
+            // Setup the descriptor information
+            final EjbModule ejbModule = new EjbModule(new EjbJar(), new 
OpenejbJar());
+            final EjbJar ejbJar = ejbModule.getEjbJar();
+            final StatelessBean statelessBean = ejbJar.addEnterpriseBean(new 
StatelessBean(WidgetBean.class));
+
+            { // Set at BeanContext level
+                final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
+                final EjbDeployment deployment = 
openejbJar.addEjbDeployment(statelessBean);
+                deployment.getProperties().put("color", "orangeBean");
+            }
+
+            { // Set at ModuleContext level
+                final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
+                openejbJar.getProperties().put("color", "orangeModule");
+            }
+
+            final AppModule appModule = new AppModule(ejbModule);
+            { // Set at AppContext level
+                appModule.getProperties().put("color", "orangeApp");
+            }
+            
assembler.createApplication(config.configureApplication(appModule));
+        }
+
+        final ContainerSystem containerSystem = 
SystemInstance.get().getComponent(ContainerSystem.class);
+        final BeanContext beanContext = 
containerSystem.getBeanContext("WidgetBean");
+
+        assertOption(beanContext.getOptions(), "color", "orangeBean");
+        assertOption(beanContext.getModuleContext().getOptions(), "color", 
"orangeModule");
+        
assertOption(beanContext.getModuleContext().getAppContext().getOptions(), 
"color", "orangeApp");
+        assertOption(SystemInstance.get().getOptions(), "color", 
"orangeSystem");
+    }
+
+    private void assertOption(Options options, final String key, final String 
value) {
+        assertEquals(value, options.get(key, key + " (not set)"));
+    }
+
+    private void assertNoOption(Options options, final String key) {
+        final String defaultValue = key + " (not set)";
+        assertEquals(defaultValue, options.get(key, defaultValue));
+    }
+
+
+    public static interface Widget {
+
+    }
+
+    public static class WidgetBean implements Widget {
+
+    }
+}

Copied: 
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/DeploymentContextPropertiesTest.java
 (from r1374882, 
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/EjbDeploymentPropertiesTest.java)
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/DeploymentContextPropertiesTest.java?p2=openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/DeploymentContextPropertiesTest.java&p1=openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/EjbDeploymentPropertiesTest.java&r1=1374882&r2=1374901&rev=1374901&view=diff
==============================================================================
--- 
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/EjbDeploymentPropertiesTest.java
 (original)
+++ 
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/DeploymentContextPropertiesTest.java
 Mon Aug 20 03:02:54 2012
@@ -14,13 +14,18 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.openejb.config;
+package org.apache.openejb;
 
 import junit.framework.TestCase;
 import org.apache.openejb.BeanContext;
+import org.apache.openejb.assembler.classic.AppInfo;
 import org.apache.openejb.assembler.classic.Assembler;
+import org.apache.openejb.assembler.classic.EjbJarInfo;
 import org.apache.openejb.assembler.classic.SecurityServiceInfo;
 import org.apache.openejb.assembler.classic.TransactionServiceInfo;
+import org.apache.openejb.config.AppModule;
+import org.apache.openejb.config.ConfigurationFactory;
+import org.apache.openejb.config.EjbModule;
 import org.apache.openejb.jee.EjbJar;
 import org.apache.openejb.jee.StatelessBean;
 import org.apache.openejb.jee.oejb3.EjbDeployment;
@@ -33,34 +38,117 @@ import java.util.Properties;
 /**
  * @version $Rev$ $Date$
  */
-public class EjbDeploymentPropertiesTest extends TestCase {
+public class DeploymentContextPropertiesTest extends TestCase {
 
-    public void test() throws Exception {
-        ConfigurationFactory config = new ConfigurationFactory();
-        Assembler assembler = new Assembler();
+    @Override
+    protected void setUp() throws Exception {
+        SystemInstance.reset();
+    }
+
+    public void testBeanContextProperties() throws Exception {
+
+        final ConfigurationFactory config = new ConfigurationFactory();
+        final Assembler assembler = new Assembler();
+
+        {
+            
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
+            
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
+        }
+
+        {
+            // Setup the descriptor information
+            final EjbModule ejbModule = new EjbModule(new EjbJar(), new 
OpenejbJar());
+            final EjbJar ejbJar = ejbModule.getEjbJar();
+            final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
+
+            final StatelessBean statelessBean = ejbJar.addEnterpriseBean(new 
StatelessBean(WidgetBean.class));
+            final EjbDeployment deployment = 
openejbJar.addEjbDeployment(statelessBean);
+
+            deployment.getProperties().put("color", "orange");
+            
assembler.createApplication(config.configureApplication(ejbModule));
+        }
+
+
+        final ContainerSystem containerSystem = 
SystemInstance.get().getComponent(ContainerSystem.class);
+        final BeanContext beanContext = 
containerSystem.getBeanContext("WidgetBean");
+
+        final Properties properties = beanContext.getProperties();
+        assertProperty(properties, "color", "orange");
+    }
+
+    public void testModuleContextProperties() throws Exception {
+
+        final ConfigurationFactory config = new ConfigurationFactory();
+        final Assembler assembler = new Assembler();
+
+        {
+            
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
+            
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
+        }
+
+        {
+            // Setup the descriptor information
+            final EjbModule ejbModule = new EjbModule(new EjbJar(), new 
OpenejbJar());
 
-        
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
-        
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
+            final EjbJar ejbJar = ejbModule.getEjbJar();
+            final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
+            openejbJar.getProperties().setProperty("color", "orange");
 
-        // Setup the descriptor information
+            ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
 
-        EjbModule ejbModule = new EjbModule(new EjbJar(), new OpenejbJar());
-        EjbJar ejbJar = ejbModule.getEjbJar();
-        OpenejbJar openejbJar = ejbModule.getOpenejbJar();
 
-        StatelessBean statelessBean = ejbJar.addEnterpriseBean(new 
StatelessBean(WidgetBean.class));
-        EjbDeployment deployment = openejbJar.addEjbDeployment(statelessBean);
-        deployment.getProperties().put("color", "orange");
+            final EjbJarInfo moduleInfo = 
config.configureApplication(ejbModule);
+            assertProperty(moduleInfo.properties, "color" , "orange");
 
-        assembler.createApplication(config.configureApplication(ejbModule));
+            assembler.createApplication(moduleInfo);
+        }
 
-        ContainerSystem containerSystem = 
SystemInstance.get().getComponent(ContainerSystem.class);
+        final ContainerSystem containerSystem = 
SystemInstance.get().getComponent(ContainerSystem.class);
+        final BeanContext beanContext = 
containerSystem.getBeanContext("WidgetBean");
 
-        BeanContext beanContext = containerSystem.getBeanContext("WidgetBean");
+        final Properties properties = 
beanContext.getModuleContext().getProperties();
+
+        assertProperty(properties, "color", "orange");
+    }
+
+    public void testAppContextProperties() throws Exception {
+
+        final ConfigurationFactory config = new ConfigurationFactory();
+        final Assembler assembler = new Assembler();
+
+        {
+            
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
+            
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
+        }
+
+        {
+            // Setup the descriptor information
+            final EjbModule ejbModule = new EjbModule(new EjbJar(), new 
OpenejbJar());
+            final EjbJar ejbJar = ejbModule.getEjbJar();
+            ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
+
+            final AppModule appModule = new AppModule(ejbModule);
+            appModule.getProperties().setProperty("color", "orange");
+
+
+            final AppInfo appInfo = config.configureApplication(appModule);
+
+            assertProperty(appInfo.properties, "color" , "orange");
+
+            assembler.createApplication(appInfo);
+        }
+
+        final ContainerSystem containerSystem = 
SystemInstance.get().getComponent(ContainerSystem.class);
+        final BeanContext beanContext = 
containerSystem.getBeanContext("WidgetBean");
+
+        final Properties properties = 
beanContext.getModuleContext().getAppContext().getProperties();
+
+        assertProperty(properties, "color", "orange");
+    }
 
-        Properties properties = beanContext.getProperties();
-        assertTrue(properties.containsKey("color"));
-        assertEquals("orange", properties.getProperty("color"));
+    private void assertProperty(Properties properties, final String key, final 
String value) {
+        assertTrue(properties.containsKey(key));
+        assertEquals(value, properties.getProperty(key));
     }
 
 

Propchange: 
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/DeploymentContextPropertiesTest.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to