final String factoryPid0 = "test_ManagedServiceFactory_change_pid_0";
final String factoryPid1 = "test_ManagedServiceFactory_change_pid_1";
final String factoryPid2 = "test_ManagedServiceFactory_change_pid_2";
final Configuration config0 = createFactoryConfiguration( factoryPid0, null, true );
final String pid0 = config0.getPid();
final Configuration config1 = createFactoryConfiguration( factoryPid1, null, true );
final String pid1 = config1.getPid();
final Configuration config2 = createFactoryConfiguration( factoryPid2, null, true );
final String pid2 = config2.getPid();
delay();
bundle = installBundle( factoryPid0 + "," + factoryPid1, ManagedServiceFactoryTestActivator.class );
bundle.start();
delay();
// pid0 properties provided on registration
final ManagedServiceFactoryTestActivator tester = ManagedServiceFactoryTestActivator.INSTANCE;
Dictionary<?, ?> props0 = tester.configs.get( pid0 );
TestCase.assertNotNull( props0 );
TestCase.assertEquals( pid0, props0.get( Constants.SERVICE_PID ) );
TestCase.assertEquals( factoryPid0, props0.get( ConfigurationAdmin.SERVICE_FACTORYPID ) );
TestCase.assertNull( props0.get( ConfigurationAdmin.SERVICE_BUNDLELOCATION ) );
TestCase.assertEquals( PROP_NAME, props0.get( PROP_NAME ) );
Dictionary<?, ?> props1 = tester.configs.get( pid1 );
TestCase.assertNotNull( props1 );
TestCase.assertEquals( pid1, props1.get( Constants.SERVICE_PID ) );
TestCase.assertEquals( factoryPid1, props1.get( ConfigurationAdmin.SERVICE_FACTORYPID ) );
TestCase.assertNull( props1.get( ConfigurationAdmin.SERVICE_BUNDLELOCATION ) );
TestCase.assertEquals( PROP_NAME, props1.get( PROP_NAME ) );
TestCase.assertEquals( 0, tester.numManagedServiceUpdatedCalls );
TestCase.assertEquals( 2, tester.numManagedServiceFactoryUpdatedCalls );
TestCase.assertEquals( 0, tester.numManagedServiceFactoryDeleteCalls );
// change ManagedService PID
tester.changePid( factoryPid1 + "," + factoryPid2 );
delay();
// pid2 properties must have been added
Dictionary<?, ?> props2 = tester.configs.get( pid2 );
TestCase.assertNotNull( props2 );
TestCase.assertEquals( pid2, props2.get( Constants.SERVICE_PID ) );
TestCase.assertEquals( factoryPid2, props2.get( ConfigurationAdmin.SERVICE_FACTORYPID ) );
TestCase.assertNull( props2.get( ConfigurationAdmin.SERVICE_BUNDLELOCATION ) );
TestCase.assertEquals( PROP_NAME, props2.get( PROP_NAME ) );
// pid0 properties must still exist !
Dictionary<?, ?> props01 = tester.configs.get( pid0 );
TestCase.assertNotNull( props01 );
TestCase.assertEquals( pid0, props01.get( Constants.SERVICE_PID ) );
TestCase.assertEquals( factoryPid0, props01.get( ConfigurationAdmin.SERVICE_FACTORYPID ) );
TestCase.assertNull( props01.get( ConfigurationAdmin.SERVICE_BUNDLELOCATION ) );
TestCase.assertEquals( PROP_NAME, props01.get( PROP_NAME ) );
// pid1 properties must still exist !
Dictionary<?, ?> props11 = tester.configs.get( pid1 );
TestCase.assertNotNull( props11 );
TestCase.assertEquals( pid1, props11.get( Constants.SERVICE_PID ) );
TestCase.assertEquals( factoryPid1, props11.get( ConfigurationAdmin.SERVICE_FACTORYPID ) );
TestCase.assertNull( props11.get( ConfigurationAdmin.SERVICE_BUNDLELOCATION ) );
TestCase.assertEquals( PROP_NAME, props11.get( PROP_NAME ) );
TestCase.assertEquals( 0, tester.numManagedServiceUpdatedCalls );
TestCase.assertEquals( 3, tester.numManagedServiceFactoryUpdatedCalls );
TestCase.assertEquals( 0, tester.numManagedServiceFactoryDeleteCalls );
// delete
config0.delete();
config1.delete();
config2.delete();
delay();
// only pid1 and pid2 properties removed because pid0 is not registered any longer
TestCase.assertNotNull( tester.configs.get( pid0 ) );
TestCase.assertNull( tester.configs.get( pid1 ) );