Package org.apache.felix.ipojo.runtime.core.services

Examples of org.apache.felix.ipojo.runtime.core.services.CheckService


        prov.start();

        // The two consumers are started and use their own objects.
        ServiceReference refcons1 = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), cons1.getInstanceName());
        assertNotNull("Cons1 Service available", refcons1);
        CheckService cs_cons1 = (CheckService) osgiHelper.getRawServiceObject(refcons1);
        Properties props = cs_cons1.getProps();
        FooService fscons1 = (FooService) props.get("object");

        ServiceReference refcons2 = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), cons2.getInstanceName());
        assertNotNull("Cons2 Service available", refcons2);
        CheckService cs_cons2 = (CheckService) osgiHelper.getRawServiceObject(refcons2);
        Properties props2 = cs_cons2.getProps();
        FooService fscons2 = (FooService) props2.get("object");

        checkCreatedObjects(prov, 2);
        assertNotSame("Two objects", fscons1, fscons2);

        // Stop the provider
        prov.stop();
        // Cons1 and 2 are invalid.
        assertEquals("Cons1 invalidity", ComponentInstance.INVALID, cons1.getState());
        assertEquals("Cons2 invalidity", ComponentInstance.INVALID, cons2.getState());

        // No object created in prov
        checkCreatedObjects(prov, 0);

        // Restart the provider
        prov.start();

        // Consumers are valid.
        assertEquals("Cons1 validity", ComponentInstance.VALID, cons1.getState());
        assertEquals("Cons2 validity", ComponentInstance.VALID, cons2.getState());

        // Check objects
        refcons1 = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), cons1.getInstanceName());
        assertNotNull("Cons1 Service available", refcons1);
        cs_cons1 = (CheckService) osgiHelper.getRawServiceObject(refcons1);
        props = cs_cons1.getProps();
        Object fscons3 = (FooService) props.get("object");

        refcons2 = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), cons2.getInstanceName());
        assertNotNull("Cons2 Service available", refcons2);
        cs_cons2 = (CheckService) osgiHelper.getRawServiceObject(refcons2);
        props2 = cs_cons2.getProps();
        Object fscons4 = (FooService) props2.get("object");

        checkCreatedObjects(prov, 2);
        assertNotSame("Two objects", fscons3, fscons4);
        assertNotSame("Two new objects - 1", fscons3, fscons1);
View Full Code Here


        // Step 1 : create start one consumer
        cons1.start();
        ServiceReference refcons1 = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), cons1.getInstanceName());
        assertNotNull("Cons1 Service available", refcons1);

        CheckService cs_cons1 = (CheckService) osgiHelper.getRawServiceObject(refcons1);
        Properties props = cs_cons1.getProps();
        Long id = (Long) props.get("id");
        FooService fscons1 = (FooService) props.get("object");
        assertEquals("id 1", 1, id.intValue());
        checkCreatedObjects(prov2, 1);


        // Step 2 : create a second consumer
        cons3.start();
        ServiceReference refcons2 = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), cons3.getInstanceName());
        assertNotNull("Cons2 Service available", refcons2);

        CheckService cs_cons2 = (CheckService) osgiHelper.getRawServiceObject(refcons2);
        Properties props2 = cs_cons2.getProps();
        Long id2 = (Long) props2.get("id");
        FooService fscons2 = (FooService) props2.get("object");
        assertEquals("id 2", 2, id2.intValue());
        checkCreatedObjects(prov2, 2);
View Full Code Here

        // Step 1 : create start one consumer
        cons1.start();
        ServiceReference refcons1 = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), cons1.getInstanceName());
        assertNotNull("Cons1 Service available", refcons1);

        CheckService cs_cons1 = (CheckService) osgiHelper.getRawServiceObject(refcons1);
        Properties props = cs_cons1.getProps();
        Long id = (Long) props.get("id");
        FooService fscons1 = (FooService) props.get("object");
        assertEquals("id 1", 1, id.intValue());
        checkCreatedObjects(prov, 1);


        // Step 2 : create a second consumer
        cons2.start();
        ServiceReference refcons2 = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), cons2.getInstanceName());
        assertNotNull("Cons2 Service available", refcons2);

        CheckService cs_cons2 = (CheckService) osgiHelper.getRawServiceObject(refcons2);
        Properties props2 = cs_cons2.getProps();
        Long id2 = (Long) props2.get("id");
        FooService fscons2 = (FooService) props2.get("object");
        assertEquals("id 2", 2, id2.intValue());
        checkCreatedObjects(prov, 2);
View Full Code Here

        // Controller set to true.
        osgiHelper.waitForService(FooService.class.getName(), null, 5000);
        osgiHelper.waitForService(CheckService.class.getName(), null, 5000);

        CheckService check = (CheckService) osgiHelper.getServiceObject(CheckService.class.getName(), null);
        assertNotNull(check);

        // Register listeners :
        // 1- CountingListener l1
        // 2- ThrowingListener bad
        // 3- TotalCountingListener l2
        // 4- AppendingListener l3
        ProvidedServiceListener l1 = new CountingListener();
        ps.addListener(l1);
        ProvidedServiceListener bad = new ThrowingListener();
        ps.addListener(bad);
        ProvidedServiceListener l2 = new TotalCountingListener();
        ps.addListener(l2);
        ProvidedServiceListener l3 = new AppendingListener();
        ps.addListener(l3);

        // Check initial valued are untouched
        assertEquals(0, registrations);
        assertEquals(0, unregistrations);
        assertEquals(0, updates);
        assertEquals(0, total);

        // Unregister the service and check.
        assertFalse(check.check());
        assertEquals(0, registrations);
        assertEquals(1, unregistrations);
        assertEquals(0, updates);
        assertEquals(1, total);

        // Modify the service while it is unregistered. Nothing should move.
        Hashtable<String, Object> props = new Hashtable<String, Object>();
        props.put("change1", "1");
        ps.addProperties(props);
        assertEquals(0, registrations);
        assertEquals(1, unregistrations);
        assertEquals(0, updates);
        assertEquals(1, total);

        // Register the service and check.
        assertTrue(check.check());
        assertEquals(1, registrations);
        assertEquals(1, unregistrations);
        assertEquals(0, updates);
        assertEquals(2, total);

        // Modify the service while it is REGISTERED
        props.clear();
        props.put("change2", "2");
        ps.addProperties(props);
        assertEquals(1, registrations);
        assertEquals(1, unregistrations);
        assertEquals(1, updates);
        assertEquals(3, total);

        // One more time, just to be sure...
        assertFalse(check.check()); // Unregister
        assertEquals(1, registrations);
        assertEquals(2, unregistrations);
        assertEquals(1, updates);
        assertEquals(4, total);
        assertTrue(check.check()); // Register
        assertEquals(2, registrations);
        assertEquals(2, unregistrations);
        assertEquals(1, updates);
        assertEquals(5, total);

        // Unregister the listener
        ps.removeListener(l1);
        ps.removeListener(bad);
        ps.removeListener(l2);
        ps.removeListener(l3);

        // Play with the controller and check that nothing moves
        assertFalse(check.check()); // Unregister
        assertEquals(2, registrations);
        assertEquals(2, unregistrations);
        assertEquals(1, updates);
        assertEquals(5, total);
        assertTrue(check.check()); // Register
        assertEquals(2, registrations);
        assertEquals(2, unregistrations);
        assertEquals(1, updates);
        assertEquals(5, total);
        props.clear(); props.put("change3", "3"); ps.addProperties(props); // Modify
View Full Code Here

        ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Callbacks-reg-only");
        // Controller set to true.
        osgiHelper.waitForService(FooService.class.getName(), null, 5000);
        osgiHelper.waitForService(CheckService.class.getName(), null, 5000);

        CheckService check = (CheckService) osgiHelper.getServiceObject(CheckService.class.getName(), null);
        assertNotNull(check);

        Integer reg = (Integer) check.getProps().get("registered");
        Integer unreg = (Integer) check.getProps().get("unregistered");
        assertNotNull(reg);
        assertNotNull(unreg);
        assertEquals(new Integer(1), reg);
        assertEquals(new Integer(0), unreg);

        ci.stop();

        reg = (Integer) check.getProps().get("registered");
        unreg = (Integer) check.getProps().get("unregistered");
        assertNotNull(reg);
        assertNotNull(unreg);
        assertEquals(new Integer(1), reg);
        assertEquals(new Integer(0), unreg);
    }
View Full Code Here

        ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Callbacks-both");
        // Controller set to true.
        osgiHelper.waitForService(FooService.class.getName(), null, 5000);
        osgiHelper.waitForService(CheckService.class.getName(), null, 5000);

        CheckService check = (CheckService) osgiHelper.getServiceObject(CheckService.class.getName(), null);
        assertNotNull(check);

        Integer reg = (Integer) check.getProps().get("registered");
        Integer unreg = (Integer) check.getProps().get("unregistered");
        assertNotNull(reg);
        assertNotNull(unreg);
        assertEquals(new Integer(1), reg);
        assertEquals(new Integer(0), unreg);

        ci.stop();

        reg = (Integer) check.getProps().get("registered");
        unreg = (Integer) check.getProps().get("unregistered");
        assertNotNull(reg);
        assertNotNull(unreg);
        assertEquals(new Integer(1), reg);
        assertEquals(new Integer(1), unreg);
    }
View Full Code Here

        ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Callbacks-unreg-only");
        // Controller set to true.
        osgiHelper.waitForService(FooService.class.getName(), null, 5000);
        osgiHelper.waitForService(CheckService.class.getName(), null, 5000);

        CheckService check = (CheckService) osgiHelper.getServiceObject(CheckService.class.getName(), null);
        assertNotNull(check);

        Integer reg = (Integer) check.getProps().get("registered");
        Integer unreg = (Integer) check.getProps().get("unregistered");
        assertNotNull(reg);
        assertNotNull(unreg);
        assertEquals(new Integer(0), reg);
        assertEquals(new Integer(0), unreg);

        ci.stop();

        reg = (Integer) check.getProps().get("registered");
        unreg = (Integer) check.getProps().get("unregistered");
        assertNotNull(reg);
        assertNotNull(unreg);
        assertEquals(new Integer(0), reg);
        assertEquals(new Integer(1), unreg);
    }
View Full Code Here

        ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Callbacks-both-2");
        // Controller set to true.
        osgiHelper.waitForService(FooService.class.getName(), null, 5000);
        osgiHelper.waitForService(CheckService.class.getName(), null, 5000);

        CheckService check = (CheckService) osgiHelper.getServiceObject(CheckService.class.getName(), null);
        assertNotNull(check);

        Integer reg = (Integer) check.getProps().get("registered");
        Integer unreg = (Integer) check.getProps().get("unregistered");
        Integer reg2 = (Integer) check.getProps().get("registered2");
        Integer unreg2 = (Integer) check.getProps().get("unregistered2");
        assertNotNull(reg);
        assertNotNull(unreg);
        assertNotNull(reg2);
        assertNotNull(unreg2);
        assertEquals(new Integer(1), reg);
        assertEquals(new Integer(0), unreg);
        assertEquals(new Integer(1), reg2);
        assertEquals(new Integer(0), unreg2);

        ci.stop();

        reg = (Integer) check.getProps().get("registered");
        unreg = (Integer) check.getProps().get("unregistered");
        reg2 = (Integer) check.getProps().get("registered2");
        unreg2 = (Integer) check.getProps().get("unregistered2");
        assertNotNull(reg2);
        assertNotNull(unreg2);
        assertEquals(new Integer(1), reg);
        assertEquals(new Integer(1), unreg);
        assertEquals(new Integer(1), reg2);
View Full Code Here

        ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Callbacks-both-1");
        // Controller set to true.
        osgiHelper.waitForService(FooService.class.getName(), null, 5000);
        osgiHelper.waitForService(CheckService.class.getName(), null, 5000);

        CheckService check = (CheckService) osgiHelper.getServiceObject(CheckService.class.getName(), null);
        assertNotNull(check);

        Integer reg = (Integer) check.getProps().get("registered");
        Integer unreg = (Integer) check.getProps().get("unregistered");
        assertNotNull(reg);
        assertNotNull(unreg);
        assertEquals(new Integer(2), reg);
        assertEquals(new Integer(0), unreg);

        ci.stop();

        reg = (Integer) check.getProps().get("registered");
        unreg = (Integer) check.getProps().get("unregistered");
        assertEquals(new Integer(2), reg);
        assertEquals(new Integer(2), unreg);
    }
View Full Code Here

    @Test
    public void testConfigurationPrimitive() {
        ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance.getInstanceName());
        assertNotNull("Test check service availability", ref);
        CheckService check = (CheckService) osgiHelper.getRawServiceObject(ref);
        Properties props = check.getProps();

        Byte b = (Byte) props.get("b");
        Short s = (Short) props.get("s");
        Integer i = (Integer) props.get("i");
        Long l = (Long) props.get("l");
        Double d = (Double) props.get("d");
        Float f = (Float) props.get("f");
        Character c = (Character) props.get("c");
        Boolean bool = (Boolean) props.get("bool");

        assertEquals("Check b", b, new Byte("1"));
        assertEquals("Check s", s, new Short("1"));
        assertEquals("Check i", i, new Integer("1"));
        assertEquals("Check l", l, new Long("1"));
        assertEquals("Check d", d, new Double("1"));
        assertEquals("Check f", f, new Float("1"));
        assertEquals("Check c", c, new Character('a'));
        assertEquals("Check bool", bool, new Boolean("true"));

//        Integer upb = (Integer) props.get("upb");
//        Integer ups = (Integer) props.get("ups");
//        Integer upi = (Integer) props.get("upi");
//        Integer upl = (Integer) props.get("upl");
//        Integer upd = (Integer) props.get("upd");
//        Integer upf = (Integer) props.get("upf");
//        Integer upc = (Integer) props.get("upc");
//        Integer upbool = (Integer) props.get("upbool");
//       
//        assertEquals("Check upb", upb, new Integer(1));
//        assertEquals("Check ups", ups, new Integer(1));
//        assertEquals("Check upi", upi, new Integer(1));
//        assertEquals("Check upl", upl, new Integer(1));
//        assertEquals("Check upd", upd, new Integer(1));
//        assertEquals("Check upf", upf, new Integer(1));
//        assertEquals("Check upc", upc, new Integer(1));
//        assertEquals("Check upbool", upbool, new Integer(1));

        reconfigure(instance);

        ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance.getInstanceName());
        assertNotNull("Test check service availability", ref);
        check = (CheckService) osgiHelper.getRawServiceObject(ref);
        props = check.getProps();

        b = (Byte) props.get("b");
        s = (Short) props.get("s");
        i = (Integer) props.get("i");
        l = (Long) props.get("l");
View Full Code Here

TOP

Related Classes of org.apache.felix.ipojo.runtime.core.services.CheckService

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.