use of org.apache.felix.cm.integration.helper.ManagedServiceTestActivator2 in project felix by apache.
the class MultiServicePIDTest method test_two_services_same_pid_in_two_bundle_configure_before_registration.
@Test
public void test_two_services_same_pid_in_two_bundle_configure_before_registration() throws BundleException {
Bundle bundle2 = null;
try {
final String pid = "test.pid";
configure(pid);
final Configuration config = getConfiguration(pid);
TestCase.assertEquals(pid, config.getPid());
TestCase.assertNull(config.getBundleLocation());
bundle = installBundle(pid, ManagedServiceTestActivator.class);
bundle.start();
bundle2 = installBundle(pid, ManagedServiceTestActivator2.class);
bundle2.start();
// give cm time for distribution
delay();
final ManagedServiceTestActivator tester = ManagedServiceTestActivator.INSTANCE;
TestCase.assertNotNull("Activator not started !!", tester);
final ManagedServiceTestActivator2 tester2 = ManagedServiceTestActivator2.INSTANCE;
TestCase.assertNotNull("Activator 2 not started !!", tester2);
// expect first activator to have received properties
// assert first bundle has configuration (one calls, one per srv)
TestCase.assertNotNull("Expect Properties after Service Registration", tester.props);
TestCase.assertEquals("Expect a single update call", 1, tester.numManagedServiceUpdatedCalls);
// assert second bundle has no configuration (but called with null)
TestCase.assertNull(tester2.props);
TestCase.assertEquals(1, tester2.numManagedServiceUpdatedCalls);
// expect configuration bound to first bundle
TestCase.assertEquals(bundle.getLocation(), config.getBundleLocation());
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();
}
}
}
use of org.apache.felix.cm.integration.helper.ManagedServiceTestActivator2 in project felix by apache.
the class ConfigurationBindingTest method test_switch_dynamic_binding_after_uninstall.
@Test
public void test_switch_dynamic_binding_after_uninstall() throws BundleException, IOException {
// 1. create config with pid with null location
// 2. update config with properties
final String pid = "test_switch_dynamic_binding";
final String locationA = "test:location/A/" + pid;
final Configuration config = configure(pid, null, true);
TestCase.assertNull(config.getBundleLocation());
// 3. register ManagedService ms1 with pid from locationA
final Bundle bundleA = installBundle(pid, ManagedServiceTestActivator.class, locationA);
bundleA.start();
delay();
// ==> configuration supplied to the service ms1
final ManagedServiceTestActivator testerA1 = ManagedServiceTestActivator.INSTANCE;
TestCase.assertNotNull(testerA1.props);
TestCase.assertEquals(1, testerA1.numManagedServiceUpdatedCalls);
// ==> configuration is dynamically bound to locationA
TestCase.assertEquals(locationA, config.getBundleLocation());
// 4. register ManagedService ms2 with pid from locationB
final String locationB = "test:location/B/" + pid;
final Bundle bundleB = installBundle(pid, ManagedServiceTestActivator2.class, locationB);
bundleB.start();
delay();
// ==> invisible configuration supplied as null to service ms2
final ManagedServiceTestActivator2 testerB1 = ManagedServiceTestActivator2.INSTANCE;
TestCase.assertNull(testerB1.props);
TestCase.assertEquals(1, testerB1.numManagedServiceUpdatedCalls);
// 5. Uninstall bundle A
bundleA.uninstall();
delay();
// ==> configuration is bound to locationB
TestCase.assertEquals(locationB, config.getBundleLocation());
// ==> configuration supplied to the service ms2
TestCase.assertNotNull(testerB1.props);
TestCase.assertEquals(2, testerB1.numManagedServiceUpdatedCalls);
// 6. Update configuration now
config.update();
delay();
// ==> configuration supplied to the service ms2
TestCase.assertNotNull(testerB1.props);
TestCase.assertEquals(3, testerB1.numManagedServiceUpdatedCalls);
}
use of org.apache.felix.cm.integration.helper.ManagedServiceTestActivator2 in project felix by apache.
the class ConfigurationBindingTest method test_switch_dynamic_binding.
@Test
public void test_switch_dynamic_binding() throws BundleException, IOException {
// 1. create config with pid with null location
// 2. update config with properties
final String pid = "test_switch_dynamic_binding";
final String locationA = "test:location/A/" + pid;
final Configuration config = configure(pid, null, true);
// 3. register ManagedService ms1 with pid from locationA
final Bundle bundleA = installBundle(pid, ManagedServiceTestActivator.class, locationA);
bundleA.start();
delay();
// ==> configuration supplied to the service ms1
final ManagedServiceTestActivator testerA1 = ManagedServiceTestActivator.INSTANCE;
TestCase.assertNotNull(testerA1.props);
TestCase.assertEquals(1, testerA1.numManagedServiceUpdatedCalls);
// ==> configuration is dynamically bound to locationA
TestCase.assertEquals(locationA, config.getBundleLocation());
// 4. register ManagedService ms2 with pid from locationB
final String locationB = "test:location/B/" + pid;
final Bundle bundleB = installBundle(pid, ManagedServiceTestActivator2.class, locationB);
bundleB.start();
delay();
// ==> invisible configuration supplied as null to service ms2
final ManagedServiceTestActivator2 testerB1 = ManagedServiceTestActivator2.INSTANCE;
TestCase.assertNull(testerB1.props);
TestCase.assertEquals(1, testerB1.numManagedServiceUpdatedCalls);
// 5. Call Configuration.setBundleLocation( "locationB" )
config.setBundleLocation(locationB);
delay();
// ==> configuration is bound to locationB
TestCase.assertEquals(locationB, config.getBundleLocation());
// ==> configuration removed from service ms1
TestCase.assertNull(testerA1.props);
TestCase.assertEquals(2, testerA1.numManagedServiceUpdatedCalls);
// ==> configuration supplied to the service ms2
TestCase.assertNotNull(testerB1.props);
TestCase.assertEquals(2, testerB1.numManagedServiceUpdatedCalls);
// 6. Update configuration now
config.update();
delay();
// ==> configuration supplied to the service ms2
TestCase.assertNotNull(testerB1.props);
TestCase.assertEquals(3, testerB1.numManagedServiceUpdatedCalls);
}
use of org.apache.felix.cm.integration.helper.ManagedServiceTestActivator2 in project felix by apache.
the class ConfigurationBindingTest method test_switch_static_binding.
@Test
public void test_switch_static_binding() throws BundleException {
// 1. create config with pid and locationA
// 2. update config with properties
final String pid = "test_switch_static_binding";
final String locationA = "test:location/A/" + pid;
final Configuration config = configure(pid, locationA, true);
// 3. register ManagedService ms1 with pid from said locationA
final Bundle bundleA = installBundle(pid, ManagedServiceTestActivator.class, locationA);
bundleA.start();
delay();
// ==> configuration supplied to the service ms1
final ManagedServiceTestActivator testerA1 = ManagedServiceTestActivator.INSTANCE;
TestCase.assertNotNull(testerA1.props);
TestCase.assertEquals(1, testerA1.numManagedServiceUpdatedCalls);
// 4. register ManagedService ms2 with pid from locationB
final String locationB = "test:location/B/" + pid;
final Bundle bundleB = installBundle(pid, ManagedServiceTestActivator2.class, locationB);
bundleB.start();
delay();
// ==> invisible configuration supplied as null to service ms2
final ManagedServiceTestActivator2 testerB1 = ManagedServiceTestActivator2.INSTANCE;
TestCase.assertNull(testerB1.props);
TestCase.assertEquals(1, testerB1.numManagedServiceUpdatedCalls);
// 5. Call Configuration.setBundleLocation( "locationB" )
config.setBundleLocation(locationB);
delay();
// ==> configuration is bound to locationB
TestCase.assertEquals(locationB, config.getBundleLocation());
// ==> configuration removed from service ms1
TestCase.assertNull(testerA1.props);
TestCase.assertEquals(2, testerA1.numManagedServiceUpdatedCalls);
// ==> configuration supplied to the service ms2
TestCase.assertNotNull(testerB1.props);
TestCase.assertEquals(2, testerB1.numManagedServiceUpdatedCalls);
}
use of org.apache.felix.cm.integration.helper.ManagedServiceTestActivator2 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