Factory fact = ipojoHelper.getFactory(factName);
assertNotNull("Cannot find the factory FooProvider-1", fact);
Properties props = new Properties();
props.put("instance.name", compName);
ComponentInstance ci = null;
try {
ci = fact.createComponentInstance(props);
} catch (Exception e1) {
fail(e1.getMessage());
}
assertEquals("Check instance name", compName, ci.getInstanceName());
// Get a FooService provider
ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), compName);
assertNotNull("FS not available", ref);
// Get foo object
FooService fs = (FooService) osgiHelper.getServiceObject(ref);
// Cast to POJO
Pojo pojo = (Pojo) fs;
Field im = fs.getClass().getDeclaredField("__IM");
assertNotNull(im);
im.setAccessible(true);
assertNotNull(im.get(fs));
Method method = fs.getClass().getMethod("getComponentInstance");
assertNotNull(method);
// GetComponentInstance
ComponentInstance instance = pojo.getComponentInstance();
assertNotNull(instance);
assertEquals("Check component instance name", instance.getInstanceName(), compName);
assertEquals("Check component factory name", instance.getFactory().getName(), factName);
assertNotNull("Instance description not null", instance.getInstanceDescription());
PrimitiveInstanceDescription id = (PrimitiveInstanceDescription) instance.getInstanceDescription();
assertTrue("Check instance state", id.getState() == ComponentInstance.VALID);
assertEquals("Check created pojo count", id.getCreatedObjects().length, 1);
assertEquals("Check instance description name", id.getName(), compName);
ci.dispose();