felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1649781 - in /felix/trunk/deploymentadmin/deploymentadmin/src: main/java/org/apache/felix/deploymentadmin/ main/java/org/apache/felix/deploymentadmin/spi/ test/java/org/apache/felix/deploymentadmin/
Date Tue, 06 Jan 2015 11:14:31 GMT
Author: jawi
Date: Tue Jan  6 11:14:30 2015
New Revision: 1649781

URL: http://svn.apache.org/r1649781
Log:
FELIX-3780 - alternative way of configuring DA:

- no longer depend on the ConfigAdmin APIs for runtime configurations;
- use framework/system properties instead.


Modified:
    felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Activator.java
    felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentAdminConfig.java
    felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentAdminImpl.java
    felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DeploymentSessionImpl.java
    felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/SnapshotCommand.java
    felix/trunk/deploymentadmin/deploymentadmin/src/test/java/org/apache/felix/deploymentadmin/DeploymentAdminConfigTest.java

Modified: felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Activator.java
URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Activator.java?rev=1649781&r1=1649780&r2=1649781&view=diff
==============================================================================
--- felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Activator.java
(original)
+++ felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Activator.java
Tue Jan  6 11:14:30 2015
@@ -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 @@ import org.osgi.service.packageadmin.Pac
 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)

Modified: felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentAdminConfig.java
URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentAdminConfig.java?rev=1649781&r1=1649780&r2=1649781&view=diff
==============================================================================
--- felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentAdminConfig.java
(original)
+++ felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentAdminConfig.java
Tue Jan  6 11:14:30 2015
@@ -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 m_stopUnaffectedBundles;
+    }
+
+    private static boolean parseBoolean(String value, boolean dflt) {
+        if (value == null || "".equals(value.trim())) {
+            return dflt;
         }
-        return (result == null) ? DEFAULT_STOP_UNAFFECTED_BUNDLE : result.booleanValue();
+        return Boolean.parseBoolean(value);
     }
 
-    private String getFrameworkProperty(String key) {
-        String prop = m_context.getProperty(DeploymentAdminImpl.PID + "." + key);
+    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;
     }

Modified: felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentAdminImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentAdminImpl.java?rev=1649781&r1=1649780&r2=1649781&view=diff
==============================================================================
--- felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentAdminImpl.java
(original)
+++ felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentAdminImpl.java
Tue Jan  6 11:14:30 2015
@@ -48,8 +48,6 @@ import org.apache.felix.deploymentadmin.
 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.event.EventAdmin
 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 @@ public class DeploymentAdminImpl impleme
     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 @@ public class DeploymentAdminImpl impleme
         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 @@ public class DeploymentAdminImpl impleme
             }
 
             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 @@ public class DeploymentAdminImpl impleme
      * 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 class DeploymentAdminImpl impleme
      */
     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 @@ public class DeploymentAdminImpl impleme
 
         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 class DeploymentAdminImpl impleme
         }
     }
 
-    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 @@ public class DeploymentAdminImpl impleme
     /**
      * 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 @@ public class DeploymentAdminImpl impleme
 
     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

Modified: felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DeploymentSessionImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DeploymentSessionImpl.java?rev=1649781&r1=1649780&r2=1649781&view=diff
==============================================================================
--- felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DeploymentSessionImpl.java
(original)
+++ felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DeploymentSessionImpl.java
Tue Jan  6 11:14:30 2015
@@ -50,12 +50,12 @@ public class DeploymentSessionImpl imple
     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 @@ public class DeploymentSessionImpl imple
      * 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 @@ public class DeploymentSessionImpl imple
                     // 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 @@ public class DeploymentSessionImpl imple
     }
 
     /**
-     * @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;

Modified: felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/SnapshotCommand.java
URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/SnapshotCommand.java?rev=1649781&r1=1649780&r2=1649781&view=diff
==============================================================================
--- felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/SnapshotCommand.java
(original)
+++ felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/SnapshotCommand.java
Tue Jan  6 11:14:30 2015
@@ -30,6 +30,7 @@ import java.util.zip.ZipInputStream;
 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.deploymentadmin.
 import org.osgi.service.log.LogService;
 
 public class SnapshotCommand extends Command {
-
     private final GetStorageAreaCommand m_getStorageAreaCommand;
 
     public SnapshotCommand(GetStorageAreaCommand getStorageAreaCommand) {
@@ -81,18 +81,6 @@ public class SnapshotCommand extends Com
         }
     }
 
-    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 @@ public class SnapshotCommand extends Com
 
         protected void doRun() throws Exception {
             try {
-                delete(m_root, false /* deleteRoot */);
+                Utils.delete(m_root, false /* deleteRoot */);
                 restore(m_snapshot, m_root);
             }
             finally {

Modified: felix/trunk/deploymentadmin/deploymentadmin/src/test/java/org/apache/felix/deploymentadmin/DeploymentAdminConfigTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/deploymentadmin/src/test/java/org/apache/felix/deploymentadmin/DeploymentAdminConfigTest.java?rev=1649781&r1=1649780&r2=1649781&view=diff
==============================================================================
--- felix/trunk/deploymentadmin/deploymentadmin/src/test/java/org/apache/felix/deploymentadmin/DeploymentAdminConfigTest.java
(original)
+++ felix/trunk/deploymentadmin/deploymentadmin/src/test/java/org/apache/felix/deploymentadmin/DeploymentAdminConfigTest.java
Tue Jan  6 11:14:30 2015
@@ -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 @@ import org.osgi.service.cm.Configuration
 /**
  * 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 @@ public class DeploymentAdminConfigTest e
     /**
      * 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");
-
-        DeploymentAdminConfig config = createDeploymentAdminConfig(dict);
-
-        // Should use the explicit configured value...
-        assertFalse(config.isStopUnaffectedBundles());
-        assertTrue(config.isAllowForeignCustomizers());
-    }
+    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));
 
-    /**
-     * 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());
-        }
+        DeploymentAdminConfig config = createDeploymentAdminConfig();
+
+        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);
-
-        assertEquals(false, config.isStopUnaffectedBundles());
-        assertEquals(DEFAULT_ALLOW_FOREIGN_CUSTOMIZERS, config.isAllowForeignCustomizers());
-    }
+        System.setProperty(stopUnaffectedBundle, Boolean.toString(!DEFAULT_STOP_UNAFFECTED_BUNDLE));
+        System.setProperty(allowForeignCustomizers, Boolean.toString(!DEFAULT_ALLOW_FOREIGN_CUSTOMIZERS));
 
-    /**
-     * 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);
+        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);
+        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;



Mime
View raw message