use of org.apache.felix.cm.integration.helper.ManagedServiceTestActivator in project felix by apache.
the class TargetedPidTest method test_targetet_pid_delete_fallback.
@Test
public void test_targetet_pid_delete_fallback() throws BundleException {
String basePid = "test_targeted";
String[] pids = null;
try {
// start the bundle and assert this
bundle = installBundle(basePid);
pids = new String[] { String.format("%s|%s|%s|%s", basePid, bundle.getSymbolicName(), bundle.getHeaders().get(Constants.BUNDLE_VERSION), bundle.getLocation()), String.format("%s|%s|%s", basePid, bundle.getSymbolicName(), bundle.getHeaders().get(Constants.BUNDLE_VERSION)), String.format("%s|%s", basePid, bundle.getSymbolicName()), basePid };
for (String pid : pids) {
configure(pid);
}
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;
for (String pid : pids) {
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();
}
// final delete
TestCase.assertNull("Expect Properties after delete", 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 TargetedPidTest method test_targetet_pid_replace.
@Test
public void test_targetet_pid_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);
}
// 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.
@Test
public void test_ManagedService_change_pid() throws BundleException, IOException {
final String pid0 = "test_ManagedService_change_pid_0";
final String pid1 = "test_ManagedService_change_pid_1";
final Configuration config0 = configure(pid0, null, true);
final Configuration config1 = configure(pid1, null, true);
delay();
// register ManagedService ms1 with pid from said locationA
bundle = installBundle(pid0, ManagedServiceTestActivator.class);
bundle.start();
delay();
final ManagedServiceTestActivator tester = ManagedServiceTestActivator.INSTANCE;
TestCase.assertNotNull(tester.props);
TestCase.assertEquals(pid0, tester.props.get(Constants.SERVICE_PID));
TestCase.assertNull(tester.props.get(ConfigurationAdmin.SERVICE_FACTORYPID));
TestCase.assertNull(tester.props.get(ConfigurationAdmin.SERVICE_BUNDLELOCATION));
TestCase.assertEquals(PROP_NAME, tester.props.get(PROP_NAME));
TestCase.assertEquals(1, tester.numManagedServiceUpdatedCalls);
// change ManagedService PID
tester.changePid(pid1);
delay();
TestCase.assertNotNull(tester.props);
TestCase.assertEquals(pid1, tester.props.get(Constants.SERVICE_PID));
TestCase.assertNull(tester.props.get(ConfigurationAdmin.SERVICE_FACTORYPID));
TestCase.assertNull(tester.props.get(ConfigurationAdmin.SERVICE_BUNDLELOCATION));
TestCase.assertEquals(PROP_NAME, tester.props.get(PROP_NAME));
TestCase.assertEquals(2, tester.numManagedServiceUpdatedCalls);
// delete
config0.delete();
config1.delete();
delay();
// ==> update with null
TestCase.assertNull(tester.props);
TestCase.assertEquals(3, tester.numManagedServiceUpdatedCalls);
}
use of org.apache.felix.cm.integration.helper.ManagedServiceTestActivator in project felix by apache.
the class ConfigurationBaseTest method test_basic_configuration_configure_then_start.
@Test
public void test_basic_configuration_configure_then_start() throws BundleException, IOException {
// 1. create config with pid and locationA
// 2. update config with properties
final String pid = "test_basic_configuration_configure_then_start";
final Configuration config = configure(pid, null, true);
// 3. register ManagedService ms1 with pid from said locationA
bundle = installBundle(pid, ManagedServiceTestActivator.class);
bundle.start();
delay();
// ==> configuration supplied to the service ms1
final ManagedServiceTestActivator tester = ManagedServiceTestActivator.INSTANCE;
TestCase.assertNotNull(tester.props);
TestCase.assertEquals(pid, tester.props.get(Constants.SERVICE_PID));
TestCase.assertNull(tester.props.get(ConfigurationAdmin.SERVICE_FACTORYPID));
TestCase.assertNull(tester.props.get(ConfigurationAdmin.SERVICE_BUNDLELOCATION));
TestCase.assertEquals(PROP_NAME, tester.props.get(PROP_NAME));
TestCase.assertEquals(1, tester.numManagedServiceUpdatedCalls);
// delete
config.delete();
delay();
// ==> update with null
TestCase.assertNull(tester.props);
TestCase.assertEquals(2, tester.numManagedServiceUpdatedCalls);
}
use of org.apache.felix.cm.integration.helper.ManagedServiceTestActivator in project felix by apache.
the class ConfigurationBaseTest method test_basic_configuration_start_then_configure.
@Test
public void test_basic_configuration_start_then_configure() throws BundleException, IOException {
final String pid = "test_basic_configuration_start_then_configure";
// 1. register ManagedService ms1 with pid from said locationA
bundle = installBundle(pid, ManagedServiceTestActivator.class);
bundle.start();
delay();
// 1. create config with pid and locationA
// 2. update config with properties
final Configuration config = configure(pid, null, true);
delay();
// ==> configuration supplied to the service ms1
final ManagedServiceTestActivator tester = ManagedServiceTestActivator.INSTANCE;
TestCase.assertNotNull(tester.props);
TestCase.assertEquals(pid, tester.props.get(Constants.SERVICE_PID));
TestCase.assertNull(tester.props.get(ConfigurationAdmin.SERVICE_FACTORYPID));
TestCase.assertNull(tester.props.get(ConfigurationAdmin.SERVICE_BUNDLELOCATION));
TestCase.assertEquals(PROP_NAME, tester.props.get(PROP_NAME));
TestCase.assertEquals(2, tester.numManagedServiceUpdatedCalls);
// delete
config.delete();
delay();
// ==> update with null
TestCase.assertNull(tester.props);
TestCase.assertEquals(3, tester.numManagedServiceUpdatedCalls);
}
Aggregations