FELIX-3780 - alternative way of configuring DA:
- no longer depend on the ConfigAdmin APIs for runtime configurations;
- use framework/system properties instead.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1649781 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Activator.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Activator.java
index e6089d5..7013e78 100644
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Activator.java
+++ b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Activator.java
@@ -18,13 +18,9 @@
*/
package org.apache.felix.deploymentadmin;
-import java.util.Dictionary;
-import java.util.Hashtable;
-
import org.apache.felix.dm.DependencyActivatorBase;
import org.apache.felix.dm.DependencyManager;
import org.osgi.framework.BundleContext;
-import org.osgi.service.cm.ManagedService;
import org.osgi.service.deploymentadmin.DeploymentAdmin;
import org.osgi.service.event.EventAdmin;
import org.osgi.service.log.LogService;
@@ -38,13 +34,8 @@
public class Activator extends DependencyActivatorBase {
public void init(BundleContext context, DependencyManager manager) throws Exception {
- String[] ifaces = { DeploymentAdmin.class.getName(), ManagedService.class.getName() };
-
- Dictionary props = new Hashtable();
- props.put(Constants.SERVICE_PID, DeploymentAdminImpl.PID);
-
manager.add(createComponent()
- .setInterface(ifaces, props)
+ .setInterface(DeploymentAdmin.class.getName(), null)
.setImplementation(DeploymentAdminImpl.class)
.add(createServiceDependency()
.setService(PackageAdmin.class)
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentAdminConfig.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentAdminConfig.java
index dcfb9cc..e180ad7 100644
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentAdminConfig.java
+++ b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentAdminConfig.java
@@ -18,110 +18,62 @@
*/
package org.apache.felix.deploymentadmin;
-import java.util.Dictionary;
-
import org.osgi.framework.BundleContext;
-import org.osgi.service.cm.ConfigurationException;
-import org.osgi.service.deploymentadmin.DeploymentAdmin;
/**
- * Provides the configuration options for this implementation of {@link DeploymentAdmin}.
+ * Provides the configuration options for this DeploymentAdmin implementation.
*/
public class DeploymentAdminConfig {
+ /** Prefix used for the configuration properties of DA. */
+ private static final String PREFIX = "org.apache.felix.deploymentadmin.";
+
/** Configuration key used to stop only bundles mentioned in a DP instead of all bundles. */
- static final String KEY_STOP_UNAFFECTED_BUNDLE = "stopUnaffectedBundle";
+ static final String KEY_STOP_UNAFFECTED_BUNDLE = PREFIX.concat("stopUnaffectedBundle");
/** Configuration key used to allow usage of customizers outside a DP. */
- static final String KEY_ALLOW_FOREIGN_CUSTOMIZERS = "allowForeignCustomizers";
+ static final String KEY_ALLOW_FOREIGN_CUSTOMIZERS = PREFIX.concat("allowForeignCustomizers");
static final boolean DEFAULT_STOP_UNAFFECTED_BUNDLE = true;
static final boolean DEFAULT_ALLOW_FOREIGN_CUSTOMIZERS = false;
- private final BundleContext m_context;
- private final Boolean m_stopUnaffectedBundles;
- private final Boolean m_allowForeignCustomizers;
+ private final boolean m_stopUnaffectedBundles;
+ private final boolean m_allowForeignCustomizers;
/**
* Creates a new {@link DeploymentAdminConfig} instance with the default settings.
*/
public DeploymentAdminConfig(BundleContext context) {
- m_context = context;
- m_stopUnaffectedBundles = null;
- m_allowForeignCustomizers = null;
+ m_stopUnaffectedBundles = parseBoolean(getFrameworkProperty(context, KEY_STOP_UNAFFECTED_BUNDLE), DEFAULT_STOP_UNAFFECTED_BUNDLE);
+ m_allowForeignCustomizers = parseBoolean(getFrameworkProperty(context, KEY_ALLOW_FOREIGN_CUSTOMIZERS), DEFAULT_ALLOW_FOREIGN_CUSTOMIZERS);
}
/**
- * Creates a new {@link DeploymentAdminConfig} instance with the given configuration properties.
- */
- public DeploymentAdminConfig(BundleContext context, Dictionary properties) throws ConfigurationException {
- Boolean stopUnaffectedBundles = null;
- Boolean allowForeignCustomizers = null;
-
- if (properties != null) {
- stopUnaffectedBundles = getMandatoryValue(properties, KEY_STOP_UNAFFECTED_BUNDLE);
- allowForeignCustomizers = getMandatoryValue(properties, KEY_ALLOW_FOREIGN_CUSTOMIZERS);
- }
-
- m_context = context;
- m_stopUnaffectedBundles = stopUnaffectedBundles;
- m_allowForeignCustomizers = allowForeignCustomizers;
- }
-
- /**
- * Creates a new {@link DeploymentAdminConfig} instance as copy of the given configuration.
- */
- public DeploymentAdminConfig(DeploymentAdminConfig configuration) {
- m_context = configuration.m_context;
- m_stopUnaffectedBundles = configuration.m_stopUnaffectedBundles;
- m_allowForeignCustomizers = configuration.m_allowForeignCustomizers;
- }
-
- private static Boolean getMandatoryValue(Dictionary dict, String key) throws ConfigurationException {
- Object value = dict.get(key);
- if (value == null || !(value instanceof String || value instanceof Boolean)) {
- throw new ConfigurationException(key, "missing or invalid value!");
- }
- return parseBoolean(value);
- }
-
- private static Boolean parseBoolean(Object value) {
- if (value instanceof Boolean) {
- return (Boolean) value;
- }
- return value != null ? Boolean.valueOf(value.toString()) : null;
- }
-
- /**
- * @return <code>true</code> if foreign customizers (that are not part of a DP) are allowed, <code>false</code> if all customizers should be provided by this or an earlier DP.
+ * @return <code>true</code> if foreign customizers (that are not part of a DP) are allowed, <code>false</code> if
+ * all customizers should be provided by this or an earlier DP.
*/
public boolean isAllowForeignCustomizers() {
- Boolean result = m_allowForeignCustomizers;
- if (result == null) {
- String prop = getFrameworkProperty(KEY_ALLOW_FOREIGN_CUSTOMIZERS);
- if (prop != null) {
- result = Boolean.valueOf(prop);
- }
- }
- return (result == null) ? DEFAULT_ALLOW_FOREIGN_CUSTOMIZERS : result.booleanValue();
+ return m_allowForeignCustomizers;
}
/**
- * @return <code>true</code> if all bundles should be stopped during the installation of a DP, <code>false</code> if only affected bundles should be stopped.
+ * @return <code>true</code> if all bundles should be stopped during the installation of a DP, <code>false</code> if
+ * only affected bundles should be stopped.
*/
public boolean isStopUnaffectedBundles() {
- Boolean result = m_stopUnaffectedBundles;
- if (result == null) {
- String prop = getFrameworkProperty(KEY_STOP_UNAFFECTED_BUNDLE);
- if (prop != null) {
- result = Boolean.valueOf(prop);
- }
- }
- return (result == null) ? DEFAULT_STOP_UNAFFECTED_BUNDLE : result.booleanValue();
+ return m_stopUnaffectedBundles;
}
- private String getFrameworkProperty(String key) {
- String prop = m_context.getProperty(DeploymentAdminImpl.PID + "." + key);
+ private static boolean parseBoolean(String value, boolean dflt) {
+ if (value == null || "".equals(value.trim())) {
+ return dflt;
+ }
+ return Boolean.parseBoolean(value);
+ }
+
+ private static String getFrameworkProperty(BundleContext context, String key) {
+ String prop = context.getProperty(key);
if (prop == null) {
- prop = m_context.getProperty(DeploymentAdminImpl.PID + "." + key.toLowerCase());
+ // be lenient wrt the naming...
+ prop = context.getProperty(key.toLowerCase());
}
return prop;
}
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentAdminImpl.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentAdminImpl.java
index 70f9a3d..d5965f2 100644
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentAdminImpl.java
+++ b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentAdminImpl.java
@@ -48,8 +48,6 @@
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Version;
-import org.osgi.service.cm.ConfigurationException;
-import org.osgi.service.cm.ManagedService;
import org.osgi.service.deploymentadmin.DeploymentAdmin;
import org.osgi.service.deploymentadmin.DeploymentException;
import org.osgi.service.deploymentadmin.DeploymentPackage;
@@ -58,10 +56,7 @@
import org.osgi.service.log.LogService;
import org.osgi.service.packageadmin.PackageAdmin;
-public class DeploymentAdminImpl implements DeploymentAdmin, ManagedService, Constants {
- /** Configuration PID used to dynamically configure DA at runtime. */
- public static final String PID = "org.apache.felix.deploymentadmin";
-
+public class DeploymentAdminImpl implements DeploymentAdmin, Constants {
public static final String PACKAGE_DIR = "packages";
public static final String TEMP_DIR = "temp";
public static final String PACKAGECONTENTS_DIR = "contents";
@@ -76,7 +71,6 @@
private volatile EventAdmin m_eventAdmin; /* will be injected by dependencymanager */
private volatile LogService m_log; /* will be injected by dependencymanager */
private volatile DeploymentSessionImpl m_session;
- private volatile DeploymentAdminConfig m_config;
private final Map /* BSN -> DeploymentPackage */m_packages = new HashMap();
private final Semaphore m_semaphore = new Semaphore();
@@ -113,13 +107,6 @@
return m_context;
}
- /**
- * @return the configuration for this {@link DeploymentAdmin} instance, never <code>null</code>.
- */
- public DeploymentAdminConfig getConfiguration() {
- return m_config;
- }
-
public DeploymentPackage getDeploymentPackage(Bundle bundle) {
if (bundle == null) {
throw new IllegalArgumentException("Bundle can not be null");
@@ -228,7 +215,7 @@
}
try {
- m_session = new DeploymentSessionImpl(source, target, createInstallCommandChain(), this);
+ m_session = new DeploymentSessionImpl(source, target, createInstallCommandChain(), this, new DeploymentAdminConfig(m_context));
m_session.call(false /* ignoreExceptions */);
}
catch (DeploymentException de) {
@@ -294,9 +281,6 @@
* Called by dependency manager upon start of this component.
*/
public void start() throws DeploymentException {
- // Create a default configuration...
- m_config = new DeploymentAdminConfig(m_context);
-
File packageDir = m_context.getDataFile(PACKAGE_DIR);
if (packageDir == null) {
throw new DeploymentException(CODE_OTHER_ERROR, "Could not create directories needed for deployment package persistence");
@@ -327,15 +311,14 @@
*/
public void stop() {
cancel();
-
- m_config = null;
}
/**
* Uninstalls the given deployment package from the system.
*
* @param dp the deployment package to uninstall, cannot be <code>null</code>;
- * @param forced <code>true</code> to force the uninstall, meaning that any exceptions are ignored during the uninstallation.
+ * @param forced <code>true</code> to force the uninstall, meaning that any exceptions are ignored during the
+ * uninstallation.
* @throws DeploymentException in case the uninstall failed.
*/
public void uninstallDeploymentPackage(DeploymentPackage dp, boolean forced) throws DeploymentException {
@@ -357,7 +340,7 @@
try {
try {
- m_session = new DeploymentSessionImpl(source, target, createUninstallCommandChain(), this);
+ m_session = new DeploymentSessionImpl(source, target, createUninstallCommandChain(), this, new DeploymentAdminConfig(m_context));
m_session.call(forced /* ignoreExceptions */);
}
catch (DeploymentException de) {
@@ -380,10 +363,6 @@
}
}
- public void updated(Dictionary properties) throws ConfigurationException {
- m_config = new DeploymentAdminConfig(m_context, properties);
- }
-
/**
* Creates the properties for a new event.
*
@@ -449,8 +428,10 @@
/**
* Searches for a deployment package that contains a bundle with the given symbolic name.
*
- * @param symbolicName the symbolic name of the <em>bundle</em> to return the containing deployment package for, cannot be <code>null</code>.
- * @return the deployment package containing the given bundle, or <code>null</code> if no deployment package contained such bundle.
+ * @param symbolicName the symbolic name of the <em>bundle</em> to return the containing deployment package for,
+ * cannot be <code>null</code>.
+ * @return the deployment package containing the given bundle, or <code>null</code> if no deployment package
+ * contained such bundle.
*/
private AbstractDeploymentPackage getDeploymentPackageContainingBundleWithSymbolicName(String symbolicName) {
for (Iterator i = m_packages.values().iterator(); i.hasNext();) {
@@ -621,7 +602,9 @@
private void verifySourcePackage(AbstractDeploymentPackage source) throws DeploymentException {
// TODO this method should do a X-ref check between DP-manifest and JAR-entries...
-// m_log.log(LogService.LOG_ERROR, "Missing bundle '" + symbolicName + "/" + bundleInfos[i].getVersion() + " does not exist in target package!");
-// throw new DeploymentException(CODE_OTHER_ERROR, "Missing bundle '" + symbolicName + "/" + bundleInfos[i].getVersion() + " is not part of target package!");
+// m_log.log(LogService.LOG_ERROR, "Missing bundle '" + symbolicName + "/" + bundleInfos[i].getVersion() +
+// " does not exist in target package!");
+// throw new DeploymentException(CODE_OTHER_ERROR, "Missing bundle '" + symbolicName + "/" + bundleInfos[i].getVersion()
+// + " is not part of target package!");
}
}
\ No newline at end of file
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DeploymentSessionImpl.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DeploymentSessionImpl.java
index 68d0fb0..3c8cc1d 100644
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DeploymentSessionImpl.java
+++ b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DeploymentSessionImpl.java
@@ -50,12 +50,12 @@
private volatile Command m_currentCommand = null;
private volatile boolean m_cancelled;
- public DeploymentSessionImpl(AbstractDeploymentPackage source, AbstractDeploymentPackage target, List commands, DeploymentAdminImpl admin) {
+ public DeploymentSessionImpl(AbstractDeploymentPackage source, AbstractDeploymentPackage target, List commands, DeploymentAdminImpl admin, DeploymentAdminConfig config) {
m_source = source;
m_target = target;
m_commands = commands;
m_admin = admin;
- m_config = new DeploymentAdminConfig(m_admin.getConfiguration());
+ m_config = config;
}
/**
@@ -64,8 +64,8 @@
* or if an exception is caused by one of the commands.
*
* @throws DeploymentException If the session was canceled (
- * <code>DeploymentException.CODE_CANCELLED</code>) or if one of the
- * commands caused an exception (<code>DeploymentException.*</code>)
+ * <code>DeploymentException.CODE_CANCELLED</code>) or if one of the
+ * commands caused an exception (<code>DeploymentException.*</code>)
*/
public void call(boolean ignoreExceptions) throws DeploymentException {
List executedCommands = new ArrayList();
@@ -86,6 +86,8 @@
// have exceptions during a rollback
rollback(executedCommands);
throw de;
+ } else {
+ m_admin.getLog().log(LogService.LOG_DEBUG, "Ignoring exception as requested!", de);
}
}
}
@@ -123,7 +125,8 @@
}
/**
- * @return the configuration for this session, is guaranteed to remain stable during this session, never <code>null</code>.
+ * @return the configuration for this session, is guaranteed to remain stable during this session, never
+ * <code>null</code>.
*/
public DeploymentAdminConfig getConfiguration() {
return m_config;
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/SnapshotCommand.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/SnapshotCommand.java
index 987718f..a233d55 100644
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/SnapshotCommand.java
+++ b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/SnapshotCommand.java
@@ -30,6 +30,7 @@
import java.util.zip.ZipOutputStream;
import org.apache.felix.deploymentadmin.AbstractDeploymentPackage;
+import org.apache.felix.deploymentadmin.Utils;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.service.deploymentadmin.BundleInfo;
@@ -37,7 +38,6 @@
import org.osgi.service.log.LogService;
public class SnapshotCommand extends Command {
-
private final GetStorageAreaCommand m_getStorageAreaCommand;
public SnapshotCommand(GetStorageAreaCommand getStorageAreaCommand) {
@@ -81,18 +81,6 @@
}
}
- protected static void delete(File root, boolean deleteRoot) {
- if (root.isDirectory()) {
- File[] childs = root.listFiles();
- for (int i = 0; i < childs.length; i++) {
- delete(childs[i], true);
- }
- }
- if (deleteRoot) {
- root.delete();
- }
- }
-
protected static void restore(File archiveFile, File targetDir) throws IOException {
ZipInputStream input = null;
try {
@@ -216,7 +204,7 @@
protected void doRun() throws Exception {
try {
- delete(m_root, false /* deleteRoot */);
+ Utils.delete(m_root, false /* deleteRoot */);
restore(m_snapshot, m_root);
}
finally {
diff --git a/deploymentadmin/deploymentadmin/src/test/java/org/apache/felix/deploymentadmin/DeploymentAdminConfigTest.java b/deploymentadmin/deploymentadmin/src/test/java/org/apache/felix/deploymentadmin/DeploymentAdminConfigTest.java
index f53ff36..83f4bfd 100644
--- a/deploymentadmin/deploymentadmin/src/test/java/org/apache/felix/deploymentadmin/DeploymentAdminConfigTest.java
+++ b/deploymentadmin/deploymentadmin/src/test/java/org/apache/felix/deploymentadmin/DeploymentAdminConfigTest.java
@@ -18,9 +18,7 @@
*/
package org.apache.felix.deploymentadmin;
-import java.util.Dictionary;
import java.util.HashMap;
-import java.util.Hashtable;
import java.util.Map;
import junit.framework.TestCase;
@@ -35,25 +33,20 @@
/**
* Test cases for {@link DeploymentAdminConfig}.
*/
-public class DeploymentAdminConfigTest extends TestCase
-{
+public class DeploymentAdminConfigTest extends TestCase {
private static final String KEY_STOP_UNAFFECTED_BUNDLE = DeploymentAdminConfig.KEY_STOP_UNAFFECTED_BUNDLE;
private static final String KEY_ALLOW_FOREIGN_CUSTOMIZERS = DeploymentAdminConfig.KEY_ALLOW_FOREIGN_CUSTOMIZERS;
-
+
private static final boolean DEFAULT_STOP_UNAFFECTED_BUNDLE = DeploymentAdminConfig.DEFAULT_STOP_UNAFFECTED_BUNDLE;
private static final boolean DEFAULT_ALLOW_FOREIGN_CUSTOMIZERS = DeploymentAdminConfig.DEFAULT_ALLOW_FOREIGN_CUSTOMIZERS;
- private static final String SYS_PROP = DeploymentAdminImpl.PID + "." + KEY_STOP_UNAFFECTED_BUNDLE.toLowerCase();
- private static final String SYS_PROP_LOWERCASE = DeploymentAdminImpl.PID + "." + KEY_STOP_UNAFFECTED_BUNDLE.toLowerCase();
-
private final Map m_fwProperties = new HashMap();
/**
* Tests the configuration values of {@link DeploymentAdminImpl} without any explicit configuration.
*/
- public void testDefaultConfigurationOk() throws ConfigurationException
- {
- DeploymentAdminConfig config = createDeploymentAdminConfig(null);
+ public void testDefaultConfigurationOk() throws ConfigurationException {
+ DeploymentAdminConfig config = createDeploymentAdminConfig();
assertEquals(DEFAULT_STOP_UNAFFECTED_BUNDLE, config.isStopUnaffectedBundles());
assertEquals(DEFAULT_ALLOW_FOREIGN_CUSTOMIZERS, config.isAllowForeignCustomizers());
@@ -62,118 +55,68 @@
/**
* Tests the configuration values of {@link DeploymentAdminImpl} without any explicit configuration.
*/
- public void testExplicitConfigurationOk() throws ConfigurationException
- {
- Dictionary dict = new Hashtable();
- dict.put(KEY_STOP_UNAFFECTED_BUNDLE, "false");
- dict.put(KEY_ALLOW_FOREIGN_CUSTOMIZERS, "true");
+ public void testFrameworkConfigurationOk() throws ConfigurationException {
+ m_fwProperties.put(KEY_STOP_UNAFFECTED_BUNDLE, Boolean.toString(!DEFAULT_STOP_UNAFFECTED_BUNDLE));
+ m_fwProperties.put(KEY_ALLOW_FOREIGN_CUSTOMIZERS, Boolean.toString(!DEFAULT_ALLOW_FOREIGN_CUSTOMIZERS));
- DeploymentAdminConfig config = createDeploymentAdminConfig(dict);
+ DeploymentAdminConfig config = createDeploymentAdminConfig();
- // Should use the explicit configured value...
- assertFalse(config.isStopUnaffectedBundles());
- assertTrue(config.isAllowForeignCustomizers());
- }
-
- /**
- * Tests that an explicit configuration cannot miss any properties.
- */
- public void testExplicitConfigurationWithMissingValueFail() throws ConfigurationException
- {
- Dictionary dict = new Hashtable();
- dict.put(KEY_ALLOW_FOREIGN_CUSTOMIZERS, "true");
-
- try
- {
- createDeploymentAdminConfig(dict);
- fail("ConfigurationException expected!");
- }
- catch (ConfigurationException e)
- {
- assertEquals(KEY_STOP_UNAFFECTED_BUNDLE, e.getProperty());
- }
-
- dict = new Hashtable();
- dict.put(KEY_STOP_UNAFFECTED_BUNDLE, "true");
-
- try
- {
- createDeploymentAdminConfig(dict);
- fail("ConfigurationException expected!");
- }
- catch (ConfigurationException e)
- {
- assertEquals(KEY_ALLOW_FOREIGN_CUSTOMIZERS, e.getProperty());
- }
+ assertEquals(!DEFAULT_STOP_UNAFFECTED_BUNDLE, config.isStopUnaffectedBundles());
+ assertEquals(!DEFAULT_ALLOW_FOREIGN_CUSTOMIZERS, config.isAllowForeignCustomizers());
}
/**
* Tests the configuration values of {@link DeploymentAdminImpl} without any explicit configuration.
*/
- public void testFrameworkConfigurationOk() throws ConfigurationException
- {
- m_fwProperties.put(SYS_PROP, "false");
+ public void testSystemConfigurationOk() throws ConfigurationException {
+ String stopUnaffectedBundle = KEY_STOP_UNAFFECTED_BUNDLE;
+ String allowForeignCustomizers = KEY_ALLOW_FOREIGN_CUSTOMIZERS;
- DeploymentAdminConfig config = createDeploymentAdminConfig(null);
+ System.setProperty(stopUnaffectedBundle, Boolean.toString(!DEFAULT_STOP_UNAFFECTED_BUNDLE));
+ System.setProperty(allowForeignCustomizers, Boolean.toString(!DEFAULT_ALLOW_FOREIGN_CUSTOMIZERS));
- assertEquals(false, config.isStopUnaffectedBundles());
- assertEquals(DEFAULT_ALLOW_FOREIGN_CUSTOMIZERS, config.isAllowForeignCustomizers());
- }
+ try {
+ DeploymentAdminConfig config = createDeploymentAdminConfig();
- /**
- * Tests the configuration values of {@link DeploymentAdminImpl} without any explicit configuration.
- */
- public void testSystemConfigurationOk() throws ConfigurationException
- {
- System.setProperty(SYS_PROP, "false");
-
- try
- {
- DeploymentAdminConfig config = createDeploymentAdminConfig(null);
-
- assertFalse(config.isStopUnaffectedBundles());
+ assertEquals(!DEFAULT_STOP_UNAFFECTED_BUNDLE, config.isStopUnaffectedBundles());
+ assertEquals(!DEFAULT_ALLOW_FOREIGN_CUSTOMIZERS, config.isAllowForeignCustomizers());
}
- finally
- {
- System.clearProperty(SYS_PROP);
+ finally {
+ System.clearProperty(stopUnaffectedBundle);
+ System.clearProperty(allowForeignCustomizers);
}
- System.setProperty(SYS_PROP_LOWERCASE, "false");
+ System.setProperty(stopUnaffectedBundle.toLowerCase(), Boolean.toString(!DEFAULT_STOP_UNAFFECTED_BUNDLE));
+ System.setProperty(allowForeignCustomizers.toLowerCase(), Boolean.toString(!DEFAULT_ALLOW_FOREIGN_CUSTOMIZERS));
- try
- {
- DeploymentAdminConfig config = createDeploymentAdminConfig(null);
+ try {
+ DeploymentAdminConfig config = createDeploymentAdminConfig();
- assertFalse(config.isStopUnaffectedBundles());
+ assertEquals(!DEFAULT_STOP_UNAFFECTED_BUNDLE, config.isStopUnaffectedBundles());
+ assertEquals(!DEFAULT_ALLOW_FOREIGN_CUSTOMIZERS, config.isAllowForeignCustomizers());
}
- finally
- {
- System.clearProperty(SYS_PROP_LOWERCASE);
+ finally {
+ System.clearProperty(stopUnaffectedBundle.toLowerCase());
+ System.clearProperty(allowForeignCustomizers.toLowerCase());
}
}
- protected void setUp() throws Exception
- {
+ protected void setUp() throws Exception {
m_fwProperties.clear();
}
- private DeploymentAdminConfig createDeploymentAdminConfig(Dictionary dict) throws ConfigurationException
- {
- return new DeploymentAdminConfig(createMockBundleContext(), dict);
+ private DeploymentAdminConfig createDeploymentAdminConfig() throws ConfigurationException {
+ return new DeploymentAdminConfig(createMockBundleContext());
}
- private BundleContext createMockBundleContext()
- {
+ private BundleContext createMockBundleContext() {
BundleContext result = (BundleContext) Mockito.mock(BundleContext.class);
- Mockito.when(result.getProperty(Matchers.anyString())).thenAnswer(new Answer()
- {
- public Object answer(InvocationOnMock invocation) throws Throwable
- {
+ Mockito.when(result.getProperty(Matchers.anyString())).thenAnswer(new Answer() {
+ public Object answer(InvocationOnMock invocation) throws Throwable {
String prop = (String) invocation.getArguments()[0];
Object result = m_fwProperties.get(prop);
- if (result == null)
- {
+ if (result == null) {
result = System.getProperty(prop);
}
return result;