Package org.osgi.service.cm

Examples of org.osgi.service.cm.Configuration


        final String factoryPid = "test_basic_configuration_factory_configure_then_start";
        bundle = installBundle( factoryPid, ManagedServiceFactoryTestActivator.class );
        bundle.start();
        delay();

        final Configuration config = createFactoryConfiguration( factoryPid, null, true );
        final String pid = config.getPid();
        delay();

        // ==> configuration supplied to the service ms1
        final ManagedServiceFactoryTestActivator tester = ManagedServiceFactoryTestActivator.INSTANCE;
        Dictionary<?, ?> props = tester.configs.get( pid );
        TestCase.assertNotNull( props );
        TestCase.assertEquals( pid, props.get( Constants.SERVICE_PID ) );
        TestCase.assertEquals( factoryPid, props.get( ConfigurationAdmin.SERVICE_FACTORYPID ) );
        TestCase.assertNull( props.get( ConfigurationAdmin.SERVICE_BUNDLELOCATION ) );
        TestCase.assertEquals( PROP_NAME, props.get( PROP_NAME ) );
        TestCase.assertEquals( 0, tester.numManagedServiceUpdatedCalls );
        TestCase.assertEquals( 1, tester.numManagedServiceFactoryUpdatedCalls );
        TestCase.assertEquals( 0, tester.numManagedServiceFactoryDeleteCalls );

        // delete
        config.delete();
        delay();

        // ==> update with null
        TestCase.assertNull( tester.configs.get( pid ) );
        TestCase.assertEquals( 0, tester.numManagedServiceUpdatedCalls );
View Full Code Here


    public void test_basic_configuration_factory_configure_then_start() throws BundleException, IOException
    {
        // 1. create config with pid and locationA
        // 2. update config with properties
        final String factoryPid = "test_basic_configuration_factory_start_then_configure";
        final Configuration config = createFactoryConfiguration( factoryPid, null, true );
        final String pid = config.getPid();
        delay();

        // 3. register ManagedService ms1 with pid from said locationA
        bundle = installBundle( factoryPid, ManagedServiceFactoryTestActivator.class );
        bundle.start();
        delay();

        // ==> configuration supplied to the service ms1
        final ManagedServiceFactoryTestActivator tester = ManagedServiceFactoryTestActivator.INSTANCE;
        Dictionary<?, ?> props = tester.configs.get( pid );
        TestCase.assertNotNull( props );
        TestCase.assertEquals( pid, props.get( Constants.SERVICE_PID ) );
        TestCase.assertEquals( factoryPid, props.get( ConfigurationAdmin.SERVICE_FACTORYPID ) );
        TestCase.assertNull( props.get( ConfigurationAdmin.SERVICE_BUNDLELOCATION ) );
        TestCase.assertEquals( PROP_NAME, props.get( PROP_NAME ) );
        TestCase.assertEquals( 0, tester.numManagedServiceUpdatedCalls );
        TestCase.assertEquals( 1, tester.numManagedServiceFactoryUpdatedCalls );
        TestCase.assertEquals( 0, tester.numManagedServiceFactoryDeleteCalls );

        // delete
        config.delete();
        delay();

        // ==> update with null
        TestCase.assertNull( tester.configs.get( pid ) );
        TestCase.assertEquals( 0, tester.numManagedServiceUpdatedCalls );
View Full Code Here

    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() );
    }
View Full Code Here

    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 );
View Full Code Here

    {
        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
        config0.delete(); // ignored by MS
        config1.delete();
        config2.delete();
        delay();

        // ==> update with null
        TestCase.assertNull( tester.props );
View Full Code Here

    {

        final String factoryPid0 = "test_ManagedServiceFactory_change_pid_0";
        final String factoryPid1 = "test_ManagedServiceFactory_change_pid_1";

        final Configuration config0 = createFactoryConfiguration( factoryPid0, null, true );
        final String pid0 = config0.getPid();
        final Configuration config1 = createFactoryConfiguration( factoryPid1, null, true );
        final String pid1 = config1.getPid();
        delay();

        bundle = installBundle( factoryPid0, ManagedServiceFactoryTestActivator.class );
        bundle.start();
        delay();

        // pid0 properties provided on registration
        final ManagedServiceFactoryTestActivator tester = ManagedServiceFactoryTestActivator.INSTANCE;
        Dictionary<?, ?> props0 = tester.configs.get( pid0 );
        TestCase.assertNotNull( props0 );
        TestCase.assertEquals( pid0, props0.get( Constants.SERVICE_PID ) );
        TestCase.assertEquals( factoryPid0, props0.get( ConfigurationAdmin.SERVICE_FACTORYPID ) );
        TestCase.assertNull( props0.get( ConfigurationAdmin.SERVICE_BUNDLELOCATION ) );
        TestCase.assertEquals( PROP_NAME, props0.get( PROP_NAME ) );
        TestCase.assertEquals( 0, tester.numManagedServiceUpdatedCalls );
        TestCase.assertEquals( 1, tester.numManagedServiceFactoryUpdatedCalls );
        TestCase.assertEquals( 0, tester.numManagedServiceFactoryDeleteCalls );

        // change ManagedService PID
        tester.changePid( factoryPid1 );
        delay();

        // pid1 properties must have been added
        Dictionary<?, ?> props1 = tester.configs.get( pid1 );
        TestCase.assertNotNull( props1 );
        TestCase.assertEquals( pid1, props1.get( Constants.SERVICE_PID ) );
        TestCase.assertEquals( factoryPid1, props1.get( ConfigurationAdmin.SERVICE_FACTORYPID ) );
        TestCase.assertNull( props1.get( ConfigurationAdmin.SERVICE_BUNDLELOCATION ) );
        TestCase.assertEquals( PROP_NAME, props1.get( PROP_NAME ) );
        TestCase.assertEquals( 0, tester.numManagedServiceUpdatedCalls );
        TestCase.assertEquals( 2, tester.numManagedServiceFactoryUpdatedCalls );
        TestCase.assertEquals( 0, tester.numManagedServiceFactoryDeleteCalls );

        // pid0 properties must still exist !
        Dictionary<?, ?> props01 = tester.configs.get( pid0 );
        TestCase.assertNotNull( props01 );
        TestCase.assertEquals( pid0, props01.get( Constants.SERVICE_PID ) );
        TestCase.assertEquals( factoryPid0, props01.get( ConfigurationAdmin.SERVICE_FACTORYPID ) );
        TestCase.assertNull( props01.get( ConfigurationAdmin.SERVICE_BUNDLELOCATION ) );
        TestCase.assertEquals( PROP_NAME, props01.get( PROP_NAME ) );


        // delete
        config0.delete();
        config1.delete();
        delay();

        // only pid1 properties removed because pid0 is not registered any longer
        TestCase.assertNotNull( tester.configs.get( pid0 ) );
        TestCase.assertNull( tester.configs.get( pid1 ) );
View Full Code Here

        final String factoryPid0 = "test_ManagedServiceFactory_change_pid_0";
        final String factoryPid1 = "test_ManagedServiceFactory_change_pid_1";
        final String factoryPid2 = "test_ManagedServiceFactory_change_pid_2";

        final Configuration config0 = createFactoryConfiguration( factoryPid0, null, true );
        final String pid0 = config0.getPid();
        final Configuration config1 = createFactoryConfiguration( factoryPid1, null, true );
        final String pid1 = config1.getPid();
        final Configuration config2 = createFactoryConfiguration( factoryPid2, null, true );
        final String pid2 = config2.getPid();
        delay();

        bundle = installBundle( factoryPid0 + "," + factoryPid1, ManagedServiceFactoryTestActivator.class );
        bundle.start();
        delay();

        // pid0 properties provided on registration
        final ManagedServiceFactoryTestActivator tester = ManagedServiceFactoryTestActivator.INSTANCE;
        Dictionary<?, ?> props0 = tester.configs.get( pid0 );
        TestCase.assertNotNull( props0 );
        TestCase.assertEquals( pid0, props0.get( Constants.SERVICE_PID ) );
        TestCase.assertEquals( factoryPid0, props0.get( ConfigurationAdmin.SERVICE_FACTORYPID ) );
        TestCase.assertNull( props0.get( ConfigurationAdmin.SERVICE_BUNDLELOCATION ) );
        TestCase.assertEquals( PROP_NAME, props0.get( PROP_NAME ) );

        Dictionary<?, ?> props1 = tester.configs.get( pid1 );
        TestCase.assertNotNull( props1 );
        TestCase.assertEquals( pid1, props1.get( Constants.SERVICE_PID ) );
        TestCase.assertEquals( factoryPid1, props1.get( ConfigurationAdmin.SERVICE_FACTORYPID ) );
        TestCase.assertNull( props1.get( ConfigurationAdmin.SERVICE_BUNDLELOCATION ) );
        TestCase.assertEquals( PROP_NAME, props1.get( PROP_NAME ) );

        TestCase.assertEquals( 0, tester.numManagedServiceUpdatedCalls );
        TestCase.assertEquals( 2, tester.numManagedServiceFactoryUpdatedCalls );
        TestCase.assertEquals( 0, tester.numManagedServiceFactoryDeleteCalls );

        // change ManagedService PID
        tester.changePid( factoryPid1 + "," + factoryPid2 );
        delay();

        // pid2 properties must have been added
        Dictionary<?, ?> props2 = tester.configs.get( pid2 );
        TestCase.assertNotNull( props2 );
        TestCase.assertEquals( pid2, props2.get( Constants.SERVICE_PID ) );
        TestCase.assertEquals( factoryPid2, props2.get( ConfigurationAdmin.SERVICE_FACTORYPID ) );
        TestCase.assertNull( props2.get( ConfigurationAdmin.SERVICE_BUNDLELOCATION ) );
        TestCase.assertEquals( PROP_NAME, props2.get( PROP_NAME ) );

        // pid0 properties must still exist !
        Dictionary<?, ?> props01 = tester.configs.get( pid0 );
        TestCase.assertNotNull( props01 );
        TestCase.assertEquals( pid0, props01.get( Constants.SERVICE_PID ) );
        TestCase.assertEquals( factoryPid0, props01.get( ConfigurationAdmin.SERVICE_FACTORYPID ) );
        TestCase.assertNull( props01.get( ConfigurationAdmin.SERVICE_BUNDLELOCATION ) );
        TestCase.assertEquals( PROP_NAME, props01.get( PROP_NAME ) );

        // pid1 properties must still exist !
        Dictionary<?, ?> props11 = tester.configs.get( pid1 );
        TestCase.assertNotNull( props11 );
        TestCase.assertEquals( pid1, props11.get( Constants.SERVICE_PID ) );
        TestCase.assertEquals( factoryPid1, props11.get( ConfigurationAdmin.SERVICE_FACTORYPID ) );
        TestCase.assertNull( props11.get( ConfigurationAdmin.SERVICE_BUNDLELOCATION ) );
        TestCase.assertEquals( PROP_NAME, props11.get( PROP_NAME ) );

        TestCase.assertEquals( 0, tester.numManagedServiceUpdatedCalls );
        TestCase.assertEquals( 3, tester.numManagedServiceFactoryUpdatedCalls );
        TestCase.assertEquals( 0, tester.numManagedServiceFactoryDeleteCalls );

        // delete
        config0.delete();
        config1.delete();
        config2.delete();
        delay();

        // only pid1 and pid2 properties removed because pid0 is not registered any longer
        TestCase.assertNotNull( tester.configs.get( pid0 ) );
        TestCase.assertNull( tester.configs.get( pid1 ) );
View Full Code Here

    @Test
    public void test_factory_configuration_collision() throws IOException, InvalidSyntaxException, BundleException {
        final String factoryPid = "test_factory_configuration_collision";

        final Configuration cf = getConfigurationAdmin().createFactoryConfiguration( factoryPid, null );
        TestCase.assertNotNull( cf );
        final String pid = cf.getPid();

        // check factory configuration setup
        TestCase.assertNotNull( "Configuration must have PID", pid );
        TestCase.assertEquals( "Factory configuration must have requested factory PID", factoryPid, cf.getFactoryPid() );

        try
        {
            bundle = installBundle( factoryPid, ManagedServiceFactoryTestActivator.class );
            bundle.start();
            delay();

            final ManagedServiceFactoryTestActivator tester = ManagedServiceFactoryTestActivator.INSTANCE;
            TestCase.assertEquals( "MSF must not be updated with new configuration", 0, tester.numManagedServiceFactoryUpdatedCalls );

            // assert getConfiguration returns the same configurtion
            final Configuration c1 = getConfigurationAdmin().getConfiguration( pid, null );
            TestCase.assertEquals( "getConfiguration must retrieve required PID", pid, c1.getPid() );
            TestCase.assertEquals( "getConfiguration must retrieve new factory configuration", factoryPid, c1.getFactoryPid() );
            TestCase.assertNull( "Configuration must not have properties", c1.getProperties() );

            TestCase.assertEquals( "MSF must not be updated with new configuration", 0, tester.numManagedServiceFactoryUpdatedCalls );

            // restart config admin and verify getConfiguration persisted
            // the new factory configuration as such
            final Bundle cmBundle = getCmBundle();
            TestCase.assertNotNull( "Config Admin Bundle missing", cmBundle );
            cmBundle.stop();
            delay();
            cmBundle.start();
            delay();

            TestCase.assertEquals( "MSF must not be updated with new configuration even after CM restart", 0, tester.numManagedServiceFactoryUpdatedCalls );

            final Configuration c2 = getConfigurationAdmin().getConfiguration( pid, null );
            TestCase.assertEquals( "getConfiguration must retrieve required PID", pid, c2.getPid() );
            TestCase.assertEquals( "getConfiguration must retrieve new factory configuration from persistence", factoryPid, c2.getFactoryPid() );
            TestCase.assertNull( "Configuration must not have properties", c2.getProperties() );

            c2.update( theConfig );
            delay();

            TestCase.assertEquals( 1, tester.numManagedServiceFactoryUpdatedCalls );
            TestCase.assertEquals( theConfig.get( PROP_NAME ), tester.configs.get( cf.getPid() ).get( PROP_NAME ) );
View Full Code Here

    }


    public void testScalar() throws IOException
    {
        Configuration cimpl = getConfiguration();
        Dictionary props = cimpl.getProperties();
        assertNull( "Configuration is fresh", props );

        props = new Hashtable();
        props.put( SCALAR, STRING_VALUE );
        cimpl.update( props );

        Dictionary newProps = cimpl.getProperties();
        assertNotNull( "Configuration is not fresh", newProps );
        assertEquals( "Expect 2 elements", 2, newProps.size() );
        assertEquals( "Service.pid must match", TEST_PID, newProps.get( Constants.SERVICE_PID ) );
        assertEquals( "Scalar value must match", STRING_VALUE, newProps.get( SCALAR ) );
    }
View Full Code Here

    }


    public void testArray() throws IOException
    {
        Configuration cimpl = getConfiguration();

        Dictionary props = cimpl.getProperties();
        assertNull( "Configuration is fresh", props );

        props = new Hashtable();
        props.put( ARRAY, ARRAY_VALUE );
        cimpl.update( props );

        Dictionary newProps = cimpl.getProperties();
        assertNotNull( "Configuration is not fresh", newProps );
        assertEquals( "Expect 2 elements", 2, newProps.size() );
        assertEquals( "Service.pid must match", TEST_PID, newProps.get( Constants.SERVICE_PID ) );

        Object testProp = newProps.get( ARRAY );
        assertNotNull( testProp );
        assertTrue( testProp.getClass().isArray() );
        assertEquals( 1, Array.getLength( testProp ) );
        assertEquals( STRING_VALUE, Array.get( testProp, 0 ) );

        // modify the array property
        Array.set( testProp, 0, STRING_VALUE2 );

        // the array element change must not be reflected in the configuration
        Dictionary newProps2 = cimpl.getProperties();
        Object testProp2 = newProps2.get( ARRAY );
        assertNotNull( testProp2 );
        assertTrue( testProp2.getClass().isArray() );
        assertEquals( 1, Array.getLength( testProp2 ) );
        assertEquals( STRING_VALUE, Array.get( testProp2, 0 ) );
View Full Code Here

TOP

Related Classes of org.osgi.service.cm.Configuration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.