use of org.apache.felix.cm.integration.helper.ManagedServiceTestActivator in project felix by apache.
the class MultiServicePIDTest method test_two_services_same_pid_in_two_bundle_configure_after_registration.
@Test
public void test_two_services_same_pid_in_two_bundle_configure_after_registration() throws BundleException {
Bundle bundle2 = null;
try {
final String pid = "test.pid";
bundle = installBundle(pid, ManagedServiceTestActivator.class);
bundle.start();
bundle2 = installBundle(pid, ManagedServiceTestActivator2.class);
bundle2.start();
final ManagedServiceTestActivator tester = ManagedServiceTestActivator.INSTANCE;
TestCase.assertNotNull("Activator not started !!", tester);
final ManagedServiceTestActivator2 tester2 = ManagedServiceTestActivator2.INSTANCE;
TestCase.assertNotNull("Activator not started !!", tester2);
delay();
// expect no configuration but a call in each service
TestCase.assertNull("Expect Properties after Service Registration", tester.props);
TestCase.assertEquals("Expect a single update call", 1, tester.numManagedServiceUpdatedCalls);
TestCase.assertNull("Expect Properties after Service Registration", tester2.props);
TestCase.assertEquals("Expect a single update call", 1, tester2.numManagedServiceUpdatedCalls);
configure(pid);
delay();
final Configuration config = getConfiguration(pid);
TestCase.assertEquals(pid, config.getPid());
TestCase.assertEquals("Configuration must be bound to first bundle because the service has higher ranking", bundle.getLocation(), config.getBundleLocation());
// configuration assigned to the first bundle
TestCase.assertNotNull("Expect Properties after Service Registration", tester.props);
TestCase.assertEquals("Expect a single update call", 2, tester.numManagedServiceUpdatedCalls);
TestCase.assertNull("Expect Properties after Service Registration", tester2.props);
TestCase.assertEquals("Expect a single update call", 1, tester2.numManagedServiceUpdatedCalls);
bundle.uninstall();
bundle = null;
delay();
// after uninstallation, the configuration is redispatched
// due to the dynamic binding being removed
// expect configuration reassigned
TestCase.assertEquals(bundle2.getLocation(), config.getBundleLocation());
// assert second bundle now has the configuration
TestCase.assertNotNull("Expect Properties after Configuration redispatch", tester2.props);
TestCase.assertEquals("Expect a single update call after Configuration redispatch", 2, tester2.numManagedServiceUpdatedCalls);
// remove the configuration for good
deleteConfig(pid);
} finally {
if (bundle2 != null) {
bundle2.uninstall();
}
}
}
Aggregations