Package org.apache.felix.scr

Examples of org.apache.felix.scr.Component


    @Test
    public void test_mutable_properties_returned() throws InvalidSyntaxException
    {
        String componentName = "components.mutable.properties.return";
        final Component component = findComponentByName( componentName );
        TestCase.assertNotNull( component );
        TestCase.assertEquals( Component.STATE_REGISTERED, component.getState() );

        ServiceReference[] serviceReferences = bundleContext.getServiceReferences( MutatingService.class.getName(), "(service.pid=" + componentName + ")" );
        TestCase.assertEquals( 1, serviceReferences.length );
        ServiceReference serviceReference = serviceReferences[0];
        checkProperties( serviceReference, 8, "otherValue", "p1", "p2" );

        //update theValue
        MutatingService s = ( MutatingService ) bundleContext.getService( serviceReference );
        Assert.assertNotNull(s);
        checkProperties( serviceReference, 8, "anotherValue1", "p1", "p2" );
        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
        Dictionary d = new Hashtable(Collections.singletonMap( PROP_NAME, "anotherValue" ));
        s.updateProperties(d);
        checkProperties(serviceReference, 5, "anotherValue", "p1", "p2");

        //configure with configAdmin
View Full Code Here


    @Test
    public void test_mutable_properties_returned_public() throws InvalidSyntaxException
    {
        String componentName = "components.mutable.properties.return.public";
        final Component component = findComponentByName( componentName );
        TestCase.assertNotNull( component );
        TestCase.assertEquals( Component.STATE_REGISTERED, component.getState() );

        ServiceReference[] serviceReferences = bundleContext.getServiceReferences( MutatingService.class.getName(), "(service.pid=" + componentName + ")" );
        TestCase.assertEquals( 1, serviceReferences.length );
        ServiceReference serviceReference = serviceReferences[0];
        checkProperties( serviceReference, 8, "otherValue", "p1", "p2" );

        //update theValue
        MutatingService s = ( MutatingService ) bundleContext.getService( serviceReference );
        Assert.assertNotNull(s);
        checkProperties( serviceReference, 8, "anotherValue1", "p1", "p2" );
        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
        Dictionary d = new Hashtable(Collections.singletonMap( PROP_NAME, "anotherValue" ));
        s.updateProperties(d);
        checkProperties(serviceReference, 5, "anotherValue", "p1", "p2");

        //configure with configAdmin
View Full Code Here

    @Test
    public void test_mutable_properties_bind_returned() throws InvalidSyntaxException
    {
        String componentName = "components.mutable.properties.bind";
        final Component component = findComponentByName( componentName );
        TestCase.assertNotNull( component );
        TestCase.assertEquals( Component.STATE_REGISTERED, component.getState() );

        ServiceReference[] serviceReferences = bundleContext.getServiceReferences( MutatingService.class.getName(), "(service.pid=" + componentName + ")" );
        TestCase.assertEquals( 1, serviceReferences.length );
        ServiceReference serviceReference = serviceReferences[0];
        checkProperties( serviceReference, 8, "otherValue", "p1", "p2" );
View Full Code Here

        configSNVL.setBundleLocation( REGION );
       
        //Add more and more specific components to check that they pick up the appropriate configuration
        Set<Component> known = new HashSet<Component>();
       
        final Component component = findComponentByName( COMPONENT_NAME );
        known.add( component );
        component.enable();
        delay();

        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
        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();
        Component[] components = findComponentsByName( pid );
        TestCase.assertEquals( 2, components.length );
        Component cSN = getNewComponent( known, components );

       
        cSN.enable();
        delay();
        TestCase.assertEquals( Component.STATE_ACTIVE, cSN.getState() );
        SimpleComponent scSN = SimpleComponent.INSTANCE;
        TestCase.assertEquals( pidSN, scSN.getProperty( TARGETED_PID ) );
       
        Bundle bSNV = installBundle( descriptorFile, COMPONENT_PACKAGE, "simplecomponent2", "0.0.12", null );
        bSNV.start();
        components = findComponentsByName( pid );
        TestCase.assertEquals( 3, components.length );
        Component cSNV = getNewComponent( known, components );
       
        cSNV.enable();
        delay();
        TestCase.assertEquals( Component.STATE_ACTIVE, cSNV.getState() );
        SimpleComponent scSNV = SimpleComponent.INSTANCE;
        TestCase.assertEquals( pidSNV, scSNV.getProperty( TARGETED_PID ) );
       
        Bundle bSNVL = installBundle( descriptorFile, COMPONENT_PACKAGE, "simplecomponent2", "0.0.12", "bundleLocation" );
        bSNVL.start();
        components = findComponentsByName( pid );
        TestCase.assertEquals( 4, components.length );
        Component cSNVL = getNewComponent( known, components );
       
        cSNVL.enable();
        delay();
        TestCase.assertEquals( Component.STATE_ACTIVE, cSNVL.getState() );
        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();
        TestCase.assertEquals( Component.STATE_ACTIVE, cSNVL.getState() );
        TestCase.assertEquals( pidSNV, scSNVL.getProperty( TARGETED_PID ) );
       
        configSNV.delete();
        delay();
        TestCase.assertEquals( Component.STATE_ACTIVE, cSNVL.getState() );
        TestCase.assertEquals( pidSN, scSNVL.getProperty( TARGETED_PID ) );
        TestCase.assertEquals( Component.STATE_ACTIVE, cSNV.getState() );
        TestCase.assertEquals( pidSN, scSNV.getProperty( TARGETED_PID ) );
       
        configSN.delete();
        delay();
        TestCase.assertEquals( Component.STATE_ACTIVE, cSNVL.getState() );
        TestCase.assertEquals( pid, scSNVL.getProperty( TARGETED_PID ) );
        TestCase.assertEquals( Component.STATE_ACTIVE, cSNV.getState() );
        TestCase.assertEquals( pid, scSNV.getProperty( TARGETED_PID ) );
        TestCase.assertEquals( Component.STATE_ACTIVE, cSN.getState() );
        TestCase.assertEquals( pid, scSN.getProperty( TARGETED_PID ) );
View Full Code Here

    private Component getNewComponent(Set<Component> known, Component[] components)
    {
        List<Component> cs = new ArrayList(Arrays.asList( components ));
        cs.removeAll( known );
        Component c = cs.get( 0 );
        known.add(c);
        return c;
    }
View Full Code Here

    @Test
    public void test_concurrent_injection_with_bundleContext() throws Throwable
    {
        for ( int i = 0; i < 6; i++ )
        {
            final Component main = findComponentByName( "org.apache.felix.scr.integration.components.felix3680_2.Main" );
            TestCase.assertNotNull( main );
            main.enable();
            delay( 5 ); //run test for 30 seconds
            main.disable();
            delay(); //async deactivate
            if ( log.getFirstFrameworkThrowable() != null )
            {
                throw log.getFirstFrameworkThrowable();
            }
View Full Code Here

    }

    @Test
    public void test_multi_service_bind_unbind_order()
    {
        final Component component = findComponentByName( "test_multi_service_bind_unbind_order" );
        TestCase.assertNotNull( component );
        TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );

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

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

        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
        final SimpleComponent2 comp10 = SimpleComponent2.INSTANCE;
        TestCase.assertNotNull( comp10 );
        TestCase.assertEquals( 2, comp10.getBindings().size() );
        TestCase.assertEquals( "bindSimpleService", comp10.getBindings().get( 0 ) );
        TestCase.assertEquals( "bindSimpleService2", comp10.getBindings().get( 1 ) );

        component.disable();
        delay();

        TestCase.assertEquals( 4, comp10.getBindings().size() );
        TestCase.assertEquals( "bindSimpleService", comp10.getBindings().get( 0 ) );
        TestCase.assertEquals( "bindSimpleService2", comp10.getBindings().get( 1 ) );
View Full Code Here

        bundle1.start();

        final Bundle bundle2 = installBundle("/integration_test_FELIX_4188_2.xml", "", "simplecomponent2");
        bundle2.start();

        final Component aComp1 =
                findComponentByName("org.apache.felix.scr.integration.components.Felix4188Component-1");
        aComp1.enable();
        final Object aInst1 = aComp1.getComponentInstance().getInstance();

        final Component aComp2 =
                findComponentByName("org.apache.felix.scr.integration.components.Felix4188Component-2");
        aComp2.enable();
        final Object aInst2 = aComp2.getComponentInstance().getInstance();

        final CountDownLatch latch = new CountDownLatch(1);

        new Thread() {
            public void run() {
View Full Code Here

    @Test
    public void test_configurationpid_use_other_pid()
    {
        final String pid = "ConfigurationPid.otherPid";
        final String name = "ConfigurationPid.componentName";
        final Component component = findComponentByName( name );

        deleteConfig( pid );
        delay();

        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_UNSATISFIED, component.getState() );
        TestCase.assertNull( SimpleComponent.INSTANCE );

        configure( pid );
        delay();

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

        deleteConfig( pid );
        delay();

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

        component.disable();
        delay();

        TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
        TestCase.assertNull( SimpleComponent.INSTANCE );
    }
View Full Code Here

    @Test
    public void test_configurationpid_must_not_use_name_as_pid()
    {
        final String name = "ConfigurationPid.componentName";
        final String pid = name;
        final Component component = findComponentByName( name );

        deleteConfig( pid );
        delay();

        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_UNSATISFIED, component.getState() );
        TestCase.assertNull( SimpleComponent.INSTANCE );

        configure( pid );
        delay();

        TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );

        deleteConfig( pid );
        delay();
    }
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.