Package org.osgi.service.cm

Examples of org.osgi.service.cm.Configuration


    }


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

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

        props = new Hashtable();
        props.put( COLLECTION, COLLECTION_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( COLLECTION );
        assertNotNull( testProp );
        assertTrue( testProp instanceof Collection );
        Collection coll = ( Collection ) testProp;
        assertEquals( 1, coll.size() );
        assertEquals( STRING_VALUE, coll.iterator().next() );

        // modify the array property
        coll.clear();
        coll.add( STRING_VALUE2 );

        // the array element change must not be reflected in the configuration
        Dictionary newProps2 = cimpl.getProperties();
        Object testProp2 = newProps2.get( COLLECTION );
        assertNotNull( testProp2 );
        assertTrue( testProp2 instanceof Collection );
        Collection coll2 = ( Collection ) testProp2;
        assertEquals( 1, coll2.size() );
View Full Code Here


        {
            return;//not an R5 CA
        }
        String pid = COMPONENT_NAME;
        theConfig.put(TARGETED_PID, pid);
        Configuration config = configure( pid );
        config.setBundleLocation( REGION );
       
        String pidSN = pid + "|simplecomponent2";
        theConfig.put(TARGETED_PID, pidSN);
        Configuration configSN = configure( pidSN );
        configSN.setBundleLocation( REGION );
       
        String pidSNV = pidSN + "|0.0.12";
        theConfig.put(TARGETED_PID, pidSNV);
        Configuration configSNV = configure( pidSNV );
        configSNV.setBundleLocation( REGION );
       
        String pidSNVL = pidSNV + "|bundleLocation";
        theConfig.put(TARGETED_PID, pidSNVL);
        Configuration configSNVL = configure( pidSNVL );
        configSNVL.setBundleLocation( REGION );
       
        delay();
       
        //Add more and more specific components to check that they pick up the appropriate configuration
        Set<ComponentConfigurationDTO> known = new HashSet<ComponentConfigurationDTO>();
       
        final ComponentConfigurationDTO component = findComponentConfigurationByName( COMPONENT_NAME, ComponentConfigurationDTO.ACTIVE );
        known.add( component );

        TestCase.assertNotNull( SimpleComponent.INSTANCE );
        SimpleComponent sc = SimpleComponent.INSTANCE;
        TestCase.assertEquals( pid, sc.getProperty( TARGETED_PID ) );
       
       
        Bundle bSN = installBundle( descriptorFile, COMPONENT_PACKAGE, "simplecomponent2", "0.0.11", null );
        bSN.start();
        findComponentConfigurationByName( bSN, pid, ComponentConfigurationDTO.ACTIVE );

       
        SimpleComponent scSN = SimpleComponent.INSTANCE;
        TestCase.assertEquals( pidSN, scSN.getProperty( TARGETED_PID ) );
       
        Bundle bSNV = installBundle( descriptorFile, COMPONENT_PACKAGE, "simplecomponent2", "0.0.12", null );
        bSNV.start();
        findComponentConfigurationByName( bSNV, pid, ComponentConfigurationDTO.ACTIVE );
        SimpleComponent scSNV = SimpleComponent.INSTANCE;
        TestCase.assertEquals( pidSNV, scSNV.getProperty( TARGETED_PID ) );
       
        Bundle bSNVL = installBundle( descriptorFile, COMPONENT_PACKAGE, "simplecomponent2", "0.0.12", "bundleLocation" );
        bSNVL.start();
        findComponentConfigurationsByName( bSNVL, pid, ComponentConfigurationDTO.ACTIVE );

        SimpleComponent scSNVL = SimpleComponent.INSTANCE;
        TestCase.assertEquals( pidSNVL, scSNVL.getProperty( TARGETED_PID ) );
       
        //remove configurations to check that the components now use the less specific configurations.
       
        configSNVL.delete();
        delay();
        findComponentConfigurationsByName( bSNVL, pid, ComponentConfigurationDTO.ACTIVE );
        TestCase.assertEquals( pidSNV, scSNVL.getProperty( TARGETED_PID ) );
       
        configSNV.delete();
View Full Code Here

        final String pid2 = "test.pid.2";

        configure( pid1 );
        configure( pid2 );

        final Configuration config1 = getConfiguration( pid1 );
        TestCase.assertEquals( pid1, config1.getPid() );
        TestCase.assertNull( config1.getBundleLocation() );

        final Configuration config2 = getConfiguration( pid2 );
        TestCase.assertEquals( pid2, config2.getPid() );
        TestCase.assertNull( config2.getBundleLocation() );

        // multi-pid with array
        bundle = installBundle( pid1 + "," + pid2 );
        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", 2, tester.numManagedServiceUpdatedCalls );

        TestCase.assertEquals( bundle.getLocation(), config1.getBundleLocation() );
        TestCase.assertEquals( bundle.getLocation(), config2.getBundleLocation() );

        bundle.uninstall();
        bundle = null;

        delay();

        TestCase.assertNull( config1.getBundleLocation() );
        TestCase.assertNull( config2.getBundleLocation() );

        // remove the configuration for good
        deleteConfig( pid1 );
        deleteConfig( pid2 );
    }
View Full Code Here

        String pid2 = "test.pid.2";

        configure( pid1 );
        configure( pid2 );

        final Configuration config1 = getConfiguration( pid1 );
        TestCase.assertEquals( pid1, config1.getPid() );
        TestCase.assertNull( config1.getBundleLocation() );

        final Configuration config2 = getConfiguration( pid2 );
        TestCase.assertEquals( pid2, config2.getPid() );
        TestCase.assertNull( config2.getBundleLocation() );

        // multi-pid with collection
        bundle = installBundle( pid1 + ";" + pid2 );
        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", 2, tester.numManagedServiceUpdatedCalls );

        TestCase.assertEquals( bundle.getLocation(), config1.getBundleLocation() );
        TestCase.assertEquals( bundle.getLocation(), config2.getBundleLocation() );

        bundle.uninstall();
        bundle = null;

        delay();

        TestCase.assertNull( config1.getBundleLocation() );
        TestCase.assertNull( config2.getBundleLocation() );

        // remove the configuration for good
        deleteConfig( pid1 );
        deleteConfig( pid2 );
    }
View Full Code Here

        configure( pid );
        delay();
        configListener.assertEvents( ConfigurationEvent.CM_UPDATED, 1 );

        // ensure configuration is unbound
        final Configuration config = getConfiguration( pid );
        TestCase.assertNull( config.getBundleLocation() );

        bundle = installBundle( pid );
        bundle.start();
        delay();

        // ensure no configuration bound before start
        configListener.assertEvents( ConfigurationEvent.CM_LOCATION_CHANGED, 1 );

        // uninstall the bundle, dynamic location changed
        bundle.uninstall();
        bundle = null;
        delay();
        configListener.assertEvents( ConfigurationEvent.CM_LOCATION_CHANGED, 1 );

        // change the location
        config.setBundleLocation( "some_location_1" );
        delay();
        configListener.assertEvents( ConfigurationEvent.CM_LOCATION_CHANGED, 1 );

        // change the location
        config.setBundleLocation( "some_location_2" );
        delay();
        configListener.assertEvents( ConfigurationEvent.CM_LOCATION_CHANGED, 1 );

        // remove configuration, delete event
        config.delete();
        delay();
        configListener.assertEvents( ConfigurationEvent.CM_DELETED, 1 );

        // no more events
        delay();
View Full Code Here

        bundle = installBundle( ignoredPid );
        bundle.start();
        delay();

        // ensure config1 unbound
        Configuration config1 = getConfiguration( pid1 );
        TestCase.assertNull( config1.getBundleLocation() );

        ServiceReference<ConfigurationAdmin> sr = bundle.getBundleContext().getServiceReference( ConfigurationAdmin.class );
        ConfigurationAdmin bundleCa = bundle.getBundleContext().getService( sr );

        // ensure dynamic binding
        Configuration bundleConfig1 = bundleCa.getConfiguration( pid1 );
        TestCase.assertEquals( bundle.getLocation(), bundleConfig1.getBundleLocation() );
        delay();
        configListener.assertEvents( ConfigurationEvent.CM_LOCATION_CHANGED, 1 );

        // create config2; ensure dynamic binding
        Configuration bundleConfig2 = bundleCa.getConfiguration( pid2 );
        TestCase.assertNull(bundleConfig2.getProperties());
        TestCase.assertEquals( bundle.getLocation(), bundleConfig2.getBundleLocation() );
        bundleConfig2.update( new Hashtable<String, String>()
        {
            {
                put( "key", "value" );
            }
        } );

        // uninstall the bundle, 2 dynamic locations changed
        bundle.uninstall();
        bundle = null;
        delay();
        configListener.assertEvents( ConfigurationEvent.CM_LOCATION_CHANGED, 2 );

        bundleConfig1 = getConfiguration( pid1 );
        TestCase.assertNull( bundleConfig1.getBundleLocation() );

        bundleConfig2 = getConfiguration( pid2 );
        TestCase.assertNull(bundleConfig2.getBundleLocation());

        bundleConfig1.delete();
        bundleConfig2.delete();
    }
View Full Code Here

        bundle = installBundle( ignoredPid );
        bundle.start();
        delay();

        // ensure config1 unbound
        Configuration config1 = getConfiguration( pid1 );
        TestCase.assertNull( config1.getBundleLocation() );

        ServiceReference<ConfigurationAdmin> sr = bundle.getBundleContext().getServiceReference( ConfigurationAdmin.class );
        ConfigurationAdmin bundleCa = bundle.getBundleContext().getService( sr );

        // ensure dynamic binding
        Configuration bundleConfig1 = bundleCa.getConfiguration( pid1 );
        TestCase.assertEquals( bundle.getLocation(), bundleConfig1.getBundleLocation() );
        delay();
        configListener.assertEvents( ConfigurationEvent.CM_LOCATION_CHANGED, 1 );

        // create config2; ensure dynamic binding
        Configuration bundleConfig2 = bundleCa.createFactoryConfiguration( factoryPid2 );
        pid2 = bundleConfig2.getPid();
        TestCase.assertNull(bundleConfig2.getProperties());
        TestCase.assertEquals( bundle.getLocation(), bundleConfig2.getBundleLocation() );
        bundleConfig2.update( new Hashtable<String, String>()
        {
            {
                put( "key", "value" );
            }
        } );

        // uninstall the bundle, 2 dynamic locations changed
        bundle.uninstall();
        bundle = null;
        delay();
        configListener.assertEvents( ConfigurationEvent.CM_LOCATION_CHANGED, 2 );

        bundleConfig1 = getConfiguration( pid1 );
        TestCase.assertNull( bundleConfig1.getBundleLocation() );

        bundleConfig2 = getConfiguration( pid2 );
        TestCase.assertNull(bundleConfig2.getBundleLocation());

        bundleConfig1.delete();
        bundleConfig2.delete();
    }
View Full Code Here

        final TestListener testListener = new TestListener();
        final ServiceRegistration listener = this.bundleContext.registerService( ConfigurationListener.class.getName(),
            testListener, null );
        int eventCount = 0;

        Configuration config = configure( pid, null, false );
        try
        {
            delay();
            testListener.assertNoEvent();

            config.update( new Hashtable<String, Object>()
            {
                {
                    put( "x", "x" );
                }
            } );
            delay();
            testListener.assertEvent( ConfigurationEvent.CM_UPDATED, pid, null, true, ++eventCount );

            config.update( new Hashtable<String, Object>()
            {
                {
                    put( "x", "x" );
                }
            } );
            delay();
            testListener.assertEvent( ConfigurationEvent.CM_UPDATED, pid, null, true, ++eventCount );

            config.setBundleLocation( "new_Location" );
            delay();
            testListener.assertEvent( ConfigurationEvent.CM_LOCATION_CHANGED, pid, null, true, ++eventCount );

            config.update();
            testListener.assertNoEvent();

            config.delete();
            config = null;
            delay();
            testListener.assertEvent( ConfigurationEvent.CM_DELETED, pid, null, true, ++eventCount );
        }
        finally
        {
            if ( config != null )
            {
                try
                {
                    config.delete();
                }
                catch ( IOException ioe )
                {
                    // ignore
                }
View Full Code Here

    @Test
    public void test_sync_listener() throws IOException
    {
        final String pid = "test_listener";
        Configuration config = configure( pid, null, false );

        // Synchronous listener expecting synchronous events being
        // registered as a SynchronousConfigurationListener
        final TestListener testListener = new SynchronousTestListener();
        final ServiceRegistration listener = this.bundleContext.registerService(
            SynchronousConfigurationListener.class.getName(), testListener, null );

        // Synchronous listener expecting asynchronous events being
        // registered as a regular ConfigurationListener
        final TestListener testListenerAsync = new SynchronousTestListener();
        final ServiceRegistration listenerAsync = this.bundleContext.registerService(
            ConfigurationListener.class.getName(), testListenerAsync, null );

        int eventCount = 0;
        int eventCountAsync = 0;

        try
        {
            delay();
            testListener.assertNoEvent();
            testListenerAsync.assertNoEvent();

            config.update( new Hashtable<String, Object>()
            {
                {
                    put( "x", "x" );
                }
            } );
            delay();
            testListener.assertEvent( ConfigurationEvent.CM_UPDATED, pid, null, false, ++eventCount );
            testListenerAsync.assertEvent( ConfigurationEvent.CM_UPDATED, pid, null, true, ++eventCountAsync );

            config.update( new Hashtable<String, Object>()
            {
                {
                    put( "x", "x" );
                }
            } );
            delay();
            testListener.assertEvent( ConfigurationEvent.CM_UPDATED, pid, null, false, ++eventCount );
            testListenerAsync.assertEvent( ConfigurationEvent.CM_UPDATED, pid, null, true, ++eventCountAsync );

            config.setBundleLocation( "new_Location" );
            delay();
            testListener.assertEvent( ConfigurationEvent.CM_LOCATION_CHANGED, pid, null, false, ++eventCount );
            testListenerAsync.assertEvent( ConfigurationEvent.CM_LOCATION_CHANGED, pid, null, true, ++eventCountAsync );

            config.update();
            testListener.assertNoEvent();
            testListenerAsync.assertNoEvent();

            config.delete();
            config = null;
            delay();
            testListener.assertEvent( ConfigurationEvent.CM_DELETED, pid, null, false, ++eventCount );
            testListenerAsync.assertEvent( ConfigurationEvent.CM_DELETED, pid, null, true, ++eventCountAsync );
        }
        finally
        {
            if ( config != null )
            {
                try
                {
                    config.delete();
                }
                catch ( IOException ioe )
                {
                    // ignore
                }
View Full Code Here

    public static Configuration getConfiguration(final ConfigurationAdmin ca,
            final String factoryPid,
            final String configPid,
            final boolean createIfNeeded)
                    throws IOException, InvalidSyntaxException {
        Configuration result = null;

        if (factoryPid == null) {
            if (createIfNeeded) {
                result = ca.getConfiguration(configPid, null);
            } else {
                String filter = "(" + Constants.SERVICE_PID + "=" + encode(configPid)
                        + ")";
                Configuration[] configs = ca.listConfigurations(filter);
                if (configs != null && configs.length > 0) {
                    result = configs[0];
                }
            }
        } else {
            Configuration configs[] = null;
            if ( configPid != null ) {
                configs = ca.listConfigurations("(&("
                        + ConfigurationAdmin.SERVICE_FACTORYPID + "=" + encode(factoryPid)
                        + ")(" + Constants.SERVICE_PID + "=" + encode(configPid)
                        + "))");
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.