SimpleServiceImpl match = SimpleServiceImpl.create( bundleContext, "required" ).setFilterProperty( "required" );
delay();
TestCase.assertNull( SimpleComponent.INSTANCE );
final ComponentInstance instance = createFactoryComponentInstance(componentfactory);
TestCase.assertEquals( 1, SimpleComponent.INSTANCE.m_multiRef.size() );
TestCase.assertTrue( SimpleComponent.INSTANCE.m_multiRef.contains( match ) );
// check registered components
checkConfigurationCount(componentname, 1, ComponentConfigurationDTO.ACTIVE);
instance.dispose();
TestCase.assertNull( SimpleComponent.INSTANCE );
TestCase.assertNull( instance.getInstance() ); // SCR 112.12.6.2
checkConfigurationCount(componentname, 0, ComponentConfigurationDTO.ACTIVE);
// overwritten filterprop
Hashtable<String, String> propsNonMatch = new Hashtable<String, String>();
propsNonMatch.put( PROP_NAME_FACTORY, PROP_NAME_FACTORY );
propsNonMatch.put( "ref.target", "(filterprop=nomatch)" );
ComponentFactory factory = getComponentFactory(componentfactory);
try
{
factory.newInstance( propsNonMatch );
TestCase.fail( "Missing reference must fail instance creation" );
}
catch ( ComponentException ce )
{
// expected
}
final SimpleServiceImpl noMatch = SimpleServiceImpl.create( bundleContext, "nomatch" ).setFilterProperty(
"nomatch" );
delay();
final ComponentInstance instanceNonMatch = factory.newInstance( propsNonMatch );
TestCase.assertNotNull( instanceNonMatch );
TestCase.assertNotNull( instanceNonMatch.getInstance() );
TestCase.assertEquals( SimpleComponent.INSTANCE, instanceNonMatch.getInstance() );
TestCase.assertEquals( PROP_NAME_FACTORY, SimpleComponent.INSTANCE.getProperty( PROP_NAME_FACTORY ) );
TestCase.assertEquals( 1, SimpleComponent.INSTANCE.m_multiRef.size() );
TestCase.assertTrue( SimpleComponent.INSTANCE.m_multiRef.contains( noMatch ) );
// check registered components
checkConfigurationCount(componentname, 1, ComponentConfigurationDTO.ACTIVE);
match.getRegistration().unregister();
delay();
// check registered components (ComponentFactory aint no longer)
checkConfigurationCount(componentname, 1, ComponentConfigurationDTO.ACTIVE);
//it has already been deactivated.... this should cause an exception?
noMatch.getRegistration().unregister();
delay();
// check registered components (ComponentFactory aint no longer)
checkConfigurationCount(componentname, 0, ComponentConfigurationDTO.ACTIVE);
// deactivated due to unsatisfied reference
TestCase.assertNull( instanceNonMatch.getInstance() );
TestCase.assertNull( SimpleComponent.INSTANCE );
//Check that calling dispose on a deactivated instance has no effect
instanceNonMatch.dispose();
TestCase.assertNull( SimpleComponent.INSTANCE );
TestCase.assertNull( instanceNonMatch.getInstance() ); // SCR 112.12.6.2
}