use of org.apache.felix.ipojo.runtime.core.test.services.FooService in project felix by apache.
the class SetCheckService method getLong.
private long getLong() {
long r = 0;
Iterator it = fs.iterator();
while (it.hasNext()) {
r = r + ((FooService) it.next()).getLong();
}
return r;
}
use of org.apache.felix.ipojo.runtime.core.test.services.FooService in project felix by apache.
the class SetCheckService method check.
public boolean check() {
boolean r = fs.size() != 0;
Iterator it = fs.iterator();
while (it.hasNext()) {
r = r & ((FooService) it.next()).foo();
}
return r;
}
use of org.apache.felix.ipojo.runtime.core.test.services.FooService in project felix by apache.
the class TestDependencyArchitecture method testOptionalDependency.
@Test
public void testOptionalDependency() {
ServiceReference arch_dep = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance2.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.VALID);
// Check dependency handler invalidity
DependencyHandlerDescription dhd = getDependencyDesc(id_dep);
assertTrue("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");
assertFalse("Check dependency cardinality", dhd.getDependencies()[0].isMultiple());
assertTrue("Check dependency optionality", dhd.getDependencies()[0].isOptional());
assertNull("Check dependency ref -1", dhd.getDependencies()[0].getServiceReferences());
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(), instance2.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.VALID);
dhd = getDependencyDesc(id_dep);
assertTrue("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(), instance2.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.VALID);
dhd = getDependencyDesc(id_dep);
assertTrue("Check dependency handler invalidity", dhd.isValid());
id_dep = null;
cs = null;
getContext().ungetService(arch_dep);
getContext().ungetService(cs_ref);
}
use of org.apache.felix.ipojo.runtime.core.test.services.FooService in project felix by apache.
the class TestDynamicPriority method testSimple.
@Test
public void testSimple() {
ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance1.getInstanceName());
assertNotNull("Check architecture availability", arch_ref);
InstanceDescription id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
assertTrue("Check instance invalidity - 1", id.getState() == ComponentInstance.INVALID);
fooProvider.start();
fooProvider2.start();
id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance1.getInstanceName());
assertNotNull("Check CheckService availability", cs_ref);
CheckService cs = (CheckService) getContext().getService(cs_ref);
// Check grade
Integer grade = (Integer) cs.getProps().get("int");
assertEquals("Check first grade", 1, grade.intValue());
// Turn off the best provider.
fooProvider.stop();
id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance1.getInstanceName());
assertNotNull("Check CheckService availability", cs_ref);
cs = (CheckService) getContext().getService(cs_ref);
// Check grade
grade = (Integer) cs.getProps().get("int");
assertEquals("Check second grade", 0, grade.intValue());
// Turn on the best provider.
fooProvider.start();
id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance1.getInstanceName());
assertNotNull("Check CheckService availability", cs_ref);
cs = (CheckService) getContext().getService(cs_ref);
// Check grade
grade = (Integer) cs.getProps().get("int");
assertEquals("Check third grade", 1, grade.intValue());
// Increase the second provider grade.
ServiceReference fs_ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), fooProvider2.getInstanceName());
assertNotNull("Check foo service (2) reference", fs_ref);
FooService fs = (FooService) getContext().getService(fs_ref);
// Increase the grade (now = 2)
fs.foo();
cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance1.getInstanceName());
assertNotNull("Check CheckService availability", cs_ref);
cs = (CheckService) getContext().getService(cs_ref);
// Check grade
grade = (Integer) cs.getProps().get("int");
assertEquals("Check fourth grade", 2, grade.intValue());
// Increase the other provider grade.
fs_ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), fooProvider.getInstanceName());
assertNotNull("Check foo service (1) reference", fs_ref);
fs = (FooService) getContext().getService(fs_ref);
// (grade = 3)
fs.foo();
cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance1.getInstanceName());
assertNotNull("Check CheckService availability", cs_ref);
cs = (CheckService) getContext().getService(cs_ref);
// Check grade
grade = (Integer) cs.getProps().get("int");
assertEquals("Check fifth grade", 3, grade.intValue());
id = null;
cs = null;
getContext().ungetService(arch_ref);
getContext().ungetService(cs_ref);
getContext().ungetService(fs_ref);
fooProvider.stop();
fooProvider2.stop();
}
Aggregations