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

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


        // async enabling
        component.enable();
        delay();

        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
        final SimpleComponent comp10 = SimpleComponent.INSTANCE;
        TestCase.assertNotNull( comp10 );
        TestCase.assertNull( comp10.m_singleRef );
        TestCase.assertTrue( comp10.m_multiRef.contains( srv1 ) );
        TestCase.assertEquals( 1, comp10.m_multiRefBind );
        TestCase.assertEquals( 0, comp10.m_multiRefUnbind);

        // update a service property
        srv1.update( "srv1-modified" );

        // no changes in bindings expected
        TestCase.assertNull( comp10.m_singleRef );
        TestCase.assertTrue( comp10.m_multiRef.contains( srv1 ) );
        TestCase.assertEquals( 1, comp10.m_multiRefBind );
        TestCase.assertEquals( 0, comp10.m_multiRefUnbind);

        // set target to not match any more
        srv1.setFilterProperty( "don't match" );
        delay(); // async reactivation (for unbind)

        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
        final SimpleComponent comp11 = SimpleComponent.INSTANCE;
        TestCase.assertNotSame( comp10, comp11 );
        TestCase.assertNull( comp10.m_singleRef );
        TestCase.assertFalse( comp10.m_multiRef.contains( srv1 ) );
        TestCase.assertEquals( 1, comp10.m_multiRefBind );
        TestCase.assertEquals( 1, comp10.m_multiRefUnbind);
        TestCase.assertNull( comp11.m_singleRef );
        TestCase.assertFalse( comp11.m_multiRef.contains( srv1 ) );
        TestCase.assertEquals( 0, comp11.m_multiRefBind );
        TestCase.assertEquals( 0, comp11.m_multiRefUnbind);

        final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
        delay(); // async binding (not expected for an optional static ref)

        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
        final SimpleComponent comp12 = SimpleComponent.INSTANCE;
        TestCase.assertNotSame( comp10, comp12 );
        TestCase.assertSame( comp11, comp12 );
        TestCase.assertNull( comp12.m_singleRef );
        TestCase.assertFalse( comp12.m_multiRef.contains( srv1 ) );
        TestCase.assertFalse( comp12.m_multiRef.contains( srv2 ) );
        TestCase.assertEquals( 0, comp12.m_multiRefBind );
        TestCase.assertEquals( 0, comp12.m_multiRefUnbind);

        // make srv1 match again, expect not changes in bindings
        srv1.setFilterProperty( "match" );
        TestCase.assertNull( comp12.m_singleRef );
        TestCase.assertFalse( comp12.m_multiRef.contains( srv1 ) );
        TestCase.assertFalse( comp12.m_multiRef.contains( srv2 ) );
        TestCase.assertEquals( 0, comp12.m_multiRefBind );
        TestCase.assertEquals( 0, comp12.m_multiRefUnbind);

        // make srv2 to not match, expect binding to srv1
        srv2.setFilterProperty( "don't match" );
        delay(); // allow reactivation delay (for unbind/bind)

        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
        final SimpleComponent comp13 = SimpleComponent.INSTANCE;
        TestCase.assertNotSame( comp10, comp13 );
        TestCase.assertSame( comp11, comp13 );
        TestCase.assertSame( comp12, comp13 );
        TestCase.assertNull( comp13.m_singleRef );
        TestCase.assertFalse( comp13.m_multiRef.contains( srv1 ) );
View Full Code Here


        // async enabling
        component.enable();
        delay();

        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
        final SimpleComponent comp10 = SimpleComponent.INSTANCE;
        TestCase.assertNotNull( comp10 );
        TestCase.assertNull( comp10.m_singleRef );
        TestCase.assertTrue( comp10.m_multiRef.contains( srv1 ) );
        TestCase.assertEquals( 1, comp10.m_multiRefBind );
        TestCase.assertEquals( 0, comp10.m_multiRefUnbind);

        // update a service property
        srv1.update( "srv1-modified" );

        // no changes in bindings expected
        TestCase.assertNull( comp10.m_singleRef );
        TestCase.assertTrue( comp10.m_multiRef.contains( srv1 ) );
        TestCase.assertEquals( 1, comp10.m_multiRefBind );
        TestCase.assertEquals( 0, comp10.m_multiRefUnbind);

        // set target to not match any more
        srv1.setFilterProperty( "don't match" );

        TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
        final SimpleComponent comp11 = SimpleComponent.INSTANCE;
        TestCase.assertNull( comp11 );
        TestCase.assertNull( comp10.m_singleRef );
        TestCase.assertFalse( comp10.m_multiRef.contains( srv1 ) );
        TestCase.assertEquals( 1, comp10.m_multiRefBind );
        TestCase.assertEquals( 1, comp10.m_multiRefUnbind);

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

        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
        final SimpleComponent comp12 = SimpleComponent.INSTANCE;
        TestCase.assertNotSame( comp10, comp12 );
        TestCase.assertNull( comp12.m_singleRef );
        TestCase.assertFalse( comp12.m_multiRef.contains( srv1 ) );
        TestCase.assertTrue( comp12.m_multiRef.contains( srv2 ) );
        TestCase.assertEquals( 1, comp12.m_multiRefBind );
        TestCase.assertEquals( 0, comp12.m_multiRefUnbind);

        // make srv1 match again, expect not changes in bindings
        srv1.setFilterProperty( "match" );
        TestCase.assertNull( comp12.m_singleRef );
        TestCase.assertFalse( comp12.m_multiRef.contains( srv1 ) );
        TestCase.assertTrue( comp12.m_multiRef.contains( srv2 ) );
        TestCase.assertEquals( 1, comp12.m_multiRefBind );
        TestCase.assertEquals( 0, comp12.m_multiRefUnbind);

        // make srv2 to not match, expect binding to srv1
        srv2.setFilterProperty( "don't match" );
        delay(); // allow reactivation/rebinding

        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
        final SimpleComponent comp13 = SimpleComponent.INSTANCE;
        TestCase.assertNotSame( comp10, comp13 );
        TestCase.assertNotSame( comp11, comp13 );
        TestCase.assertNotSame( comp12, comp13 );
        TestCase.assertNull( comp13.m_singleRef );
        TestCase.assertTrue( comp13.m_multiRef.contains( srv1 ) );
View Full Code Here

        // async enabling
        component.enable();
        delay();

        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
        final SimpleComponent comp10 = SimpleComponent.INSTANCE;
        TestCase.assertNotNull( comp10 );
        TestCase.assertEquals( srv1, comp10.m_singleRef );
        TestCase.assertTrue( comp10.m_multiRef.isEmpty() );
        TestCase.assertEquals( 1, comp10.m_singleRefBind );
        TestCase.assertEquals( 0, comp10.m_singleRefUnbind);

        // update configuration to target srv2
        theConfig.put("ref.target", "(value=srv2)");
        configure( pid );

        delay();
        // should bind to srv2
        SimpleComponent comp20;
        if ( dynamic )
        {
            TestCase.assertEquals( 1, comp10.m_modified );
            comp20 = comp10;
            TestCase.assertEquals( 2, comp20.m_singleRefBind );
View Full Code Here

        // async enabling
        component.enable();
        delay();

        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
        final SimpleComponent comp10 = SimpleComponent.INSTANCE;
        TestCase.assertNotNull( comp10 );
        TestCase.assertEquals( 1, comp10.m_multiRef.size() );
        TestCase.assertEquals( srv1, comp10.m_multiRef.iterator().next() );
        TestCase.assertEquals( 1, comp10.m_multiRefBind );
        TestCase.assertEquals( 0, comp10.m_multiRefUnbind);

        // update configuration to target srv2
        theConfig.put("ref.target", "(value=srv2)");
        configure( pid );

        delay();
        // should bind to srv2
        SimpleComponent comp20;
        if ( dynamic )
        {
            TestCase.assertEquals( 1, comp10.m_modified );
            comp20 = comp10;
            TestCase.assertEquals( 2, comp20.m_multiRefBind );
View Full Code Here

        final ComponentInstance instance = factory.newInstance( props );
        TestCase.assertNotNull( instance );
        TestCase.assertNotNull( instance.getInstance() );
        TestCase.assertEquals( SimpleComponent.INSTANCE, instance.getInstance() );

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

        // update configuration to target srv2
        theConfig.put("ref.target", "(value=srv2)");
        configure( pid );

        delay();
        // should bind to srv2
        SimpleComponent comp20;
        if ( dynamic )
        {
            //fails here, config modifications are not propagated to instances from factory.
            TestCase.assertEquals( 1, comp10.m_modified );
            comp20 = comp10;
View Full Code Here

    protected void doTest(String componentName)
    {
        final Component main = findComponentByName(componentName);
        TestCase.assertNotNull(main);

        ServiceRegistration dep1Reg = register(new SimpleComponent(), 0);
        ServiceRegistration dep2Reg = register(new SimpleComponent2(), 1000);
        main.enable();
        delay(300);
        dep1Reg.unregister();
        delay(2000);

        ComponentInstance mainCompInst = main.getComponentInstance();
        TestCase.assertNull(mainCompInst);

        dep1Reg = register(new SimpleComponent(), 0);
        delay(300);

        mainCompInst = main.getComponentInstance();
        TestCase.assertNotNull(mainCompInst);

        main.disable();
        dep1Reg.unregister();
        dep2Reg.unregister();

        dep1Reg = register(new SimpleComponent(), 0);
        dep2Reg = register(new SimpleComponent2(), 1000);
        main.enable();
        delay(300);
        dep1Reg.unregister();
        delay(100);
        dep1Reg = register(new SimpleComponent(), 0);
        delay(2000);

        mainCompInst = main.getComponentInstance();
        TestCase.assertNotNull(mainCompInst);
    }
View Full Code Here

        TestCase.assertEquals( 2, SimpleComponent.INSTANCES.size() );
        TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( twoConfigs[0].getId() ) );
        TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( twoConfigs[1].getId() ) );

        // dispose an instance
        final SimpleComponent anInstance = SimpleComponent.INSTANCE;
        TestCase.assertNotNull( anInstance );
        TestCase.assertNotNull( anInstance.m_activateContext );
        anInstance.m_activateContext.getComponentInstance().dispose();
        delay();

        // expect one component
        final Component[] oneConfig = findComponentsByName( factoryPid );
        TestCase.assertNotNull( oneConfig );
        TestCase.assertEquals( 1, oneConfig.length );
        TestCase.assertEquals( Component.STATE_ACTIVE, oneConfig[0].getState() );
        TestCase.assertEquals( 1, SimpleComponent.INSTANCES.size() );
        TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( oneConfig[0].getId() ) );

        final SimpleComponent instance = SimpleComponent.INSTANCES.values().iterator().next();

        final Object holder = getComponentHolder( instance.m_activateContext );
        TestCase.assertNotNull( holder );

        Map<?, ?> m_components = ( Map<?, ?> ) getFieldValue( holder, "m_components" );
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.