@Test
public void testLocationChangeToRegionBinding() throws Exception
{
final String pid = COMPONENT_NAME;
final Component component = findComponentByName( pid );
deleteConfig( pid );
delay();
TestCase.assertNotNull( component );
TestCase.assertFalse( component.isDefaultEnabled() );
TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
TestCase.assertNull( SimpleComponent.INSTANCE );
component.enable();
delay();
TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
TestCase.assertNull( SimpleComponent.INSTANCE );
Configuration config = configure( pid );
delay();
TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
TestCase.assertNotNull( SimpleComponent.INSTANCE );
TestCase.assertEquals( PROP_NAME, SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
Bundle b2 = installBundle( descriptorFile, COMPONENT_PACKAGE, "simplecomponent2", "0.0.11", null );
b2.start();
Component[] components = findComponentsByName( pid );
TestCase.assertEquals( 2, components.length );
Component c2 = components[0] == component? components[1]: components[0];
c2.enable();
delay();
TestCase.assertEquals( Component.STATE_UNSATISFIED, c2.getState() );
bundle.stop();
delay();
TestCase.assertEquals( Component.STATE_UNSATISFIED, c2.getState() );
ConfigurationListener listener = new ConfigurationListener() {
public void configurationEvent(ConfigurationEvent event)
{
if (event.getType() == ConfigurationEvent.CM_LOCATION_CHANGED)
{
eventReceived = true;
}
}
};
ServiceRegistration<ConfigurationListener> sr = bundleContext.registerService( ConfigurationListener.class, listener, null );
config.setBundleLocation( REGION );
delay();
if ( eventReceived )
{
TestCase.assertEquals( Component.STATE_ACTIVE, c2.getState() );
}
sr.unregister();