use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.
the class TestDynamicPropsReconfiguration method testFactoryReconfNoValue.
@Test
public void testFactoryReconfNoValue() {
ServiceReference sr = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-4");
assertNotNull("Check the availability of the FS service", sr);
// Check service properties
Integer intProp = (Integer) sr.getProperty("int");
Object boolProp = sr.getProperty("boolean");
Object strProp = sr.getProperty("string");
Object strAProp = sr.getProperty("strAProp");
int[] intAProp = (int[]) sr.getProperty("intAProp");
assertEquals("Check intProp equality", intProp, new Integer(4));
assertEquals("Check longProp equality", boolProp, null);
assertEquals("Check strProp equality", strProp, null);
assertNull("Check strAProp nullity", strAProp);
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");
}
}
// Reconfiguration
ServiceReference fact_ref = ipojoHelper.getServiceReferenceByName(Factory.class.getName(), "PS-FooProviderType-Dyn2");
Factory fact = (Factory) osgiHelper.getRawServiceObject(fact_ref);
Properties p3 = new Properties();
p3.put("instance.name", "FooProvider-4");
p3.put("int", new Integer(1));
p3.put("boolean", new Boolean(true));
p3.put("string", new String("foo"));
p3.put("strAProp", new String[] { "foo", "bar", "baz" });
p3.put("intAProp", new int[] { 1, 2, 3 });
try {
fact.reconfigure(p3);
} catch (Exception e) {
fail("Unable to reconfigure the instance with : " + p3);
}
sr = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-4");
assertNotNull("Check the availability of the FS service", sr);
// Check service properties
intProp = (Integer) sr.getProperty("int");
boolProp = (Boolean) sr.getProperty("boolean");
strProp = (String) sr.getProperty("string");
strAProp = (String[]) sr.getProperty("strAProp");
intAProp = (int[]) sr.getProperty("intAProp");
assertEquals("Check intProp equality", intProp, new Integer(1));
assertEquals("Check longProp equality", boolProp, new Boolean(true));
assertEquals("Check strProp equality", strProp, new String("foo"));
assertNotNull("Check strAProp not nullity", strAProp);
String[] v = new String[] { "foo", "bar", "baz" };
for (int i = 0; i < ((String[]) strAProp).length; i++) {
if (!((String[]) strAProp)[i].equals(v[i])) {
fail("Check the strAProp Equality");
}
}
assertNotNull("Check intAProp not nullity", intAProp);
v2 = new int[] { 1, 2, 3 };
for (int i = 0; i < intAProp.length; i++) {
if (intAProp[i] != v2[i]) {
fail("Check the intAProp Equality");
}
}
// Invoke
FooService fs = (FooService) osgiHelper.getRawServiceObject(sr);
assertTrue("invoke fs", fs.foo());
// Re-check the property (change)
intProp = (Integer) sr.getProperty("int");
boolProp = (Boolean) sr.getProperty("boolean");
strProp = (String) sr.getProperty("string");
strAProp = (String[]) sr.getProperty("strAProp");
intAProp = (int[]) sr.getProperty("intAProp");
assertEquals("Check intProp equality", intProp, new Integer(2));
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" };
for (int i = 0; i < ((String[]) strAProp).length; i++) {
if (!((String[]) strAProp)[i].equals(v[i])) {
fail("Check the strAProp Equality");
}
}
assertNull("Check intAProp hidding (no value)", intAProp);
// Reconfiguration
fact_ref = ipojoHelper.getServiceReferenceByName(Factory.class.getName(), "PS-FooProviderType-Dyn2");
fact = (Factory) osgiHelper.getRawServiceObject(fact_ref);
p3 = new Properties();
p3.put("instance.name", "FooProvider-3");
p3.put("int", new Integer(1));
p3.put("boolean", new Boolean(true));
p3.put("string", new String("foo"));
p3.put("strAProp", new String[] { "foo", "bar", "baz" });
p3.put("intAProp", new int[] { 1, 2, 3 });
try {
fact.reconfigure(p3);
} catch (Exception e) {
fail("Unable to reconfigure the instance with : " + p3);
}
sr = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-3");
assertNotNull("Check the availability of the FS service", sr);
// Check service properties
intProp = (Integer) sr.getProperty("int");
boolProp = (Boolean) sr.getProperty("boolean");
strProp = (String) sr.getProperty("string");
strAProp = (String[]) sr.getProperty("strAProp");
intAProp = (int[]) sr.getProperty("intAProp");
assertEquals("Check intProp equality", intProp, new Integer(1));
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 < ((String[]) strAProp).length; i++) {
if (!((String[]) strAProp)[i].equals(v[i])) {
fail("Check the strAProp Equality");
}
}
assertNotNull("Check intAProp not nullity", intAProp);
v2 = new int[] { 1, 2, 3 };
for (int i = 0; i < intAProp.length; i++) {
if (intAProp[i] != v2[i]) {
fail("Check the intAProp Equality");
}
}
fact = null;
fs = null;
}
use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.
the class TestExposition method testSimpleExposition.
@Test
public void testSimpleExposition() {
ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), fooProviderSimple.getInstanceName());
assertNotNull("Check the availability of the FS from " + fooProviderSimple.getInstanceName(), ref);
FooService fs = (FooService) osgiHelper.getRawServiceObject(ref);
assertTrue("Check fs invocation", fs.foo());
fooProviderSimple.stop();
assertFalse("Check the absence of the FS from " + fooProviderSimple.getInstanceName(), ipojoHelper.isServiceAvailableByName(FooService.class.getName(), fooProviderSimple.getInstanceName()));
}
use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.
the class TestExposition method testItfsExposition3.
@Test
public void testItfsExposition3() {
ServiceReference refFoo = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), fooBarProvider3.getInstanceName());
assertNotNull("Check the availability of the FS from " + fooBarProvider3.getInstanceName(), refFoo);
ServiceReference refBar = ipojoHelper.getServiceReferenceByName(BarService.class.getName(), fooBarProvider3.getInstanceName());
assertNotNull("Check the availability of the BS from " + fooBarProvider3.getInstanceName(), refBar);
assertNotSame("Check service reference inequality", refFoo, refBar);
FooService fs = (FooService) osgiHelper.getRawServiceObject(refFoo);
assertTrue("Check fs invocation", fs.foo());
BarService bs = (BarService) osgiHelper.getRawServiceObject(refBar);
assertTrue("Check bs invocation", bs.bar());
// Check properties
String baz1 = (String) refFoo.getProperty("baz");
String baz2 = (String) refBar.getProperty("baz");
assertEquals("Check Baz Property 1", baz1, "foo");
assertEquals("Check Baz Property 2", baz2, "bar");
fooBarProvider3.stop();
assertFalse("Check the absence of the FS from " + fooBarProvider3.getInstanceName(), ipojoHelper.isServiceAvailableByName(FooService.class.getName(), fooBarProvider3.getInstanceName()));
assertFalse("Check the absence of the BS from " + fooBarProvider3.getInstanceName(), ipojoHelper.isServiceAvailableByName(BarService.class.getName(), fooBarProvider3.getInstanceName()));
}
use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.
the class TestExposition method testItfExposition.
@Test
public void testItfExposition() {
ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), fooProviderItf.getInstanceName());
assertNotNull("Check the availability of the FS from " + fooProviderItf.getInstanceName(), ref);
FooService fs = (FooService) osgiHelper.getRawServiceObject(ref);
assertTrue("Check fs invocation", fs.foo());
fooProviderItf.stop();
assertFalse("Check the absence of the FS from " + fooProviderSimple.getInstanceName(), ipojoHelper.isServiceAvailableByName(FooService.class.getName(), fooProviderItf.getInstanceName()));
}
use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.
the class TestExposition method testItfsExposition2.
@Test
public void testItfsExposition2() {
ServiceReference refFoo = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), fooBarProvider2.getInstanceName());
assertNotNull("Check the availability of the FS from " + fooBarProvider2.getInstanceName(), refFoo);
ServiceReference refBar = ipojoHelper.getServiceReferenceByName(BarService.class.getName(), fooBarProvider2.getInstanceName());
assertNotNull("Check the availability of the BS from " + fooBarProvider2.getInstanceName(), refBar);
assertSame("Check service reference equality", refFoo, refBar);
FooService fs = (FooService) osgiHelper.getRawServiceObject(refFoo);
assertTrue("Check fs invocation", fs.foo());
BarService bs = (BarService) osgiHelper.getRawServiceObject(refBar);
assertTrue("Check bs invocation", bs.bar());
fooBarProvider2.stop();
assertFalse("Check the absence of the FS from " + fooBarProvider2.getInstanceName(), ipojoHelper.isServiceAvailableByName(FooService.class.getName(), fooBarProvider2.getInstanceName()));
assertFalse("Check the absence of the BS from " + fooBarProvider2.getInstanceName(), ipojoHelper.isServiceAvailableByName(BarService.class.getName(), fooBarProvider2.getInstanceName()));
}
Aggregations