Package org.apache.felix.scr.integration.components

Examples of org.apache.felix.scr.integration.components.SimpleComponent


        final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );

        String name ="test_required_single_static";
        ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(name, ComponentConfigurationDTO.ACTIVE);

        final SimpleComponent comp10 = SimpleComponent.INSTANCE;
        TestCase.assertNotNull( comp10 );
        TestCase.assertEquals( srv1, comp10.m_singleRef );
        TestCase.assertTrue( comp10.m_multiRef.isEmpty() );

        srv1.drop();
        delay(); // async reactivate

        findComponentConfigurationByName(name, ComponentConfigurationDTO.UNSATISFIED_REFERENCE);
        final SimpleComponent comp11 = SimpleComponent.INSTANCE;
        TestCase.assertNull( comp11 );

        final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
        delay(); // async binding

        findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);

        final SimpleComponent comp12 = SimpleComponent.INSTANCE;
        TestCase.assertNotSame( comp10, comp12 );
        TestCase.assertEquals( srv2, comp12.m_singleRef );
        TestCase.assertTrue( comp12.m_multiRef.isEmpty() );

        disableAndCheck(cc);
        delay(); // async disabling

        final SimpleServiceImpl srv3 = SimpleServiceImpl.create( bundleContext, "srv3" );

        // enable component with two services available, expect srv2 bind
        // async enabling
        enableAndCheck(cc.description);
        delay();

        findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);

        final SimpleComponent comp20 = SimpleComponent.INSTANCE;
        TestCase.assertNotNull( comp20 );
        TestCase.assertNotSame( comp10, comp20 );
        TestCase.assertEquals( srv2, comp20.m_singleRef );
        TestCase.assertTrue( comp20.m_multiRef.isEmpty() );

        // drop srv2, expect rebind to srv3
        srv2.drop();
        delay(); // async reactivate

        findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);

        final SimpleComponent comp21 = SimpleComponent.INSTANCE;
        TestCase.assertNotSame( comp20, comp21 );
        TestCase.assertEquals( srv3, comp21.m_singleRef );
        TestCase.assertTrue( comp21.m_multiRef.isEmpty() );

        // create srv4, expect no rebind
        final SimpleServiceImpl srv4 = SimpleServiceImpl.create( bundleContext, "srv4" );
        delay();

        findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);

        final SimpleComponent comp22 = SimpleComponent.INSTANCE;
        TestCase.assertNotSame( comp20, comp22 );
        TestCase.assertSame( comp21, comp22 );
        TestCase.assertEquals( srv3, comp22.m_singleRef );
        TestCase.assertTrue( comp22.m_multiRef.isEmpty() );

        // drop srv4 again, expect no rebind
        srv4.drop();
        delay();

        findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);

        final SimpleComponent comp23 = SimpleComponent.INSTANCE;
        TestCase.assertNotSame( comp20, comp23 );
        TestCase.assertSame( comp21, comp23 );
        TestCase.assertSame( comp22, comp23 );
        TestCase.assertEquals( srv3, comp23.m_singleRef );
        TestCase.assertTrue( comp23.m_multiRef.isEmpty() );

        // "reset"
        disableAndCheck(cc);
        srv3.drop();
        delay();

        // two services with service ranking (srv6 > srv5)
        final SimpleServiceImpl srv5 = SimpleServiceImpl.create( bundleContext, "srv5", 10 );
        final SimpleServiceImpl srv6 = SimpleServiceImpl.create( bundleContext, "srv6", 20 );

        enableAndCheck(cc.description);
        delay();

        findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);

        final SimpleComponent comp30 = SimpleComponent.INSTANCE;
        TestCase.assertNotSame( comp23, comp30 );
        TestCase.assertEquals( srv6, comp30.m_singleRef );
        TestCase.assertTrue( comp30.m_multiRef.isEmpty() );

        // another service with higher ranking -- rebind !
        final SimpleServiceImpl srv7 = SimpleServiceImpl.create( bundleContext, "srv7", 30 );
        delay();

        findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);

        final SimpleComponent comp31 = SimpleComponent.INSTANCE;
        TestCase.assertNotSame( comp30, comp31 );
        TestCase.assertEquals( srv7, comp31.m_singleRef );
        TestCase.assertTrue( comp31.m_multiRef.isEmpty() );

        // srv6 goes, no rebind to srv7
        srv6.drop();
        delay();

        findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);

        final SimpleComponent comp32 = SimpleComponent.INSTANCE;
        TestCase.assertNotSame( comp30, comp32 );
        TestCase.assertSame( comp31, comp32 );
        TestCase.assertEquals( srv7, comp32.m_singleRef );
        TestCase.assertTrue( comp32.m_multiRef.isEmpty() );
    }
View Full Code Here


        final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );

        String name ="test_optional_multiple_static";
        ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(name, ComponentConfigurationDTO.ACTIVE);

        final SimpleComponent comp10 = SimpleComponent.INSTANCE;
        TestCase.assertNotNull( comp10 );
        TestCase.assertNull( comp10.m_singleRef );
        TestCase.assertTrue( comp10.m_multiRef.contains( srv1 ) );

        srv1.drop();
        delay(); // async reactivate

        findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);

        final SimpleComponent comp11 = SimpleComponent.INSTANCE;
        TestCase.assertNotSame( comp10, comp11 );
        TestCase.assertNull( comp11.m_singleRef );
        TestCase.assertTrue( comp11.m_multiRef.isEmpty() );

        final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
        delay(); // async binding

        findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);

        final SimpleComponent comp12 = SimpleComponent.INSTANCE;
        TestCase.assertNotSame( comp10, comp12 );
        TestCase.assertNotSame( comp11, comp12 );
        TestCase.assertNull( comp12.m_singleRef );
        TestCase.assertTrue( comp12.m_multiRef.contains( srv2 ) );

        disableAndCheck(cc);
        delay(); // async disabling

        final SimpleServiceImpl srv3 = SimpleServiceImpl.create( bundleContext, "srv3" );

        // enable component with two services available, expect both bind
        // async enabling
        enableAndCheck(cc.description);
        delay();

        findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);

        final SimpleComponent comp20 = SimpleComponent.INSTANCE;
        TestCase.assertNotNull( comp20 );
        TestCase.assertNotSame( comp10, comp20 );
        TestCase.assertNotSame( comp11, comp20 );
        TestCase.assertNotSame( comp12, comp20 );
        TestCase.assertNull( comp20.m_singleRef );
        TestCase.assertTrue( comp20.m_multiRef.contains( srv2 ) );
        TestCase.assertTrue( comp20.m_multiRef.contains( srv3 ) );

        srv2.drop();
        delay(); // async reactivate

        findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);

        final SimpleComponent comp21 = SimpleComponent.INSTANCE;
        TestCase.assertNotSame( comp20, comp21 );
        TestCase.assertNull( comp21.m_singleRef );
        TestCase.assertFalse( comp21.m_multiRef.contains( srv2 ) );
        TestCase.assertTrue( comp21.m_multiRef.contains( srv3 ) );

        // create srv4, expect greedy bind (static case)
        final SimpleServiceImpl srv4 = SimpleServiceImpl.create( bundleContext, "srv4" );
        delay();

        findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);

        final SimpleComponent comp22 = SimpleComponent.INSTANCE;
        TestCase.assertNotSame( comp20, comp22 );
        TestCase.assertNotSame( comp21, comp22 );
        TestCase.assertNull( comp22.m_singleRef );
        TestCase.assertFalse( comp22.m_multiRef.contains( srv2 ) );
        TestCase.assertTrue( comp22.m_multiRef.contains( srv3 ) );
        TestCase.assertTrue( comp22.m_multiRef.contains( srv4 ) );

        // drop srv4 again, expect rebind
        srv4.drop();
        delay();

        findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);

        final SimpleComponent comp23 = SimpleComponent.INSTANCE;
        TestCase.assertNotSame( comp20, comp23 );
        TestCase.assertNotSame( comp21, comp23 );
        TestCase.assertNotSame( comp22, comp23 );
        TestCase.assertNull( comp23.m_singleRef );
        TestCase.assertFalse( comp23.m_multiRef.contains( srv2 ) );
        TestCase.assertTrue( comp23.m_multiRef.contains( srv3 ) );
        TestCase.assertFalse( comp23.m_multiRef.contains( srv4 ) );

        // "reset"
        disableAndCheck(cc);
        srv3.drop();
        delay();

        // two services with service ranking (srv6 > srv5)
        final SimpleServiceImpl srv5 = SimpleServiceImpl.create( bundleContext, "srv5", 10 );
        final SimpleServiceImpl srv6 = SimpleServiceImpl.create( bundleContext, "srv6", 20 );

        enableAndCheck(cc.description);
        delay();

        findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);

        final SimpleComponent comp30 = SimpleComponent.INSTANCE;
        TestCase.assertNotSame( comp23, comp30 );
        TestCase.assertNull( comp30.m_singleRef );
        TestCase.assertTrue( comp30.m_multiRef.contains( srv5 ) );
        TestCase.assertTrue( comp30.m_multiRef.contains( srv6 ) );

        // another service with higher ranking -- greedy rebind !
        final SimpleServiceImpl srv7 = SimpleServiceImpl.create( bundleContext, "srv7", 30 );
        delay();

        findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);

        final SimpleComponent comp31 = SimpleComponent.INSTANCE;
        TestCase.assertNotSame( comp30, comp31 );
        TestCase.assertNull( comp31.m_singleRef );
        TestCase.assertTrue( comp31.m_multiRef.contains( srv5 ) );
        TestCase.assertTrue( comp31.m_multiRef.contains( srv6 ) );
        TestCase.assertTrue( comp31.m_multiRef.contains( srv7 ) );

        // srv6 goes, rebind to srv7
        srv6.drop();
        delay();

        findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);

        final SimpleComponent comp32 = SimpleComponent.INSTANCE;
        TestCase.assertNotSame( comp30, comp32 );
        TestCase.assertNotSame( comp31, comp32 );
        TestCase.assertNull( comp32.m_singleRef );
        TestCase.assertTrue( comp32.m_multiRef.contains( srv5 ) );
        TestCase.assertFalse( comp32.m_multiRef.contains( srv6 ) );
View Full Code Here

        final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );

        String name ="test_required_multiple_static";
        ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(name, ComponentConfigurationDTO.ACTIVE);

        final SimpleComponent comp10 = SimpleComponent.INSTANCE;
        TestCase.assertNotNull( comp10 );
        TestCase.assertNull( comp10.m_singleRef );
        TestCase.assertTrue( comp10.m_multiRef.contains( srv1 ) );

        srv1.drop();
        delay(); // async reactivate

        findComponentConfigurationByName(name, ComponentConfigurationDTO.UNSATISFIED_REFERENCE);
        final SimpleComponent comp11 = SimpleComponent.INSTANCE;
        TestCase.assertNull( comp11 );

        final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
        delay(); // async binding

        findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);

        final SimpleComponent comp12 = SimpleComponent.INSTANCE;
        TestCase.assertNotSame( comp10, comp12 );
        TestCase.assertNull( comp12.m_singleRef );
        TestCase.assertTrue( comp12.m_multiRef.contains( srv2 ) );

        disableAndCheck(cc);
        delay(); // async disabling

        final SimpleServiceImpl srv3 = SimpleServiceImpl.create( bundleContext, "srv3" );

        // enable component with two services available, expect both bind
        // async enabling
        enableAndCheck(cc.description);
        delay();

        findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);

        final SimpleComponent comp20 = SimpleComponent.INSTANCE;
        TestCase.assertNotNull( comp20 );
        TestCase.assertNotSame( comp10, comp20 );
        TestCase.assertNotSame( comp12, comp20 );
        TestCase.assertNull( comp20.m_singleRef );
        TestCase.assertTrue( comp20.m_multiRef.contains( srv2 ) );
        TestCase.assertTrue( comp20.m_multiRef.contains( srv3 ) );

        srv2.drop();
        delay(); // async reactivate

        findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);

        final SimpleComponent comp21 = SimpleComponent.INSTANCE;
        TestCase.assertNotSame( comp20, comp21 );
        TestCase.assertNull( comp21.m_singleRef );
        TestCase.assertFalse( comp21.m_multiRef.contains( srv2 ) );
        TestCase.assertTrue( comp21.m_multiRef.contains( srv3 ) );

        // create srv4, expect greedy bind
        final SimpleServiceImpl srv4 = SimpleServiceImpl.create( bundleContext, "srv4" );
        delay();

        findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);

        final SimpleComponent comp22 = SimpleComponent.INSTANCE;
        TestCase.assertNotSame( comp20, comp22 );
        TestCase.assertNotSame( comp21, comp22 );
        TestCase.assertNull( comp22.m_singleRef );
        TestCase.assertFalse( comp22.m_multiRef.contains( srv2 ) );
        TestCase.assertTrue( comp22.m_multiRef.contains( srv3 ) );
        TestCase.assertTrue( comp22.m_multiRef.contains( srv4 ) );

        // drop srv4 again, expect greedy rebind
        srv4.drop();
        delay();

        findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);

        final SimpleComponent comp23 = SimpleComponent.INSTANCE;
        TestCase.assertNotSame( comp20, comp23 );
        TestCase.assertNotSame( comp21, comp23 );
        TestCase.assertNotSame( comp22, comp23 );
        TestCase.assertNull( comp23.m_singleRef );
        TestCase.assertFalse( comp23.m_multiRef.contains( srv2 ) );
        TestCase.assertTrue( comp23.m_multiRef.contains( srv3 ) );
        TestCase.assertFalse( comp23.m_multiRef.contains( srv4 ) );

        // "reset"
        disableAndCheck(cc);
        srv3.drop();
        delay();

        // two services with service ranking (srv6 > srv5)
        final SimpleServiceImpl srv5 = SimpleServiceImpl.create( bundleContext, "srv5", 10 );
        final SimpleServiceImpl srv6 = SimpleServiceImpl.create( bundleContext, "srv6", 20 );

        enableAndCheck(cc.description);
        delay();

        findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);

        final SimpleComponent comp30 = SimpleComponent.INSTANCE;
        TestCase.assertNotSame( comp23, comp30 );
        TestCase.assertNull( comp30.m_singleRef );
        TestCase.assertTrue( comp30.m_multiRef.contains( srv5 ) );
        TestCase.assertTrue( comp30.m_multiRef.contains( srv6 ) );

        // another service with higher ranking -- greedy rebind !
        final SimpleServiceImpl srv7 = SimpleServiceImpl.create( bundleContext, "srv7", 30 );
        delay();

        findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);

        final SimpleComponent comp31 = SimpleComponent.INSTANCE;
        TestCase.assertNotSame( comp30, comp31 );
        TestCase.assertNull( comp31.m_singleRef );
        TestCase.assertTrue( comp31.m_multiRef.contains( srv5 ) );
        TestCase.assertTrue( comp31.m_multiRef.contains( srv6 ) );
        TestCase.assertTrue( comp31.m_multiRef.contains( srv7 ) );

        // srv6 goes, rebind to srv7
        srv6.drop();
        delay();

        findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);

        final SimpleComponent comp32 = SimpleComponent.INSTANCE;
        TestCase.assertNotSame( comp30, comp32 );
        TestCase.assertNotSame( comp31, comp32 );
        TestCase.assertNull( comp32.m_singleRef );
        TestCase.assertTrue( comp32.m_multiRef.contains( srv5 ) );
        TestCase.assertFalse( comp32.m_multiRef.contains( srv6 ) );
View Full Code Here

    public void test_SimpleComponent_configuration_optional() throws Exception
    {
        final String pid = "SimpleComponent.configuration.optional";
        ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(pid, ComponentConfigurationDTO.ACTIVE);

        final SimpleComponent firstInstance = SimpleComponent.INSTANCE;
        TestCase.assertNotNull( firstInstance );
        TestCase.assertNull( firstInstance.getProperty( PROP_NAME ) );

        configure( pid );
        delay();

        final SimpleComponent secondInstance = SimpleComponent.INSTANCE;
        findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
        TestCase.assertNotNull( secondInstance );
        TestCase.assertEquals( PROP_NAME, secondInstance.getProperty( PROP_NAME ) );

        deleteConfig( pid );
        delay();

        final SimpleComponent thirdInstance = SimpleComponent.INSTANCE;
        findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
        TestCase.assertNotNull( thirdInstance );
        TestCase.assertNull( thirdInstance.getProperty( PROP_NAME ) );

        TestCase.assertNotSame( "Expect new instance object after reconfiguration", firstInstance, secondInstance );
        TestCase.assertNotSame( "Expect new instance object after configuration deletion (1)", firstInstance,
            thirdInstance );
        TestCase.assertNotSame( "Expect new instance object after configuration deletion (2)", secondInstance,
View Full Code Here

        TestCase.assertNotNull( SimpleComponent.INSTANCE );
        TestCase.assertNull( SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
        TestCase.assertEquals(pidWithout, SimpleComponent.INSTANCE.getProperty(Constants.SERVICE_PID));

        final SimpleComponent instance = SimpleComponent.INSTANCE;

        configure( pid );
        delay();

        findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
View Full Code Here

            findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
            TestCase.assertNotNull( SimpleComponent.INSTANCE );
            TestCase.assertEquals( PROP_NAME, SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
            TestCase.assertEquals( pid, SimpleComponent.INSTANCE.getProperty( Constants.SERVICE_PID ) );

            final SimpleComponent instance = SimpleComponent.INSTANCE;

            configure( pid );
            delay();

            // same instance after reconfiguration
View Full Code Here

            findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
            TestCase.assertNotNull( SimpleComponent.INSTANCE );
            TestCase.assertEquals( PROP_NAME, SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
            TestCase.assertEquals( pid, SimpleComponent.INSTANCE.getProperty( Constants.SERVICE_PID ) );

            final SimpleComponent instance = SimpleComponent.INSTANCE;

            configure( pid );
            delay();

            //remove higher ranked service
View Full Code Here

            // optional ref missing --> component active
            ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(pid, ComponentConfigurationDTO.ACTIVE);

            TestCase.assertNotNull( SimpleComponent.INSTANCE );
            final SimpleComponent instance = SimpleComponent.INSTANCE;

            // dynamically configure without the correct target
            configure( pid );
            delay();
View Full Code Here

    {
        final String pid = "ServiceComponent";

        // one single component exists without configuration
    getDisabledConfigurationAndEnable(pid, ComponentConfigurationDTO.ACTIVE);
        final SimpleComponent instance = SimpleComponent.INSTANCE;
        TestCase.assertNotNull( instance );

        // assert component properties (all !)
        TestCase.assertEquals( "required", instance.getProperty( "prop.public" ) );
        TestCase.assertEquals( "private", instance.getProperty( ".prop.private" ) );

        // get the service
        ServiceReference reference = bundleContext.getServiceReference( "java.lang.Object" );
        TestCase.assertNotNull( reference );
        try
View Full Code Here

        TestCase.assertNull( SimpleComponent.INSTANCE );

        component.enable();
        delay();

        final SimpleComponent firstInstance = SimpleComponent.INSTANCE;
        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
        TestCase.assertNotNull( firstInstance );
        TestCase.assertNull( firstInstance.getProperty( PROP_NAME ) );

        configure( pid );
        delay();

        final SimpleComponent secondInstance = SimpleComponent.INSTANCE;
        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
        TestCase.assertNotNull( secondInstance );
        TestCase.assertEquals( PROP_NAME, secondInstance.getProperty( PROP_NAME ) );

        deleteConfig( pid );
        delay();

        final SimpleComponent thirdInstance = SimpleComponent.INSTANCE;
        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
        TestCase.assertNotNull( thirdInstance );
        TestCase.assertNull( thirdInstance.getProperty( PROP_NAME ) );

        TestCase.assertNotSame( "Expect new instance object after reconfiguration", firstInstance, secondInstance );
        TestCase.assertNotSame( "Expect new instance object after configuration deletion (1)", firstInstance,
            thirdInstance );
        TestCase.assertNotSame( "Expect new instance object after configuration deletion (2)", secondInstance,
View Full Code Here

TOP

Related Classes of org.apache.felix.scr.integration.components.SimpleComponent

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.