Package org.apache.felix.scr

Examples of org.apache.felix.scr.Component


    @Test
    public void test_component_factory_with_target_filters() throws InvalidSyntaxException
    {
        final String componentfactory = "factory.component.reference.targetfilter";
        final Component component = findComponentByName( componentfactory );

        TestCase.assertNotNull( component );
        TestCase.assertFalse( component.isDefaultEnabled() );

        TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
        TestCase.assertNull( SimpleComponent.INSTANCE );

        component.enable();
        delay();

        SimpleServiceImpl s1 = SimpleServiceImpl.create(bundleContext, "service1");
        SimpleServiceImpl s2 = SimpleServiceImpl.create(bundleContext, "service2");

        // supply configuration now and ensure active
        configure( componentfactory );
        delay();       

        TestCase.assertEquals( Component.STATE_FACTORY, component.getState() );
        TestCase.assertNull( SimpleComponent.INSTANCE );
       
        final ServiceReference[] refs = bundleContext.getServiceReferences( ComponentFactory.class.getName(), "("
            + ComponentConstants.COMPONENT_FACTORY + "=" + componentfactory + ")" );
        TestCase.assertNotNull( refs );
View Full Code Here


   
    @Test
    public void test_component_factory_set_bundle_location_null() throws Exception
    {
        final String componentfactory = "factory.component.reference.targetfilter";
        final Component component = findComponentByName( componentfactory );

        TestCase.assertNotNull( component );
        TestCase.assertFalse( component.isDefaultEnabled() );

        TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
        TestCase.assertNull( SimpleComponent.INSTANCE );

        component.enable();
        delay();

        SimpleServiceImpl s1 = SimpleServiceImpl.create(bundleContext, "service1");

        ConfigurationAdmin ca = getConfigurationAdmin();
        org.osgi.service.cm.Configuration config = ca.getConfiguration( componentfactory, null );
        config.setBundleLocation( null );
        delay();
        if ( isAtLeastR5() )
        {
            //check that ConfigurationSupport got a Location changed event and set the bundle location
            TestCase.assertNotNull( config.getBundleLocation() );
        }
        // supply configuration now and ensure active
        configure( componentfactory );
        delay();       

        TestCase.assertEquals( Component.STATE_FACTORY, component.getState() );
        TestCase.assertNull( SimpleComponent.INSTANCE );
       
        final ServiceReference[] refs = bundleContext.getServiceReferences( ComponentFactory.class.getName(), "("
            + ComponentConstants.COMPONENT_FACTORY + "=" + componentfactory + ")" );
        TestCase.assertNotNull( refs );
View Full Code Here

    @Test
    public void test_concurrent_component_activation_using_componentFactories()
    {


        final Component AFactory =
                findComponentByName( "org.apache.felix.scr.integration.components.concurrency.AFactory" );
        TestCase.assertNotNull( AFactory );
        AFactory.enable();

        final Component CFactory =
                findComponentByName( "org.apache.felix.scr.integration.components.concurrency.CFactory" );
        TestCase.assertNotNull( CFactory );
        CFactory.enable();

        delay( 30 );
        for ( Iterator it = log.foundWarnings().iterator(); it.hasNext();)
        {
            String message = ( String ) it.next();
View Full Code Here

        // this test is about non-standard behaviour of ComponentFactory services

        final String componentname = "factory.component";
        final String componentfactory = "factory.component.factory";

        final Component component = findComponentByName( componentname );

        TestCase.assertNotNull( component );
        TestCase.assertFalse( component.isDefaultEnabled() );

        TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
        TestCase.assertNull( SimpleComponent.INSTANCE );

        component.enable();
        delay();

        TestCase.assertEquals( Component.STATE_FACTORY, component.getState() );
        TestCase.assertNull( SimpleComponent.INSTANCE );

        final ServiceReference[] refs = bundleContext.getServiceReferences( ComponentFactory.class.getName(), "("
            + ComponentConstants.COMPONENT_FACTORY + "=" + componentfactory + ")" );
        TestCase.assertNotNull( refs );
        TestCase.assertEquals( 1, refs.length );
        final ComponentFactory factory = ( ComponentFactory ) bundleContext.getService( refs[0] );
        TestCase.assertNotNull( factory );

        final String factoryConfigPid = createFactoryConfiguration( componentname );
        delay();

        TestCase.assertNotNull( SimpleComponent.INSTANCE );
        TestCase.assertEquals( PROP_NAME, SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );

        final Map<?, ?> instanceMap = ( Map<?, ?> ) getFieldValue( component, "m_configuredServices" );
        TestCase.assertNotNull( instanceMap );
        TestCase.assertEquals( 1, instanceMap.size() );

        final Object instanceManager = getFieldValue( SimpleComponent.INSTANCE.m_activateContext, "m_componentManager" );
        TestCase.assertTrue( instanceMap.containsValue( instanceManager ) );


        // check registered components
        Component[] allFactoryComponents = findComponentsByName( componentname );
        TestCase.assertNotNull( allFactoryComponents );
        TestCase.assertEquals( 2, allFactoryComponents.length );
        for ( int i = 0; i < allFactoryComponents.length; i++ )
        {
            final Component c = allFactoryComponents[i];
            if ( c.getId() == component.getId() )
            {
                TestCase.assertEquals( Component.STATE_FACTORY, c.getState() );
            }
            else if ( c.getId() == SimpleComponent.INSTANCE.m_id )
            {
                TestCase.assertEquals( Component.STATE_ACTIVE, c.getState() );
            }
            else
            {
                TestCase.fail( "Unexpected Component " + c );
            }
        }

        // modify the configuration
        Configuration config = getConfigurationAdmin().getConfiguration( factoryConfigPid );
        Dictionary props = config.getProperties();
        props.put( PROP_NAME, PROP_NAME_FACTORY );
        config.update( props );
        delay();

        // ensure instance with new configuration
        TestCase.assertNotNull( SimpleComponent.INSTANCE );
        TestCase.assertEquals( PROP_NAME_FACTORY, SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );

        // check registered components
        allFactoryComponents = findComponentsByName( componentname );
        TestCase.assertNotNull( allFactoryComponents );
        TestCase.assertEquals( 2, allFactoryComponents.length );
        for ( int i = 0; i < allFactoryComponents.length; i++ )
        {
            final Component c = allFactoryComponents[i];
            if ( c.getId() == component.getId() )
            {
                TestCase.assertEquals( Component.STATE_FACTORY, c.getState() );
            }
            else if ( c.getId() == SimpleComponent.INSTANCE.m_id )
            {
                TestCase.assertEquals( Component.STATE_ACTIVE, c.getState() );
            }
            else
            {
                TestCase.fail( "Unexpected Component " + c );
            }
        }

        // disable the factory
        component.disable();
        delay();

        // factory is disabled and so is the instance
        TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
        TestCase.assertNull( SimpleComponent.INSTANCE );
        TestCase.assertEquals( 1, instanceMap.size() );

        // enabled the factory
        component.enable();
        delay();

        // factory is enabled and so is the instance
        TestCase.assertEquals( Component.STATE_FACTORY, component.getState() );
        TestCase.assertNotNull( SimpleComponent.INSTANCE );
        TestCase.assertEquals( 1, instanceMap.size() );

        // check registered components
        allFactoryComponents = findComponentsByName( componentname );
        TestCase.assertNotNull( allFactoryComponents );
        TestCase.assertEquals( 2, allFactoryComponents.length );
        for ( int i = 0; i < allFactoryComponents.length; i++ )
        {
            final Component c = allFactoryComponents[i];
            if ( c.getId() == component.getId() )
            {
                TestCase.assertEquals( Component.STATE_FACTORY, c.getState() );
            }
            else if ( c.getId() == SimpleComponent.INSTANCE.m_id )
            {
                TestCase.assertEquals( Component.STATE_ACTIVE, c.getState() );
            }
            else
            {
                TestCase.fail( "Unexpected Component " + c );
            }
        }

        // delete the configuration
        getConfigurationAdmin().getConfiguration( factoryConfigPid ).delete();
        delay();

        // factory is enabled but instance has been removed
        TestCase.assertEquals( Component.STATE_FACTORY, component.getState() );
        TestCase.assertNull( SimpleComponent.INSTANCE );
        TestCase.assertEquals( 0, instanceMap.size() );

        // check registered components
        allFactoryComponents = findComponentsByName( componentname );
        TestCase.assertNotNull( allFactoryComponents );
        TestCase.assertEquals( 1, allFactoryComponents.length );
        for ( int i = 0; i < allFactoryComponents.length; i++ )
        {
            final Component c = allFactoryComponents[i];
            if ( c.getId() == component.getId() )
            {
                TestCase.assertEquals( Component.STATE_FACTORY, c.getState() );
            }
            else
            {
                TestCase.fail( "Unexpected Component " + c );
            }
View Full Code Here

     */
    @Test
    public void test_A11_B11()
    {
        String componentNameA = "1.A.1.1.dynamic";
        final Component componentA = findComponentByName( componentNameA );
        TestCase.assertNotNull( componentA );
        TestCase.assertEquals( Component.STATE_UNSATISFIED, componentA.getState() );

        String componentNameB = "1.B.1.1.dynamic";
        final Component componentB = findComponentByName( componentNameB );
        TestCase.assertNotNull( componentB );
        TestCase.assertEquals( Component.STATE_UNSATISFIED, componentB.getState() );


    }
View Full Code Here

     */
    @Test
    public void test_A11_B0n_immediate_A_first()
    {
        String componentNameA = "2.A.1.1.dynamic";
        final Component componentA = findComponentByName( componentNameA );
        TestCase.assertNotNull( componentA );
        TestCase.assertEquals( Component.STATE_ACTIVE, componentA.getState() );
        A a = ( A ) componentA.getComponentInstance().getInstance();
        assertEquals( 1, a.getBs().size());

        String componentNameB = "2.B.0.n.dynamic";
        final Component componentB = findComponentByName( componentNameB );
        TestCase.assertNotNull( componentB );
        TestCase.assertEquals( Component.STATE_ACTIVE, componentB.getState() );
        B b = ( B ) componentB.getComponentInstance().getInstance();
        assertEquals( 1, b.getAs().size() );
    }
View Full Code Here

     */
    @Test
    public void test_A11_B0n_immediate_B_first()
    {
        String componentNameA = "3.A.1.1.dynamic";
        final Component componentA = findComponentByName( componentNameA );
        TestCase.assertNotNull( componentA );
        TestCase.assertEquals( Component.STATE_ACTIVE, componentA.getState() );
        A a = ( A ) componentA.getComponentInstance().getInstance();
        assertEquals( 1, a.getBs().size());

        String componentNameB = "3.B.0.n.dynamic";
        final Component componentB = findComponentByName( componentNameB );
        TestCase.assertNotNull( componentB );
        TestCase.assertEquals( Component.STATE_ACTIVE, componentB.getState() );
        B b = ( B ) componentB.getComponentInstance().getInstance();
        assertEquals( 1, b.getAs().size() );
    }
View Full Code Here

     */
    @Test
    public void test_A11_B0n_delayed_A_first() throws InvalidSyntaxException
    {
        String componentNameA = "4.A.1.1.dynamic";
        final Component componentA = findComponentByName( componentNameA );
        TestCase.assertNotNull( componentA );
        TestCase.assertEquals( Component.STATE_REGISTERED, componentA.getState() );

        String componentNameB = "4.B.0.n.dynamic";
        final Component componentB = findComponentByName( componentNameB );
        TestCase.assertNotNull( componentB );
        TestCase.assertEquals( Component.STATE_REGISTERED, componentB.getState() );

        ServiceReference[] serviceReferences = bundleContext.getServiceReferences( A.class.getName(), "(service.pid=" + componentNameA + ")" );
        TestCase.assertEquals( 1, serviceReferences.length );
        ServiceReference serviceReference = serviceReferences[0];
        Object service = bundleContext.getService( serviceReference );
        assertNotNull( service );

        delay();

        A a = ( A ) componentA.getComponentInstance().getInstance();
        assertEquals( 1, a.getBs().size() );
        B b = ( B ) componentB.getComponentInstance().getInstance();
        assertEquals( 1, b.getAs().size() );
    }
View Full Code Here

     */
    @Test
    public void test_A11_B0n_delayed_B_first() throws InvalidSyntaxException
    {
        String componentNameA = "4.A.1.1.dynamic";
        final Component componentA = findComponentByName( componentNameA );
        TestCase.assertNotNull( componentA );
        TestCase.assertEquals( Component.STATE_REGISTERED, componentA.getState() );

        String componentNameB = "4.B.0.n.dynamic";
        final Component componentB = findComponentByName( componentNameB );
        TestCase.assertNotNull( componentB );
        TestCase.assertEquals( Component.STATE_REGISTERED, componentB.getState() );

        ServiceReference[] serviceReferencesB = bundleContext.getServiceReferences( B.class.getName(), "(service.pid=" + componentNameB + ")" );
        TestCase.assertEquals( 1, serviceReferencesB.length );
        ServiceReference serviceReferenceB = serviceReferencesB[0];
        Object serviceB = bundleContext.getService( serviceReferenceB );
        assertNotNull( serviceB );

        ServiceReference[] serviceReferencesA = bundleContext.getServiceReferences( A.class.getName(), "(service.pid=" + componentNameA + ")" );
        TestCase.assertEquals( 1, serviceReferencesA.length );
        ServiceReference serviceReferenceA = serviceReferencesA[0];
        Object serviceA = bundleContext.getService( serviceReferenceA );
        assertNotNull( serviceA );

        delay();
        A a = ( A ) componentA.getComponentInstance().getInstance();
        assertEquals( 1, a.getBs().size() );
        B b = ( B ) componentB.getComponentInstance().getInstance();
        assertEquals( 1, b.getAs().size() );


        //disabling (removing the A service registration) and re-enabling will
        //result in a service event to B, so B will bind A.
        componentA.disable();
        delay();
        componentA.enable();
        delay();
        ServiceReference[] serviceReferencesA1 = bundleContext.getServiceReferences( A.class.getName(), "(service.pid=" + componentNameA + ")" );
        TestCase.assertEquals( 1, serviceReferencesA1.length );
        ServiceReference serviceReferenceA1 = serviceReferencesA1[0];
        Object serviceA1 = bundleContext.getService( serviceReferenceA1 );
        assertNotNull( serviceA1 );

        A a1 = ( A ) componentA.getComponentInstance().getInstance();
        assertEquals( 1, a1.getBs().size() );
        B b1 = ( B ) componentB.getComponentInstance().getInstance();
        assertEquals( 1, b1.getAs().size() );

    }
View Full Code Here

     */
    @Test
    public void test_A11_B01_immediate_A_first()
    {
        String componentNameA = "5.A.1.1.dynamic";
        final Component componentA = findComponentByName( componentNameA );
        TestCase.assertNotNull( componentA );
        TestCase.assertEquals( Component.STATE_ACTIVE, componentA.getState() );
        A a = ( A ) componentA.getComponentInstance().getInstance();
        assertEquals( 1, a.getBs().size());

        String componentNameB = "5.B.0.1.dynamic";
        final Component componentB = findComponentByName( componentNameB );
        TestCase.assertNotNull( componentB );
        TestCase.assertEquals( Component.STATE_ACTIVE, componentB.getState() );
        B b = ( B ) componentB.getComponentInstance().getInstance();
        assertEquals( 1, b.getAs().size() );
    }
View Full Code Here

TOP

Related Classes of org.apache.felix.scr.Component

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.