Search in sources :

Example 1 with BazService

use of org.apache.felix.ipojo.runtime.core.services.BazService in project felix by apache.

the class TestCompositeAPI method testInstantiator.

@Test
public void testInstantiator() {
    String type = "composite.instantiator";
    Factory fact = ipojoHelper.getFactory(type);
    ComponentInstance ci = null;
    Properties p = new Properties();
    p.put("instance.name", "mon_coeur");
    try {
        ci = fact.createComponentInstance(p);
    } catch (Exception e) {
        e.printStackTrace();
    }
    assertTrue("Check ci", ci.getState() == ComponentInstance.VALID);
    ServiceReference ref = ipojoHelper.getServiceReferenceByName(BazService.class.getName(), "mon_coeur");
    assertNotNull("Check ref", ref);
    BazService bs = (BazService) getContext().getService(ref);
    assertTrue("Check invocation", bs.foo());
    getContext().ungetService(ref);
    ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "mon_coeur");
    assertNotNull("Check ref 2 ", ref);
    FooService fs = (FooService) getContext().getService(ref);
    assertTrue("Check invocation", fs.foo());
    getContext().ungetService(ref);
    ci.dispose();
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) BazService(org.apache.felix.ipojo.runtime.core.services.BazService) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) Factory(org.apache.felix.ipojo.Factory) Properties(java.util.Properties) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 2 with BazService

use of org.apache.felix.ipojo.runtime.core.services.BazService in project felix by apache.

the class TestNativeMethod method testComponentWithNativeMethod.

@Test
public void testComponentWithNativeMethod() {
    if (isKnopflerfish()) {
        System.out.println("Test not supported on knopflerfish");
        return;
    }
    ComponentInstance ci = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.runtime.core.components" + ".nativ.NativeComponent");
    BazService baz = osgiHelper.getServiceObject(BazService.class, "(instance.name=" + ci.getInstanceName() + ")");
    assertEquals("foo: Test program of JNI.", baz.hello(""));
}
Also used : BazService(org.apache.felix.ipojo.runtime.core.services.BazService) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) Test(org.junit.Test) BaseTest(org.ow2.chameleon.testing.helpers.BaseTest)

Example 3 with BazService

use of org.apache.felix.ipojo.runtime.core.services.BazService in project felix by apache.

the class TestStereotypeAnnotation method testTypeStereotype.

@Test
public void testTypeStereotype() {
    // verify component's factory is here
    // verify BazService has been published
    // --> verify instance has been created
    Factory factory = ipojoHelper.getFactory(BAZ_FACTORY_NAME);
    Assert.assertNotNull(factory);
    assertEquals(Factory.VALID, factory.getState());
    List<BazService> services = osgiHelper.getServiceObjects(BazService.class);
    assertEquals(1, services.size());
    BazService baz = services.get(0);
    assertEquals("Hello Guillaume", baz.hello("Guillaume"));
    ipojoHelper.dispose();
}
Also used : BazService(org.apache.felix.ipojo.runtime.core.services.BazService) Factory(org.apache.felix.ipojo.Factory) Test(org.junit.Test) BaseTest(org.ow2.chameleon.testing.helpers.BaseTest)

Example 4 with BazService

use of org.apache.felix.ipojo.runtime.core.services.BazService in project felix by apache.

the class TestMultipleExport method invoke.

private boolean invoke() {
    ServiceReference ref = ipojoHelper.getServiceReferenceByName(BazService.class.getName(), export3.getInstanceName());
    if (ref == null) {
        return false;
    }
    BazService fs = (BazService) getContext().getService(ref);
    getContext().ungetService(ref);
    return fs.foo();
}
Also used : BazService(org.apache.felix.ipojo.runtime.core.services.BazService) ServiceReference(org.osgi.framework.ServiceReference)

Example 5 with BazService

use of org.apache.felix.ipojo.runtime.core.services.BazService in project felix by apache.

the class TestOptionalMultipleExport method invoke.

private boolean invoke(int nb) {
    ServiceReference[] refs = osgiHelper.getServiceReferences(BazService.class.getName(), "(instance.name=" + export3.getInstanceName() + ")");
    if (refs == null) {
        return false;
    }
    if (nb > refs.length) {
        return false;
    }
    for (int i = 0; i < nb; i++) {
        BazService fs = (BazService) getContext().getService(refs[i]);
        getContext().ungetService(refs[i]);
        if (!fs.foo()) {
            return false;
        }
    }
    return true;
}
Also used : BazService(org.apache.felix.ipojo.runtime.core.services.BazService) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

BazService (org.apache.felix.ipojo.runtime.core.services.BazService)10 ServiceReference (org.osgi.framework.ServiceReference)8 Test (org.junit.Test)3 ComponentInstance (org.apache.felix.ipojo.ComponentInstance)2 Factory (org.apache.felix.ipojo.Factory)2 BaseTest (org.ow2.chameleon.testing.helpers.BaseTest)2 Properties (java.util.Properties)1 FooService (org.apache.felix.ipojo.runtime.core.services.FooService)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1