use of org.apache.felix.ipojo.PrimitiveHandler 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