Search in sources :

Example 6 with ManagedServiceTestActivator

use of org.apache.felix.cm.integration.helper.ManagedServiceTestActivator in project felix by apache.

the class ConfigurationBaseTest method test_start_bundle_configure_stop_start_bundle.

@Test
public void test_start_bundle_configure_stop_start_bundle() throws BundleException {
    String pid = "test_start_bundle_configure_stop_start_bundle";
    // 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 no configuration
    TestCase.assertNull("Expect no Properties after Service Registration", tester.props);
    TestCase.assertEquals("Expect update call", 1, tester.numManagedServiceUpdatedCalls);
    // configure after ManagedServiceRegistration --> configure via update
    configure(pid);
    delay();
    // assert activater has configuration
    TestCase.assertNotNull("Expect Properties after Service Registration", tester.props);
    TestCase.assertEquals("Expect a second update call", 2, 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);
}
Also used : ManagedServiceTestActivator(org.apache.felix.cm.integration.helper.ManagedServiceTestActivator) Test(org.junit.Test)

Example 7 with ManagedServiceTestActivator

use of org.apache.felix.cm.integration.helper.ManagedServiceTestActivator in project felix by apache.

the class ConfigurationBaseTest method test_basic_configuration_strange_pid.

@Test
public void test_basic_configuration_strange_pid() throws BundleException, IOException {
    // 1. create config with pid and locationA
    // 2. update config with properties
    final String pid = "pid with blanks and stuff %\"'";
    theConfig.put(pid, pid);
    final Configuration config = configure(pid, null, true);
    theConfig.remove(pid);
    // 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(pid, tester.props.get(pid));
    TestCase.assertEquals(1, tester.numManagedServiceUpdatedCalls);
    // delete
    config.delete();
    delay();
    // ==> update with null
    TestCase.assertNull(tester.props);
    TestCase.assertEquals(2, tester.numManagedServiceUpdatedCalls);
}
Also used : Configuration(org.osgi.service.cm.Configuration) ManagedServiceTestActivator(org.apache.felix.cm.integration.helper.ManagedServiceTestActivator) Test(org.junit.Test)

Example 8 with ManagedServiceTestActivator

use of org.apache.felix.cm.integration.helper.ManagedServiceTestActivator 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);
}
Also used : Configuration(org.osgi.service.cm.Configuration) Bundle(org.osgi.framework.Bundle) ManagedServiceTestActivator(org.apache.felix.cm.integration.helper.ManagedServiceTestActivator) ManagedServiceTestActivator2(org.apache.felix.cm.integration.helper.ManagedServiceTestActivator2) Test(org.junit.Test)

Example 9 with ManagedServiceTestActivator

use of org.apache.felix.cm.integration.helper.ManagedServiceTestActivator in project felix by apache.

the class ConfigurationBindingTest method test_not_updated_new_configuration_not_bound_after_bundle_uninstall.

@Test
public void test_not_updated_new_configuration_not_bound_after_bundle_uninstall() throws IOException, BundleException {
    final String pid = "test_not_updated_new_configuration_not_bound_after_bundle_uninstall";
    // create a configuration but do not update with properties
    final Configuration newConfig = configure(pid, null, false);
    TestCase.assertNull(newConfig.getProperties());
    TestCase.assertNull(newConfig.getBundleLocation());
    // start and settle bundle
    bundle = installBundle(pid);
    bundle.start();
    delay();
    // ensure no properties provided to bundle
    final ManagedServiceTestActivator tester = ManagedServiceTestActivator.INSTANCE;
    TestCase.assertNotNull("Activator not started !!", tester);
    TestCase.assertNull("Expect no properties after Service Registration", tester.props);
    TestCase.assertEquals("Expect a single update call", 1, tester.numManagedServiceUpdatedCalls);
    // assert configuration is still unset but bound
    TestCase.assertNull(newConfig.getProperties());
    TestCase.assertEquals(bundle.getLocation(), newConfig.getBundleLocation());
    // uninstall bundle, should unbind configuration
    bundle.uninstall();
    bundle = null;
    delay();
    // assert configuration is still unset and unbound
    TestCase.assertNull(newConfig.getProperties());
    TestCase.assertNull(newConfig.getBundleLocation());
    // remove the configuration for good
    deleteConfig(pid);
}
Also used : Configuration(org.osgi.service.cm.Configuration) ManagedServiceTestActivator(org.apache.felix.cm.integration.helper.ManagedServiceTestActivator) Test(org.junit.Test)

Example 10 with ManagedServiceTestActivator

use of org.apache.felix.cm.integration.helper.ManagedServiceTestActivator 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);
}
Also used : Configuration(org.osgi.service.cm.Configuration) Bundle(org.osgi.framework.Bundle) ManagedServiceTestActivator(org.apache.felix.cm.integration.helper.ManagedServiceTestActivator) ManagedServiceTestActivator2(org.apache.felix.cm.integration.helper.ManagedServiceTestActivator2) Test(org.junit.Test)

Aggregations

ManagedServiceTestActivator (org.apache.felix.cm.integration.helper.ManagedServiceTestActivator)26 Test (org.junit.Test)26 Configuration (org.osgi.service.cm.Configuration)20 Bundle (org.osgi.framework.Bundle)8 ManagedServiceTestActivator2 (org.apache.felix.cm.integration.helper.ManagedServiceTestActivator2)5 MultiManagedServiceTestActivator (org.apache.felix.cm.integration.helper.MultiManagedServiceTestActivator)2 Hashtable (java.util.Hashtable)1