use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.
the class TestSimpleProperties method testInstanceConfiguration.
@Test
public void testInstanceConfiguration() {
ServiceReference sr = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-2");
assertNotNull("Check the availability of the FS service", sr);
FooService fs = (FooService) osgiHelper.getContext().getService(sr);
Properties toCheck = fs.fooProps();
// Check service properties
Integer intProp = (Integer) toCheck.get("intProp");
Boolean boolProp = (Boolean) toCheck.get("boolProp");
String strProp = (String) toCheck.get("strProp");
String[] strAProp = (String[]) toCheck.get("strAProp");
int[] intAProp = (int[]) toCheck.get("intAProp");
assertEquals("Check intProp equality", intProp, new Integer(4));
assertEquals("Check longProp equality", boolProp, new Boolean(false));
assertEquals("Check strProp equality", strProp, new String("bar"));
assertNotNull("Check strAProp not nullity", strAProp);
String[] v = new String[] { "bar", "foo" };
for (int i = 0; i < strAProp.length; i++) {
if (!strAProp[i].equals(v[i])) {
fail("Check the strAProp Equality");
}
}
assertNotNull("Check intAProp not nullity", intAProp);
int[] v2 = new int[] { 1, 2, 3 };
for (int i = 0; i < intAProp.length; i++) {
if (intAProp[i] != v2[i]) {
fail("Check the intAProp Equality");
}
}
assertTrue("invoke fs", fs.foo());
toCheck = fs.fooProps();
// Re-check the property (change)
intProp = (Integer) toCheck.get("intProp");
boolProp = (Boolean) toCheck.get("boolProp");
strProp = (String) toCheck.get("strProp");
strAProp = (String[]) toCheck.get("strAProp");
intAProp = (int[]) toCheck.get("intAProp");
assertEquals("Check intProp equality", intProp, new Integer(3));
assertEquals("Check longProp equality", boolProp, new Boolean(true));
assertEquals("Check strProp equality", strProp, new String("foo"));
assertNotNull("Check strAProp not nullity", strAProp);
v = new String[] { "foo", "bar", "baz" };
for (int i = 0; i < strAProp.length; i++) {
if (!strAProp[i].equals(v[i])) {
fail("Check the strAProp Equality");
}
}
assertNotNull("Check intAProp not nullity", intAProp);
v2 = new int[] { 3, 2, 1 };
for (int i = 0; i < intAProp.length; i++) {
if (intAProp[i] != v2[i]) {
fail("Check the intAProp Equality");
}
}
fs = null;
osgiHelper.getContext().ungetService(sr);
}
use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.
the class TestSimpleProperties method testComponentTypeConfiguration.
@Test
public void testComponentTypeConfiguration() {
ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), fooProvider1.getInstanceName());
assertNotNull("Check FooService availability", ref);
FooService fs = (FooService) osgiHelper.getContext().getService(ref);
Properties toCheck = fs.fooProps();
Integer intProp = (Integer) toCheck.get("intProp");
Boolean boolProp = (Boolean) toCheck.get("boolProp");
String strProp = (String) toCheck.get("strProp");
String[] strAProp = (String[]) toCheck.get("strAProp");
int[] intAProp = (int[]) toCheck.get("intAProp");
assertEquals("Check intProp equality (1)", intProp, new Integer(2));
assertEquals("Check longProp equality (1)", boolProp, new Boolean(false));
assertEquals("Check strProp equality (1)", strProp, new String("foo"));
assertNotNull("Check strAProp not nullity (1)", strAProp);
String[] v = new String[] { "foo", "bar" };
for (int i = 0; i < strAProp.length; i++) {
if (!strAProp[i].equals(v[i])) {
fail("Check the strAProp Equality (1) : " + strAProp[i] + " != " + v[i]);
}
}
assertNotNull("Check intAProp not nullity", intAProp);
int[] v2 = new int[] { 1, 2, 3 };
for (int i = 0; i < intAProp.length; i++) {
if (intAProp[i] != v2[i]) {
fail("Check the intAProp Equality (1) : " + intAProp[i] + " != " + v2[i]);
}
}
// change the field value
assertTrue("Invoke the fs service", fs.foo());
toCheck = fs.fooProps();
// Re-check the property (change)
intProp = (Integer) toCheck.get("intProp");
boolProp = (Boolean) toCheck.get("boolProp");
strProp = (String) toCheck.get("strProp");
strAProp = (String[]) toCheck.get("strAProp");
intAProp = (int[]) toCheck.get("intAProp");
assertEquals("Check intProp equality (2) (" + intProp + ")", intProp, new Integer(3));
assertEquals("Check longProp equality (2)", boolProp, new Boolean(true));
assertEquals("Check strProp equality (2)", strProp, new String("bar"));
assertNotNull("Check strAProp not nullity (2)", strAProp);
v = new String[] { "foo", "bar", "baz" };
for (int i = 0; i < strAProp.length; i++) {
if (!strAProp[i].equals(v[i])) {
fail("Check the strAProp Equality (2)");
}
}
assertNotNull("Check intAProp not nullity (2)", intAProp);
v2 = new int[] { 3, 2, 1 };
for (int i = 0; i < intAProp.length; i++) {
if (intAProp[i] != v2[i]) {
fail("Check the intAProp Equality (2) : " + intAProp[i] + " != " + v2[i]);
}
}
fs = null;
osgiHelper.getContext().ungetService(ref);
}
use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.
the class TestSimpleProperties method testNoValue.
@Test
public void testNoValue() {
ServiceReference sr = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-3");
assertNotNull("Check the availability of the FS service", sr);
FooService fs = (FooService) osgiHelper.getContext().getService(sr);
Properties toCheck = fs.fooProps();
// Check service properties
Integer intProp = (Integer) toCheck.get("intProp");
Boolean boolProp = (Boolean) toCheck.get("boolProp");
String strProp = (String) toCheck.get("strProp");
String[] strAProp = (String[]) toCheck.get("strAProp");
int[] intAProp = (int[]) toCheck.get("intAProp");
assertEquals("Check intProp equality", intProp, new Integer(0));
assertEquals("Check longProp equality", boolProp, new Boolean(false));
assertEquals("Check strProp equality", strProp, null);
assertNull("Check strAProp nullity", strAProp);
assertNull("Check intAProp nullity", intAProp);
assertTrue("invoke fs", fs.foo());
toCheck = fs.fooProps();
// Re-check the property (change)
intProp = (Integer) toCheck.get("intProp");
boolProp = (Boolean) toCheck.get("boolProp");
strProp = (String) toCheck.get("strProp");
strAProp = (String[]) toCheck.get("strAProp");
intAProp = (int[]) toCheck.get("intAProp");
assertEquals("Check intProp equality", intProp, new Integer(3));
assertEquals("Check longProp equality", boolProp, new Boolean(true));
assertEquals("Check strProp equality", strProp, new String("bar"));
assertNotNull("Check strAProp not nullity", strAProp);
String[] v = new String[] { "foo", "bar", "baz" };
for (int i = 0; i < strAProp.length; i++) {
if (!strAProp[i].equals(v[i])) {
fail("Check the strAProp Equality");
}
}
assertNotNull("Check intAProp not nullity", intAProp);
int[] v2 = new int[] { 3, 2, 1 };
for (int i = 0; i < intAProp.length; i++) {
if (intAProp[i] != v2[i]) {
fail("Check the intAProp Equality");
}
}
fs = null;
osgiHelper.getContext().ungetService(sr);
}
use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.
the class TestUpdatedMethod method testComponentTypeConfiguration.
@Test
public void testComponentTypeConfiguration() {
ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), fooProvider1.getInstanceName());
assertNotNull("Check FooService availability", ref);
FooService fs = (FooService) osgiHelper.getRawServiceObject(ref);
Properties toCheck = fs.fooProps();
Integer intProp = (Integer) toCheck.get("intProp");
Boolean boolProp = (Boolean) toCheck.get("boolProp");
String strProp = (String) toCheck.get("strProp");
String[] strAProp = (String[]) toCheck.get("strAProp");
int[] intAProp = (int[]) toCheck.get("intAProp");
// Check updated
Integer updated = (Integer) toCheck.get("updated");
Dictionary dict = (Dictionary) toCheck.get("lastupdated");
assertEquals("Check intProp equality (1)", intProp, new Integer(2));
assertEquals("Check longProp equality (1)", boolProp, false);
assertEquals("Check strProp equality (1)", strProp, "foo");
assertNotNull("Check strAProp not nullity (1)", strAProp);
String[] v = new String[] { "foo", "bar" };
for (int i = 0; i < strAProp.length; i++) {
if (!strAProp[i].equals(v[i])) {
fail("Check the strAProp Equality (1) : " + strAProp[i] + " != " + v[i]);
}
}
assertNotNull("Check intAProp not nullity", intAProp);
int[] v2 = new int[] { 1, 2, 3 };
for (int i = 0; i < intAProp.length; i++) {
if (intAProp[i] != v2[i]) {
fail("Check the intAProp Equality (1) : " + intAProp[i] + " != " + v2[i]);
}
}
assertEquals("updated count ", 1, updated.intValue());
assertEquals("Last updated", 5, dict.size());
// change the field value
assertTrue("Invoke the fs service", fs.foo());
toCheck = fs.fooProps();
// Re-check the property (change)
intProp = (Integer) toCheck.get("intProp");
boolProp = (Boolean) toCheck.get("boolProp");
strProp = (String) toCheck.get("strProp");
strAProp = (String[]) toCheck.get("strAProp");
intAProp = (int[]) toCheck.get("intAProp");
// Check updated
updated = (Integer) toCheck.get("updated");
dict = (Dictionary) toCheck.get("lastupdated");
assertEquals("Check intProp equality (2) (" + intProp + ")", intProp, new Integer(3));
assertEquals("Check longProp equality (2)", boolProp, true);
assertEquals("Check strProp equality (2)", strProp, "bar");
assertNotNull("Check strAProp not nullity (2)", strAProp);
v = new String[] { "foo", "bar", "baz" };
for (int i = 0; i < strAProp.length; i++) {
if (!strAProp[i].equals(v[i])) {
fail("Check the strAProp Equality (2)");
}
}
assertNotNull("Check intAProp not nullity (2)", intAProp);
v2 = new int[] { 3, 2, 1 };
for (int i = 0; i < intAProp.length; i++) {
if (intAProp[i] != v2[i]) {
fail("Check the intAProp Equality (2) : " + intAProp[i] + " != " + v2[i]);
}
}
// This does not reconfigure...
assertEquals("updated count -2 ", 1, updated.intValue());
assertEquals("Last update - 2", 5, dict.size());
fs = null;
}
use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.
the class TestUpdatedMethodAndConfigAdmin method testDynamicNoValue.
@Test
public void testDynamicNoValue() throws IOException, InterruptedException {
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 admin = 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("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(), 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());
}
Aggregations