use of org.apache.felix.ipojo.PrimitiveInstanceDescription in project felix by apache.
the class TestPOJOCreation method testLazyCreationSeveralM.
/**
* Check creation through a factory method.
* (lazy & several creation)
*/
@Test
public void testLazyCreationSeveralM() {
assertEquals("Check that no objects are created ", 0, ((PrimitiveInstanceDescription) lazzyArchSevM.getInstanceDescription()).getCreatedObjects().length);
ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), ci_lazzy_sevM.getInstanceName());
assertNotNull("Check that a FooService from " + ci_lazzy_sevM.getInstanceName() + " is available", ref);
FooService fs = (FooService) osgiHelper.getServiceObject(ref);
assertTrue("Check the FooService invocation", fs.foo());
assertEquals("Check the creation of 1 object", 1, ((PrimitiveInstanceDescription) lazzyArchSevM.getInstanceDescription()).getCreatedObjects().length);
FooService fs2 = (FooService) osgiHelper.getServiceObject(ref);
assertTrue("Check the FooService invocation-2", fs2.foo());
// Only one object as the getService method is called only once (service factory) despite the policy="method".
assertEquals("Check the creation of 1 object", 1, ((PrimitiveInstanceDescription) lazzyArchSevM.getInstanceDescription()).getCreatedObjects().length);
}
use of org.apache.felix.ipojo.PrimitiveInstanceDescription in project felix by apache.
the class TestPOJOCreation method testImmediateSingletonCreation.
/**
* Test immediate singleton creation.
*/
@Test
public void testImmediateSingletonCreation() {
assertEquals("Check that one object is created ", 1, ((PrimitiveInstanceDescription) immeArchSing.getInstanceDescription()).getCreatedObjects().length);
ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), ci_immediate_singleton.getInstanceName());
assertNotNull("Check that a FooService from " + ci_immediate_singleton.getInstanceName() + " is available", ref);
FooService fs = (FooService) osgiHelper.getServiceObject(ref);
assertTrue("Check the FooService invocation", fs.foo());
assertEquals("Check the creation of 1 object", 1, ((PrimitiveInstanceDescription) immeArchSing.getInstanceDescription()).getCreatedObjects().length);
}
use of org.apache.felix.ipojo.PrimitiveInstanceDescription in project felix by apache.
the class TestPOJOCreation method testLazyCreation.
/**
* Check lazy creation.
*/
@Test
public void testLazyCreation() {
assertEquals("Check that no objects are created ", 0, ((PrimitiveInstanceDescription) lazzyArch.getInstanceDescription()).getCreatedObjects().length);
ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), ci_lazzy.getInstanceName());
assertNotNull("Check that a FooService from " + ci_lazzy.getInstanceName() + " is available", ref);
FooService fs = (FooService) osgiHelper.getServiceObject(ref);
assertTrue("Check the FooService invocation", fs.foo());
assertEquals("Check the creation of 1 object", 1, ((PrimitiveInstanceDescription) lazzyArch.getInstanceDescription()).getCreatedObjects().length);
}
use of org.apache.felix.ipojo.PrimitiveInstanceDescription in project felix by apache.
the class TestPOJOCreation method testLazyCreationSingleton.
/**
* Check lazy and singleton creation.
*/
@Test
public void testLazyCreationSingleton() {
assertEquals("Check that no objects are created ", 0, ((PrimitiveInstanceDescription) lazzyArchSing.getInstanceDescription()).getCreatedObjects().length);
ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), ci_lazzy_sing.getInstanceName());
assertNotNull("Check that a FooService from " + ci_lazzy_sing.getInstanceName() + " is available", ref);
FooService fs = (FooService) osgiHelper.getServiceObject(ref);
assertTrue("Check the FooService invocation", fs.foo());
assertEquals("Check the creation of 1 object", 1, ((PrimitiveInstanceDescription) lazzyArchSing.getInstanceDescription()).getCreatedObjects().length);
}
use of org.apache.felix.ipojo.PrimitiveInstanceDescription in project felix by apache.
the class TestPOJOCreation method testBundleContext.
/**
* Check bundle context injection.
*/
@Test
public void testBundleContext() {
ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), ci_lazzy.getInstanceName());
assertNotNull("Check that a FooService from " + ci_lazzy.getInstanceName() + " is available", ref);
FooService fs = (FooService) osgiHelper.getServiceObject(ref);
Properties p = fs.fooProps();
assertNotNull("Check the bundle context", p.get("context"));
assertEquals("Check the creation of 1 object", 1, ((PrimitiveInstanceDescription) lazzyArch.getInstanceDescription()).getCreatedObjects().length);
}
Aggregations