Search in sources :

Example 1 with InterfaceD

use of org.apache.aries.blueprint.testbundlea.multi.InterfaceD in project aries by apache.

the class MultiInterfacesTest method testMultiInterfaceReferences.

@Test
public void testMultiInterfaceReferences() throws Exception {
    //bundlea provides the ns handlers, bean processors, interceptors etc for this test.
    startBundleBlueprint("org.apache.aries.blueprint.testbundlea");
    //bundleb makes use of the extensions provided by bundlea
    //bundleb's container will hold the beans we need to query to check the function
    //provided by bundlea functioned as expected
    BlueprintContainer beanContainer = startBundleBlueprint("org.apache.aries.blueprint.testbundleb");
    Object obj1 = beanContainer.getComponentInstance("OnlyA");
    Object obj2 = beanContainer.getComponentInstance("AandB");
    Object obj3 = beanContainer.getComponentInstance("AandBandC");
    Object obj4 = beanContainer.getComponentInstance("AandBandCandD");
    assertEquals("A", ((InterfaceA) obj1).methodA());
    assertEquals("A", ((InterfaceA) obj2).methodA());
    assertEquals("A", ((InterfaceA) obj3).methodA());
    assertEquals("B", ((InterfaceB) obj2).methodB());
    assertEquals("C", ((InterfaceC) obj3).methodC());
    assertFalse(obj1 instanceof InterfaceC);
    assertFalse(obj2 instanceof InterfaceC);
    assertFalse(obj1 instanceof InterfaceB);
    assertTrue(obj4 instanceof InterfaceD);
    try {
        ((InterfaceD) obj4).methodD();
        fail("This should not work");
    } catch (org.osgi.service.blueprint.container.ServiceUnavailableException t) {
    //expected
    }
}
Also used : BlueprintContainer(org.osgi.service.blueprint.container.BlueprintContainer) InterfaceC(org.apache.aries.blueprint.testbundlea.multi.InterfaceC) InterfaceD(org.apache.aries.blueprint.testbundlea.multi.InterfaceD) InterfaceB(org.apache.aries.blueprint.testbundlea.multi.InterfaceB) Test(org.junit.Test)

Aggregations

InterfaceB (org.apache.aries.blueprint.testbundlea.multi.InterfaceB)1 InterfaceC (org.apache.aries.blueprint.testbundlea.multi.InterfaceC)1 InterfaceD (org.apache.aries.blueprint.testbundlea.multi.InterfaceD)1 Test (org.junit.Test)1 BlueprintContainer (org.osgi.service.blueprint.container.BlueprintContainer)1