use of org.apache.felix.ipojo.runtime.core.services.CheckService in project felix by apache.
the class TestConstructorInjectionOfProperties method testInjectionOfUnnamedProperty.
@Test
public void testInjectionOfUnnamedProperty() {
Dictionary<String, String> conf = new Hashtable<String, String>();
conf.put("message", "message");
ComponentInstance instance = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.runtime.core" + ".components.constructor.CheckServiceProviderWithUnnamedProperty", conf);
ServiceReference ref = osgiHelper.waitForService(CheckService.class.getName(), "(instance.name=" + instance.getInstanceName() + ")", 1000);
CheckService cs = (CheckService) osgiHelper.getRawServiceObject(ref);
assertEquals(cs.getProps().getProperty("message"), "message");
}
use of org.apache.felix.ipojo.runtime.core.services.CheckService in project felix by apache.
the class TestFieldProperties method testConfigurationObjString.
@Test
public void testConfigurationObjString() {
ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance.getInstanceName());
CheckService check = (CheckService) osgiHelper.getRawServiceObject(ref);
Properties props = check.getProps();
String s = (String) props.get("string");
String[] ss = (String[]) props.get("strings");
assertEquals("Check string", s, "foo");
assertEquals("Check strings 0", ss[0], "foo");
assertEquals("Check strings 1", ss[1], "bar");
assertEquals("Check strings 2", ss[2], "baz");
reconfigureString(instance);
ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance.getInstanceName());
check = (CheckService) osgiHelper.getRawServiceObject(ref);
props = check.getProps();
s = (String) props.get("string");
ss = (String[]) props.get("strings");
assertEquals("2) Check string", s, "bar");
assertEquals("2) Check strings 0", ss[0], "baz");
assertEquals("2) Check strings 1", ss[1], "bar");
assertEquals("2) Check strings 2", ss[2], "foo");
}
use of org.apache.felix.ipojo.runtime.core.services.CheckService in project felix by apache.
the class TestFieldProperties method testConfigurationPrimitiveNoValue.
@Test
public void testConfigurationPrimitiveNoValue() {
ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance2.getInstanceName());
assertNotNull("Test check service availability", ref);
CheckService check = (CheckService) osgiHelper.getRawServiceObject(ref);
Properties props = check.getProps();
Byte b = (Byte) props.get("b");
Short s = (Short) props.get("s");
Integer i = (Integer) props.get("i");
Long l = (Long) props.get("l");
Double d = (Double) props.get("d");
Float f = (Float) props.get("f");
Character c = (Character) props.get("c");
Boolean bool = (Boolean) props.get("bool");
assertEquals("Check b", b, new Byte("0"));
assertEquals("Check s", s, new Short("0"));
assertEquals("Check i", i, new Integer("0"));
assertEquals("Check l", l, new Long("0"));
assertEquals("Check d", d, new Double("0"));
assertEquals("Check f", f, new Float("0"));
assertEquals("Check c", c, new Character((char) 0));
assertEquals("Check bool", bool, new Boolean(false));
reconfigure(instance2);
ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance2.getInstanceName());
assertNotNull("Test check service availability", ref);
check = (CheckService) osgiHelper.getRawServiceObject(ref);
props = check.getProps();
b = (Byte) props.get("b");
s = (Short) props.get("s");
i = (Integer) props.get("i");
l = (Long) props.get("l");
d = (Double) props.get("d");
f = (Float) props.get("f");
c = (Character) props.get("c");
bool = (Boolean) props.get("bool");
assertEquals("2) Check b", b, new Byte("2"));
assertEquals("2) Check s", s, new Short("2"));
assertEquals("2) Check i", i, new Integer("2"));
assertEquals("2) Check l", l, new Long("2"));
assertEquals("2) Check d", d, new Double("2"));
assertEquals("2) Check f", f, new Float("2"));
assertEquals("2) Check c", c, new Character('b'));
assertEquals("2) Check bool", bool, new Boolean("false"));
}
use of org.apache.felix.ipojo.runtime.core.services.CheckService in project felix by apache.
the class TestFieldProperties method testConfigurationPrimitiveArrays.
@Test
public void testConfigurationPrimitiveArrays() {
ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance.getInstanceName());
assertNotNull("Test check service availability", ref);
CheckService check = (CheckService) osgiHelper.getRawServiceObject(ref);
Properties props = check.getProps();
byte[] b = (byte[]) props.get("bs");
short[] s = (short[]) props.get("ss");
int[] i = (int[]) props.get("is");
long[] l = (long[]) props.get("ls");
double[] d = (double[]) props.get("ds");
float[] f = (float[]) props.get("fs");
char[] c = (char[]) props.get("cs");
boolean[] bool = (boolean[]) props.get("bools");
assertEquals("Check b 0", b[0], 1);
assertEquals("Check b 1", b[1], 2);
assertEquals("Check b 2", b[2], 3);
assertEquals("Check s 0", s[0], 1);
assertEquals("Check s 1", s[1], 2);
assertEquals("Check s 2", s[2], 3);
assertEquals("Check i 0", i[0], 1);
assertEquals("Check i 1", i[1], 2);
assertEquals("Check i 2", i[2], 3);
assertEquals("Check l 0", l[0], 1);
assertEquals("Check l 1", l[1], 2);
assertEquals("Check l 2", l[2], 3);
assertEquals("Check d 0", d[0], 1, 0);
assertEquals("Check d 1", d[1], 2, 0);
assertEquals("Check d 2", d[2], 3, 0);
assertEquals("Check f 0", f[0], 1, 0);
assertEquals("Check f 1", f[1], 2, 0);
assertEquals("Check f 2", f[2], 3, 0);
assertEquals("Check c 0", c[0], 'a');
assertEquals("Check c 1", c[1], 'b');
assertEquals("Check c 2", c[2], 'c');
assertTrue("Check bool 0", bool[0]);
assertTrue("Check bool 1", bool[0]);
assertTrue("Check bool 2", bool[0]);
reconfigure(instance);
ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance.getInstanceName());
assertNotNull("Test check service availability", ref);
check = (CheckService) osgiHelper.getRawServiceObject(ref);
props = check.getProps();
b = (byte[]) props.get("bs");
s = (short[]) props.get("ss");
i = (int[]) props.get("is");
l = (long[]) props.get("ls");
d = (double[]) props.get("ds");
f = (float[]) props.get("fs");
c = (char[]) props.get("cs");
bool = (boolean[]) props.get("bools");
assertEquals("2) Check b 0", b[0], 3);
assertEquals("2) Check b 1", b[1], 2);
assertEquals("2) Check b 2", b[2], 1);
assertEquals("2) Check s 0", s[0], 3);
assertEquals("2) Check s 1", s[1], 2);
assertEquals("2) Check s 2", s[2], 1);
assertEquals("2) Check i 0", i[0], 3);
assertEquals("2) Check i 1", i[1], 2);
assertEquals("2) Check i 2", i[2], 1);
assertEquals("2) Check l 0", l[0], 3);
assertEquals("2) Check l 1", l[1], 2);
assertEquals("2) Check l 2", l[2], 1);
assertEquals("2) Check d 0", d[0], 3, 0);
assertEquals("2) Check d 1", d[1], 2, 0);
assertEquals("2) Check d 2", d[2], 1, 0);
assertEquals("2) Check f 0", f[0], 3, 0);
assertEquals("2) Check f 1", f[1], 2, 0);
assertEquals("2) Check f 2", f[2], 1, 0);
assertEquals("2) Check c 0", c[0], 'c');
assertEquals("2) Check c 1", c[1], 'b');
assertEquals("2) Check c 2", c[2], 'a');
assertFalse("2) Check bool 0", bool[0]);
assertFalse("2) Check bool 1", bool[0]);
assertFalse("2) Check bool 2", bool[0]);
}
use of org.apache.felix.ipojo.runtime.core.services.CheckService in project felix by apache.
the class TestFieldProperties method testConfigurationPrimitiveArraysNoValue.
@Test
public void testConfigurationPrimitiveArraysNoValue() {
ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance2.getInstanceName());
assertNotNull("Test check service availability", ref);
CheckService check = (CheckService) osgiHelper.getRawServiceObject(ref);
Properties props = check.getProps();
byte[] b = (byte[]) props.get("bs");
short[] s = (short[]) props.get("ss");
int[] i = (int[]) props.get("is");
long[] l = (long[]) props.get("ls");
double[] d = (double[]) props.get("ds");
float[] f = (float[]) props.get("fs");
char[] c = (char[]) props.get("cs");
boolean[] bool = (boolean[]) props.get("bools");
assertNull("Check b nullity", b);
assertNull("Check s nullity", s);
assertNull("Check i nullity", i);
assertNull("Check l nullity", l);
assertNull("Check d nullity", d);
assertNull("Check f nullity", f);
assertNull("Check c nullity", c);
assertNull("Check bool nullity", bool);
reconfigure(instance2);
ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance2.getInstanceName());
assertNotNull("Test check service availability", ref);
check = (CheckService) osgiHelper.getRawServiceObject(ref);
props = check.getProps();
b = (byte[]) props.get("bs");
s = (short[]) props.get("ss");
i = (int[]) props.get("is");
l = (long[]) props.get("ls");
d = (double[]) props.get("ds");
f = (float[]) props.get("fs");
c = (char[]) props.get("cs");
bool = (boolean[]) props.get("bools");
assertEquals("2) Check b 0", b[0], 3);
assertEquals("2) Check b 1", b[1], 2);
assertEquals("2) Check b 2", b[2], 1);
assertEquals("2) Check s 0", s[0], 3);
assertEquals("2) Check s 1", s[1], 2);
assertEquals("2) Check s 2", s[2], 1);
assertEquals("2) Check i 0", i[0], 3);
assertEquals("2) Check i 1", i[1], 2);
assertEquals("2) Check i 2", i[2], 1);
assertEquals("2) Check l 0", l[0], 3);
assertEquals("2) Check l 1", l[1], 2);
assertEquals("2) Check l 2", l[2], 1);
assertEquals("2) Check d 0", d[0], 3, 0);
assertEquals("2) Check d 1", d[1], 2, 0);
assertEquals("2) Check d 2", d[2], 1, 0);
assertEquals("2) Check f 0", f[0], 3, 0);
assertEquals("2) Check f 1", f[1], 2, 0);
assertEquals("2) Check f 2", f[2], 1, 0);
assertEquals("2) Check c 0", c[0], 'c');
assertEquals("2) Check c 1", c[1], 'b');
assertEquals("2) Check c 2", c[2], 'a');
assertFalse("2) Check bool 0", bool[0]);
assertFalse("2) Check bool 1", bool[0]);
assertFalse("2) Check bool 2", bool[0]);
}
Aggregations