use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.
the class TestExposition method testItfsExposition.
@Test
public void testItfsExposition() {
ServiceReference refFoo = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), fooBarProvider.getInstanceName());
assertNotNull("Check the availability of the FS from " + fooBarProvider.getInstanceName(), refFoo);
ServiceReference refBar = ipojoHelper.getServiceReferenceByName(BarService.class.getName(), fooBarProvider.getInstanceName());
assertNotNull("Check the availability of the BS from " + fooBarProvider.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());
fooBarProvider.stop();
assertFalse("Check the absence of the FS from " + fooBarProvider.getInstanceName(), ipojoHelper.isServiceAvailableByName(FooService.class.getName(), fooBarProvider.getInstanceName()));
assertFalse("Check the absence of the BS from " + fooBarProvider.getInstanceName(), ipojoHelper.isServiceAvailableByName(BarService.class.getName(), fooBarProvider.getInstanceName()));
}
use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.
the class TestNullCheck method testNull.
@Test
public void testNull() {
String factName = "PS-Null";
String compName = "NullCheck";
ServiceReference ref = null;
// Check that no Foo Service are available
ref = osgiHelper.getServiceReference(FooService.class.getName());
assertNull("FS already available", ref);
// Get the factory to create a component instance
Factory fact = ipojoHelper.getFactory(factName);
assertNotNull("Cannot find the factory FooProvider-1", fact);
// Don't give any configuration so, properties are null.
ipojoHelper.createComponentInstance(factName, compName);
// Get a FooService provider
ref = osgiHelper.getServiceReference(FooService.class.getName(), "(" + "instance.name" + "=" + compName + ")");
assertNotNull("FS not available", ref);
// Check service properties
assertNull(ref.getProperty("prop1"));
assertNotNull(ref.getProperty("prop2"));
// Test foo invocation
FooService fs = (FooService) osgiHelper.getRawServiceObject(ref);
assertTrue("FooService invocation failed", fs.foo());
ref = osgiHelper.getServiceReference(FooService.class.getName(), "(" + "instance.name" + "=" + compName + ")");
// Check service properties
assertNotNull(ref.getProperty("prop1"));
assertNull(ref.getProperty("prop2"));
ipojoHelper.dispose();
// Check that there is no more FooService
ref = osgiHelper.getServiceReference(FooService.class.getName(), null);
assertNull("FS available, but component instance stopped", ref);
}
use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.
the class TestOSGiProperties method testOSGiProperties.
@Test
public void testOSGiProperties() {
String factName = "PS-FooProviderType-1";
String compName = "FooProvider-1";
ServiceReference ref = null;
// Check that no Foo Service are available
ref = osgiHelper.getServiceReference(FooService.class.getName());
assertNull("FS already available", ref);
// Get the factory to create a component instance
Factory fact = ipojoHelper.getFactory(factName);
assertNotNull("Cannot find the factory FooProvider-1", fact);
Dictionary conf = new Properties();
conf.put(Constants.SERVICE_DESCRIPTION, "description");
conf.put(Constants.SERVICE_RANKING, "10");
conf.put(Constants.SERVICE_VENDOR, "ASF");
conf.put(Constants.SERVICE_PID, "my.pid");
ipojoHelper.createComponentInstance(factName, compName, conf);
// Get a FooService provider
ref = osgiHelper.getServiceReference(FooService.class.getName(), "(" + "instance.name" + "=" + compName + ")");
assertNotNull("FS not available", ref);
// Check properties
assertEquals("description", ref.getProperty(Constants.SERVICE_DESCRIPTION));
assertEquals(new Integer(10), ref.getProperty(Constants.SERVICE_RANKING));
assertEquals("ASF", ref.getProperty(Constants.SERVICE_VENDOR));
assertEquals("my.pid", ref.getProperty(Constants.SERVICE_PID));
// Test foo invocation
FooService fs = (FooService) osgiHelper.getRawServiceObject(ref);
assertTrue("FooService invocation failed", fs.foo());
ipojoHelper.dispose();
// Check that there is no more FooService
ref = osgiHelper.getServiceReference(FooService.class.getName(), null);
assertNull("FS available, but component instance stopped", ref);
}
use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.
the class TestPropertiesInAnonymousClass method testWorkerThread.
@Test
public void testWorkerThread() {
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.getBoolean());
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 testComponentWithTwoControllersSetToTrue.
@Test
public void testComponentWithTwoControllersSetToTrue() {
ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Controller-2-truetrue");
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();
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