Package org.apache.felix.ipojo.handlers.providedservice

Examples of org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandlerDescription


     
      HandlerDescription[] handlers = id.getHandlers();
      assertEquals("Number of handlers", handlers.length, 3);
     
      //Look for the ProvidedService Handler
      ProvidedServiceHandlerDescription pshd = null;
        pshd = (ProvidedServiceHandlerDescription) id.getHandlerDescription("org.apache.felix.ipojo:provides");

//      for(int i = 0; i < handlers.length; i++) {
//        if(handlers[i].getHandlerName().equals("org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandler")) {
//          pshd = (ProvidedServiceHandlerDescription) handlers[i];
//        }
//      }
     
      assertNotNull("Check ProvidedServiceHandlerDescription", pshd);
      ProvidedServiceDescription[] ps = pshd.getProvidedServices();
     
      assertEquals("Check ProvidedService number", ps.length, 1);
      assertEquals("Check Provided Service Specs - 1", ps[0].getServiceSpecifications().length, 1);
      assertEquals("Check Provided Service Specs - 2", ps[0].getServiceSpecifications()[0], FooService.class.getName());
      assertEquals("Check Provided Service availability", ps[0].getState(), ProvidedServiceDescription.REGISTERED);
View Full Code Here


        ComponentInstance ci = helper.createComponentInstance("PS-Controller-1-default");
        // Controller set to true.
        waitForService(FooService.class.getName(), null, 5000);
        waitForService(CheckService.class.getName(), null, 5000);
       
        ProvidedServiceHandlerDescription pshd = null;
        pshd = (ProvidedServiceHandlerDescription) ci.getInstanceDescription()
            .getHandlerDescription("org.apache.felix.ipojo:provides");
       
        ProvidedServiceDescription ps = getPS(FooService.class.getName(), pshd.getProvidedServices());
        assertEquals("true", ps.getController());
       
        CheckService check = (CheckService) getServiceObject(CheckService.class.getName(), null);
        assertNotNull(check);
       
        assertFalse(check.check());
       
        ps = getPS(FooService.class.getName(), pshd.getProvidedServices());
        assertEquals("false", ps.getController());
       
        assertTrue(check.check());
       
        ps = getPS(FooService.class.getName(), pshd.getProvidedServices());
        assertEquals("true", ps.getController());
       
    }
View Full Code Here

            PrimitiveInstanceDescription id, String spec) {
        return id.getDependency(spec);
    }
   
    private ProvidedServiceHandlerDescription getPSDesc(InstanceDescription id) {
        ProvidedServiceHandlerDescription handler = (ProvidedServiceHandlerDescription) id.getHandlerDescription("org.apache.felix.ipojo:provides");
        if (handler == null) {
            fail("Provided Service Handler not found");
            return null;
        } else {
            return handler;
View Full Code Here

       
        // Check object graph
        //id_dep = ((Architecture) getContext().getService(arch_dep)).getInstanceDescription();
        dhd = getDependencyDesc(id_dep);
        //id_ps = ((Architecture) getContext().getService(arch_ps)).getInstanceDescription();
        ProvidedServiceHandlerDescription psh = getPSDesc(id_ps);
        assertEquals("Check Service Reference equality", psh.getProvidedServices()[0].getServiceReference(), dhd.getDependencies()[0].getServiceReference());
        assertEquals("Check POJO creation", id_ps.getCreatedObjects().length, 1);
        assertTrue("Check service reference - 1", 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.INVALID);
        dhd = getDependencyDesc(id_dep);
        assertFalse("Check dependency handler invalidity", dhd.isValid());
       
        fooProvider1.start();
       
        //id_dep = ((Architecture) getContext().getService(arch_dep)).getInstanceDescription();
        dhd = getDependencyDesc(id_dep);
        arch_ps = Utils.getServiceReferenceByName(getContext(), Architecture.class.getName(), fooProvider1.getInstanceName());
        assertNotNull("Check architecture availability", arch_ps);
        //id_ps = ((Architecture) getContext().getService(arch_ps)).getInstanceDescription();
        assertTrue("Check instance invalidity - 1", id_ps.getState() == ComponentInstance.VALID);
        psh = getPSDesc(id_ps);
        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(), instance1.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_ps = ((Architecture) getContext().getService(arch_ps)).getInstanceDescription();
        psh = getPSDesc(id_ps);
        assertEquals("Check Service Reference equality", psh.getProvidedServices()[0].getServiceReference(), dhd.getDependencies()[0].getServiceReference());
        assertTrue("Check service reference - 1", 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.INVALID);
View Full Code Here

       
        // Check object graph
        //id_dep = ((Architecture) getContext().getService(arch_dep)).getInstanceDescription();
        dhd = getDependencyDesc(id_dep);
        //id_ps = ((Architecture) getContext().getService(arch_ps)).getInstanceDescription();
        ProvidedServiceHandlerDescription psh = getPSDesc(id_ps);
        assertEquals("Check Service Reference equality", psh.getProvidedServices()[0].getServiceReference(), dhd.getDependencies()[0].getServiceReference());
        assertEquals("Check POJO creation", id_ps.getCreatedObjects().length, 1);
        assertTrue("Check service reference - 1", 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.INVALID);
        dhd = getDependencyDesc(id_dep);
        assertFalse("Check dependency handler invalidity", dhd.isValid());
       
        fooProvider1.start();
       
        //id_dep = ((Architecture) getContext().getService(arch_dep)).getInstanceDescription();
        dhd = getDependencyDesc(id_dep);
        arch_ps = Utils.getServiceReferenceByName(getContext(), Architecture.class.getName(), fooProvider1.getInstanceName());
        assertNotNull("Check architecture availability", arch_ps);
        //id_ps = ((Architecture) getContext().getService(arch_ps)).getInstanceDescription();
        assertTrue("Check instance invalidity - 1", id_ps.getState() == ComponentInstance.VALID);
        psh = getPSDesc(id_ps);
        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(), instance5.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_ps = ((Architecture) getContext().getService(arch_ps)).getInstanceDescription();
        psh = getPSDesc(id_ps);
        assertEquals("Check Service Reference equality", psh.getProvidedServices()[0].getServiceReference(), dhd.getDependencies()[0].getServiceReference());
        assertTrue("Check service reference - 1", 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.INVALID);
View Full Code Here

       
        // Check object graph
        //id_dep = ((Architecture) getContext().getService(arch_dep)).getInstanceDescription();
        dhd = getDependencyDesc(id_dep);
        //id_ps = ((Architecture) getContext().getService(arch_ps)).getInstanceDescription();
        ProvidedServiceHandlerDescription psh = getPSDesc(id_ps);
        assertEquals("Check Service Reference equality", psh.getProvidedServices()[0].getServiceReference(), dhd.getDependencies()[0].getServiceReference());
        assertEquals("Check POJO creation", id_ps.getCreatedObjects().length, 1);
        assertTrue("Check service reference - 1", 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());
       
        fooProvider1.start();
       
        //id_dep = ((Architecture) getContext().getService(arch_dep)).getInstanceDescription();
        dhd = getDependencyDesc(id_dep);
        arch_ps = Utils.getServiceReferenceByName(getContext(), Architecture.class.getName(), fooProvider1.getInstanceName());
        assertNotNull("Check architecture availability", arch_ps);
        //id_ps = ((Architecture) getContext().getService(arch_ps)).getInstanceDescription();
        assertTrue("Check instance invalidity - 1", id_ps.getState() == ComponentInstance.VALID);
        psh = getPSDesc(id_ps);
        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(), instance2.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_ps = ((Architecture) getContext().getService(arch_ps)).getInstanceDescription();
        psh = getPSDesc(id_ps);
        assertEquals("Check Service Reference equality", psh.getProvidedServices()[0].getServiceReference(), dhd.getDependencies()[0].getServiceReference());
        assertTrue("Check service reference - 1", 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);
View Full Code Here

       
        // 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 - 2", 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);
        assertEquals("Check used ref - 2 ", dhd.getDependencies()[0].getUsedServices().size(), 1); // provider 2 not already used
       
        cs_ref = Utils.getServiceReferenceByName(getContext(), CheckService.class.getName(), instance3.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 - 3.1", dhd.getDependencies()[0].getUsedServices().contains(psh1.getProvidedServices()[0].getServiceReference()));
        assertTrue("Check service reference - 3.2", dhd.getDependencies()[0].getUsedServices().contains(psh2.getProvidedServices()[0].getServiceReference()));
        assertEquals("Check used ref - 3 ("+dhd.getDependencies()[0].getUsedServices().size()+")", dhd.getDependencies()[0].getUsedServices().size(), 2);
       
        fooProvider2.stop();
       
        arch_ps1 = Utils.getServiceReferenceByName(getContext(), Architecture.class.getName(), fooProvider1.getInstanceName());
View Full Code Here

       
        // 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);
View Full Code Here

TOP

Related Classes of org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandlerDescription

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.