FELIX-1448 setting the static bundle to a different location than
the dynamic bundle location is currently set to has to remove the
dynamic bundle location binding to be able to send further updates
to the new target bundle

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@806083 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationBase.java b/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationBase.java
index 0ef0ecd..3f4e839 100644
--- a/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationBase.java
+++ b/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationBase.java
@@ -196,6 +196,18 @@
         }
          *
          */
+
+        // corrollary to not reassigning configurations: we have to check
+        // whether the dynamic bundle location is different from the static
+        // now. If so, the dynamic bundle location has to be removed.
+        // also set the service reference to null because we assume to not
+        // be bound to a service anymore
+        if ( bundleLocation != null && getDynamicBundleLocation() != null
+            && !bundleLocation.equals( getDynamicBundleLocation() ) )
+        {
+            setDynamicBundleLocation( null );
+            setServiceReference( null );
+        }
     }
 
 
diff --git a/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationBindingTest.java b/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationBindingTest.java
index 2998375..8475f03 100644
--- a/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationBindingTest.java
+++ b/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationBindingTest.java
@@ -605,7 +605,7 @@
 
 
     @Test
-    public void test_switch_dynamic_binding() throws BundleException
+    public void test_switch_dynamic_binding() throws BundleException, IOException
     {
         // 1. create config with pid with null location
         // 2. update config with properties
@@ -672,11 +672,19 @@
             TestCase.assertNull( testerB1.props );
             TestCase.assertEquals( 0, testerB1.numManagedServiceUpdatedCalls );
         }
+
+        // 6. Update configuration now
+        config.update();
+        delay();
+
+        // ==> configuration supplied to the service ms2
+        TestCase.assertNotNull( testerB1.props );
+        TestCase.assertEquals( 1, testerB1.numManagedServiceUpdatedCalls );
     }
 
 
     @Test
-    public void test_switch_static_binding_factory() throws BundleException
+    public void test_switch_static_binding_factory() throws BundleException, IOException
     {
         // 1. create config with pid and locationA
         // 2. update config with properties
@@ -743,11 +751,19 @@
             TestCase.assertNull( testerB1.configs.get( pid ) );
             TestCase.assertEquals( 0, testerB1.numManagedServiceFactoryUpdatedCalls );
         }
-    }
+
+        // 6. Update configuration now
+        config.update();
+        delay();
+
+        // ==> configuration supplied to the service ms2
+        TestCase.assertNotNull( testerB1.configs.get( pid ) );
+        TestCase.assertEquals( 1, testerB1.numManagedServiceFactoryUpdatedCalls );
+   }
 
 
     @Test
-    public void test_switch_dynamic_binding_factory() throws BundleException
+    public void test_switch_dynamic_binding_factory() throws BundleException, IOException
     {
         // 1. create config with pid and locationA
         // 2. update config with properties
@@ -818,11 +834,19 @@
             TestCase.assertNull( testerB1.configs.get( pid ) );
             TestCase.assertEquals( 0, testerB1.numManagedServiceFactoryUpdatedCalls );
         }
+
+        // 6. Update configuration now
+        config.update();
+        delay();
+
+        // ==> configuration supplied to the service ms2
+        TestCase.assertNotNull( testerB1.configs.get( pid ) );
+        TestCase.assertEquals( 1, testerB1.numManagedServiceFactoryUpdatedCalls );
     }
 
 
     @Test
-    public void test_switch_dynamic_binding_after_uninstall() throws BundleException
+    public void test_switch_dynamic_binding_after_uninstall() throws BundleException, IOException
     {
         // 1. create config with pid with null location
         // 2. update config with properties
@@ -886,11 +910,19 @@
             TestCase.assertNull( testerB1.props );
             TestCase.assertEquals( 0, testerB1.numManagedServiceUpdatedCalls );
         }
+
+        // 6. Update configuration now
+        config.update();
+        delay();
+
+        // ==> configuration supplied to the service ms2
+        TestCase.assertNotNull( testerB1.props );
+        TestCase.assertEquals( 1, testerB1.numManagedServiceUpdatedCalls );
     }
 
 
     @Test
-    public void test_switch_dynamic_binding_factory_after_uninstall() throws BundleException
+    public void test_switch_dynamic_binding_factory_after_uninstall() throws BundleException, IOException
     {
         // 1. create config with pid and locationA
         // 2. update config with properties
@@ -954,5 +986,13 @@
             TestCase.assertNull( testerB1.configs.get( pid ) );
             TestCase.assertEquals( 0, testerB1.numManagedServiceFactoryUpdatedCalls );
         }
+
+        // 6. Update configuration now
+        config.update();
+        delay();
+
+        // ==> configuration supplied to the service ms2
+        TestCase.assertNotNull( testerB1.configs.get( pid ) );
+        TestCase.assertEquals( 1, testerB1.numManagedServiceFactoryUpdatedCalls );
     }
 }