use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.
the class TestPropertiesInAnonymousClass method testRunnable.
@Test
public void testRunnable() {
ServiceReference sr = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "FooProviderAno-1");
assertNotNull("Check the availability of the FS service", sr);
// Check service properties
Integer intProp = (Integer) sr.getProperty("int");
Boolean boolProp = (Boolean) sr.getProperty("boolean");
String strProp = (String) sr.getProperty("string");
String[] strAProp = (String[]) sr.getProperty("strAProp");
int[] intAProp = (int[]) sr.getProperty("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)");
}
}
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)");
}
}
// Invoke
FooService fs = (FooService) osgiHelper.getRawServiceObject(sr);
assertTrue("invoke fs", fs.foo());
sr = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "FooProviderAno-1");
// 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 (2)", 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)");
}
}
fs = null;
}
use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.
the class TestServiceController method testComponentWithTwoControllersUsingBothSpecificationsTrueFalse.
@Test
public void testComponentWithTwoControllersUsingBothSpecificationsTrueFalse() {
ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Controller-2-spec1");
osgiHelper.waitForService(CheckService.class.getName(), null, 5000);
assertFalse(osgiHelper.isServiceAvailable(FooService.class.getName()));
CheckService check = (CheckService) osgiHelper.getServiceObject(CheckService.class.getName(), null);
assertNotNull(check);
check.getProps();
assertFalse(osgiHelper.isServiceAvailable(CheckService.class.getName()));
assertTrue(osgiHelper.isServiceAvailable(FooService.class.getName()));
FooService fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), null);
fs.fooProps();
assertTrue(osgiHelper.isServiceAvailable(CheckService.class.getName()));
assertTrue(osgiHelper.isServiceAvailable(FooService.class.getName()));
ci.dispose();
}
use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.
the class TestServiceController method testComponentWithTwoControllersUsingBothSpecificationsTrueTrue.
@Test
public void testComponentWithTwoControllersUsingBothSpecificationsTrueTrue() {
ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Controller-2-spec2");
osgiHelper.waitForService(CheckService.class.getName(), null, 5000);
osgiHelper.waitForService(FooService.class.getName(), null, 5000);
CheckService check = (CheckService) osgiHelper.getServiceObject(CheckService.class.getName(), null);
assertNotNull(check);
check.check();
// CheckService not available
assertNull(osgiHelper.getServiceReference(CheckService.class.getName()));
assertNotNull(osgiHelper.getServiceReference(FooService.class.getName()));
FooService fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), null);
fs.foo();
assertNull(osgiHelper.getServiceReference(CheckService.class.getName()));
assertNull(osgiHelper.getServiceReference(FooService.class.getName()));
ci.dispose();
}
use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.
the class TestServiceController method testComponentWithTwoControllersSetToTrueAndFalse.
@Test
public void testComponentWithTwoControllersSetToTrueAndFalse() {
ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Controller-2-truefalse");
osgiHelper.waitForService(CheckService.class.getName(), null, 5000);
assertFalse(osgiHelper.isServiceAvailable(FooService.class.getName()));
CheckService check = (CheckService) osgiHelper.getServiceObject(CheckService.class.getName(), null);
assertNotNull(check);
check.getProps();
assertFalse(osgiHelper.isServiceAvailable(CheckService.class.getName()));
assertTrue(osgiHelper.isServiceAvailable(FooService.class.getName()));
FooService fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), null);
fs.fooProps();
assertTrue(osgiHelper.isServiceAvailable(CheckService.class.getName()));
assertTrue(osgiHelper.isServiceAvailable(FooService.class.getName()));
ci.dispose();
}
use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.
the class TestServiceController method testComponentWithTwoControllersUsingSpecificationAndAllTrueTrue.
@Test
public void testComponentWithTwoControllersUsingSpecificationAndAllTrueTrue() {
ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Controller-2-spec3");
osgiHelper.waitForService(CheckService.class.getName(), null, 5000);
osgiHelper.waitForService(FooService.class.getName(), null, 5000);
CheckService check = (CheckService) osgiHelper.getServiceObject(CheckService.class.getName(), null);
assertNotNull(check);
check.check();
// CheckService not available
assertNull(osgiHelper.getServiceReference(CheckService.class.getName()));
assertNotNull(osgiHelper.getServiceReference(FooService.class.getName()));
FooService fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), null);
fs.foo();
assertNull(osgiHelper.getServiceReference(CheckService.class.getName()));
assertNull(osgiHelper.getServiceReference(FooService.class.getName()));
ci.dispose();
}
Aggregations