use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.
the class TestUpdatedMethodAndConfigAdmin method testDynamicString.
@Test
public void testDynamicString() throws IOException, InterruptedException {
ServiceReference fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.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");
ConfigurationAdmin admin = osgiHelper.getServiceObject(ConfigurationAdmin.class);
assertNotNull("Check Configuration Admin availability", admin);
Configuration configuration = admin.getConfiguration(instance.getInstanceName(), getTestBundle().getLocation());
// Configuration of baz
Dictionary<String, Object> conf = new Hashtable<String, Object>();
conf.put("baz", "zab");
conf.put("foo", "oof");
conf.put("bar", "0");
// Asynchronous dispatching of the configuration
configuration.update(conf);
grace();
// Recheck props
fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.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.getRawServiceObject(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));
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.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.
the class TestUpdatedMethodAndManagedService method testDynamicInstance1.
@Test
public void testDynamicInstance1() {
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 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.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", fooP, "oof");
assertEquals("Check bar equality", barP, new Integer(0));
assertEquals("Check baz equality", bazP, "zab");
// Check field value
FooService fs = (FooService) osgiHelper.getRawServiceObject(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));
Integer updated = (Integer) fs.fooProps().get("updated");
Dictionary dict = (Dictionary) fs.fooProps().get("lastupdated");
assertEquals("Check updated -1", 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.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.
the class TestUpdatedMethodAndManagedService 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-managed-service");
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.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", fooP, "oof");
assertEquals("Check bar equality", barP, new Integer(0));
assertEquals("Check baz equality", bazP, "zab");
// Check field value
FooService fs = (FooService) osgiHelper.getRawServiceObject(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));
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.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.
the class TestUpdatedNoArgMethodAndConfigAdmin method testStaticNoValue.
@Test
public void testStaticNoValue() throws InterruptedException, IOException {
ServiceReference fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance2.getInstanceName());
assertNotNull("Check FS availability", fooRef);
Object fooP = fooRef.getProperty("foo");
Object barP = fooRef.getProperty("bar");
Object bazP = fooRef.getProperty("baz");
assertEquals("Check foo equality -1", fooP, null);
assertEquals("Check bar equality -1", barP, null);
assertEquals("Check baz equality -1", bazP, null);
ConfigurationAdmin ad = osgiHelper.getServiceObject(ConfigurationAdmin.class);
assertNotNull("Check Configuration Admin availability", admin);
Configuration configuration = admin.getConfiguration(instance2.getInstanceName(), getTestBundle().getLocation());
// 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");
// Asynchronous dispatching of the configuration
configuration.update(conf);
grace();
// 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");
assertEquals("Check updated", 1, updated.intValue());
}
use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.
the class TestUpdatedNoArgMethodAndConfigAdmin method testDynamic.
@Test
public void testDynamic() throws InterruptedException, IOException {
ServiceReference fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.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");
ConfigurationAdmin admin = osgiHelper.getServiceObject(ConfigurationAdmin.class);
assertNotNull("Check Configuration Admin availability", admin);
Configuration configuration = admin.getConfiguration(instance.getInstanceName(), getTestBundle().getLocation());
// 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));
// Asynchronous dispatching of the configuration
configuration.update(conf);
grace();
// Recheck props
fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.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.getRawServiceObject(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));
Integer updated = (Integer) fs.fooProps().get("updated");
assertEquals("Check updated", 1, updated.intValue());
}
Aggregations