Package org.osgi.service.component

Examples of org.osgi.service.component.ComponentInstance


        final ComponentFactory factory = ( ComponentFactory ) bundleContext.getService( refs[0] );
        TestCase.assertNotNull( factory );

        Hashtable<String, String> props = new Hashtable<String, String>();
        props.put( PROP_NAME_FACTORY, PROP_NAME_FACTORY );
        final ComponentInstance instance = factory.newInstance( props );
        TestCase.assertNotNull( instance );
        TestCase.assertNotNull( instance.getInstance() );
        TestCase.assertEquals( SimpleComponent.INSTANCE, instance.getInstance() );

        // ensure instance is bound
        final SimpleComponent sc = SimpleComponent.INSTANCE;
        TestCase.assertEquals( 1, sc.m_multiRef.size() );
        TestCase.assertTrue( sc.m_multiRef.contains( srv1 ) );

        // ensure factory is not bound
//        TestCase.assertNull( component.getReferences()[0].getServiceReferences() );

        // assert two components managed
        checkConfigurationCount(name, 1, ComponentConfigurationDTO.ACTIVE);
//        final Component[] allFactoryComponents = findComponentConfigurationsByName( pid, -1 );
//        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 );
//            }
//        }

        // register second service
        final SimpleServiceImpl srv11 = SimpleServiceImpl.create( bundleContext, "srv11" );
        delay();

        // ensure instance is bound
        TestCase.assertEquals( 2, sc.m_multiRef.size() );
        TestCase.assertTrue( sc.m_multiRef.contains( srv1 ) );
        TestCase.assertTrue( sc.m_multiRef.contains( srv11 ) );

        // ensure factory is not bound
//        TestCase.assertNull( component.getReferences()[0].getServiceReferences() );

        // drop second service and ensure unbound (and active)
        srv11.drop();
        delay();
        TestCase.assertNotNull( instance.getInstance() );
        TestCase.assertEquals( SimpleComponent.INSTANCE, instance.getInstance() );
        TestCase.assertEquals( 1, sc.m_multiRef.size() );
        TestCase.assertTrue( sc.m_multiRef.contains( srv1 ) );
//        TestCase.assertNull( component.getReferences()[0].getServiceReferences() );


        // remove the service, expect factory to deactivate and instance to dispose
        srv1.drop();
        delay();

        checkConfigurationCount(name, 0, -1);
        TestCase.assertNull( instance.getInstance() );

        // assert component factory only managed
        //TODO this check should be whether the service is registered.
//        final Component[] allFactoryComponents2 = findComponentConfigurationsByName( pid, -1 );
//        TestCase.assertNotNull( allFactoryComponents2 );
//        TestCase.assertEquals( 1, allFactoryComponents2.length );
//        for ( int i = 0; i < allFactoryComponents2.length; i++ )
//        {
//            final Component c = allFactoryComponents2[i];
//            if ( c.getId() == component.getId() )
//            {
//                TestCase.assertEquals( Component.STATE_UNSATISFIED, c.getState() );
//            }
//            else
//            {
//                TestCase.fail( "Unexpected Component " + c );
//            }
//        }

        // registeranother service, factory must come back, instance not
        final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
        delay();

//        TestCase.assertEquals( Component.STATE_FACTORY, component.getState() );
        TestCase.assertNull( instance.getInstance() );

        // assert component factory only managed
        checkConfigurationCount(name, 0, -1);
//        final Component[] allFactoryComponents3 = findComponentConfigurationsByName( pid, -1 );
//        TestCase.assertNotNull( allFactoryComponents3 );
View Full Code Here


        final ComponentFactory factory = ( ComponentFactory ) bundleContext.getService( refs[0] );
        TestCase.assertNotNull( factory );

        Hashtable<String, String> props = new Hashtable<String, String>();
        props.put( PROP_NAME_FACTORY, PROP_NAME_FACTORY );
        final ComponentInstance instance = factory.newInstance( props );
        TestCase.assertNotNull( instance );
        TestCase.assertNotNull( instance.getInstance() );
        TestCase.assertEquals( SimpleComponent.INSTANCE, instance.getInstance() );

        // ensure instance is bound
        final SimpleComponent sc = SimpleComponent.INSTANCE;
        TestCase.assertEquals( 1, sc.m_multiRef.size() );
        TestCase.assertTrue( sc.m_multiRef.contains( srv1 ) );

        // ensure factory is not bound
        TestCase.assertNull( component.getReferences()[0].getServiceReferences() );

        // assert two components managed
        final Component[] allFactoryComponents = findComponentsByName( pid );
        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 );
            }
        }

        // register second service
        final SimpleServiceImpl srv11 = SimpleServiceImpl.create( bundleContext, "srv11" );
        delay();

        // ensure instance is bound
        TestCase.assertEquals( 2, sc.m_multiRef.size() );
        TestCase.assertTrue( sc.m_multiRef.contains( srv1 ) );
        TestCase.assertTrue( sc.m_multiRef.contains( srv11 ) );

        // ensure factory is not bound
        TestCase.assertNull( component.getReferences()[0].getServiceReferences() );

        // drop second service and ensure unbound (and active)
        srv11.drop();
        delay();
        TestCase.assertNotNull( instance.getInstance() );
        TestCase.assertEquals( SimpleComponent.INSTANCE, instance.getInstance() );
        TestCase.assertEquals( 1, sc.m_multiRef.size() );
        TestCase.assertTrue( sc.m_multiRef.contains( srv1 ) );
        TestCase.assertNull( component.getReferences()[0].getServiceReferences() );


        // remove the service, expect factory to deactivate and instance to dispose
        srv1.drop();
        delay();

        TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
        TestCase.assertNull( instance.getInstance() );

        // assert component factory only managed
        final Component[] allFactoryComponents2 = findComponentsByName( pid );
        TestCase.assertNotNull( allFactoryComponents2 );
        TestCase.assertEquals( 1, allFactoryComponents2.length );
        for ( int i = 0; i < allFactoryComponents2.length; i++ )
        {
            final Component c = allFactoryComponents2[i];
            if ( c.getId() == component.getId() )
            {
                TestCase.assertEquals( Component.STATE_UNSATISFIED, c.getState() );
            }
            else
            {
                TestCase.fail( "Unexpected Component " + c );
            }
        }

        // registeranother service, factory must come back, instance not
        final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
        delay();

        TestCase.assertEquals( Component.STATE_FACTORY, component.getState() );
        TestCase.assertNull( instance.getInstance() );

        // assert component factory only managed
        final Component[] allFactoryComponents3 = findComponentsByName( pid );
        TestCase.assertNotNull( allFactoryComponents3 );
        TestCase.assertEquals( 1, allFactoryComponents3.length );
View Full Code Here

        final ComponentFactory factory = ( ComponentFactory ) bundleContext.getService( refs[0] );
        TestCase.assertNotNull( factory );

        Hashtable<String, String> props = new Hashtable<String, String>();
        props.put( PROP_NAME_FACTORY, PROP_NAME_FACTORY );
        final ComponentInstance instance = factory.newInstance( props );
        TestCase.assertNotNull( instance );
        TestCase.assertNotNull( instance.getInstance() );
        TestCase.assertEquals( SimpleComponent.INSTANCE, instance.getInstance() );

        // ensure instance is bound
        final SimpleComponent sc = SimpleComponent.INSTANCE;
        TestCase.assertEquals( 1, sc.m_multiRef.size() );
        TestCase.assertTrue( sc.m_multiRef.contains( srv1 ) );

        // ensure factory is not bound
        TestCase.assertNull( component.getReferences()[0].getServiceReferences() );

        // assert two components managed
        final Component[] allFactoryComponents = findComponentsByName( pid );
        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 );
            }
        }

        // register second service
        final SimpleServiceImpl srv11 = SimpleServiceImpl.create( bundleContext, "srv11" );
        delay();

        // ensure instance is bound
        TestCase.assertEquals( 2, sc.m_multiRef.size() );
        TestCase.assertTrue( sc.m_multiRef.contains( srv1 ) );
        TestCase.assertTrue( sc.m_multiRef.contains( srv11 ) );

        // ensure factory is not bound
        TestCase.assertNull( component.getReferences()[0].getServiceReferences() );

        // drop second service and ensure unbound (and active)
        srv11.drop();
        delay();
        TestCase.assertNotNull( instance.getInstance() );
        TestCase.assertEquals( SimpleComponent.INSTANCE, instance.getInstance() );
        TestCase.assertEquals( 1, sc.m_multiRef.size() );
        TestCase.assertTrue( sc.m_multiRef.contains( srv1 ) );
        TestCase.assertNull( component.getReferences()[0].getServiceReferences() );


        // remove the service, expect factory to deactivate and instance to dispose
        srv1.drop();
        delay();

        TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
        TestCase.assertNull( instance.getInstance() );

        // assert component factory only managed
        final Component[] allFactoryComponents2 = findComponentsByName( pid );
        TestCase.assertNotNull( allFactoryComponents2 );
        TestCase.assertEquals( 1, allFactoryComponents2.length );
        for ( int i = 0; i < allFactoryComponents2.length; i++ )
        {
            final Component c = allFactoryComponents2[i];
            if ( c.getId() == component.getId() )
            {
                TestCase.assertEquals( Component.STATE_UNSATISFIED, c.getState() );
            }
            else
            {
                TestCase.fail( "Unexpected Component " + c );
            }
        }

        // registeranother service, factory must come back, instance not
        final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
        delay();

        TestCase.assertEquals( Component.STATE_FACTORY, component.getState() );
        TestCase.assertNull( instance.getInstance() );

        // assert component factory only managed
        final Component[] allFactoryComponents3 = findComponentsByName( pid );
        TestCase.assertNotNull( allFactoryComponents3 );
        TestCase.assertEquals( 1, allFactoryComponents3.length );
View Full Code Here

        final ComponentFactory factory = ( ComponentFactory ) bundleContext.getService( refs[0] );
        TestCase.assertNotNull( factory );

        Hashtable<String, String> props = new Hashtable<String, String>();
        props.put( PROP_NAME_FACTORY, PROP_NAME_FACTORY );
        final ComponentInstance instance = factory.newInstance( props );
        TestCase.assertNotNull( instance );

        TestCase.assertNotNull( instance.getInstance() );
        TestCase.assertEquals( SimpleComponent.INSTANCE, instance.getInstance() );
        TestCase.assertEquals( PROP_NAME_FACTORY, SimpleComponent.INSTANCE.getProperty( PROP_NAME_FACTORY ) );

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

        final Object instanceManager = getComponentManagerFromComponentInstance( instance );
        TestCase.assertTrue( instanceMap.containsValue( instanceManager ) );

        // check registered components
        final 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 );
            }
        }

        instance.dispose();
        TestCase.assertNull( SimpleComponent.INSTANCE );
        TestCase.assertNull( instance.getInstance() ); // SCR 112.12.6.2

        TestCase.assertEquals( 0, instanceMap.size() );
        TestCase.assertFalse( instanceMap.containsValue( instanceManager ) );
    }
View Full Code Here

        final ComponentFactory factory = ( ComponentFactory ) bundleContext.getService( refs[0] );
        TestCase.assertNotNull( factory );

        Hashtable<String, String> props = new Hashtable<String, String>();
        props.put( PROP_NAME_FACTORY, PROP_NAME_FACTORY );
        final ComponentInstance instance = factory.newInstance( props );
        TestCase.assertNotNull( instance );

        TestCase.assertNotNull( instance.getInstance() );
        TestCase.assertEquals( SimpleComponent.INSTANCE, instance.getInstance() );
        TestCase.assertEquals( PROP_NAME_FACTORY, SimpleComponent.INSTANCE.getProperty( PROP_NAME_FACTORY ) );

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

        final Object instanceManager = getComponentManagerFromComponentInstance( instance );
        TestCase.assertTrue( instanceMap.containsValue( instanceManager ) );

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

        // factory is disabled but the instance is still alive
        TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
        TestCase.assertNotNull( SimpleComponent.INSTANCE );
        TestCase.assertEquals( 1, instanceMap.size() );
        TestCase.assertTrue( instanceMap.containsValue( instanceManager ) );

        instance.dispose();
        TestCase.assertNull( SimpleComponent.INSTANCE );
        TestCase.assertNull( instance.getInstance() ); // SCR 112.12.6.2

        TestCase.assertEquals( 0, instanceMap.size() );
        TestCase.assertFalse( instanceMap.containsValue( instanceManager ) );
    }
View Full Code Here

        Hashtable<String, String> props = new Hashtable<String, String>();
        props.put( PROP_NAME_FACTORY, PROP_NAME_FACTORY );
        props.put( SimpleComponent.PROP_ACTIVATE_FAILURE, "Requested Failure" );
        try
        {
            final ComponentInstance instance = factory.newInstance( props );
            TestCase.assertNotNull( instance );
            TestCase.fail( "Expected newInstance method to fail with ComponentException" );
        }
        catch ( ComponentException ce )
        {
View Full Code Here

        TestCase.assertNotNull( factory );

        // create an instance
        Hashtable<String, String> props = new Hashtable<String, String>();
        props.put( PROP_NAME_FACTORY, PROP_NAME_FACTORY );
        final ComponentInstance instance = factory.newInstance( props );
        TestCase.assertNotNull( instance );

        final Object instanceObject = instance.getInstance();
        TestCase.assertNotNull( instanceObject );
        TestCase.assertEquals( SimpleComponent.INSTANCE, instanceObject );
        TestCase.assertEquals( PROP_NAME_FACTORY, SimpleComponent.INSTANCE.getProperty( PROP_NAME_FACTORY ) );
        TestCase.assertEquals( PROP_NAME, SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );                       

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

        final Object instanceManager = getComponentManagerFromComponentInstance( instance );
        TestCase.assertTrue( instanceMap.containsValue( instanceManager ) );

        // delete config, ensure factory is not active anymore and component instance not changed
        deleteConfig( componentname );
        delay();
        TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );

        TestCase.assertNotNull( instance.getInstance() );
        TestCase.assertEquals( SimpleComponent.INSTANCE, instance.getInstance() );
        TestCase.assertEquals( instanceObject, instance.getInstance() );
        TestCase.assertEquals( PROP_NAME_FACTORY, SimpleComponent.INSTANCE.getProperty( PROP_NAME_FACTORY ) );
        TestCase.assertEquals( PROP_NAME, SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );

        instance.dispose();
        TestCase.assertNull( SimpleComponent.INSTANCE ); // component is deactivated
        TestCase.assertNull( instance.getInstance() ); // SCR 112.12.6.2

        // with removal of the factory, the created instance should also be removed
        TestCase.assertEquals( 0, instanceMap.size() );
        TestCase.assertFalse( instanceMap.containsValue( instanceManager ) );
    }
View Full Code Here

        TestCase.assertNotNull( factory );

        // non-overwrite filterprop
        Hashtable<String, String> props = new Hashtable<String, String>();
        props.put( PROP_NAME_FACTORY, PROP_NAME_FACTORY );
        final ComponentInstance instance = factory.newInstance( props );
        TestCase.assertNotNull( instance );

        TestCase.assertNotNull( instance.getInstance() );
        TestCase.assertEquals( SimpleComponent.INSTANCE, instance.getInstance() );
        TestCase.assertEquals( PROP_NAME_FACTORY, SimpleComponent.INSTANCE.getProperty( PROP_NAME_FACTORY ) );
        TestCase.assertEquals( 1, SimpleComponent.INSTANCE.m_multiRef.size() );
        TestCase.assertTrue( SimpleComponent.INSTANCE.m_multiRef.contains( match ) );

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

        final Object instanceManager = getComponentManagerFromComponentInstance( instance );
        TestCase.assertTrue( instanceMap.containsValue( instanceManager ) );

        // check registered components
        final 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 );
            }
        }

        instance.dispose();
        TestCase.assertNull( SimpleComponent.INSTANCE );
        TestCase.assertNull( instance.getInstance() ); // SCR 112.12.6.2

        TestCase.assertEquals( 0, instanceMap.size() );
        TestCase.assertFalse( instanceMap.containsValue( instanceManager ) );

        // overwritten filterprop
        Hashtable<String, String> propsNonMatch = new Hashtable<String, String>();
        propsNonMatch.put( PROP_NAME_FACTORY, PROP_NAME_FACTORY );
        propsNonMatch.put( "ref.target", "(filterprop=nomatch)" );
        try
        {
            factory.newInstance( propsNonMatch );
            TestCase.fail( "Missing reference must fail instance creation" );
        }
        catch ( ComponentException ce )
        {
            // expected
        }

        final SimpleServiceImpl noMatch = SimpleServiceImpl.create( bundleContext, "nomatch" ).setFilterProperty(
            "nomatch" );
        delay();

        final ComponentInstance instanceNonMatch = factory.newInstance( propsNonMatch );

        TestCase.assertNotNull( instanceNonMatch );

        TestCase.assertNotNull( instanceNonMatch.getInstance() );
        TestCase.assertEquals( SimpleComponent.INSTANCE, instanceNonMatch.getInstance() );
        TestCase.assertEquals( PROP_NAME_FACTORY, SimpleComponent.INSTANCE.getProperty( PROP_NAME_FACTORY ) );

        TestCase.assertEquals( 1, SimpleComponent.INSTANCE.m_multiRef.size() );
        TestCase.assertTrue( SimpleComponent.INSTANCE.m_multiRef.contains( noMatch ) );

        // check registered components
        final Component[] allFactoryComponents2 = findComponentsByName( componentname );
        TestCase.assertNotNull( allFactoryComponents2 );
        TestCase.assertEquals( 2, allFactoryComponents2.length );
        for ( int i = 0; i < allFactoryComponents2.length; i++ )
        {
            final Component c = allFactoryComponents2[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 );
            }
        }

        match.getRegistration().unregister();
        delay();

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

        //it has already been deactivated.... this should cause an exception?
        noMatch.getRegistration().unregister();
        delay();

        // check registered components (ComponentFactory aint no longer)
        final Component[] allFactoryComponents4 = findComponentsByName( componentname );
        TestCase.assertNotNull( allFactoryComponents4 );
        TestCase.assertEquals( 1, allFactoryComponents4.length );
        for ( int i = 0; i < allFactoryComponents4.length; i++ )
        {
            final Component c = allFactoryComponents4[i];
            if ( c.getId() == component.getId() )
            {
                TestCase.assertEquals( Component.STATE_UNSATISFIED, c.getState() );
            }
            else
            {
                TestCase.fail( "Unexpected Component " + c );
            }
        }

        // deactivated due to unsatisfied reference
        TestCase.assertNull( instanceNonMatch.getInstance() );
        TestCase.assertNull( SimpleComponent.INSTANCE );

        //Check that calling dispose on a deactivated instance has no effect
        instanceNonMatch.dispose();
        TestCase.assertNull( SimpleComponent.INSTANCE );
        TestCase.assertNull( instanceNonMatch.getInstance() ); // SCR 112.12.6.2
    }
View Full Code Here

        TestCase.assertNotNull( factory );

        // create the factory instance
        Hashtable<String, String> props = new Hashtable<String, String>();
        props.put( "service.pid", "myFactoryInstance" );
        final ComponentInstance instance = factory.newInstance( props );
        TestCase.assertNotNull( instance );

        TestCase.assertNotNull( instance.getInstance() );

        //The referring service should now be active
        TestCase.assertEquals( Component.STATE_ACTIVE, referringComponent.getState() );

        instance.dispose();
        TestCase.assertNull( instance.getInstance() ); // SCR 112.12.6.2

        //make sure it's unsatisfied (service is no longer available)
        TestCase.assertEquals( Component.STATE_UNSATISFIED, referringComponent.getState() );
    }
View Full Code Here

        TestCase.assertNotNull( factory );

        Hashtable<String, String> props = new Hashtable<String, String>();
        props.put( PROP_NAME_FACTORY, PROP_NAME_FACTORY );
        props.put("ref.target", "(value=service2)");
        final ComponentInstance instance = factory.newInstance( props );
        TestCase.assertNotNull( instance );

        TestCase.assertNotNull( instance.getInstance() );
        TestCase.assertEquals( SimpleComponent.INSTANCE, instance.getInstance() );
        TestCase.assertEquals( PROP_NAME_FACTORY, SimpleComponent.INSTANCE.getProperty( PROP_NAME_FACTORY ) );

        log.log(LogService.LOG_WARNING, "Bound Services: " +  SimpleComponent.INSTANCE.m_multiRef);
        TestCase.assertFalse( SimpleComponent.INSTANCE.m_multiRef.contains( s1 ) );
        TestCase.assertTrue( SimpleComponent.INSTANCE.m_multiRef.contains( s2 ) );

        instance.dispose();
        TestCase.assertNull( SimpleComponent.INSTANCE );
        TestCase.assertNull( instance.getInstance() ); // SCR 112.12.6.2
       
        s2.drop();
        s1.drop();
    }
View Full Code Here

TOP

Related Classes of org.osgi.service.component.ComponentInstance

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.