Search in sources :

Example 26 with ManagedServiceTestActivator

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