Author: dblevins
Date: Mon Aug 20 06:09:11 2012
New Revision: 1374920
URL: http://svn.apache.org/viewvc?rev=1374920&view=rev
Log:
TOMEE-387 - Support for META-INF/application.properties file and overriding
TOMEE-386 - Support for META-INF/module.properties file and overriding
TOMEE-385 - Complete application properties scoping
Added:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ApplicationProperties.java
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ModuleProperties.java
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/ApplicationPropertiesTest.java
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/ModulePropertiesTest.java
Modified:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/DeploymentContext.java
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AppModule.java
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentModule.java
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/EjbJarInfoBuilder.java
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/Module.java
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/PersistenceModule.java
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/SuperProperties.java
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/util/Archives.java
Modified:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/DeploymentContext.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/DeploymentContext.java?rev=1374920&r1=1374919&r2=1374920&view=diff
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/DeploymentContext.java
(original)
+++
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/DeploymentContext.java
Mon Aug 20 06:09:11 2012
@@ -17,6 +17,7 @@
package org.apache.openejb;
import org.apache.openejb.loader.Options;
+import org.apache.openejb.util.SuperProperties;
import java.util.Properties;
import java.util.Map;
@@ -28,7 +29,7 @@ import java.util.HashMap;
public class DeploymentContext {
private final String id;
private final Map<Class, Object> data = new HashMap<Class, Object>();
- private final Properties properties = new Properties();
+ private final Properties properties = new
SuperProperties().caseInsensitive(true);
private Options options;
public DeploymentContext(String id, Options parent) {
Modified:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AppModule.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AppModule.java?rev=1374920&r1=1374919&r2=1374920&view=diff
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AppModule.java
(original)
+++
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AppModule.java
Mon Aug 20 06:09:11 2012
@@ -35,13 +35,14 @@ import java.util.TreeSet;
import org.apache.openejb.jee.jpa.unit.Persistence;
import org.apache.openejb.jee.jpa.unit.PersistenceUnit;
import org.apache.openejb.jee.jpa.unit.TransactionType;
+import org.apache.openejb.util.SuperProperties;
/**
* @version $Rev$ $Date$
*/
public class AppModule implements DeploymentModule {
- private final Properties properties = new Properties();
+ private final Properties properties = new
SuperProperties().caseInsensitive(true);
private final Application application;
private final ValidationContext validation;
private final List<URL> additionalLibraries = new ArrayList<URL>();
Added:
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=1374920&view=auto
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ApplicationProperties.java
(added)
+++
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ApplicationProperties.java
Mon Aug 20 06:09:11 2012
@@ -0,0 +1,98 @@
+/*
+ * 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 org.apache.openejb.OpenEJBException;
+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 java.io.IOException;
+import java.net.URL;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ApplicationProperties implements DynamicDeployer {
+
+ private static final Logger log =
Logger.getInstance(LogCategory.OPENEJB_STARTUP_CONFIG,
ApplicationProperties.class);
+
+ @Override
+ public AppModule deploy(AppModule appModule) throws OpenEJBException {
+
+ readPropertiesFiles(appModule);
+
+ applyOverrides(appModule);
+
+ return appModule;
+ }
+
+ private void readPropertiesFiles(AppModule appModule) throws
OpenEJBException {
+ final Collection<DeploymentModule> deploymentModule =
appModule.getDeploymentModule();
+
+ // We intentionally add the AppModule itself LAST so its properties
trump all
+ deploymentModule.add(appModule);
+
+ for (DeploymentModule module : deploymentModule) {
+
+ final Object o = module.getAltDDs().get("application.properties");
+
+ if (o instanceof URL) {
+ final URL url = (URL) o;
+ try {
+ final Properties properties = IO.readProperties(url);
+ appModule.getProperties().putAll(properties);
+ } catch (IOException e) {
+ throw new OpenEJBException("Cannot read
application.properties: " + url, e);
+ }
+ } else if (o instanceof Properties) {
+ appModule.getProperties().putAll((Properties) o);
+ } else if (o != null) {
+ throw new OpenEJBException("Unknown application.properties
type: "+o.getClass().getName());
+ }
+ }
+
+
+ }
+
+ private void applyOverrides(AppModule appModule) {
+ final String id = appModule.getModuleId() + ".";
+
+ final Properties properties = SystemInstance.get().getProperties();
+
+ for (Map.Entry<Object, Object> entry : properties.entrySet()) {
+ final String key = entry.getKey().toString();
+
+ if (key.startsWith(id)) {
+ final String property = key.substring(id.length());
+
+ if (appModule.getProperties().containsKey(property)) {
+ log.debug("Overriding application " +
appModule.getModuleId() + " property " + property + "=" + entry.getValue());
+ } else {
+ log.debug("Adding application " + appModule.getModuleId()
+ " property " + property + "=" + entry.getValue());
+ }
+
+ appModule.getProperties().put(property, entry.getValue());
+ }
+ }
+ }
+
+}
Modified:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java?rev=1374920&r1=1374919&r2=1374920&view=diff
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
(original)
+++
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
Mon Aug 20 06:09:11 2012
@@ -166,6 +166,10 @@ public class ConfigurationFactory implem
chain.add(new ReadDescriptors());
+ chain.add(new ApplicationProperties());
+
+ chain.add(new ModuleProperties());
+
chain.add(new LegacyProcessor());
chain.add(new AnnotationDeployer());
Modified:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentModule.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentModule.java?rev=1374920&r1=1374919&r2=1374920&view=diff
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentModule.java
(original)
+++
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentModule.java
Mon Aug 20 06:09:11 2012
@@ -17,6 +17,7 @@
package org.apache.openejb.config;
import org.apache.openejb.jee.NamedModule;
+import org.apache.openejb.jee.jpa.unit.Properties;
import org.apache.openejb.loader.SystemInstance;
import java.io.File;
@@ -52,6 +53,8 @@ public interface DeploymentModule {
void setStandaloneModule(boolean isStandalone);
+ java.util.Properties getProperties();
+
class ID {
private final String name;
private final File location;
Modified:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/EjbJarInfoBuilder.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/EjbJarInfoBuilder.java?rev=1374920&r1=1374919&r2=1374920&view=diff
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/EjbJarInfoBuilder.java
(original)
+++
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/EjbJarInfoBuilder.java
Mon Aug 20 06:09:11 2012
@@ -146,6 +146,7 @@ public class EjbJarInfoBuilder {
ejbJar.watchedResources.addAll(jar.getWatchedResources());
+ ejbJar.properties.putAll(jar.getProperties());
ejbJar.properties.putAll(jar.getOpenejbJar().getProperties());
for (EnterpriseBean bean : jar.getEjbJar().getEnterpriseBeans()) {
Modified:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/Module.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/Module.java?rev=1374920&r1=1374919&r2=1374920&view=diff
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/Module.java
(original)
+++
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/Module.java
Mon Aug 20 06:09:11 2012
@@ -18,10 +18,12 @@ package org.apache.openejb.config;
import org.apache.openejb.config.sys.Resources;
import org.apache.openejb.jee.bval.ValidationConfigType;
+import org.apache.openejb.util.SuperProperties;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
+import java.util.Properties;
import java.util.Set;
public class Module {
@@ -37,6 +39,7 @@ public class Module {
private AppModule appModule = null;
private Resources resources = null;
private final Set<String> mbeans = new HashSet<String>();
+ private final Properties properties = new
SuperProperties().caseInsensitive(true);
public Module(boolean needId) {
if (needId) {
@@ -48,6 +51,10 @@ public class Module {
this(true);
}
+ public Properties getProperties() {
+ return properties;
+ }
+
public ValidationConfigType getValidationConfig() {
return validationConfig;
}
Added:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ModuleProperties.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ModuleProperties.java?rev=1374920&view=auto
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ModuleProperties.java
(added)
+++
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ModuleProperties.java
Mon Aug 20 06:09:11 2012
@@ -0,0 +1,92 @@
+/*
+ * 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 org.apache.openejb.OpenEJBException;
+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 java.io.IOException;
+import java.net.URL;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ModuleProperties implements DynamicDeployer {
+
+ private static final Logger log =
Logger.getInstance(LogCategory.OPENEJB_STARTUP_CONFIG, ModuleProperties.class);
+
+ @Override
+ public AppModule deploy(AppModule appModule) throws OpenEJBException {
+
+ final Properties overrides = new Properties();
+ overrides.putAll(SystemInstance.get().getProperties());
+ overrides.putAll(appModule.getProperties());
+
+ for (DeploymentModule module : appModule.getDeploymentModule()) {
+
+ readProperties(module);
+
+ applyOverrides(overrides, module);
+
+ }
+
+ return appModule;
+ }
+
+ private static void readProperties(DeploymentModule module) throws
OpenEJBException {
+ final Object o = module.getAltDDs().get("module.properties");
+
+ if (o instanceof URL) {
+ final URL url = (URL) o;
+ try {
+ final Properties properties = IO.readProperties(url);
+ module.getProperties().putAll(properties);
+ } catch (IOException e) {
+ throw new OpenEJBException("Cannot read module.properties: " +
url, e);
+ }
+ } else if (o instanceof Properties) {
+ module.getProperties().putAll((Properties) o);
+ } else if (o != null) {
+ throw new OpenEJBException("Unknown module.properties type:
"+o.getClass().getName());
+ }
+ }
+
+ private static void applyOverrides(Properties overrides, DeploymentModule
module) {
+ final String id = module.getModuleId() + ".";
+
+ for (Map.Entry<Object, Object> entry : overrides.entrySet()) {
+ final String key = entry.getKey().toString();
+
+ if (key.startsWith(id)) {
+ final String property = key.substring(id.length());
+
+ if (module.getProperties().containsKey(property)) {
+ log.debug("Overriding module " + module.getModuleId() + "
property " + property + "=" + entry.getValue());
+ } else {
+ log.debug("Adding module " + module.getModuleId() + "
property " + property + "=" + entry.getValue());
+ }
+
+ module.getProperties().put(property, entry.getValue());
+ }
+ }
+ }
+}
Modified:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/PersistenceModule.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/PersistenceModule.java?rev=1374920&r1=1374919&r2=1374920&view=diff
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/PersistenceModule.java
(original)
+++
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/PersistenceModule.java
Mon Aug 20 06:09:11 2012
@@ -22,6 +22,7 @@ import org.apache.openejb.jee.jpa.unit.P
import java.io.File;
import java.net.URI;
+import java.util.Properties;
import java.util.Set;
import java.util.TreeSet;
import java.util.Map;
@@ -88,6 +89,11 @@ public class PersistenceModule implement
}
@Override
+ public Properties getProperties() {
+ return null;
+ }
+
+ @Override
public String toString() {
return "PersistenceModule{" +
"rootUrl='" + rootUrl + '\'' +
Modified:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/SuperProperties.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/SuperProperties.java?rev=1374920&r1=1374919&r2=1374920&view=diff
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/SuperProperties.java
(original)
+++
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/SuperProperties.java
Mon Aug 20 06:09:11 2012
@@ -162,6 +162,11 @@ public class SuperProperties extends Pro
this.caseInsensitive = caseInsensitive;
}
+ public SuperProperties caseInsensitive(boolean caseInsensitive) {
+ setCaseInsensitive(caseInsensitive);
+ return this;
+ }
+
/**
* Gets the text that separates keys and values.
* The default is "=".
Modified:
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=1374920&r1=1374919&r2=1374920&view=diff
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/DeploymentContextOptionsTest.java
(original)
+++
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/DeploymentContextOptionsTest.java
Mon Aug 20 06:09:11 2012
@@ -35,6 +35,7 @@ import org.apache.openejb.spi.ContainerS
* @version $Rev$ $Date$
*/
public class DeploymentContextOptionsTest extends TestCase {
+
@Override
protected void setUp() throws Exception {
SystemInstance.reset();
@@ -219,7 +220,6 @@ public class DeploymentContextOptionsTes
assertEquals(defaultValue, options.get(key, defaultValue));
}
-
public static interface Widget {
}
Added:
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=1374920&view=auto
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/ApplicationPropertiesTest.java
(added)
+++
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/ApplicationPropertiesTest.java
Mon Aug 20 06:09:11 2012
@@ -0,0 +1,233 @@
+/*
+ * 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.AppContext;
+import org.apache.openejb.BeanContext;
+import org.apache.openejb.ModuleContext;
+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.loader.Options;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.spi.ContainerSystem;
+import org.apache.openejb.util.Archives;
+
+import javax.ejb.Singleton;
+import java.io.File;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ApplicationPropertiesTest extends TestCase {
+
+ @Override
+ protected void setUp() throws Exception {
+ SystemInstance.reset();
+ }
+
+ public void test() 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));
+ }
+
+ {
+ final Map<String, String> map = new HashMap<String, String>();
+ map.put("META-INF/application.properties", "color=orange");
+
+ final File app = Archives.fileArchive(map, WidgetBean.class);
+
+ assembler.createApplication(config.configureApplication(app));
+ }
+
+ final ContainerSystem containerSystem =
SystemInstance.get().getComponent(ContainerSystem.class);
+
+ assertContexts(containerSystem);
+ }
+
+ /**
+ * A child module META-INF/application.properties sets color to white
+ *
+ * In the root ear META-INF/application.properties color is set to orange
+ *
+ * The root ear META-INF/application.properties wins
+ *
+ * @throws Exception
+ */
+ public void testConflictingFiles() 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));
+ }
+
+ {
+ final Map<String, String> moduleFiles = new HashMap<String,
String>();
+ moduleFiles.put("META-INF/ejb-jar.xml", "<ejb-jar
id=\"fooModule\"/>");
+ moduleFiles.put("META-INF/application.properties", "color=white");
+
+ final File module = Archives.jarArchive(moduleFiles, "fooModule",
WidgetBean.class);
+
+ final Map<String, String> appFiles = new HashMap<String, String>();
+ appFiles.put("META-INF/application.xml", "" +
+ "<application id=\"fooApp\">\n" +
+ " <module>\n" +
+ " <ejb>"+module.getName()+"</ejb>\n" +
+ " </module>\n" +
+ "</application>");
+
+ appFiles.put("META-INF/application.properties", "color=orange");
+ final File app = Archives.fileArchive(appFiles);
+
+ assertTrue(module.renameTo(new File(app, module.getName())));
+
+ final AppInfo appInfo = config.configureApplication(app);
+ assembler.createApplication(appInfo);
+ }
+
+ final ContainerSystem containerSystem =
SystemInstance.get().getComponent(ContainerSystem.class);
+
+ assertContexts(containerSystem);
+ }
+
+ public void testOverrideAdd() 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("fooApp.color", "orange");
+
+ 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 testOverrideReplace() 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("fooApp.color", "orange");
+
+ final Map<String, String> map = new HashMap<String, String>();
+ map.put("META-INF/ejb-jar.xml", "<ejb-jar id=\"fooModule\"/>");
+ map.put("META-INF/application.properties", "color=white");
+
+ 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);
+ }
+
+
+
+ private void assertContexts(ContainerSystem containerSystem) {
+ final BeanContext beanContext =
containerSystem.getBeanContext("WidgetBean");
+ final ModuleContext moduleContext = beanContext.getModuleContext();
+ final AppContext appContext = moduleContext.getAppContext();
+
+ { // Assert as Properties
+
+ // AppContext should have color property
+ assertProperty(appContext.getProperties(), "color", "orange");
+
+ // BeanContext and ModuleContext should not
+ assertNoProperty(beanContext.getProperties(), "color");
+ assertNoProperty(moduleContext.getProperties(), "color");
+
+ // Try all the above again with mixed case
+ assertProperty(appContext.getProperties(), "coLOr", "orange");
+ assertNoProperty(beanContext.getProperties(), "coLOr");
+ assertNoProperty(moduleContext.getProperties(), "coLOr");
+ }
+
+ { // Assert as Options
+
+ // AppContext should have color option
+ assertOption(appContext.getOptions(), "color", "orange");
+
+ // BeanContext and ModuleContext should inherit AppContext color
+ assertOption(beanContext.getOptions(), "color", "orange");
+ assertOption(moduleContext.getOptions(), "color", "orange");
+
+ // Try all the above again using mixed case
+ assertOption(appContext.getOptions(), "coLoR", "orange");
+ assertOption(moduleContext.getOptions(), "coLoR", "orange");
+ assertOption(beanContext.getOptions(), "coLoR", "orange");
+ }
+ }
+
+ 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));
+ }
+
+ private void assertProperty(Properties properties, final String key, final
String value) {
+ assertTrue(properties.containsKey(key));
+ assertEquals(value, properties.getProperty(key));
+ }
+
+ private void assertNoProperty(Properties properties, final String key) {
+ assertFalse(properties.containsKey(key));
+ }
+
+ @Singleton
+ public static class WidgetBean {
+
+ }
+}
Added:
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/ModulePropertiesTest.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/ModulePropertiesTest.java?rev=1374920&view=auto
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/ModulePropertiesTest.java
(added)
+++
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/ModulePropertiesTest.java
Mon Aug 20 06:09:11 2012
@@ -0,0 +1,243 @@
+/*
+ * 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.AppContext;
+import org.apache.openejb.BeanContext;
+import org.apache.openejb.ModuleContext;
+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.loader.Options;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.spi.ContainerSystem;
+import org.apache.openejb.util.Archives;
+
+import javax.ejb.Singleton;
+import java.io.File;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ModulePropertiesTest extends TestCase {
+
+ @Override
+ protected void setUp() throws Exception {
+ SystemInstance.reset();
+ }
+
+ public void testFile() 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));
+ }
+
+ {
+ final Map<String, String> map = new HashMap<String, String>();
+ map.put("META-INF/module.properties", "color=orange");
+
+ final File app = Archives.fileArchive(map, WidgetBean.class);
+
+ assembler.createApplication(config.configureApplication(app));
+ }
+
+ final ContainerSystem containerSystem =
SystemInstance.get().getComponent(ContainerSystem.class);
+
+ assertContexts(containerSystem);
+ }
+
+ public void testOverrideAdd() 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("fooModule.color",
"orange");
+
+ 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 testOverrideReplace() 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("fooModule.color",
"orange");
+
+ final Map<String, String> map = new HashMap<String, String>();
+ map.put("META-INF/ejb-jar.xml", "<ejb-jar id=\"fooModule\"/>");
+ map.put("META-INF/module.properties", "color=white");
+
+ 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 testOverrideFromApplicationProperties() 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));
+ }
+
+ {
+ final Map<String, String> map = new HashMap<String, String>();
+ map.put("META-INF/ejb-jar.xml", "<ejb-jar id=\"fooModule\"/>");
+ map.put("META-INF/module.properties", "color=white");
+
+ final File module = Archives.fileArchive(map, WidgetBean.class);
+
+ final AppModule appModule =
config.loadApplication(this.getClass().getClassLoader(), "fooApp",
Arrays.asList(module));
+ appModule.getProperties().put("fooModule.color", "orange");
+
+ final AppInfo appInfo = config.configureApplication(appModule);
+ assembler.createApplication(appInfo);
+ }
+
+ final ContainerSystem containerSystem =
SystemInstance.get().getComponent(ContainerSystem.class);
+
+ assertContexts(containerSystem);
+ }
+
+ public void testOverrideFromFullDottedPath() 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("fooApp.fooModule.color",
"orange");
+
+ final Map<String, String> map = new HashMap<String, String>();
+ map.put("META-INF/ejb-jar.xml", "<ejb-jar id=\"fooModule\"/>");
+ map.put("META-INF/module.properties", "color=white");
+
+ 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);
+ }
+
+ private void assertContexts(ContainerSystem containerSystem) {
+ final BeanContext beanContext =
containerSystem.getBeanContext("WidgetBean");
+ final ModuleContext moduleContext = beanContext.getModuleContext();
+ final AppContext appContext = moduleContext.getAppContext();
+
+ { // Assert as Properties
+
+ // ModuleContext should have color property
+ assertProperty(moduleContext.getProperties(), "color", "orange");
+
+ // BeanContext and AppContext should not
+ assertNoProperty(beanContext.getProperties(), "color");
+ assertNoProperty(appContext.getProperties(), "color");
+
+ // Try all the above again with mixed case
+ assertProperty(moduleContext.getProperties(), "coLOr", "orange");
+ assertNoProperty(beanContext.getProperties(), "coLOr");
+ assertNoProperty(appContext.getProperties(), "coLOr");
+ }
+
+ { // Assert as Options
+
+ // ModuleContext should have color option
+ assertOption(moduleContext.getOptions(), "color", "orange");
+
+ // BeanContext should inherit ModuleContext color
+ assertOption(beanContext.getOptions(), "color", "orange");
+
+ // AppContext should remain unpolluted
+ assertNoOption(appContext.getOptions(), "color");
+
+ // Try all the above again using mixed case
+ assertOption(moduleContext.getOptions(), "coLoR", "orange");
+ assertOption(beanContext.getOptions(), "coLoR", "orange");
+ assertNoOption(appContext.getOptions(), "coLoR");
+ }
+ }
+
+ 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));
+ }
+
+ private void assertProperty(Properties properties, final String key, final
String value) {
+ assertTrue(properties.containsKey(key));
+ assertEquals(value, properties.getProperty(key));
+ }
+
+ private void assertNoProperty(Properties properties, final String key) {
+ assertFalse(properties.containsKey(key));
+ }
+
+ @Singleton
+ public static class WidgetBean {
+
+ }
+}
Modified:
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/util/Archives.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/util/Archives.java?rev=1374920&r1=1374919&r2=1374920&view=diff
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/util/Archives.java
(original)
+++
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/util/Archives.java
Mon Aug 20 06:09:11 2012
@@ -26,7 +26,6 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
-import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;