use of org.apache.felix.cm.integration.helper.ManagedServiceTestActivator in project felix by apache.
the class ConfigurationBaseTest method test_listConfiguration.
@Test
public void test_listConfiguration() throws BundleException, IOException {
// 1. create a new Conf1 with pid1 and null location.
// 2. Conf1#update(props) is called.
final String pid = "test_listConfiguration";
final Configuration config = configure(pid, null, true);
// 3. bundleA will locationA registers ManagedServiceA with pid1.
bundle = installBundle(pid);
bundle.start();
delay();
// ==> ManagedServiceA is called back.
final ManagedServiceTestActivator tester = ManagedServiceTestActivator.INSTANCE;
TestCase.assertNotNull(tester);
TestCase.assertNotNull(tester.props);
TestCase.assertEquals(1, tester.numManagedServiceUpdatedCalls);
// 4. bundleA is stopped but *NOT uninstalled*.
bundle.stop();
delay();
// 5. test bundle calls cm.listConfigurations(null).
final Configuration listed = getConfiguration(pid);
// ==> Conf1 is included in the returned list and
// it has locationA.
// (In debug mode, dynamicBundleLocation==locationA
// and staticBundleLocation==null)
TestCase.assertNotNull(listed);
TestCase.assertEquals(bundle.getLocation(), listed.getBundleLocation());
// 6. test bundle calls cm.getConfiguration(pid1)
final Configuration get = getConfigurationAdmin().getConfiguration(pid);
TestCase.assertEquals(bundle.getLocation(), get.getBundleLocation());
final Bundle cmBundle = getCmBundle();
cmBundle.stop();
delay();
cmBundle.start();
delay();
// 5. test bundle calls cm.listConfigurations(null).
final Configuration listed2 = getConfiguration(pid);
// ==> Conf1 is included in the returned list and
// it has locationA.
// (In debug mode, dynamicBundleLocation==locationA
// and staticBundleLocation==null)
TestCase.assertNotNull(listed2);
TestCase.assertEquals(bundle.getLocation(), listed2.getBundleLocation());
// 6. test bundle calls cm.getConfiguration(pid1)
final Configuration get2 = getConfigurationAdmin().getConfiguration(pid);
TestCase.assertEquals(bundle.getLocation(), get2.getBundleLocation());
}
use of org.apache.felix.cm.integration.helper.ManagedServiceTestActivator in project felix by apache.
the class ConfigurationBindingTest method test_statically_bound.
@Test
public void test_statically_bound() throws BundleException {
final String pid = "test_statically_bound";
// install the bundle (we need the location)
bundle = installBundle(pid);
final String location = bundle.getLocation();
// create and statically bind the configuration
configure(pid);
final Configuration config = getConfiguration(pid);
TestCase.assertEquals(pid, config.getPid());
TestCase.assertNull(config.getBundleLocation());
config.setBundleLocation(location);
TestCase.assertEquals(location, config.getBundleLocation());
// ensure configuration is settled before starting the bundle
delay();
// expect single config update and location change
configListener.assertEvents(ConfigurationEvent.CM_UPDATED, 1);
configListener.assertEvents(ConfigurationEvent.CM_LOCATION_CHANGED, 1);
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", 1, tester.numManagedServiceUpdatedCalls);
TestCase.assertEquals(location, config.getBundleLocation());
// config already statically bound, no change event
configListener.assertEvents(ConfigurationEvent.CM_LOCATION_CHANGED, 0);
bundle.uninstall();
bundle = null;
delay();
// statically bound configurations must remain bound after bundle
// uninstall
TestCase.assertEquals(location, config.getBundleLocation());
// configuration statically bound, no change event
configListener.assertEvents(ConfigurationEvent.CM_LOCATION_CHANGED, 0);
// remove the configuration for good
deleteConfig(pid);
delay();
configListener.assertEvents(ConfigurationEvent.CM_DELETED, 1);
configListener.assertEvents(ConfigurationEvent.CM_UPDATED, 0);
configListener.assertEvents(ConfigurationEvent.CM_LOCATION_CHANGED, 0);
}
use of org.apache.felix.cm.integration.helper.ManagedServiceTestActivator in project felix by apache.
the class ConfigurationBindingTest method test_configuration_unbound_on_uninstall.
@Test
public void test_configuration_unbound_on_uninstall() throws BundleException {
String pid = "test_configuration_unbound_on_uninstall";
configure(pid);
// for the event to be distributed
delay();
configListener.assertEvents(ConfigurationEvent.CM_UPDATED, 1);
// ensure configuration is unbound
final Configuration beforeInstall = getConfiguration(pid);
TestCase.assertNull(beforeInstall.getBundleLocation());
bundle = installBundle(pid);
// ensure no configuration bound before start
final Configuration beforeStart = getConfiguration(pid);
TestCase.assertNull(beforeInstall.getBundleLocation());
TestCase.assertNull(beforeStart.getBundleLocation());
configListener.assertEvents(ConfigurationEvent.CM_LOCATION_CHANGED, 0);
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 a single update call", 1, tester.numManagedServiceUpdatedCalls);
configListener.assertEvents(ConfigurationEvent.CM_LOCATION_CHANGED, 1);
// ensure a freshly retrieved object also has the location
final Configuration beforeStop = getConfiguration(pid);
TestCase.assertEquals(beforeStop.getBundleLocation(), bundle.getLocation());
// check whether bundle context is set on first configuration
TestCase.assertEquals(beforeInstall.getBundleLocation(), bundle.getLocation());
TestCase.assertEquals(beforeStart.getBundleLocation(), bundle.getLocation());
bundle.stop();
delay();
// ensure configuration still bound
TestCase.assertEquals(beforeInstall.getBundleLocation(), bundle.getLocation());
TestCase.assertEquals(beforeStart.getBundleLocation(), bundle.getLocation());
TestCase.assertEquals(beforeStop.getBundleLocation(), bundle.getLocation());
// ensure a freshly retrieved object also has the location
final Configuration beforeUninstall = getConfiguration(pid);
TestCase.assertEquals(beforeUninstall.getBundleLocation(), bundle.getLocation());
bundle.uninstall();
bundle = null;
delay();
// ensure configuration is not bound any more
TestCase.assertNull(beforeInstall.getBundleLocation());
TestCase.assertNull(beforeStart.getBundleLocation());
TestCase.assertNull(beforeStop.getBundleLocation());
TestCase.assertNull(beforeUninstall.getBundleLocation());
configListener.assertEvents(ConfigurationEvent.CM_LOCATION_CHANGED, 1);
// ensure a freshly retrieved object also does not have the location
final Configuration atEnd = getConfiguration(pid);
TestCase.assertNull(atEnd.getBundleLocation());
// remove the configuration for good
deleteConfig(pid);
delay();
configListener.assertEvents(ConfigurationEvent.CM_DELETED, 1);
}
use of org.apache.felix.cm.integration.helper.ManagedServiceTestActivator in project felix by apache.
the class ConfigurationBindingTest method test_two_bundles_one_pid.
@Test
public void test_two_bundles_one_pid() throws BundleException, IOException {
// 1. Bundle registers service with pid1
final String pid = "test_two_bundles_one_pid";
final Bundle bundleA = installBundle(pid, ManagedServiceTestActivator.class);
final String locationA = bundleA.getLocation();
bundleA.start();
delay();
// call back with null
final ManagedServiceTestActivator tester = ManagedServiceTestActivator.INSTANCE;
TestCase.assertNull(tester.props);
TestCase.assertEquals(1, tester.numManagedServiceUpdatedCalls);
// 2. create new Conf with pid1 and locationA.
final Configuration config = configure(pid, locationA, false);
delay();
// ==> No call back.
TestCase.assertNull(tester.props);
TestCase.assertEquals(1, tester.numManagedServiceUpdatedCalls);
// 3. Configuration#update(prop) is called.
config.update(theConfig);
delay();
// ==> call back with the prop.
TestCase.assertNotNull(tester.props);
TestCase.assertEquals(2, tester.numManagedServiceUpdatedCalls);
// 4. Stop BundleA
bundleA.stop();
delay();
// 5. Start BundleA
bundleA.start();
delay();
// ==> call back with the prop.
final ManagedServiceTestActivator tester2 = ManagedServiceTestActivator.INSTANCE;
TestCase.assertNotNull(tester2.props);
TestCase.assertEquals(1, tester2.numManagedServiceUpdatedCalls);
// 6. Configuration#deleted() is called.
config.delete();
delay();
// ==> call back with null.
TestCase.assertNull(tester2.props);
TestCase.assertEquals(2, tester2.numManagedServiceUpdatedCalls);
// 7. uninstall Bundle A for cleanup.
bundleA.uninstall();
delay();
// Test 2
// 8. BundleA registers ManagedService with pid1.
final Bundle bundleA2 = installBundle(pid, ManagedServiceTestActivator.class);
final String locationA2 = bundleA.getLocation();
bundleA2.start();
delay();
// call back with null
final ManagedServiceTestActivator tester21 = ManagedServiceTestActivator.INSTANCE;
TestCase.assertNull(tester21.props);
TestCase.assertEquals(1, tester21.numManagedServiceUpdatedCalls);
// 9. create new Conf with pid1 and locationB.
final String locationB = "test:locationB/" + pid;
final Configuration configB = configure(pid, locationB, false);
delay();
// ==> No call back.
TestCase.assertNull(tester21.props);
TestCase.assertEquals(1, tester21.numManagedServiceUpdatedCalls);
// 10. Configuration#update(prop) is called.
configB.update(theConfig);
delay();
// ==> No call back because the Conf is not bound to locationA.
TestCase.assertNull(tester21.props);
TestCase.assertEquals(1, tester21.numManagedServiceUpdatedCalls);
}
use of org.apache.felix.cm.integration.helper.ManagedServiceTestActivator in project felix by apache.
the class ConfigurationBindingTest method test_create_with_location_unbind_before_service_supply.
@Test
public void test_create_with_location_unbind_before_service_supply() throws BundleException, IOException {
final String pid = "test_create_with_location_unbind_before_service_supply";
final String dummyLocation = "http://some/dummy/location";
// 1. create and statically bind the configuration
final Configuration config = configure(pid, dummyLocation, false);
TestCase.assertEquals(pid, config.getPid());
TestCase.assertEquals(dummyLocation, config.getBundleLocation());
// 2. update configuration
Hashtable<String, String> props = new Hashtable<String, String>();
props.put(PROP_NAME, PROP_NAME);
config.update(props);
TestCase.assertEquals(PROP_NAME, config.getProperties().get(PROP_NAME));
TestCase.assertEquals(pid, config.getPid());
TestCase.assertEquals(dummyLocation, config.getBundleLocation());
// 3. (statically) set location to null
config.setBundleLocation(null);
TestCase.assertNull(config.getBundleLocation());
// 4. install bundle with service
bundle = installBundle(pid);
bundle.start();
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", 1, tester.numManagedServiceUpdatedCalls);
TestCase.assertEquals(bundle.getLocation(), config.getBundleLocation());
bundle.uninstall();
bundle = null;
delay();
// statically bound configurations must remain bound after bundle
// uninstall
TestCase.assertNull(config.getBundleLocation());
// remove the configuration for good
deleteConfig(pid);
}
Aggregations