FELIX-1488 Setting a static configuration binding must
also set the "staticallyBound" flag according to the
new binding: true if bound, false if unbound
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@804915 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationImpl.java b/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationImpl.java
index b8d6f4b..9e11d81 100644
--- a/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationImpl.java
+++ b/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationImpl.java
@@ -307,7 +307,7 @@
{
// set binding and mark static and store everything
this.bundleLocation = bundleLocation;
- this.staticallyBound = staticBinding;
+ this.staticallyBound = bundleLocation != null;
// 104.15.2.8 The bundle location will be set persistently
try
diff --git a/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationTest.java b/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationTest.java
index 9eff377..5284d58 100644
--- a/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationTest.java
+++ b/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationTest.java
@@ -492,6 +492,65 @@
@Test
+ public void test_create_with_location_unbind_before_service_supply() throws BundleException, IOException
+ {
+
+ /*
+ * 1. create Configuration with pid and non-null location.
+ * 2. update the configuration with non-null props.
+ * 3. set location of the configuration to null.
+ * 4. bundleA registers a ManagedService service with the pid.
+ */
+
+ final String pid = "test_create_with_location_unbind_before_service_supply";
+ final String dummyLocation = "http://some/dummy/location";
+
+ // 1. create and statically bind the configuration
+ final ConfigurationAdmin ca = getConfigurationAdmin();
+ final Configuration config = ca.getConfiguration( pid, dummyLocation );
+ TestCase.assertEquals( pid, config.getPid() );
+ TestCase.assertEquals( dummyLocation, config.getBundleLocation() );
+
+ // 2. update configuration
+ Hashtable<String, String> props = new Hashtable<String, String>();
+ props.put( PROP_NAME, PROP_NAME );
+ config.update(props);
+ TestCase.assertEquals( PROP_NAME, config.getProperties().get( PROP_NAME ) );
+ TestCase.assertEquals( pid, config.getPid() );
+ TestCase.assertEquals( dummyLocation, config.getBundleLocation() );
+
+ // 3. (statically) set location to null
+ config.setBundleLocation( null );
+ TestCase.assertNull( config.getBundleLocation() );
+
+ // 4. install bundle with service
+ bundle = installBundle( pid);
+ bundle.start();
+ delay();
+
+ final TestActivator tester = TestActivator.INSTANCE;
+ TestCase.assertNotNull( "Activator not started !!", tester );
+
+ // assert activater has configuration (two calls, one per pid)
+ TestCase.assertNotNull( "Expect Properties after Service Registration", tester.props );
+ TestCase.assertEquals( "Expect a single update call", 1, tester.numUpdatedCalls );
+
+ TestCase.assertEquals( bundle.getLocation(), config.getBundleLocation() );
+
+ bundle.uninstall();
+ bundle = null;
+
+ delay();
+
+ // statically bound configurations must remain bound after bundle uninstall
+ TestCase.assertNull( config.getBundleLocation() );
+
+ // remove the configuration for good
+ deleteConfig( pid );
+ }
+
+
+ @Test
public void test_statically_bound() throws BundleException
{
final String pid = "test_statically_bound";