Package org.apache.felix.ipojo.handlers.dependency

Examples of org.apache.felix.ipojo.handlers.dependency.DependencyHandlerDescription


        assertNotNull("Check architecture availability", arch_dep);
        PrimitiveInstanceDescription id_dep = (PrimitiveInstanceDescription) ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
        assertTrue("Check instance invalidity - 1", id_dep.getState() == ComponentInstance.VALID);

        // Check dependency handler invalidity
        DependencyHandlerDescription dhd = getDependencyDesc(id_dep);
        assertTrue("Check dependency handler invalidity", dhd.isValid());

        // Check dependency metadata
        assertEquals("Check dependency interface", dhd.getDependencies()[0].getInterface(), FooService.class.getName());
        assertTrue("Check dependency cardinality", dhd.getDependencies()[0].isMultiple());
        assertTrue("Check dependency optionality", dhd.getDependencies()[0].isOptional());
        assertNull("Check dependency ref -1", dhd.getDependencies()[0].getServiceReferences());

        fooProvider1.start();

        ServiceReference arch_ps1 = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), fooProvider1.getInstanceName());
        assertNotNull("Check architecture availability", arch_ps1);
        PrimitiveInstanceDescription id_ps1 = (PrimitiveInstanceDescription) ((Architecture) osgiHelper.getRawServiceObject(arch_ps1)).getInstanceDescription();
        assertTrue("Check instance invalidity - 1", id_ps1.getState() == ComponentInstance.VALID);

        //id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
        assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
        dhd = getDependencyDesc(id_dep);
        assertTrue("Check dependency handler validity", dhd.isValid());
        assertEquals("Check dependency ref - 2 ", dhd.getDependencies()[0].getServiceReferences().size(), 1);

        ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance4.getInstanceName());
        assertNotNull("Check CheckService availability", cs_ref);
        CheckService cs = (CheckService) osgiHelper.getRawServiceObject(cs_ref);
        assertTrue("check CheckService invocation", cs.check());

        // Check object graph
        //id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
        dhd = getDependencyDesc(id_dep);
        //id_ps1 = ((Architecture) osgiHelper.getRawServiceObject(arch_ps1)).getInstanceDescription();
        ProvidedServiceHandlerDescription psh = getPSDesc(id_ps1);
        assertEquals("Check POJO creation", id_ps1.getCreatedObjects().length, 1);

        // Start a second foo service provider
        fooProvider2.start();

        arch_ps1 = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), fooProvider1.getInstanceName());
        ServiceReference arch_ps2 = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), fooProvider2.getInstanceName());
        assertNotNull("Check architecture availability", arch_ps1);
        assertNotNull("Check architecture 2 availability", arch_ps2);
        //id_ps1 = ((Architecture) osgiHelper.getRawServiceObject(arch_ps1)).getInstanceDescription();
        PrimitiveInstanceDescription id_ps2 = (PrimitiveInstanceDescription) ((Architecture) osgiHelper.getRawServiceObject(arch_ps2)).getInstanceDescription();
        assertTrue("Check instance invalidity - 1", id_ps1.getState() == ComponentInstance.VALID);
        assertTrue("Check instance 2 invalidity - 1", id_ps2.getState() == ComponentInstance.VALID);

        //id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
        assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
        dhd = getDependencyDesc(id_dep);
        assertTrue("Check dependency handler validity", dhd.isValid());
        assertEquals("Check dependency ref - 3 ", dhd.getDependencies()[0].getServiceReferences().size(), 2);

        cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance4.getInstanceName());
        assertNotNull("Check CheckService availability", cs_ref);
        cs = (CheckService) osgiHelper.getRawServiceObject(cs_ref);
        assertTrue("check CheckService invocation", cs.check());

        // Check object graph
        //id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
        dhd = getDependencyDesc(id_dep);
        //id_ps1 = ((Architecture) osgiHelper.getRawServiceObject(arch_ps1)).getInstanceDescription();
        //id_ps2 = ((Architecture) osgiHelper.getRawServiceObject(arch_ps1)).getInstanceDescription();
        ProvidedServiceHandlerDescription psh1 = getPSDesc(id_ps1);
        ProvidedServiceHandlerDescription psh2 = getPSDesc(id_ps2);
        assertEquals("Check POJO creation", id_ps1.getCreatedObjects().length, 1);
        assertEquals("Check POJO creation", id_ps2.getCreatedObjects().length, 1);

        fooProvider2.stop();

        arch_ps1 = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), fooProvider1.getInstanceName());
        assertNotNull("Check architecture availability", arch_ps1);
        //id_ps1 = ((Architecture) osgiHelper.getRawServiceObject(arch_ps1)).getInstanceDescription();
        assertTrue("Check instance invalidity - 1", id_ps1.getState() == ComponentInstance.VALID);

        //id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
        assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
        dhd = getDependencyDesc(id_dep);
        assertTrue("Check dependency handler validity", dhd.isValid());
        assertEquals("Check dependency ref - 2 ", dhd.getDependencies()[0].getServiceReferences().size(), 1);

        cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance4.getInstanceName());
        assertNotNull("Check CheckService availability", cs_ref);
        cs = (CheckService) osgiHelper.getRawServiceObject(cs_ref);
        assertTrue("check CheckService invocation", cs.check());

        // Check object graph
        //id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
        dhd = getDependencyDesc(id_dep);
        //id_ps1 = ((Architecture) osgiHelper.getRawServiceObject(arch_ps1)).getInstanceDescription();
        psh = getPSDesc(id_ps1);
        assertEquals("Check POJO creation", id_ps1.getCreatedObjects().length, 1);

        fooProvider1.stop();

        //id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
        assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.VALID);
        dhd = getDependencyDesc(id_dep);
        assertTrue("Check dependency handler invalidity", dhd.isValid());

        fooProvider2.start();

        //id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
        dhd = getDependencyDesc(id_dep);
        arch_ps2 = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), fooProvider2.getInstanceName());
        assertNotNull("Check architecture availability", arch_ps2);
        //id_ps1 = ((Architecture) osgiHelper.getRawServiceObject(arch_ps1)).getInstanceDescription();
        assertTrue("Check instance invalidity - 1", id_ps2.getState() == ComponentInstance.VALID);
        psh = getPSDesc(id_ps2);
        assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
        assertTrue("Check dependency handler validity", dhd.isValid());

        assertEquals("Check dependency ref -3", dhd.getDependencies()[0].getServiceReferences().size(), 1);

        cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance4.getInstanceName());
        assertNotNull("Check CheckService availability", cs_ref);
        cs = (CheckService) osgiHelper.getRawServiceObject(cs_ref);
        assertTrue("check CheckService invocation", cs.check());

        // Check object graph
        //id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
        dhd = getDependencyDesc(id_dep);
        //id_ps1 = ((Architecture) osgiHelper.getRawServiceObject(arch_ps1)).getInstanceDescription();
        psh = getPSDesc(id_ps2);

        fooProvider2.stop();

        //id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
        assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.VALID);
        dhd = getDependencyDesc(id_dep);
        assertTrue("Check dependency handler invalidity", dhd.isValid());

        id_dep = null;
        cs = null;
        getContext().ungetService(arch_dep);
        getContext().ungetService(cs_ref);
View Full Code Here


        Architecture arch = (Architecture) osgiHelper.getRawServiceObject(refv1);

        HandlerDescription desc = arch.getInstanceDescription().getHandlerDescription("org.apache.felix.ipojo:requires");
        Assert.assertNotNull(desc);

        DependencyHandlerDescription d = (DependencyHandlerDescription) desc;
        Assert.assertNotNull(d.getDependencies());
        Assert.assertEquals(1, d.getDependencies().length);

        DependencyDescription dep = d.getDependencies()[0];
        Assert.assertEquals(Dependency.RESOLVED, dep.getState());

        Assert.assertEquals(1, dep.getServiceReferences().size());
        ServiceReference r = dep.getServiceReferences().get(0);
        Assert.assertEquals("provider", r.getProperty("factory.name"));
View Full Code Here

        Architecture arch = (Architecture) osgiHelper.getRawServiceObject(refv1);

        HandlerDescription desc = arch.getInstanceDescription().getHandlerDescription("org.apache.felix.ipojo:requires");
        Assert.assertNotNull(desc);

        DependencyHandlerDescription d = (DependencyHandlerDescription) desc;
        Assert.assertNotNull(d.getDependencies());
        Assert.assertEquals(1, d.getDependencies().length);

        DependencyDescription dep = d.getDependencies()[0];
        Assert.assertEquals(Dependency.RESOLVED, dep.getState());

        Assert.assertEquals(1, dep.getServiceReferences().size());
        ServiceReference r = dep.getServiceReferences().get(0);
View Full Code Here

        configuration.put("requires.filters", filters);
        ComponentInstance instance = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.runtime.core.test" +
                ".components.context.ContextualFilterConsumer", configuration);

        assertTrue(instance.getState() == ComponentInstance.VALID);
        DependencyHandlerDescription desc = (DependencyHandlerDescription) instance.getInstanceDescription().getHandlerDescription("org.apache.felix" +
                ".ipojo:requires");

        // Only one dependency.
        DependencyDescription dependency = desc.getDependencies()[0];
        assertEquals("(id=2)", dependency.getFilter());
    }
View Full Code Here

        configuration.put("requires.filters", filters);
        ComponentInstance instance = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.runtime.core.test" +
                ".components.context.ContextualFilterConsumer", configuration);

        assertTrue(instance.getState() == ComponentInstance.INVALID);
        DependencyHandlerDescription desc = (DependencyHandlerDescription) instance.getInstanceDescription().getHandlerDescription("org.apache.felix" +
                ".ipojo:requires");

        // Only one dependency.
        DependencyDescription dependency = desc.getDependencies()[0];
        assertEquals("(id=${source.id})", dependency.getFilter());

        registration = context.registerService(ContextSource.class.getName(),
                source, null);

        assertTrue(instance.getState() == ComponentInstance.VALID);
        desc = (DependencyHandlerDescription) instance.getInstanceDescription().getHandlerDescription("org.apache.felix" +
                ".ipojo:requires");

        // Only one dependency.
        dependency = desc.getDependencies()[0];
        assertEquals("(id=2)", dependency.getFilter());
    }
View Full Code Here

        // Set id to null
        source.set("source.id", null);
        assertTrue(instance.getState() == ComponentInstance.INVALID);

        DependencyHandlerDescription desc = (DependencyHandlerDescription) instance.getInstanceDescription()
                .getHandlerDescription("org.apache.felix.ipojo:requires");
        DependencyDescription dependency = desc.getDependencies()[0];
        assertEquals("(id=${source.id})", dependency.getFilter());

        // Register a new source.
        MyContextSource source2 = new MyContextSource();
        source2.set("source.id", 2);
View Full Code Here

        Assert.assertEquals(dref.getBundle().getSymbolicName(), "C");

    }

    private DependencyDescription getDependency(Architecture arch, String id) {
        DependencyHandlerDescription hd = (DependencyHandlerDescription) arch.getInstanceDescription().getHandlerDescription("org.apache.felix.ipojo:requires");
        Assert.assertNotNull(hd);
        for (DependencyDescription dd : hd.getDependencies()) {
            if (dd.getId().equals(id)) {
                return dd;
            }
        }
        Assert.fail("Dependency " + id + " not found");
View Full Code Here

        Assert.assertEquals(dref.getBundle().getSymbolicName(), "C");

    }

    private DependencyDescription getDependency(Architecture arch, String id) {
        DependencyHandlerDescription hd = (DependencyHandlerDescription) arch.getInstanceDescription().getHandlerDescription("org.apache.felix.ipojo:requires");
        Assert.assertNotNull(hd);
        for(DependencyDescription dd : hd.getDependencies()) {
            if (dd.getId().equals(id)) { return dd; }
        }
        Assert.fail("Dependency " + id + " not found");
        return null;
    }
View Full Code Here

        assertNotNull("Check architecture availability", arch_dep);
        PrimitiveInstanceDescription id_dep = (PrimitiveInstanceDescription) ((Architecture) getContext().getService(arch_dep)).getInstanceDescription();
        assertTrue("Check instance invalidity - 1", id_dep.getState() == ComponentInstance.VALID);
       
        // Check dependency handler invalidity
        DependencyHandlerDescription dhd = getDependencyDesc(id_dep);
        assertTrue("Check dependency handler invalidity", dhd.isValid());
       
        // Check dependency metadata
        assertEquals("Check dependency interface", dhd.getDependencies()[0].getInterface(), FooService.class.getName());
        assertTrue("Check dependency cardinality", dhd.getDependencies()[0].isMultiple());
        assertTrue("Check dependency optionality", dhd.getDependencies()[0].isOptional());
        assertNull("Check dependency ref -1", dhd.getDependencies()[0].getServiceReferences());
       
        fooProvider1.start();
       
        ServiceReference arch_ps1 = Utils.getServiceReferenceByName(getContext(), Architecture.class.getName(), fooProvider1.getInstanceName());
        assertNotNull("Check architecture availability", arch_ps1);
        PrimitiveInstanceDescription id_ps1 = (PrimitiveInstanceDescription) ((Architecture) getContext().getService(arch_ps1)).getInstanceDescription();
        assertTrue("Check instance invalidity - 1", id_ps1.getState() == ComponentInstance.VALID);       
       
        //id_dep = ((Architecture) getContext().getService(arch_dep)).getInstanceDescription();
        assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
        dhd = getDependencyDesc(id_dep);
        assertTrue("Check dependency handler validity", dhd.isValid());
        assertEquals("Check dependency ref - 2 ", dhd.getDependencies()[0].getServiceReferences().size(), 1);
       
        ServiceReference cs_ref = Utils.getServiceReferenceByName(getContext(), CheckService.class.getName(), instance4.getInstanceName());
        assertNotNull("Check CheckService availability", cs_ref);
        CheckService cs = (CheckService) getContext().getService(cs_ref);
        assertTrue("check CheckService invocation", cs.check());
       
        // Check object graph
        //id_dep = ((Architecture) getContext().getService(arch_dep)).getInstanceDescription();
        dhd = getDependencyDesc(id_dep);
        //id_ps1 = ((Architecture) getContext().getService(arch_ps1)).getInstanceDescription();
        ProvidedServiceHandlerDescription psh = getPSDesc(id_ps1);
        assertEquals("Check Service Reference equality", psh.getProvidedServices()[0].getServiceReference(), dhd.getDependencies()[0].getServiceReference());
        assertEquals("Check POJO creation", id_ps1.getCreatedObjects().length, 1);
        assertTrue("Check service reference - 1", dhd.getDependencies()[0].getUsedServices().contains(psh.getProvidedServices()[0].getServiceReference()));
       
        // Start a second foo service provider
        fooProvider2.start();
       
        arch_ps1 = Utils.getServiceReferenceByName(getContext(), Architecture.class.getName(), fooProvider1.getInstanceName());
        ServiceReference arch_ps2 = Utils.getServiceReferenceByName(getContext(), Architecture.class.getName(), fooProvider2.getInstanceName());
        assertNotNull("Check architecture availability", arch_ps1);
        assertNotNull("Check architecture 2 availability", arch_ps2);
        //id_ps1 = ((Architecture) getContext().getService(arch_ps1)).getInstanceDescription();
        PrimitiveInstanceDescription id_ps2 = (PrimitiveInstanceDescription) ((Architecture) getContext().getService(arch_ps2)).getInstanceDescription();
        assertTrue("Check instance invalidity - 1", id_ps1.getState() == ComponentInstance.VALID);
        assertTrue("Check instance 2 invalidity - 1", id_ps2.getState() == ComponentInstance.VALID);
       
        //id_dep = ((Architecture) getContext().getService(arch_dep)).getInstanceDescription();
        assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
        dhd = getDependencyDesc(id_dep);
        assertTrue("Check dependency handler validity", dhd.isValid());
        assertEquals("Check dependency ref - 3 ", dhd.getDependencies()[0].getServiceReferences().size(), 2);
       
        cs_ref = Utils.getServiceReferenceByName(getContext(), CheckService.class.getName(), instance4.getInstanceName());
        assertNotNull("Check CheckService availability", cs_ref);
        cs = (CheckService) getContext().getService(cs_ref);
        assertTrue("check CheckService invocation", cs.check());
       
        // Check object graph
        //id_dep = ((Architecture) getContext().getService(arch_dep)).getInstanceDescription();
        dhd = getDependencyDesc(id_dep);
        //id_ps1 = ((Architecture) getContext().getService(arch_ps1)).getInstanceDescription();
        //id_ps2 = ((Architecture) getContext().getService(arch_ps1)).getInstanceDescription();
        ProvidedServiceHandlerDescription psh1 = getPSDesc(id_ps1);
        ProvidedServiceHandlerDescription psh2 = getPSDesc(id_ps2);
        assertEquals("Check POJO creation", id_ps1.getCreatedObjects().length, 1);
        assertEquals("Check POJO creation", id_ps2.getCreatedObjects().length, 1);
        assertTrue("Check service reference - 2.1", dhd.getDependencies()[0].getUsedServices().contains(psh1.getProvidedServices()[0].getServiceReference()));
        assertTrue("Check service reference - 2.2", dhd.getDependencies()[0].getUsedServices().contains(psh2.getProvidedServices()[0].getServiceReference()));
       
        fooProvider2.stop();
       
        arch_ps1 = Utils.getServiceReferenceByName(getContext(), Architecture.class.getName(), fooProvider1.getInstanceName());
        assertNotNull("Check architecture availability", arch_ps1);
        //id_ps1 = ((Architecture) getContext().getService(arch_ps1)).getInstanceDescription();
        assertTrue("Check instance invalidity - 1", id_ps1.getState() == ComponentInstance.VALID);       
       
        //id_dep = ((Architecture) getContext().getService(arch_dep)).getInstanceDescription();
        assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
        dhd = getDependencyDesc(id_dep);
        assertTrue("Check dependency handler validity", dhd.isValid());
        assertEquals("Check dependency ref - 2 ", dhd.getDependencies()[0].getServiceReferences().size(), 1);
       
        cs_ref = Utils.getServiceReferenceByName(getContext(), CheckService.class.getName(), instance4.getInstanceName());
        assertNotNull("Check CheckService availability", cs_ref);
        cs = (CheckService) getContext().getService(cs_ref);
        assertTrue("check CheckService invocation", cs.check());
       
        // Check object graph
        //id_dep = ((Architecture) getContext().getService(arch_dep)).getInstanceDescription();
        dhd = getDependencyDesc(id_dep);
        //id_ps1 = ((Architecture) getContext().getService(arch_ps1)).getInstanceDescription();
        psh = getPSDesc(id_ps1);
        assertEquals("Check Service Reference equality", psh.getProvidedServices()[0].getServiceReference(), dhd.getDependencies()[0].getServiceReference());
        assertEquals("Check POJO creation", id_ps1.getCreatedObjects().length, 1);
        assertTrue("Check service reference - 3", dhd.getDependencies()[0].getUsedServices().contains(psh.getProvidedServices()[0].getServiceReference()));

        fooProvider1.stop();
       
        //id_dep = ((Architecture) getContext().getService(arch_dep)).getInstanceDescription();
        assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.VALID);
        dhd = getDependencyDesc(id_dep);
        assertTrue("Check dependency handler invalidity", dhd.isValid());
       
        fooProvider2.start();
       
        //id_dep = ((Architecture) getContext().getService(arch_dep)).getInstanceDescription();
        dhd = getDependencyDesc(id_dep);
        arch_ps2 = Utils.getServiceReferenceByName(getContext(), Architecture.class.getName(), fooProvider2.getInstanceName());
        assertNotNull("Check architecture availability", arch_ps2);
        //id_ps1 = ((Architecture) getContext().getService(arch_ps1)).getInstanceDescription();
        assertTrue("Check instance invalidity - 1", id_ps2.getState() == ComponentInstance.VALID);
        psh = getPSDesc(id_ps2);
        assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
        assertTrue("Check dependency handler validity", dhd.isValid());
       
        assertEquals("Check dependency ref -3", dhd.getDependencies()[0].getServiceReferences().size(), 1);
       
        cs_ref = Utils.getServiceReferenceByName(getContext(), CheckService.class.getName(), instance4.getInstanceName());
        assertNotNull("Check CheckService availability", cs_ref);
        cs = (CheckService) getContext().getService(cs_ref);
        assertTrue("check CheckService invocation", cs.check());
       
        // Check object graph
        //id_dep = ((Architecture) getContext().getService(arch_dep)).getInstanceDescription();
        dhd = getDependencyDesc(id_dep);
        //id_ps1 = ((Architecture) getContext().getService(arch_ps1)).getInstanceDescription();
        psh = getPSDesc(id_ps2);
        assertEquals("Check Service Reference equality", psh.getProvidedServices()[0].getServiceReference(), dhd.getDependencies()[0].getServiceReference());
        assertTrue("Check service reference - 4", dhd.getDependencies()[0].getUsedServices().contains(psh.getProvidedServices()[0].getServiceReference()));

        fooProvider2.stop();
       
        //id_dep = ((Architecture) getContext().getService(arch_dep)).getInstanceDescription();
        assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.VALID);
        dhd = getDependencyDesc(id_dep);
        assertTrue("Check dependency handler invalidity", dhd.isValid());
       
        id_dep = null;
        cs = null;
        getContext().ungetService(arch_dep);
        getContext().ungetService(cs_ref);
View Full Code Here

TOP

Related Classes of org.apache.felix.ipojo.handlers.dependency.DependencyHandlerDescription

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.