Search in sources :

Example 6 with DependencyHandlerDescription

use of org.apache.felix.ipojo.handlers.dependency.DependencyHandlerDescription in project felix by apache.

the class TestDependencyIdDetection method testAddAndRemoveMethods.

@Test
public void testAddAndRemoveMethods() {
    ComponentInstance instance = ipojoHelper.createComponentInstance(factory);
    DependencyHandlerDescription dh = (DependencyHandlerDescription) instance.getInstanceDescription().getHandlerDescription("org.apache.felix.ipojo:requires");
    DependencyDescription dd = findDependencyById(dh, "MyService");
    assertThat(dd).isNotNull();
    DependencyCallback[] callbacks = dd.getDependency().getDependencyCallbacks();
    assertThat(callbacks).isNotNull();
    DependencyCallback bind = getBindCallback(callbacks);
    DependencyCallback unbind = getUnbindCallback(callbacks);
    assertThat(bind).isNotNull();
    assertThat(unbind).isNotNull();
    assertThat(bind.getMethodName()).isEqualTo("addMyService");
    assertThat(unbind.getMethodName()).isEqualTo("removeMyService");
}
Also used : DependencyCallback(org.apache.felix.ipojo.handlers.dependency.DependencyCallback) DependencyHandlerDescription(org.apache.felix.ipojo.handlers.dependency.DependencyHandlerDescription) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) DependencyDescription(org.apache.felix.ipojo.handlers.dependency.DependencyDescription) Test(org.junit.Test)

Example 7 with DependencyHandlerDescription

use of org.apache.felix.ipojo.handlers.dependency.DependencyHandlerDescription in project felix by apache.

the class TestDependencyIdDetection method testSetAndUnSetMethods.

@Test
public void testSetAndUnSetMethods() {
    ComponentInstance instance = ipojoHelper.createComponentInstance(factory);
    DependencyHandlerDescription dh = (DependencyHandlerDescription) instance.getInstanceDescription().getHandlerDescription("org.apache.felix.ipojo:requires");
    DependencyDescription dd = findDependencyById(dh, "MyOtherService");
    assertThat(dd).isNotNull();
    DependencyCallback[] callbacks = dd.getDependency().getDependencyCallbacks();
    assertThat(callbacks).isNotNull();
    DependencyCallback bind = getBindCallback(callbacks);
    DependencyCallback unbind = getUnbindCallback(callbacks);
    assertThat(bind).isNotNull();
    assertThat(unbind).isNotNull();
    assertThat(bind.getMethodName()).isEqualTo("setMyOtherService");
    assertThat(unbind.getMethodName()).isEqualTo("unsetMyOtherService");
}
Also used : DependencyCallback(org.apache.felix.ipojo.handlers.dependency.DependencyCallback) DependencyHandlerDescription(org.apache.felix.ipojo.handlers.dependency.DependencyHandlerDescription) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) DependencyDescription(org.apache.felix.ipojo.handlers.dependency.DependencyDescription) Test(org.junit.Test)

Example 8 with DependencyHandlerDescription

use of org.apache.felix.ipojo.handlers.dependency.DependencyHandlerDescription in project felix by apache.

the class VersionConflictTest method deployBundlesAtRuntime.

@Test
public void deployBundlesAtRuntime() throws MalformedURLException, BundleException, InvalidSyntaxException {
    if (isKF()) {
        System.out.println("Test disabled on knopflerfish");
        return;
    }
    Bundle b1 = context.installBundle(context.getProperty("url1"));
    b1.start();
    Bundle b3 = context.installBundle(context.getProperty("c1"));
    b3.start();
    Bundle b2 = context.installBundle(context.getProperty("url2"));
    b2.start();
    Bundle b4 = context.installBundle(context.getProperty("c2"));
    b4.start();
    Bundle b5 = context.installBundle(context.getProperty("cons"));
    b5.start();
    Stability.waitForStability(bc);
    Bundle[] bundles = context.getBundles();
    for (Bundle bundle : bundles) {
        System.out.println("bundle " + bundle.getSymbolicName() + " : " + (bundle.getState() == Bundle.ACTIVE));
    // Assert.assertEquals(bundles[i].getSymbolicName() + " is not active", Bundle.ACTIVE, bundles[i].getState());
    }
    // Bundle consBundle = osgiHelper.getBundle("MyCons");
    // BundleWiring wiring = consBundle.adapt(BundleWiring.class);
    // System.out.println("Bundle Wiring req: ");
    // for (BundleWire wire : wiring.getRequiredWires(null)) {
    // System.out.println(wire.getCapability().getAttributes() + " - " + wire.getCapability().getDirectives());
    // }
    osgiHelper.waitForService(Architecture.class.getName(), "(architecture.instance=mycons)", 2000);
    // Check that the two services are provided.
    ServiceReference[] refs = context.getAllServiceReferences("org.apache.felix.ipojo.core.tests.services.MyService", null);
    Assert.assertNotNull(refs);
    Assert.assertEquals(2, refs.length);
    ServiceReference refv1 = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "mycons");
    Assert.assertNotNull(refv1);
    Architecture arch = (Architecture) osgiHelper.getRawServiceObject(refv1);
    HandlerDescription desc = arch.getInstanceDescription().getHandlerDescription("org.apache.felix.ipojo:requires");
    Assert.assertNotNull(desc);
    DependencyHandlerDescription d = (DependencyHandlerDescription) desc;
    Assert.assertNotNull(d.getDependencies());
    Assert.assertEquals(1, d.getDependencies().length);
    DependencyDescription dep = d.getDependencies()[0];
    Assert.assertEquals(Dependency.RESOLVED, dep.getState());
    Assert.assertEquals(1, dep.getServiceReferences().size());
    ServiceReference r = dep.getServiceReferences().get(0);
    Assert.assertEquals("provider", r.getProperty("factory.name"));
    Assert.assertEquals("2.0", r.getProperty("factory.version"));
}
Also used : DependencyHandlerDescription(org.apache.felix.ipojo.handlers.dependency.DependencyHandlerDescription) Architecture(org.apache.felix.ipojo.architecture.Architecture) HandlerDescription(org.apache.felix.ipojo.architecture.HandlerDescription) DependencyHandlerDescription(org.apache.felix.ipojo.handlers.dependency.DependencyHandlerDescription) DependencyDescription(org.apache.felix.ipojo.handlers.dependency.DependencyDescription) Test(org.junit.Test)

Example 9 with DependencyHandlerDescription

use of org.apache.felix.ipojo.handlers.dependency.DependencyHandlerDescription in project felix by apache.

the class VersionConflictTest method deployBundlesAtRuntimeV1.

@Test
@Ignore("Does not work anymore, but the scenario runs as expected in a regular framework. The check find the " + "version 2.0 of the service instead of the 1.0")
public void deployBundlesAtRuntimeV1() throws MalformedURLException, BundleException, InvalidSyntaxException {
    Bundle b1 = context.installBundle(context.getProperty("url1"));
    b1.start();
    Bundle b3 = context.installBundle(context.getProperty("c1"));
    b3.start();
    Bundle b2 = context.installBundle(context.getProperty("url2"));
    b2.start();
    Bundle b4 = context.installBundle(context.getProperty("c2"));
    b4.start();
    Bundle b5 = context.installBundle(context.getProperty("consV1"));
    b5.start();
    Bundle[] bundles = context.getBundles();
    for (int i = 0; i < bundles.length; i++) {
        System.out.println("bundle " + bundles[i].getSymbolicName() + " : " + (bundles[i].getState() == Bundle.ACTIVE));
    }
    osgiHelper.waitForService(Architecture.class.getName(), "(architecture.instance=mycons)", 2000);
    // Check that the two services are provided.
    ServiceReference[] refs = context.getAllServiceReferences("org.apache.felix.ipojo.core.tests.services.MyService", null);
    Assert.assertNotNull(refs);
    Assert.assertEquals(2, refs.length);
    ServiceReference refv1 = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "mycons");
    Assert.assertNotNull(refv1);
    Architecture arch = (Architecture) osgiHelper.getRawServiceObject(refv1);
    HandlerDescription desc = arch.getInstanceDescription().getHandlerDescription("org.apache.felix.ipojo:requires");
    Assert.assertNotNull(desc);
    DependencyHandlerDescription d = (DependencyHandlerDescription) desc;
    Assert.assertNotNull(d.getDependencies());
    Assert.assertEquals(1, d.getDependencies().length);
    DependencyDescription dep = d.getDependencies()[0];
    Assert.assertEquals(Dependency.RESOLVED, dep.getState());
    Assert.assertEquals(1, dep.getServiceReferences().size());
    ServiceReference r = dep.getServiceReferences().get(0);
    Assert.assertEquals("provider", r.getProperty("factory.name"));
    Assert.assertEquals("1.0", r.getProperty("factory.version"));
}
Also used : DependencyHandlerDescription(org.apache.felix.ipojo.handlers.dependency.DependencyHandlerDescription) Architecture(org.apache.felix.ipojo.architecture.Architecture) HandlerDescription(org.apache.felix.ipojo.architecture.HandlerDescription) DependencyHandlerDescription(org.apache.felix.ipojo.handlers.dependency.DependencyHandlerDescription) DependencyDescription(org.apache.felix.ipojo.handlers.dependency.DependencyDescription) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 10 with DependencyHandlerDescription

use of org.apache.felix.ipojo.handlers.dependency.DependencyHandlerDescription in project felix by apache.

the class TestDependencyArchitecture method testProxiedSimpleDependency.

@Test
public void testProxiedSimpleDependency() {
    ServiceReference arch_dep = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance5.getInstanceName());
    assertNotNull("Check architecture availability", arch_dep);
    PrimitiveInstanceDescription id_dep = (PrimitiveInstanceDescription) ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
    assertTrue("Check instance invalidity - 1", id_dep.getState() == ComponentInstance.INVALID);
    // Check dependency handler invalidity
    DependencyHandlerDescription dhd = getDependencyDesc(id_dep);
    assertFalse("Check dependency handler invalidity", dhd.isValid());
    // Check dependency metadata
    assertEquals("Check dependency interface", dhd.getDependencies()[0].getInterface(), FooService.class.getName());
    assertEquals("Check dependency id", dhd.getDependencies()[0].getId(), FooService.class.getName());
    assertFalse("Check dependency cardinality", dhd.getDependencies()[0].isMultiple());
    assertFalse("Check dependency optionality", dhd.getDependencies()[0].isOptional());
    assertNull("Check dependency ref -1", dhd.getDependencies()[0].getServiceReferences());
    assertTrue("Check dependency proxy", dhd.getDependencies()[0].isProxy());
    fooProvider1.start();
    ServiceReference arch_ps = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), fooProvider1.getInstanceName());
    assertNotNull("Check architecture availability", arch_ps);
    PrimitiveInstanceDescription id_ps = (PrimitiveInstanceDescription) ((Architecture) osgiHelper.getRawServiceObject(arch_ps)).getInstanceDescription();
    assertTrue("Check instance invalidity - 1", id_ps.getState() == ComponentInstance.VALID);
    // id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
    assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
    dhd = getDependencyDesc(id_dep);
    assertTrue("Check dependency handler validity", dhd.isValid());
    assertEquals("Check dependency ref - 2 ", dhd.getDependencies()[0].getServiceReferences().size(), 1);
    ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance5.getInstanceName());
    assertNotNull("Check CheckService availability", cs_ref);
    CheckService cs = (CheckService) osgiHelper.getRawServiceObject(cs_ref);
    assertTrue("check CheckService invocation", cs.check());
    // Check object graph
    // id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
    dhd = getDependencyDesc(id_dep);
    // id_ps = ((Architecture) osgiHelper.getRawServiceObject(arch_ps)).getInstanceDescription();
    ProvidedServiceHandlerDescription psh = getPSDesc(id_ps);
    assertEquals("Check POJO creation", id_ps.getCreatedObjects().length, 1);
    fooProvider1.stop();
    // id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
    assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.INVALID);
    dhd = getDependencyDesc(id_dep);
    assertFalse("Check dependency handler invalidity", dhd.isValid());
    fooProvider1.start();
    // id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
    dhd = getDependencyDesc(id_dep);
    arch_ps = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), fooProvider1.getInstanceName());
    assertNotNull("Check architecture availability", arch_ps);
    // id_ps = ((Architecture) osgiHelper.getRawServiceObject(arch_ps)).getInstanceDescription();
    assertTrue("Check instance invalidity - 1", id_ps.getState() == ComponentInstance.VALID);
    psh = getPSDesc(id_ps);
    assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
    assertTrue("Check dependency handler validity", dhd.isValid());
    assertEquals("Check dependency ref -3", dhd.getDependencies()[0].getServiceReferences().size(), 1);
    cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance5.getInstanceName());
    assertNotNull("Check CheckService availability", cs_ref);
    cs = (CheckService) osgiHelper.getRawServiceObject(cs_ref);
    assertTrue("check CheckService invocation", cs.check());
    // Check object graph
    // id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
    dhd = getDependencyDesc(id_dep);
    // id_ps = ((Architecture) osgiHelper.getRawServiceObject(arch_ps)).getInstanceDescription();
    psh = getPSDesc(id_ps);
    fooProvider1.stop();
    // id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
    assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.INVALID);
    dhd = getDependencyDesc(id_dep);
    assertFalse("Check dependency handler invalidity", dhd.isValid());
    id_dep = null;
    cs = null;
    getContext().ungetService(arch_dep);
    getContext().ungetService(cs_ref);
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.test.services.FooService) DependencyHandlerDescription(org.apache.felix.ipojo.handlers.dependency.DependencyHandlerDescription) Architecture(org.apache.felix.ipojo.architecture.Architecture) CheckService(org.apache.felix.ipojo.runtime.core.test.services.CheckService) ProvidedServiceHandlerDescription(org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandlerDescription) PrimitiveInstanceDescription(org.apache.felix.ipojo.PrimitiveInstanceDescription) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Aggregations

DependencyHandlerDescription (org.apache.felix.ipojo.handlers.dependency.DependencyHandlerDescription)18 Test (org.junit.Test)16 DependencyDescription (org.apache.felix.ipojo.handlers.dependency.DependencyDescription)14 ComponentInstance (org.apache.felix.ipojo.ComponentInstance)9 Architecture (org.apache.felix.ipojo.architecture.Architecture)7 PrimitiveInstanceDescription (org.apache.felix.ipojo.PrimitiveInstanceDescription)5 ProvidedServiceHandlerDescription (org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandlerDescription)5 CheckService (org.apache.felix.ipojo.runtime.core.test.services.CheckService)5 FooService (org.apache.felix.ipojo.runtime.core.test.services.FooService)5 ServiceReference (org.osgi.framework.ServiceReference)5 Properties (java.util.Properties)4 HandlerDescription (org.apache.felix.ipojo.architecture.HandlerDescription)2 DependencyCallback (org.apache.felix.ipojo.handlers.dependency.DependencyCallback)2 Ignore (org.junit.Ignore)1