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_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.ManagedServiceTestActivator in project felix by apache.
the class MultiValuePIDTest method test_multi_value_pid_collection.
@Test
public void test_multi_value_pid_collection() throws BundleException {
String pid1 = "test.pid.1";
String pid2 = "test.pid.2";
configure(pid1);
configure(pid2);
final Configuration config1 = getConfiguration(pid1);
TestCase.assertEquals(pid1, config1.getPid());
TestCase.assertNull(config1.getBundleLocation());
final Configuration config2 = getConfiguration(pid2);
TestCase.assertEquals(pid2, config2.getPid());
TestCase.assertNull(config2.getBundleLocation());
// multi-pid with collection
bundle = installBundle(pid1 + ";" + pid2);
bundle.start();
// give cm time for distribution
delay();
final ManagedServiceTestActivator tester = ManagedServiceTestActivator.INSTANCE;
TestCase.assertNotNull("Activator not started !!", tester);
// assert activater has configuration (two calls, one per pid)
TestCase.assertNotNull("Expect Properties after Service Registration", tester.props);
TestCase.assertEquals("Expect a single update call", 2, tester.numManagedServiceUpdatedCalls);
TestCase.assertEquals(bundle.getLocation(), config1.getBundleLocation());
TestCase.assertEquals(bundle.getLocation(), config2.getBundleLocation());
bundle.uninstall();
bundle = null;
delay();
TestCase.assertNull(config1.getBundleLocation());
TestCase.assertNull(config2.getBundleLocation());
// remove the configuration for good
deleteConfig(pid1);
deleteConfig(pid2);
}
use of org.apache.felix.cm.integration.helper.ManagedServiceTestActivator in project felix by apache.
the class TargetedPidTest method test_targetet_pid_no_replace.
@Test
public void test_targetet_pid_no_replace() throws BundleException {
String basePid = "test_targeted";
String[] pids = null;
try {
// start the bundle and assert this
bundle = installBundle(basePid);
bundle.start();
final ManagedServiceTestActivator tester = ManagedServiceTestActivator.INSTANCE;
TestCase.assertNotNull("Activator not started !!", tester);
// give cm time for distribution
delay();
// assert activater has configuration
int callCount = 0;
TestCase.assertNull("Expect no Properties after Service Registration", tester.props);
TestCase.assertEquals("Expect calls", ++callCount, tester.numManagedServiceUpdatedCalls);
pids = new String[] { basePid, String.format("%s|%s", basePid, bundle.getSymbolicName()), String.format("%s|%s|%s", basePid, bundle.getSymbolicName(), bundle.getHeaders().get(Constants.BUNDLE_VERSION)), String.format("%s|%s|%s|%s", basePid, bundle.getSymbolicName(), bundle.getHeaders().get(Constants.BUNDLE_VERSION), bundle.getLocation()) };
for (String pid : pids) {
configure(pid);
delay();
TestCase.assertNotNull("Expect Properties after update " + pid, tester.props);
TestCase.assertEquals("Expect PID", pid, tester.props.get(Constants.SERVICE_PID));
TestCase.assertEquals("Expect calls", ++callCount, tester.numManagedServiceUpdatedCalls);
deleteConfig(pid);
delay();
TestCase.assertNull("Expect no Properties after delete " + pid, tester.props);
TestCase.assertEquals("Expect calls", ++callCount, tester.numManagedServiceUpdatedCalls);
}
// cleanup
bundle.uninstall();
bundle = null;
} finally {
// remove the configuration for good
if (pids != null) {
for (String p : pids) {
deleteConfig(p);
}
}
}
}
use of org.apache.felix.cm.integration.helper.ManagedServiceTestActivator in project felix by apache.
the class ConfigurationBaseTest method test_ManagedService_change_pid_overlap.
@Test
public void test_ManagedService_change_pid_overlap() throws BundleException, IOException {
final String pid0 = "test_ManagedService_change_pid_0";
final String pid1 = "test_ManagedService_change_pid_1";
final String pid2 = "test_ManagedService_change_pid_2";
final Configuration config0 = configure(pid0, null, true);
final Configuration config1 = configure(pid1, null, true);
final Configuration config2 = configure(pid2, null, true);
delay();
// register ManagedService ms1 with pid from said locationA
bundle = installBundle(pid0 + "," + pid1, ManagedServiceTestActivator.class);
bundle.start();
delay();
final ManagedServiceTestActivator tester = ManagedServiceTestActivator.INSTANCE;
TestCase.assertNotNull(tester.props);
TestCase.assertEquals(pid0, tester.configs.get(pid0).get(Constants.SERVICE_PID));
TestCase.assertNull(tester.configs.get(pid0).get(ConfigurationAdmin.SERVICE_FACTORYPID));
TestCase.assertNull(tester.configs.get(pid0).get(ConfigurationAdmin.SERVICE_BUNDLELOCATION));
TestCase.assertEquals(PROP_NAME, tester.configs.get(pid0).get(PROP_NAME));
TestCase.assertEquals(pid1, tester.configs.get(pid1).get(Constants.SERVICE_PID));
TestCase.assertNull(tester.configs.get(pid1).get(ConfigurationAdmin.SERVICE_FACTORYPID));
TestCase.assertNull(tester.configs.get(pid1).get(ConfigurationAdmin.SERVICE_BUNDLELOCATION));
TestCase.assertEquals(PROP_NAME, tester.configs.get(pid1).get(PROP_NAME));
// two pids, two calls
TestCase.assertEquals(2, tester.numManagedServiceUpdatedCalls);
// change ManagedService PID
tester.changePid(pid1 + "," + pid2);
delay();
TestCase.assertNotNull(tester.props);
// config pid0 is not "removed"
TestCase.assertEquals(pid0, tester.configs.get(pid0).get(Constants.SERVICE_PID));
TestCase.assertNull(tester.configs.get(pid0).get(ConfigurationAdmin.SERVICE_FACTORYPID));
TestCase.assertNull(tester.configs.get(pid0).get(ConfigurationAdmin.SERVICE_BUNDLELOCATION));
TestCase.assertEquals(PROP_NAME, tester.configs.get(pid0).get(PROP_NAME));
// config pid1 is retained
TestCase.assertEquals(pid1, tester.configs.get(pid1).get(Constants.SERVICE_PID));
TestCase.assertNull(tester.configs.get(pid1).get(ConfigurationAdmin.SERVICE_FACTORYPID));
TestCase.assertNull(tester.configs.get(pid1).get(ConfigurationAdmin.SERVICE_BUNDLELOCATION));
TestCase.assertEquals(PROP_NAME, tester.configs.get(pid1).get(PROP_NAME));
// config pid2 is added
TestCase.assertEquals(pid2, tester.configs.get(pid2).get(Constants.SERVICE_PID));
TestCase.assertNull(tester.configs.get(pid2).get(ConfigurationAdmin.SERVICE_FACTORYPID));
TestCase.assertNull(tester.configs.get(pid2).get(ConfigurationAdmin.SERVICE_BUNDLELOCATION));
TestCase.assertEquals(PROP_NAME, tester.configs.get(pid2).get(PROP_NAME));
// one "additional" pid, one additional call
TestCase.assertEquals(3, tester.numManagedServiceUpdatedCalls);
// delete
// ignored by MS
config0.delete();
config1.delete();
config2.delete();
delay();
// ==> update with null
TestCase.assertNull(tester.props);
// two pids removed, two calls
TestCase.assertEquals(5, tester.numManagedServiceUpdatedCalls);
}
use of org.apache.felix.cm.integration.helper.ManagedServiceTestActivator in project felix by apache.
the class ConfigurationBaseTest method test_configure_start_bundle_stop_start_bundle.
@Test
public void test_configure_start_bundle_stop_start_bundle() throws BundleException {
String pid = "test_configure_start_bundle_stop_start_bundle";
configure(pid);
// start the bundle and assert this
bundle = installBundle(pid);
bundle.start();
final ManagedServiceTestActivator tester = ManagedServiceTestActivator.INSTANCE;
TestCase.assertNotNull("Activator not started !!", tester);
// give cm time for distribution
delay();
// assert activater has configuration
TestCase.assertNotNull("Expect Properties after Service Registration", tester.props);
TestCase.assertEquals("Expect no update call", 1, tester.numManagedServiceUpdatedCalls);
// stop the bundle now
bundle.stop();
// assert INSTANCE is null
TestCase.assertNull(ManagedServiceTestActivator.INSTANCE);
delay();
// start the bundle again (and check)
bundle.start();
final ManagedServiceTestActivator tester2 = ManagedServiceTestActivator.INSTANCE;
TestCase.assertNotNull("Activator not started the second time!!", tester2);
TestCase.assertNotSame("Instances must not be the same", tester, tester2);
// give cm time for distribution
delay();
// assert activater has configuration
TestCase.assertNotNull("Expect Properties after Service Registration", tester2.props);
TestCase.assertEquals("Expect a second update call", 1, tester2.numManagedServiceUpdatedCalls);
// cleanup
bundle.uninstall();
bundle = null;
// remove the configuration for good
deleteConfig(pid);
}
Aggregations