felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r1301388 - in /felix/trunk/fileinstall/src: main/java/org/apache/felix/fileinstall/internal/ test/java/org/apache/felix/fileinstall/internal/
Date Fri, 16 Mar 2012 09:22:15 GMT
Author: gnodet
Date: Fri Mar 16 09:22:14 2012
New Revision: 1301388

URL: http://svn.apache.org/viewvc?rev=1301388&view=rev
Log:
[FELIX-2763] disableConfigSave actually enables configuration save

Modified:
    felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/ConfigInstaller.java
    felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java
    felix/trunk/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/ConfigInstallerTest.java

Modified: felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/ConfigInstaller.java
URL: http://svn.apache.org/viewvc/felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/ConfigInstaller.java?rev=1301388&r1=1301387&r2=1301388&view=diff
==============================================================================
--- felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/ConfigInstaller.java
(original)
+++ felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/ConfigInstaller.java
Fri Mar 16 09:22:14 2012
@@ -98,11 +98,7 @@ public class ConfigInstaller implements 
     {
         // Check if writing back configurations has been disabled.
         {
-            Object obj = this.context.getProperty( DirectoryWatcher.DISABLE_CONFIG_SAVE );
-            if (obj instanceof String) {
-                obj = new Boolean((String) obj );
-            }
-            if( Boolean.FALSE.equals( obj ) )
+            if (shouldSaveConfig())
             {
                 return;
             }
@@ -170,6 +166,32 @@ public class ConfigInstaller implements 
         }
     }
 
+    boolean shouldSaveConfig()
+    {
+        Object obj = this.context.getProperty( DirectoryWatcher.ENABLE_CONFIG_SAVE );
+        if (obj instanceof String)
+        {
+            obj = Boolean.valueOf((String) obj);
+        }
+        if (Boolean.FALSE.equals( obj ))
+        {
+            return false;
+        }
+        else if ( !Boolean.TRUE.equals( obj ))
+        {
+            obj = this.context.getProperty( DirectoryWatcher.DISABLE_CONFIG_SAVE );
+            if (obj instanceof String)
+            {
+                obj = Boolean.valueOf((String) obj);
+            }
+            if( Boolean.FALSE.equals( obj ) )
+            {
+                return false;
+            }
+        }
+        return true;
+    }
+
     ConfigurationAdmin getConfigurationAdmin()
     {
         return configAdmin;

Modified: felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java
URL: http://svn.apache.org/viewvc/felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java?rev=1301388&r1=1301387&r2=1301388&view=diff
==============================================================================
--- felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java
(original)
+++ felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java
Fri Mar 16 09:22:14 2012
@@ -92,6 +92,7 @@ public class DirectoryWatcher extends Th
     public final static String USE_START_ACTIVATION_POLICY = "felix.fileinstall.bundles.startActivationPolicy";
     public final static String NO_INITIAL_DELAY = "felix.fileinstall.noInitialDelay";
     public final static String DISABLE_CONFIG_SAVE = "felix.fileinstall.disableConfigSave";
+    public final static String ENABLE_CONFIG_SAVE = "felix.fileinstall.enableConfigSave";
     public final static String START_LEVEL = "felix.fileinstall.start.level";
     public final static String ACTIVE_LEVEL = "felix.fileinstall.active.level";
 

Modified: felix/trunk/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/ConfigInstallerTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/ConfigInstallerTest.java?rev=1301388&r1=1301387&r2=1301388&view=diff
==============================================================================
--- felix/trunk/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/ConfigInstallerTest.java
(original)
+++ felix/trunk/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/ConfigInstallerTest.java
Fri Mar 16 09:22:14 2012
@@ -21,9 +21,11 @@ package org.apache.felix.fileinstall.int
 import java.io.File;
 import java.util.Dictionary;
 import java.util.Hashtable;
+import java.util.concurrent.atomic.AtomicReference;
 
 import junit.framework.TestCase;
 import org.easymock.EasyMock;
+import org.easymock.IAnswer;
 import org.easymock.IArgumentMatcher;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
@@ -163,6 +165,67 @@ public class ConfigInstallerTest extends
 
         EasyMock.verify(new Object[]{mockConfiguration, mockConfigurationAdmin, mockBundleContext});
     }
+    
+    public void testShouldSaveConfig() 
+    {
+        final AtomicReference<Boolean> disable = new AtomicReference<Boolean>();
+        final AtomicReference<Boolean> enable = new AtomicReference<Boolean>();
+        
+        EasyMock.expect(mockBundleContext.getProperty(DirectoryWatcher.DISABLE_CONFIG_SAVE)).andAnswer(
+                new IAnswer<String>() {
+                    public String answer() throws Throwable {
+                        return disable.get() != null ? disable.get().toString() : null;
+                    }
+                }
+        ).anyTimes();
+        EasyMock.expect(mockBundleContext.getProperty(DirectoryWatcher.ENABLE_CONFIG_SAVE)).andAnswer(
+                new IAnswer<String>() {
+                    public String answer() throws Throwable {
+                        return enable.get() != null ? enable.get().toString() : null;
+                    }
+                }
+        ).anyTimes();
+        EasyMock.replay(new Object[]{mockConfiguration, mockConfigurationAdmin, mockBundleContext});
+
+        ConfigInstaller ci = new ConfigInstaller( mockBundleContext, mockConfigurationAdmin,
new FileInstall() );
 
+        disable.set(null);
+        enable.set(null);
+        assertTrue( ci.shouldSaveConfig() );
+
+        disable.set(false);
+        enable.set(null);
+        assertFalse( ci.shouldSaveConfig() );
+
+        disable.set(true);
+        enable.set(null);
+        assertTrue( ci.shouldSaveConfig() );
+
+        disable.set(null);
+        enable.set(false);
+        assertFalse( ci.shouldSaveConfig() );
+
+        disable.set(false);
+        enable.set(false);
+        assertFalse( ci.shouldSaveConfig() );
+
+        disable.set(true);
+        enable.set(false);
+        assertFalse( ci.shouldSaveConfig() );
+
+        disable.set(null);
+        enable.set(true);
+        assertTrue( ci.shouldSaveConfig() );
+
+        disable.set(false);
+        enable.set(true);
+        assertTrue( ci.shouldSaveConfig() );
+
+        disable.set(true);
+        enable.set(true);
+        assertTrue( ci.shouldSaveConfig() );
+
+        EasyMock.verify(new Object[]{mockConfiguration, mockConfigurationAdmin, mockBundleContext});
+    }
 
 }



Mime
View raw message