Package org.apache.felix.ipojo

Examples of org.apache.felix.ipojo.ServiceContext


        fact3.start();
    }

    @Test
    public void testFactoryManagementLevel2() {
        ServiceContext sc = getServiceContext(empty);
        Properties props = new Properties();
        props.put("instance.name", "under");
        ComponentInstance under = null;
        try {
            under = bar2Factory.createComponentInstance(props, sc);
        } catch (Exception e) {
            fail("Cannot instantiate under : " + e.getMessage());
        }
        assertTrue("Check instance validity - 1", under.getState() == ComponentInstance.VALID);
        ServiceContext sc2 = getServiceContext(under);

        ComponentFactory fact1 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-1");
        ComponentFactory fact2 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-2");
        ComponentFactory fact3 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-3");
View Full Code Here


        }
    }

    @Test
    public void testLevelOne3() {
        ServiceContext sc2 = getServiceContext(empty);

        Factory fact1 = ipojoHelper.getFactory("COMPO-SimpleCheckServiceProvider");
        Properties props = new Properties();
        props.put("instance.name", "client");
        ComponentInstance client = null;
        try {
            client = fact1.createComponentInstance(props, sc2);
        } catch (Exception e) {
            fail("Cannot instantiate the client : " + e.getMessage());
        }

        Factory fact2 = ipojoHelper.getFactory("COMPO-FooProviderType-1");
        Properties props2 = new Properties();
        props2.put("instance.name", "provider");
        ComponentInstance provider = null;
        try {
            provider = fact2.createComponentInstance(props2, sc2);
        } catch (Exception e) {
            fail("Cannot instantiate the provider : " + e.getMessage());
        }

        ServiceReference ref = sc2.getServiceReference(CheckService.class.getName());
        CheckService check = (CheckService) sc2.getService(ref);

        assertTrue("Check invocation", check.check());

        sc2.ungetService(ref);

        // Check visibility
        assertNotNull("Check foo service visible inside the composite", sc2.getServiceReference(FooService.class.getName()));
        assertNotNull("Check check service visible inside the composite", sc2.getServiceReference(CheckService.class.getName()));
        // Check invisibilty
        assertNull("Check foo service invisible inside the context", getContext().getServiceReference(FooService.class.getName()));
        try {
            assertNull("Check check service invisible inside the context", getContext().getServiceReferences(CheckService.class.getName(), "(instance.name=client)"));
        } catch (InvalidSyntaxException e) {
            fail("Invalid filter : " + e);
        }

        client.dispose();
        provider.dispose();

        assertNull("Check foo service visible inside the composite 2", sc2.getServiceReference(FooService.class.getName()));
        assertNull("Check check service visible inside the composite 2", sc2.getServiceReference(CheckService.class.getName()));
        assertNull("Check foo service invisible inside the global", getContext().getServiceReference(FooService.class.getName()));
        try {
            assertNull("Check check service invisible inside the context", getContext().getServiceReferences(CheckService.class.getName(), "(instance.name=client)"));
        } catch (InvalidSyntaxException e) {
            fail("Invalid filter : " + e);
View Full Code Here

            under = compoFactory.createComponentInstance(props);
        } catch (Exception e) {
            fail("Cannot instantiate under : " + e.getMessage());
        }
        assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
        ServiceContext sc = getServiceContext(under);

        assertNotNull("Check service availability", sc.getServiceReference(FooService.class.getName()));
        assertEquals("Check service provider", ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null).length,
                2);

        under.dispose();
    }
View Full Code Here

        under.dispose();
    }

    @Test
    public void testCreationLevel2() {
        ServiceContext sc = getServiceContext(empty);
        Properties props = new Properties();
        props.put("instance.name", "under");
        ComponentInstance under = null;
        try {
            under = compoFactory.createComponentInstance(props, sc);
View Full Code Here

        under.dispose();
    }

    @Test
    public void testServiceAvailabilityLevel2() {
        ServiceContext sc = getServiceContext(empty);
        Properties props = new Properties();
        props.put("instance.name", "under-X");
        ComponentInstance under = null;
        try {
            under = compoFactory.createComponentInstance(props, sc);
        } catch (Exception e) {
            fail("Cannot instantiate under : " + e.getMessage());
        }
        assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
        ServiceContext sc2 = getServiceContext(under);

        assertNotNull("Check service availability", sc2.getServiceReference(FooService.class.getName()));
        assertEquals("Check service providers", ipojoHelper.getServiceReferences(sc2, FooService.class.getName(),
                null).length, 2);

        under.dispose();
    }
View Full Code Here

        fooFactory2.start();
    }

    @Test
    public void testFactoryManagementLevel2() {
        ServiceContext sc = getServiceContext(empty);
        Properties props = new Properties();
        props.put("instance.name", "under");
        ComponentInstance under = null;
        try {
            under = compoFactory.createComponentInstance(props, sc);
View Full Code Here

        }
    }

    @Test
    public void testLevelTwo1() {
        ServiceContext sc1 = getServiceContext(empty);
        Factory fact = ipojoHelper.getFactory(sc1, "composite.empty");
        Properties p = new Properties();
        p.put("instance.name", "empty2");
        ComponentInstance empty2 = null;
        try {
            empty2 = fact.createComponentInstance(p);
        } catch (Exception e) {
            fail("Cannot instantiate empty2 instance : " + e.getMessage());
        }

        ServiceContext sc2 = getServiceContext(empty2);

        Factory fact1 = ipojoHelper.getFactory(sc2, "COMPO-SimpleCheckServiceProvider");
        Properties props = new Properties();
        props.put("instance.name", "client");
        ComponentInstance client = null;
        try {
            client = fact1.createComponentInstance(props);
        } catch (Exception e) {
            fail("Cannot instantiate the client : " + e.getMessage());
        }

        Factory fact2 = ipojoHelper.getFactory(sc2, "COMPO-FooProviderType-1");
        Properties props2 = new Properties();
        props2.put("instance.name", "provider");
        ComponentInstance provider = null;
        try {
            provider = fact2.createComponentInstance(props2);
        } catch (Exception e) {
            fail("Cannot instantiate the provider : " + e.getMessage());
        }

        ServiceReference ref = sc2.getServiceReference(CheckService.class.getName());
        CheckService check = (CheckService) sc2.getService(ref);

        assertTrue("Check invocation", check.check());

        sc2.ungetService(ref);

        //  Check visibility
        assertNotNull("Check foo service visible inside the composite 2", sc2.getServiceReference(FooService.class.getName()));
        assertNotNull("Check check service visible inside the composite 2", sc2.getServiceReference(CheckService.class.getName()));
        // Check invisibilty
        assertNull("Check foo service invisible inside the composite 1", sc1.getServiceReference(FooService.class.getName()));
        assertNull("Check check service invisible inside the composite 1", sc1.getServiceReference(CheckService.class.getName()));
        assertNull("Check foo service invisible inside the global", getContext().getServiceReference(FooService.class.getName()));
        try {
            assertNull("Check check service invisible inside the context", getContext().getServiceReferences(CheckService.class.getName(), "(instance.name=client)"));
        } catch (InvalidSyntaxException e) {
            fail("Invalid filter : " + e);
        }

        client.dispose();
        provider.dispose();

        assertNull("Check foo service visible inside the composite 2", sc2.getServiceReference(FooService.class.getName()));
        assertNull("Check check service visible inside the composite 2", sc2.getServiceReference(CheckService.class.getName()));
        assertNull("Check foo service invisible inside the composite 1", sc1.getServiceReference(FooService.class.getName()));
        assertNull("Check check service invisible inside the composite 1", sc1.getServiceReference(CheckService.class.getName()));
        assertNull("Check foo service invisible inside the global", getContext().getServiceReference(FooService.class.getName()));
        try {
            assertNull("Check check service invisible inside the context", getContext().getServiceReferences(CheckService.class.getName(), "(instance.name=client)"));
View Full Code Here

        empty2.dispose();
    }

    @Test
    public void testLevelTwo2() {
        ServiceContext sc1 = getServiceContext(empty);
        Factory fact = ipojoHelper.getFactory(sc1, "composite.empty");
        Properties p = new Properties();
        p.put("instance.name", "empty2");
        ComponentInstance empty2 = null;
        try {
            empty2 = fact.createComponentInstance(p);
        } catch (Exception e) {
            fail("Cannot instantiate empty2 instance : " + e.getMessage());
        }

        ServiceContext sc2 = getServiceContext(empty2);

        Factory fact1 = ipojoHelper.getFactory(sc1, "COMPO-SimpleCheckServiceProvider");
        Properties props = new Properties();
        props.put("instance.name", "client");
        ComponentInstance client = null;
        try {
            client = fact1.createComponentInstance(props, sc2);
        } catch (Exception e) {
            fail("Cannot instantiate the client : " + e.getMessage());
        }

        Factory fact2 = ipojoHelper.getFactory(sc1, "COMPO-FooProviderType-1");
        Properties props2 = new Properties();
        props2.put("instance.name", "provider");
        ComponentInstance provider = null;
        try {
            provider = fact2.createComponentInstance(props2, sc2);
        } catch (Exception e) {
            fail("Cannot instantiate the provider : " + e.getMessage());
        }

        ServiceReference ref = sc2.getServiceReference(CheckService.class.getName());
        CheckService check = (CheckService) sc2.getService(ref);

        assertTrue("Check invocation", check.check());

        sc2.ungetService(ref);

        //  Check visibility
        assertNotNull("Check foo service visible inside the composite 2", sc2.getServiceReference(FooService.class.getName()));
        assertNotNull("Check check service visible inside the composite 2", sc2.getServiceReference(CheckService.class.getName()));
        // Check invisibilty
        assertNull("Check foo service invisible inside the composite 1", sc1.getServiceReference(FooService.class.getName()));
        assertNull("Check check service invisible inside the composite 1", sc1.getServiceReference(CheckService.class.getName()));
        assertNull("Check foo service invisible inside the global", getContext().getServiceReference(FooService.class.getName()));
        try {
            assertNull("Check check service invisible inside the context", getContext().getServiceReferences(CheckService.class.getName(), "(instance.name=client)"));
        } catch (InvalidSyntaxException e) {
            fail("Invalid filter : " + e);
        }

        client.dispose();
        provider.dispose();

        assertNull("Check foo service visible inside the composite 2", sc2.getServiceReference(FooService.class.getName()));
        assertNull("Check check service visible inside the composite 2", sc2.getServiceReference(CheckService.class.getName()));
        assertNull("Check foo service invisible inside the composite 1", sc1.getServiceReference(FooService.class.getName()));
        assertNull("Check check service invisible inside the composite 1", sc1.getServiceReference(CheckService.class.getName()));
        assertNull("Check foo service invisible inside the global", getContext().getServiceReference(FooService.class.getName()));
        try {
            assertNull("Check check service invisible inside the context", getContext().getServiceReferences(CheckService.class.getName(), "(instance.name=client)"));
View Full Code Here

        empty2.dispose();
    }

    @Test
    public void testLevelTwo3() {
        ServiceContext sc1 = getServiceContext(empty);
        Factory fact = ipojoHelper.getFactory(sc1, "composite.empty");
        Properties p = new Properties();
        p.put("instance.name", "empty2");
        ComponentInstance empty2 = null;
        try {
            empty2 = fact.createComponentInstance(p);
        } catch (Exception e) {
            fail("Cannot instantiate empty2 instance : " + e.getMessage());
        }

        ServiceContext sc2 = getServiceContext(empty2);

        Factory fact1 = ipojoHelper.getFactory("COMPO-SimpleCheckServiceProvider");
        Properties props = new Properties();
        props.put("instance.name", "client");
        ComponentInstance client = null;
        try {
            client = fact1.createComponentInstance(props, sc2);
        } catch (Exception e) {
            fail("Cannot instantiate the client : " + e.getMessage());
        }

        Factory fact2 = ipojoHelper.getFactory("COMPO-FooProviderType-1");
        Properties props2 = new Properties();
        props2.put("instance.name", "provider");
        ComponentInstance provider = null;
        try {
            provider = fact2.createComponentInstance(props2, sc2);
        } catch (Exception e) {
            fail("Cannot instantiate the provider : " + e.getMessage());
        }

        ServiceReference ref = sc2.getServiceReference(CheckService.class.getName());
        CheckService check = (CheckService) sc2.getService(ref);

        assertTrue("Check invocation", check.check());

        sc2.ungetService(ref);

        //  Check visibility
        assertNotNull("Check foo service visible inside the composite 2", sc2.getServiceReference(FooService.class.getName()));
        assertNotNull("Check check service visible inside the composite 2", sc2.getServiceReference(CheckService.class.getName()));
        // Check invisibilty
        assertNull("Check foo service invisible inside the composite 1", sc1.getServiceReference(FooService.class.getName()));
        assertNull("Check check service invisible inside the composite 1", sc1.getServiceReference(CheckService.class.getName()));
        assertNull("Check foo service invisible inside the global", getContext().getServiceReference(FooService.class.getName()));
        try {
            assertNull("Check check service invisible inside the context", getContext().getServiceReferences(CheckService.class.getName(), "(instance.name=client)"));
        } catch (InvalidSyntaxException e) {
            fail("Invalid filter : " + e);
        }

        client.dispose();
        provider.dispose();

        assertNull("Check foo service visible inside the composite 2", sc2.getServiceReference(FooService.class.getName()));
        assertNull("Check check service visible inside the composite 2", sc2.getServiceReference(CheckService.class.getName()));
        assertNull("Check foo service invisible inside the composite 1", sc1.getServiceReference(FooService.class.getName()));
        assertNull("Check check service invisible inside the composite 1", sc1.getServiceReference(CheckService.class.getName()));
        assertNull("Check foo service invisible inside the global", getContext().getServiceReference(FooService.class.getName()));
        try {
            assertNull("Check check service invisible inside the context", getContext().getServiceReferences(CheckService.class.getName(), "(instance.name=client)"));
View Full Code Here

        empty2.dispose();
    }

    @Test
    public void testLevelTwo4() {
        ServiceContext sc1 = getServiceContext(empty);
        Factory fact = ipojoHelper.getFactory(sc1, "composite.empty");
        Properties p = new Properties();
        p.put("instance.name", "empty2");
        ComponentInstance empty2 = null;
        try {
            empty2 = fact.createComponentInstance(p);
        } catch (Exception e) {
            fail("Cannot instantiate empty2 instance : " + e.getMessage());
        }

        ServiceContext sc2 = getServiceContext(empty2);

        Factory fact1 = ipojoHelper.getFactory(sc2, "COMPO-SimpleCheckServiceProvider");
        Properties props = new Properties();
        props.put("instance.name", "client");
        ComponentInstance client = null;
        try {
            client = fact1.createComponentInstance(props, sc2);
        } catch (Exception e) {
            fail("Cannot instantiate the client : " + e.getMessage());
        }

        Factory fact2 = ipojoHelper.getFactory(sc2, "COMPO-FooProviderType-1");
        Properties props2 = new Properties();
        props2.put("instance.name", "provider");
        ComponentInstance provider = null;
        try {
            provider = fact2.createComponentInstance(props2, sc2);
        } catch (Exception e) {
            fail("Cannot instantiate the provider : " + e.getMessage());
        }

        ServiceReference ref = sc2.getServiceReference(CheckService.class.getName());
        CheckService check = (CheckService) sc2.getService(ref);

        assertTrue("Check invocation", check.check());

        sc2.ungetService(ref);

        //  Check visibility
        assertNotNull("Check foo service visible inside the composite 2", sc2.getServiceReference(FooService.class.getName()));
        assertNotNull("Check check service visible inside the composite 2", sc2.getServiceReference(CheckService.class.getName()));
        // Check invisibilty
        assertNull("Check foo service invisible inside the composite 1", sc1.getServiceReference(FooService.class.getName()));
        assertNull("Check check service invisible inside the composite 1", sc1.getServiceReference(CheckService.class.getName()));
        assertNull("Check foo service invisible inside the global", getContext().getServiceReference(FooService.class.getName()));
        try {
            assertNull("Check check service invisible inside the context", getContext().getServiceReferences(CheckService.class.getName(), "(instance.name=client)"));
        } catch (InvalidSyntaxException e) {
            fail("Invalid filter : " + e);
        }

        client.dispose();
        provider.dispose();

        assertNull("Check foo service visible inside the composite 2", sc2.getServiceReference(FooService.class.getName()));
        assertNull("Check check service visible inside the composite 2", sc2.getServiceReference(CheckService.class.getName()));
        assertNull("Check foo service invisible inside the composite 1", sc1.getServiceReference(FooService.class.getName()));
        assertNull("Check check service invisible inside the composite 1", sc1.getServiceReference(CheckService.class.getName()));
        assertNull("Check foo service invisible inside the global", getContext().getServiceReference(FooService.class.getName()));
        try {
            assertNull("Check check service invisible inside the context", getContext().getServiceReferences(CheckService.class.getName(), "(instance.name=client)"));
View Full Code Here

TOP

Related Classes of org.apache.felix.ipojo.ServiceContext

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.