{
// 1. create config with pid and locationA
// 2. update config with properties
final String factoryPid = "test_switch_static_binding_factory";
final String locationA = "test:location/A/" + factoryPid;
final Configuration config = createFactoryConfiguration( factoryPid, null, true );
final String pid = config.getPid();
TestCase.assertNull( config.getBundleLocation() );
// 3. register ManagedService ms1 with pid from said locationA
final Bundle bundleA = installBundle( factoryPid, ManagedServiceFactoryTestActivator.class, locationA );
bundleA.start();
delay();
// ==> configuration supplied to the service ms1
final ManagedServiceFactoryTestActivator testerA1 = ManagedServiceFactoryTestActivator.INSTANCE;
TestCase.assertNotNull( testerA1.configs.get( pid ) );
TestCase.assertEquals( 1, testerA1.numManagedServiceFactoryUpdatedCalls );
TestCase.assertEquals( locationA, config.getBundleLocation() );
// 4. register ManagedService ms2 with pid from locationB
final String locationB = "test:location/B/" + factoryPid;
final Bundle bundleB = installBundle( factoryPid, ManagedServiceFactoryTestActivator2.class, locationB );
bundleB.start();
delay();
// ==> configuration not supplied to service ms2
final ManagedServiceFactoryTestActivator2 testerB1 = ManagedServiceFactoryTestActivator2.INSTANCE;
TestCase.assertNull( testerB1.configs.get( pid ));
TestCase.assertEquals( 0, testerB1.numManagedServiceFactoryUpdatedCalls );
TestCase.assertEquals( locationA, config.getBundleLocation() );
// 5. Call Configuration.setBundleLocation( "locationB" )
config.setBundleLocation( locationB );
delay();
// ==> configuration is bound to locationB
TestCase.assertEquals( locationB, config.getBundleLocation() );
// ==> configuration removed from service ms1
TestCase.assertNull( testerA1.configs.get( pid ));
TestCase.assertEquals( 1, testerA1.numManagedServiceFactoryUpdatedCalls );
TestCase.assertEquals( 1, testerA1.numManagedServiceFactoryDeleteCalls );
// ==> configuration supplied to the service ms2
TestCase.assertNotNull( testerB1.configs.get( pid ) );
TestCase.assertEquals( 1, testerB1.numManagedServiceFactoryUpdatedCalls );
// 6. Update configuration now
config.update();
delay();
// ==> configuration supplied to the service ms2
TestCase.assertNotNull( testerB1.configs.get( pid ) );
TestCase.assertEquals( 2, testerB1.numManagedServiceFactoryUpdatedCalls );