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

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


        if (m_specifications == null) {
            return null;
        } else {
            for (int j = 0; j < pss.length; j++) {
                ProvidedServiceDescription psd = pss[j];
                List specs = Arrays.asList(psd.getServiceSpecifications());
                if (specs.containsAll(m_specifications)) {
                    return psd;
                }
            }
        }
View Full Code Here


    @Test
    public void testProvidedServiceListener() {
        ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Controller-1-default");
        ProvidedServiceHandlerDescription pshd = (ProvidedServiceHandlerDescription) ci.getInstanceDescription()
                .getHandlerDescription("org.apache.felix.ipojo:provides");
        ProvidedServiceDescription ps = getPS(FooService.class.getName(), pshd.getProvidedServices());

        // 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
        assertEquals(2, registrations);
        assertEquals(2, unregistrations);
        assertEquals(1, updates);
        assertEquals(5, total);
View Full Code Here

    @Test(expected = NullPointerException.class)
    public void testNullProvidedServiceListener() {
        ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Controller-1-default");
        ProvidedServiceHandlerDescription pshd = (ProvidedServiceHandlerDescription) ci.getInstanceDescription()
                .getHandlerDescription("org.apache.felix.ipojo:provides");
        ProvidedServiceDescription ps = getPS(FooService.class.getName(), pshd.getProvidedServices());

        // Should fail!
        ps.addListener(null);
    }
View Full Code Here

    @Test(expected = NoSuchElementException.class)
    public void testRemoveNonexistentProvidedServiceListener() {
        ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Controller-1-default");
        ProvidedServiceHandlerDescription pshd = (ProvidedServiceHandlerDescription) ci.getInstanceDescription()
                .getHandlerDescription("org.apache.felix.ipojo:provides");
        ProvidedServiceDescription ps = getPS(FooService.class.getName(), pshd.getProvidedServices());

        // Should fail!
        ps.removeListener(new ThrowingListener());
    }
View Full Code Here

        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) osgiHelper.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

       
        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

TOP

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

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.