use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.
the class TestPOJOCreation method testImmediateCreation.
/**
* Check immediate creation.
*/
@Test
public void testImmediateCreation() {
assertEquals("Check that one object is created ", 1, ((PrimitiveInstanceDescription) immeArch.getInstanceDescription()).getCreatedObjects().length);
ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), ci_immediate.getInstanceName());
assertNotNull("Check that a FooService from " + ci_immediate.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) immeArch.getInstanceDescription()).getCreatedObjects().length);
}
use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.
the class TestPOJOCreation method testLazyCreationSingletonM.
/**
* Check creation through a factory method.
* (lazy & singleton creation)
*/
@Test
public void testLazyCreationSingletonM() {
assertEquals("Check that no objects are created ", 0, ((PrimitiveInstanceDescription) lazzyArchSingM.getInstanceDescription()).getCreatedObjects().length);
ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), ci_lazzy_singM.getInstanceName());
assertNotNull("Check that a FooService from " + ci_lazzy_singM.getInstanceName() + " is available", ref);
FooService fs = (FooService) osgiHelper.getServiceObject(ref);
FooService fs2 = (FooService) osgiHelper.getServiceObject(ref);
assertTrue("Check the FooService invocation", fs.foo());
assertTrue("Check the FooService invocation", fs2.foo());
assertEquals("Check the creation of 1 object", 1, ((PrimitiveInstanceDescription) lazzyArchSingM.getInstanceDescription()).getCreatedObjects().length);
}
use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.
the class TestPOJOCreation method testLazyCreationSeveral.
/**
* Check lazy and "several" creation.
*/
@Test
public void testLazyCreationSeveral() {
assertEquals("Check that no objects are created ", 0, ((PrimitiveInstanceDescription) lazzyArchSev.getInstanceDescription()).getCreatedObjects().length);
ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), ci_lazzy_sev.getInstanceName());
assertNotNull("Check that a FooService from " + ci_lazzy_sev.getInstanceName() + " is available", ref);
FooService fs = (FooService) osgiHelper.getServiceObject(ref);
FooService fs2 = (FooService) osgiHelper.getServiceObject(ref);
assertTrue("Check the FooService invocation", fs.foo());
assertTrue("Check the FooService invocation-2", fs2.foo());
assertEquals("Check the creation of 1 object", 1, ((PrimitiveInstanceDescription) lazzyArchSev.getInstanceDescription()).getCreatedObjects().length);
}
use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.
the class TestManagedServiceConfigurableProperties method testDynamicInstance2.
@Test
public void testDynamicInstance2() {
ServiceReference fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance2.getInstanceName());
assertNotNull("Check FS availability", fooRef);
String fooP = (String) fooRef.getProperty("foo");
Integer barP = (Integer) fooRef.getProperty("bar");
String bazP = (String) fooRef.getProperty("baz");
assertEquals("Check foo equality", fooP, "foo");
assertEquals("Check bar equality", barP, new Integer(2));
assertEquals("Check baz equality", bazP, "baz");
ServiceReference msRef = osgiHelper.getServiceReferenceByPID(ManagedService.class.getName(), "instance");
assertNotNull("Check ManagedServiceFactory availability", msRef);
// Configuration of baz
Dictionary<String, Object> conf = new Hashtable<String, Object>();
conf.put("baz", "zab");
conf.put("foo", "oof");
conf.put("bar", new Integer(0));
ManagedService ms = (ManagedService) osgiHelper.getContext().getService(msRef);
try {
ms.updated(conf);
} catch (ConfigurationException e) {
fail("Configuration Exception : " + e);
}
// Recheck props
fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance2.getInstanceName());
fooP = (String) fooRef.getProperty("foo");
barP = (Integer) fooRef.getProperty("bar");
bazP = (String) fooRef.getProperty("baz");
assertEquals("Check foo equality", fooP, "oof");
assertEquals("Check bar equality", barP, new Integer(0));
assertEquals("Check baz equality", bazP, "zab");
// Check field value
FooService fs = (FooService) osgiHelper.getContext().getService(fooRef);
Properties p = fs.fooProps();
fooP = (String) p.get("foo");
barP = (Integer) p.get("bar");
assertEquals("Check foo field equality", fooP, "oof");
assertEquals("Check bar field equality", barP, new Integer(0));
osgiHelper.getContext().ungetService(fooRef);
osgiHelper.getContext().ungetService(msRef);
}
use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.
the class TestManagedServiceConfigurableProperties method testDynamicStringInstance1.
@Test
public void testDynamicStringInstance1() {
assertEquals("Check instance1 state", ComponentInstance.VALID, instance1.getState());
ServiceReference fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance1.getInstanceName());
assertNotNull("Check FS availability", fooRef);
String fooP = (String) fooRef.getProperty("foo");
Integer barP = (Integer) fooRef.getProperty("bar");
String bazP = (String) fooRef.getProperty("baz");
assertEquals("Check foo equality - 1", fooP, "foo");
assertEquals("Check bar equality - 1", barP, new Integer(2));
assertEquals("Check baz equality - 1", bazP, "baz");
ServiceReference msRef = osgiHelper.getServiceReferenceByPID(ManagedService.class.getName(), "FooProvider-3");
assertNotNull("Check ManagedService availability", msRef);
// Configuration of baz
Dictionary<String, Object> conf = new Hashtable<String, Object>();
conf.put("baz", "zab");
conf.put("foo", "oof");
conf.put("bar", "0");
assertEquals("Check instance1 state (2)", ComponentInstance.VALID, instance1.getState());
ManagedService ms = (ManagedService) osgiHelper.getContext().getService(msRef);
PrimitiveHandler ph = (PrimitiveHandler) ms;
assertSame("Check the correct instance", ph.getInstanceManager(), instance1);
try {
ms.updated(conf);
} catch (ConfigurationException e) {
fail("Configuration Exception : " + e);
}
assertEquals("Check instance1 state (3)", ComponentInstance.VALID, instance1.getState());
// Recheck props
fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance1.getInstanceName());
fooP = (String) fooRef.getProperty("foo");
barP = (Integer) fooRef.getProperty("bar");
bazP = (String) fooRef.getProperty("baz");
assertEquals("Check foo equality - 2", fooP, "oof");
assertEquals("Check bar equality - 2", barP, new Integer(0));
assertEquals("Check baz equality - 2", bazP, "zab");
// Check field value
FooService fs = (FooService) osgiHelper.getContext().getService(fooRef);
Properties p = fs.fooProps();
fooP = (String) p.get("foo");
barP = (Integer) p.get("bar");
assertEquals("Check foo field equality", fooP, "oof");
assertEquals("Check bar field equality", barP, new Integer(0));
osgiHelper.getContext().ungetService(fooRef);
osgiHelper.getContext().ungetService(msRef);
}
Aggregations