use of org.osgi.service.cm.ManagedService in project felix by apache.
the class TestManagedServiceConfigurableProperties method testPropagationInstance2.
@Test
public void testPropagationInstance2() {
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 ManagedService availability", msRef);
// Configuration of baz
Dictionary<String, Object> conf = new Hashtable<String, Object>();
conf.put("baz", "zab");
conf.put("foo", "foo");
conf.put("bar", new Integer(2));
conf.put("propagated1", "propagated");
conf.put("propagated2", new Integer(1));
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");
assertNotNull("Check the propagated1 existency", fooRef.getProperty("propagated1"));
String prop1 = (String) fooRef.getProperty("propagated1");
assertNotNull("Check the propagated2 existency", fooRef.getProperty("propagated2"));
Integer prop2 = (Integer) fooRef.getProperty("propagated2");
assertEquals("Check foo equality", fooP, "foo");
assertEquals("Check bar equality", barP, new Integer(2));
assertEquals("Check baz equality", bazP, "zab");
assertEquals("Check propagated1 equality", prop1, "propagated");
assertEquals("Check propagated2 equality", prop2, new Integer(1));
osgiHelper.getContext().ungetService(msRef);
}
use of org.osgi.service.cm.ManagedService in project felix by apache.
the class TestManagedServiceConfigurableProperties method testPropagationInstance1.
@Test
public void testPropagationInstance1() {
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", fooP, "foo");
assertEquals("Check bar equality", barP, new Integer(2));
assertEquals("Check baz equality", 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", "foo");
conf.put("bar", new Integer(2));
conf.put("propagated1", "propagated");
conf.put("propagated2", new Integer(1));
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(), instance1.getInstanceName());
fooP = (String) fooRef.getProperty("foo");
barP = (Integer) fooRef.getProperty("bar");
bazP = (String) fooRef.getProperty("baz");
assertNotNull("Check the propagated1 existency", fooRef.getProperty("propagated1"));
String prop1 = (String) fooRef.getProperty("propagated1");
assertNotNull("Check the propagated2 existency", fooRef.getProperty("propagated2"));
Integer prop2 = (Integer) fooRef.getProperty("propagated2");
assertEquals("Check foo equality", fooP, "foo");
assertEquals("Check bar equality", barP, new Integer(2));
assertEquals("Check baz equality", bazP, "zab");
assertEquals("Check propagated1 equality", prop1, "propagated");
assertEquals("Check propagated2 equality", prop2, new Integer(1));
osgiHelper.getContext().ungetService(msRef);
}
use of org.osgi.service.cm.ManagedService in project felix by apache.
the class TestUpdatedMethodAndManagedService method testStaticInstance2.
@Test
public void testStaticInstance2() {
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 -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(), "instance-managed-service");
assertNotNull("Check ManagedService availability", msRef);
// Configuration of baz
Dictionary<String, Object> conf = new Hashtable<String, Object>();
conf.put("baz", "zab");
conf.put("bar", new Integer(2));
conf.put("foo", "foo");
ManagedService ms = (ManagedService) osgiHelper.getRawServiceObject(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 -2", fooP, "foo");
assertEquals("Check bar equality -2", barP, new Integer(2));
assertEquals("Check baz equality -2", bazP, "zab");
// Get Service
FooService fs = (FooService) osgiHelper.getRawServiceObject(fooRef);
Integer updated = (Integer) fs.fooProps().get("updated");
Dictionary dict = (Dictionary) fs.fooProps().get("lastupdated");
assertEquals("Check updated", 1, updated.intValue());
assertEquals("Check last updated", 3, dict.size());
conf.put("baz", "zab2");
conf.put("foo", "oof2");
conf.put("bar", new Integer(0));
ms = (ManagedService) osgiHelper.getRawServiceObject(msRef);
try {
ms.updated(conf);
} catch (ConfigurationException e) {
fail("Configuration Exception : " + e);
}
updated = (Integer) fs.fooProps().get("updated");
dict = (Dictionary) fs.fooProps().get("lastupdated");
assertEquals("Check updated -2", 2, updated.intValue());
assertEquals("Check last updated", 3, dict.size());
}
use of org.osgi.service.cm.ManagedService in project felix by apache.
the class TestUpdatedMethodAndManagedService method testStaticInstance1.
@Test
public void testStaticInstance1() throws IOException {
for (Architecture architecture : osgiHelper.getServiceObjects(Architecture.class)) {
System.out.println(architecture.getInstanceDescription().getName() + " " + architecture.getInstanceDescription().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 ManagedServiceFactory availability", msRef);
// Configuration of baz
Dictionary<String, Object> conf = new Hashtable<String, Object>();
conf.put("baz", "zab");
conf.put("bar", new Integer(2));
conf.put("foo", "foo");
ManagedService ms = (ManagedService) osgiHelper.getRawServiceObject(msRef);
try {
ms.updated(conf);
} catch (ConfigurationException e) {
fail("Configuration Exception : " + e);
}
// Re-check 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, "foo");
assertEquals("Check bar equality -2", barP, new Integer(2));
assertEquals("Check baz equality -2", bazP, "zab");
// Get Service
FooService fs = (FooService) osgiHelper.getRawServiceObject(fooRef);
Integer updated = (Integer) fs.fooProps().get("updated");
Dictionary dict = (Dictionary) fs.fooProps().get("lastupdated");
assertEquals("Check updated", 1, updated.intValue());
assertEquals("Check last updated", 3, dict.size());
}
use of org.osgi.service.cm.ManagedService in project felix by apache.
the class TestUpdatedNoArgMethodAndManagedService method testStaticInstance1.
@Test
public void testStaticInstance1() {
ServiceReference fooRef = osgiHelper.waitForService(FooService.class.getName(), "(instance.name=" + instance1.getInstanceName() + ")", 5000);
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 ManagedServiceFactory availability", msRef);
// Configuration of baz
Dictionary<String, Object> conf = new Hashtable<String, Object>();
conf.put("baz", "zab");
conf.put("bar", new Integer(2));
conf.put("foo", "foo");
ManagedService ms = (ManagedService) osgiHelper.getRawServiceObject(msRef);
try {
ms.updated(conf);
} catch (ConfigurationException e) {
fail("Configuration Exception : " + e);
}
// Re-check 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, "foo");
assertEquals("Check bar equality -2", barP, new Integer(2));
assertEquals("Check baz equality -2", bazP, "zab");
// Get Service
FooService fs = (FooService) osgiHelper.getRawServiceObject(fooRef);
Integer updated = (Integer) fs.fooProps().get("updated");
assertEquals("Check updated", 1, updated.intValue());
}
Aggregations