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();
}
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(""));
}
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();
}
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();
}
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;
}
Aggregations