final ComponentFactory factory = ( ComponentFactory ) bundleContext.getService( refs[0] );
TestCase.assertNotNull( factory );
Hashtable<String, String> props = new Hashtable<String, String>();
props.put( PROP_NAME_FACTORY, PROP_NAME_FACTORY );
final ComponentInstance instance = factory.newInstance( props );
TestCase.assertNotNull( instance );
TestCase.assertNotNull( instance.getInstance() );
TestCase.assertEquals( SimpleComponent.INSTANCE, instance.getInstance() );
// ensure instance is bound
final SimpleComponent sc = SimpleComponent.INSTANCE;
TestCase.assertEquals( 1, sc.m_multiRef.size() );
TestCase.assertTrue( sc.m_multiRef.contains( srv1 ) );
// ensure factory is not bound
// TestCase.assertNull( component.getReferences()[0].getServiceReferences() );
// assert two components managed
checkConfigurationCount(name, 1, ComponentConfigurationDTO.ACTIVE);
// final Component[] allFactoryComponents = findComponentConfigurationsByName( pid, -1 );
// TestCase.assertNotNull( allFactoryComponents );
// TestCase.assertEquals( 2, allFactoryComponents.length );
// for ( int i = 0; i < allFactoryComponents.length; i++ )
// {
// final Component c = allFactoryComponents[i];
// if ( c.getId() == component.getId() )
// {
// TestCase.assertEquals( Component.STATE_FACTORY, c.getState() );
// }
// else if ( c.getId() == SimpleComponent.INSTANCE.m_id )
// {
// TestCase.assertEquals( Component.STATE_ACTIVE, c.getState() );
// }
// else
// {
// TestCase.fail( "Unexpected Component " + c );
// }
// }
// register second service
final SimpleServiceImpl srv11 = SimpleServiceImpl.create( bundleContext, "srv11" );
delay();
// ensure instance is bound
TestCase.assertEquals( 2, sc.m_multiRef.size() );
TestCase.assertTrue( sc.m_multiRef.contains( srv1 ) );
TestCase.assertTrue( sc.m_multiRef.contains( srv11 ) );
// ensure factory is not bound
// TestCase.assertNull( component.getReferences()[0].getServiceReferences() );
// drop second service and ensure unbound (and active)
srv11.drop();
delay();
TestCase.assertNotNull( instance.getInstance() );
TestCase.assertEquals( SimpleComponent.INSTANCE, instance.getInstance() );
TestCase.assertEquals( 1, sc.m_multiRef.size() );
TestCase.assertTrue( sc.m_multiRef.contains( srv1 ) );
// TestCase.assertNull( component.getReferences()[0].getServiceReferences() );
// remove the service, expect factory to deactivate and instance to dispose
srv1.drop();
delay();
checkConfigurationCount(name, 0, -1);
TestCase.assertNull( instance.getInstance() );
// assert component factory only managed
//TODO this check should be whether the service is registered.
// final Component[] allFactoryComponents2 = findComponentConfigurationsByName( pid, -1 );
// TestCase.assertNotNull( allFactoryComponents2 );
// TestCase.assertEquals( 1, allFactoryComponents2.length );
// for ( int i = 0; i < allFactoryComponents2.length; i++ )
// {
// final Component c = allFactoryComponents2[i];
// if ( c.getId() == component.getId() )
// {
// TestCase.assertEquals( Component.STATE_UNSATISFIED, c.getState() );
// }
// else
// {
// TestCase.fail( "Unexpected Component " + c );
// }
// }
// registeranother service, factory must come back, instance not
final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
delay();
// TestCase.assertEquals( Component.STATE_FACTORY, component.getState() );
TestCase.assertNull( instance.getInstance() );
// assert component factory only managed
checkConfigurationCount(name, 0, -1);
// final Component[] allFactoryComponents3 = findComponentConfigurationsByName( pid, -1 );
// TestCase.assertNotNull( allFactoryComponents3 );