Package org.osgi.service.blueprint.container

Examples of org.osgi.service.blueprint.container.BlueprintContainer


        }
    }

    @Test
    public void testListReferences() throws Exception {
        BlueprintContainer blueprintContainer = getBlueprintContainerForBundle("org.apache.aries.blueprint.sample");
        assertNotNull(blueprintContainer);

        BindingListener listener = (BindingListener) blueprintContainer.getComponentInstance("listBindingListener");
        assertNull(listener.getA());
        assertNull(listener.getReference());

        List refs = (List) blueprintContainer.getComponentInstance("ref-list");
        assertNotNull(refs);
        assertTrue(refs.isEmpty());

        ServiceRegistration reg1 = bundleContext.registerService(InterfaceA.class.getName(), new InterfaceA() {
            public String hello(String msg) {
View Full Code Here


        testBlueprintContainer(bundleContext, bundle);
    }
   
   
    protected void testBlueprintContainer(BundleContext bc, Bundle bundle) throws Exception {
        BlueprintContainer blueprintContainer = getBlueprintContainerForBundle(
                bc == null ? bundleContext : bc, "org.apache.aries.blueprint.sample",
                DEFAULT_TIMEOUT);
        assertNotNull(blueprintContainer);

        Object obj = blueprintContainer.getComponentInstance("bar");
        assertNotNull(obj);
        assertEquals(Bar.class, obj.getClass());
        Bar bar = (Bar) obj;
        assertNotNull(bar.getContext());
        assertEquals("Hello FooBar", bar.getValue());
        assertNotNull(bar.getList());
        assertEquals(2, bar.getList().size());
        assertEquals("a list element", bar.getList().get(0));
        assertEquals(Integer.valueOf(5), bar.getList().get(1));
        obj = blueprintContainer.getComponentInstance("foo");
        assertNotNull(obj);
        assertEquals(Foo.class, obj.getClass());
        Foo foo = (Foo) obj;
        assertEquals(5, foo.getA());
        assertEquals(10, foo.getB());
        assertSame(bar, foo.getBar());
        assertEquals(Currency.getInstance("PLN"), foo.getCurrency());
        assertEquals(new SimpleDateFormat("yyyy.MM.dd").parse("2009.04.17"),
                foo.getDate());

        assertTrue(foo.isInitialized());
        assertFalse(foo.isDestroyed());

        obj = getOsgiService(bc == null ? bundleContext : bc, Foo.class, null, DEFAULT_TIMEOUT);
        assertNotNull(obj);
        assertEquals(obj, foo);
       
        obj = blueprintContainer.getComponentInstance("accountOne");
        assertNotNull(obj);
        Account account = (Account)obj;
        assertEquals(1, account.getAccountNumber());
    
        obj = blueprintContainer.getComponentInstance("accountTwo");
        assertNotNull(obj);
        account = (Account)obj;
        assertEquals(2, account.getAccountNumber());
       
        obj = blueprintContainer.getComponentInstance("accountThree");
        assertNotNull(obj);
        account = (Account)obj;
        assertEquals(3, account.getAccountNumber());
       
        obj = blueprintContainer.getComponentInstance("accountFactory");
        assertNotNull(obj);
        AccountFactory accountFactory = (AccountFactory)obj;
        assertEquals("account factory", accountFactory.getFactoryName());
       
        bundle.stop();
View Full Code Here

        testBlueprintContainer(bundleContext, bundle);
    }
   
   
    protected void testBlueprintContainer(BundleContext bc, Bundle bundle) throws Exception {
        BlueprintContainer blueprintContainer = getBlueprintContainerForBundle(
                bc == null ? bundleContext : bc, "org.apache.aries.blueprint.sample",
                5000);
        assertNotNull(blueprintContainer);

        Object obj = blueprintContainer.getComponentInstance("bar");
        assertNotNull(obj);
        assertEquals(Bar.class, obj.getClass());
        Bar bar = (Bar) obj;
        assertNotNull(bar.getContext());
        assertEquals("Hello FooBar", bar.getValue());
        assertNotNull(bar.getList());
        assertEquals(2, bar.getList().size());
        assertEquals("a list element", bar.getList().get(0));
        assertEquals(Integer.valueOf(5), bar.getList().get(1));
        obj = blueprintContainer.getComponentInstance("foo");
        assertNotNull(obj);
        assertEquals(Foo.class, obj.getClass());
        Foo foo = (Foo) obj;
        assertEquals(5, foo.getA());
        assertEquals(10, foo.getB());
View Full Code Here

        Bundle bundle = getInstalledBundle("org.apache.aries.blueprint.sample");
        assertNotNull(bundle);
        bundle.start();

        BlueprintContainer blueprintContainer = getBlueprintContainerForBundle("org.apache.aries.blueprint.sample", DEFAULT_TIMEOUT);
        assertNotNull(blueprintContainer);

        Foo foo = (Foo) blueprintContainer.getComponentInstance("none-managed");
        assertNotNull(foo);

        assertEquals(5, foo.getA());
        assertEquals(Currency.getInstance("PLN"), foo.getCurrency());
View Full Code Here

        Bundle bundle = getInstalledBundle("org.apache.aries.blueprint.sample");
        assertNotNull(bundle);
        bundle.start();

        BlueprintContainer blueprintContainer = getBlueprintContainerForBundle("org.apache.aries.blueprint.sample", DEFAULT_TIMEOUT);
        assertNotNull(blueprintContainer);

        Foo foo = (Foo) blueprintContainer.getComponentInstance("container-managed");
        assertNotNull(foo);

        assertEquals(5, foo.getA());
        assertEquals(Currency.getInstance("PLN"), foo.getCurrency());
View Full Code Here

        Bundle bundle = getInstalledBundle("org.apache.aries.blueprint.sample");
        assertNotNull(bundle);
        bundle.start();

        BlueprintContainer blueprintContainer = getBlueprintContainerForBundle("org.apache.aries.blueprint.sample", DEFAULT_TIMEOUT);
        assertNotNull(blueprintContainer);

        Foo foo = (Foo) blueprintContainer.getComponentInstance("component-managed");
        assertNotNull(foo);

        assertEquals(5, foo.getA());
        assertEquals(Currency.getInstance("PLN"), foo.getCurrency());
View Full Code Here

        Bundle bundle = getInstalledBundle("org.apache.aries.blueprint.sample");
        assertNotNull(bundle);
        bundle.start();

        BlueprintContainer blueprintContainer = getBlueprintContainerForBundle("org.apache.aries.blueprint.sample", DEFAULT_TIMEOUT);
        assertNotNull(blueprintContainer);

        Thread.sleep(5000);
    }
View Full Code Here

        assertNotNull(bundleb);
        bundleb.start();
       
        //bundleb's container will hold the beans we need to query to check the function
        //provided by bundlea functioned as expected
        BlueprintContainer beanContainer =
            getBlueprintContainerForBundle( bundleContext , "org.apache.aries.blueprint.testbundleb", DEFAULT_TIMEOUT);
        assertNotNull(beanContainer);

        //TestBeanA should have the values below, no interference should be present from other sources.
        Object obj1 = beanContainer.getComponentInstance("TestBeanA");
        assertTrue(obj1 instanceof TestBean);
        TestBean testBeanA = (TestBean)obj1;
        org.junit.Assert.assertEquals("RED", testBeanA.getRed());
        org.junit.Assert.assertEquals("GREEN", testBeanA.getGreen());
        org.junit.Assert.assertEquals("BLUE", testBeanA.getBlue());

        //TestBeanB tests that a custom ns handler is able to inject custom components to the blueprint,
        //and modify existing components, and use injected components as modifications.
        Object obj2 = beanContainer.getComponentInstance("TestBeanB");
        assertTrue(obj2 instanceof TestBean);
        TestBean testBeanB = (TestBean)obj2;
        //value should be set in via the added passthroughmetadata via the nshandler.
        org.junit.Assert.assertEquals("ONE_VALUE", testBeanB.getRed());
        org.junit.Assert.assertEquals("GREEN", testBeanB.getGreen());
        org.junit.Assert.assertEquals("BLUE", testBeanB.getBlue());       
       
        //TestBeanC tests that custom ns handlers can add interceptors to beans.
        Object obj3 = beanContainer.getComponentInstance("TestBeanC");
        assertTrue(obj3 instanceof TestBean);
        TestBean testBeanC = (TestBean)obj3;
      
        //handlers are in bundlea, with its own container.
        BlueprintContainer handlerContainer =
            getBlueprintContainerForBundle( bundleContext , "org.apache.aries.blueprint.testbundlea", DEFAULT_TIMEOUT);
        assertNotNull(handlerContainer);
       
        Object ns1 = handlerContainer.getComponentInstance("NSHandlerOne");
        assertTrue(ns1 instanceof NSHandlerOne);
       
        Object ns2 = handlerContainer.getComponentInstance("NSHandlerTwo");
        assertTrue(ns2 instanceof NSHandlerTwo);
        NSHandlerTwo nstwo = (NSHandlerTwo)ns2;
       
        //now we have a handle to the nshandler2, we can query what it 'saw', and ensure
        //that the interceptors are functioning as expected.
View Full Code Here

public class TestRegistrationListener extends AbstractIntegrationTest {

    @Test
    public void testWithAutoExportEnabled() throws Exception {

        BlueprintContainer blueprintContainer = getBlueprintContainerForBundle("org.apache.aries.blueprint.sample");
        assertNotNull(blueprintContainer);

        Foo foo = getOsgiService(Foo.class, "(" + BlueprintConstants.COMPONENT_NAME_PROPERTY + "=foo)", DEFAULT_TIMEOUT);
        assertEquals(5, foo.getA());

        FooRegistrationListener listener =
            (FooRegistrationListener) blueprintContainer.getComponentInstance("fooRegistrationListener");

        // If registration listener works fine, the registration method should
        // have already been called and properties that were passed to this
        // method should have been not null
View Full Code Here

@RunWith(JUnit4TestRunner.class)
public class BlueprintAnnotationTest extends AbstractIntegrationTest {

    @Test
    public void test() throws Exception {
        BlueprintContainer blueprintContainer = getBlueprintContainerForBundle(
                 bundleContext, "org.apache.aries.blueprint.sample-annotation",
                5000);

        assertNotNull(blueprintContainer);

        Object obj = blueprintContainer.getComponentInstance("bar");
        assertNotNull(obj);
        assertEquals(Bar.class, obj.getClass());
        Bar bar = (Bar) obj;
        assertEquals("Hello FooBar", bar.getValue());
       
        obj = blueprintContainer.getComponentInstance("foo");
        assertNotNull(obj);
        assertEquals(Foo.class, obj.getClass());
        Foo foo = (Foo) obj;
        assertEquals(5, foo.getA());
       // assertEquals(10, foo.getB());
View Full Code Here

TOP

Related Classes of org.osgi.service.blueprint.container.BlueprintContainer

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.