Author: dblevins
Date: Mon Aug 20 22:53:23 2012
New Revision: 1375291

URL: http://svn.apache.org/viewvc?rev=1375291&view=rev
Log:
Ensure 'openejb.foo' wins over 'foo' for properties pulled into AppContext
TOMEE-387

Added:
    
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/SystemPropertiesTest.java
Modified:
    
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ApplicationProperties.java
    
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/ApplicationPropertiesTest.java

Modified: 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ApplicationProperties.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ApplicationProperties.java?rev=1375291&r1=1375290&r2=1375291&view=diff
==============================================================================
--- 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ApplicationProperties.java
 (original)
+++ 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ApplicationProperties.java
 Mon Aug 20 22:53:23 2012
@@ -21,9 +21,11 @@ import org.apache.openejb.loader.IO;
 import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
+import org.apache.openejb.util.SuperProperties;
 
 import java.io.IOException;
 import java.net.URL;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Map;
 import java.util.Properties;
@@ -74,9 +76,31 @@ public class ApplicationProperties imple
     }
 
     private void applyOverrides(AppModule appModule) {
-        final String id = appModule.getModuleId() + ".";
 
-        final Properties properties = SystemInstance.get().getProperties();
+        final SuperProperties properties = new 
SuperProperties().caseInsensitive(false);
+        properties.putAll(SystemInstance.get().getProperties());
+
+        // Anything starting with "openejb" or "tomee" trumps other properties
+        // so "openejb.foo" always beats "foo"
+        for (Map.Entry<Object, Object> entry : 
SystemInstance.get().getProperties().entrySet()) {
+            final String key = entry.getKey().toString();
+
+            for (String prefix : Arrays.asList("openejb.", "tomee.")) {
+                if (key.startsWith(prefix)) {
+                    final String property = key.substring(prefix.length());
+
+                    if (appModule.getProperties().containsKey(property)) {
+                        log.debug("Overriding system property " + property + 
"=" + entry.getValue());
+                    } else {
+                        log.debug("Adding system property " + property + "=" + 
entry.getValue());
+                    }
+
+                    properties.put(property, entry.getValue());
+                }
+            }
+        }
+
+        final String id = appModule.getModuleId() + ".";
 
         for (Map.Entry<Object, Object> entry : properties.entrySet()) {
             final String key = entry.getKey().toString();

Modified: 
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/ApplicationPropertiesTest.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/ApplicationPropertiesTest.java?rev=1375291&r1=1375290&r2=1375291&view=diff
==============================================================================
--- 
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/ApplicationPropertiesTest.java
 (original)
+++ 
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/ApplicationPropertiesTest.java
 Mon Aug 20 22:53:23 2012
@@ -170,7 +170,71 @@ public class ApplicationPropertiesTest e
         assertContexts(containerSystem);
     }
 
+    public void testOverrideUnprefixedVsPrefixedOpenEJB() throws Exception {
+        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));
+        }
+
+        {
+            SystemInstance.get().getProperties().put("openejb.fooApp.color", 
"orange");
+            SystemInstance.get().getProperties().put("fooApp.color", "green");
+
+            final Map<String, String> map = new HashMap<String, String>();
+            map.put("META-INF/ejb-jar.xml", "<ejb-jar id=\"fooModule\"/>");
+            final File module = Archives.fileArchive(map, WidgetBean.class);
+
+            final AppModule appModule = 
config.loadApplication(this.getClass().getClassLoader(), "fooApp", 
Arrays.asList(module));
+            final AppInfo appInfo = config.configureApplication(appModule);
+            assembler.createApplication(appInfo);
+        }
+
+        final ContainerSystem containerSystem = 
SystemInstance.get().getComponent(ContainerSystem.class);
+
+        assertContexts(containerSystem);
+    }
+
+    public void testOverrideUnprefixedVsPrefixedTomEE() throws Exception {
+        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));
+        }
 
+        {
+            SystemInstance.get().getProperties().put("tomee.fooApp.color", 
"orange");
+            SystemInstance.get().getProperties().put("fooApp.color", "green");
+
+            final Map<String, String> map = new HashMap<String, String>();
+            map.put("META-INF/ejb-jar.xml", "<ejb-jar id=\"fooModule\"/>");
+            final File module = Archives.fileArchive(map, WidgetBean.class);
+
+            final AppModule appModule = 
config.loadApplication(this.getClass().getClassLoader(), "fooApp", 
Arrays.asList(module));
+            final AppInfo appInfo = config.configureApplication(appModule);
+            assembler.createApplication(appInfo);
+        }
+
+        final ContainerSystem containerSystem = 
SystemInstance.get().getComponent(ContainerSystem.class);
+
+        assertContexts(containerSystem);
+    }
+
+    /**
+     * Not implemented.  Don't do it if you want deterministic behavior
+     *
+     * Use one or the other, use both and no guarantee is made
+     * @throws Exception
+     */
+    public void _testOverrideUnprefixedVsPrefixedTomEEAndOpenEJB() throws 
Exception {
+
+        SystemInstance.get().getProperties().put("tomee.fooApp.color", 
"green");
+        SystemInstance.get().getProperties().put("openejb.fooApp.color", 
"blue");
+    }
 
     private void assertContexts(ContainerSystem containerSystem) {
         final BeanContext beanContext = 
containerSystem.getBeanContext("WidgetBean");

Added: 
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/SystemPropertiesTest.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/SystemPropertiesTest.java?rev=1375291&view=auto
==============================================================================
--- 
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/SystemPropertiesTest.java
 (added)
+++ 
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/SystemPropertiesTest.java
 Mon Aug 20 22:53:23 2012
@@ -0,0 +1,26 @@
+/*
+ * 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;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SystemPropertiesTest extends TestCase {
+
+}


Reply via email to