final String name = "test.factory";
final ComponentMetadata cm = createComponentMetadata( name );
final TestingConfiguredComponentHolder holder = new TestingConfiguredComponentHolder( cm );
// assert single component and no map
final SingleComponentManager cmgr = getSingleManager( holder );
assertNotNull( "Expect single component manager", cmgr );
assertEquals( "Expect no other component manager list", 1, getComponentManagers( holder ).length);
// assert no configuration of single component
assertFalse( "Expect no configuration", cmgr.hasConfiguration() );
// configure with configuration
final String pid1 = "test.factory.0001";
final Dictionary config1 = new Hashtable();
config1.put( "value", pid1 );
holder.configurationUpdated( pid1, config1, 0, new TargetedPID(name) );
// assert single component and single-entry map
final SingleComponentManager cmgrAfterConfig = getSingleManager( holder );
final SingleComponentManager[] cmgrsAfterConfig = getComponentManagers( holder );
assertNotNull( "Expect single component manager", cmgrAfterConfig );
assertNotNull( "Expect component manager list", cmgrsAfterConfig );
assertEquals( "Expect one component manager in list", 1, cmgrsAfterConfig.length );
// add another configuration
final String pid2 = "test.factory.0002";
final Dictionary config2 = new Hashtable();
config1.put( "value", pid2 );
holder.configurationUpdated( pid2, config2, 1, new TargetedPID(name) );
// assert single component and single-entry map
final SingleComponentManager cmgrAfterConfig2 = getSingleManager( holder );
final SingleComponentManager[] cmgrsAfterConfig2 = getComponentManagers( holder );
assertNotNull( "Expect single component manager", cmgrAfterConfig2 );
assertNotNull( "Expect component manager list", cmgrsAfterConfig2 );
assertEquals( "Expect two component manager in list", 2, cmgrsAfterConfig2.length );
// remove second configuration
holder.configurationDeleted( pid2 );
// assert single component and single-entry map
final SingleComponentManager cmgrAfterUnConfig2 = getSingleManager( holder );
final SingleComponentManager[] cmgrsAfterUnConfig2 = getComponentManagers( holder );
assertNotNull( "Expect single component manager", cmgrAfterUnConfig2 );
assertNotNull( "Expect component manager list", cmgrsAfterUnConfig2 );
assertEquals( "Expect one component manager in list", 1, cmgrsAfterUnConfig2.length );
// add second config again and remove first config -> replace singleton component
holder.configurationUpdated( pid2, config2, 2, new TargetedPID(name) );
holder.configurationDeleted( pid1 );
// assert single component and single-entry map
final SingleComponentManager cmgrAfterConfigUnconfig = getSingleManager( holder );
final SingleComponentManager[] cmgrsAfterConfigUnconfig = getComponentManagers( holder );
assertNotNull( "Expect single component manager", cmgrAfterConfigUnconfig );
assertNotNull( "Expect component manager list", cmgrsAfterConfigUnconfig );
assertEquals( "Expect one component manager in list", 1, cmgrsAfterConfigUnconfig.length );
// remove second configuration (leaving no configurations)
holder.configurationDeleted( pid2 );
// assert single component and single-entry map
final SingleComponentManager cmgrAfterAllUnconfig = getSingleManager( holder );
final SingleComponentManager[] cmgrsAfterAllUnconfig = getComponentManagers( holder );
assertNotNull( "Expect single component manager", cmgrAfterAllUnconfig );
assertEquals( "Expect no component manager list", 1, cmgrsAfterAllUnconfig.length );
}