use of org.apache.felix.ipojo.runtime.core.services.CheckService in project felix by apache.
the class TestCompositeAPI method testAPI.
@Test
public void testAPI() {
Factory fact1 = ipojoHelper.getFactory("composite.empty");
Properties p = new Properties();
p.put("instance.name", "empty-1");
ComponentInstance empty = null;
try {
empty = fact1.createComponentInstance(p);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
ServiceContext sc = getServiceContext(empty);
Factory fact2 = ipojoHelper.getFactory("composite.test.2");
Properties props2 = new Properties();
// 2
props2.put("instance.name", "2");
Factory fact3 = ipojoHelper.getFactory("composite.test.3");
Properties props3 = new Properties();
props3.put("instance.name", "3");
ComponentInstance comp2 = null;
ComponentInstance comp3 = null;
try {
comp2 = fact2.createComponentInstance(props2, sc);
comp3 = fact3.createComponentInstance(props3, sc);
} catch (Throwable e) {
e.printStackTrace();
fail(e.getMessage());
}
assertTrue("Test comp3", comp3.getState() == ComponentInstance.VALID);
assertTrue("Test comp2", comp2.getState() == ComponentInstance.VALID);
ServiceReference ref = null;
// 2
ref = ipojoHelper.getServiceReferenceByName(sc, CheckService.class.getName(), "2");
assertNotNull("Check ref", ref);
CheckService cs = (CheckService) sc.getService(ref);
assertTrue("Check invoke", cs.check());
comp3.dispose();
comp2.dispose();
empty.dispose();
}
use of org.apache.felix.ipojo.runtime.core.services.CheckService in project felix by apache.
the class TestGenericList method testTypedList.
@Test
public void testTypedList() {
ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), checker.getInstanceName());
CheckService check = (CheckService) osgiHelper.getServiceObject(ref);
assertNotNull("Checker availability", check);
// Check without providers
assertFalse("Empty list", check.check());
// Start the first provider
foo1.start();
assertTrue("List with one element", check.check());
Properties props = check.getProps();
List<FooService> list = (List<FooService>) props.get("list");
assertEquals("Check size - 1", 1, list.size());
// Start the second provider
foo2.start();
assertTrue("List with two element", check.check());
props = check.getProps();
list = (List<FooService>) props.get("list");
assertEquals("Check size - 2", 2, list.size());
// Stop the first one
foo1.stop();
assertTrue("List with one element (2)", check.check());
props = check.getProps();
list = (List<FooService>) props.get("list");
assertEquals("Check size - 3", 1, list.size());
}
use of org.apache.felix.ipojo.runtime.core.services.CheckService in project felix by apache.
the class TestNestedClasses method setUp.
@Before
public void setUp() {
Properties map = new Properties();
map.put("publicObject", "publicObject");
map.put("publicInt", new Integer(0));
map.put("packageObject", "packageObject");
map.put("packageInt", new Integer(1));
map.put("protectedObject", "protectedObject");
map.put("protectedInt", new Integer(2));
map.put("privateObject", "privateObject");
map.put("privateInt", new Integer(3));
map.put("nonObject", "nonObject");
map.put("nonInt", new Integer(4));
instance = ipojoHelper.createComponentInstance("inners", map);
ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance.getInstanceName());
assertNotNull("Check service availability", ref);
service = (CheckService) osgiHelper.getServiceObject(ref);
}
use of org.apache.felix.ipojo.runtime.core.services.CheckService in project felix by apache.
the class TestInstanceScope method testScope.
@Test
public void testScope() {
ServiceReference ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance.getInstanceName());
assertNotNull("Check architecture availability", ref);
Architecture arch = (Architecture) getContext().getService(ref);
assertTrue("Validity", arch.getInstanceDescription().getState() == ComponentInstance.VALID);
// Get internal service
ServiceContext sc = getServiceContext(instance);
ServiceReference ref2 = ipojoHelper.getServiceReference(sc, CheckService.class.getName(), null);
assertNotNull("Check CheckService availability", ref2);
CheckService svc = (CheckService) sc.getService(ref2);
Properties props = svc.getProps();
assertEquals("Check props - 1", 1, ((Integer) props.get("1")).intValue());
assertEquals("Check props - 2", 2, ((Integer) props.get("2")).intValue());
assertEquals("Check props - 3", 3, ((Integer) props.get("3")).intValue());
}
use of org.apache.felix.ipojo.runtime.core.services.CheckService in project felix by apache.
the class FactoryManagementTest method testInvocation.
@Test
public void testInvocation() {
ServiceContext sc1 = getServiceContext(empty);
Factory fact = ipojoHelper.getFactory(sc1, "composite.empty");
Properties p = new Properties();
p.put("instance.name", "empty2");
ComponentInstance empty2 = null;
try {
empty2 = fact.createComponentInstance(p);
} catch (Exception e) {
fail("Cannot instantiate empty2 instance : " + e.getMessage());
}
ServiceContext sc2 = getServiceContext(empty2);
Factory fact1 = ipojoHelper.getFactory(sc2, "COMPO-SimpleCheckServiceProvider");
Properties props = new Properties();
props.put("instance.name", "client");
ComponentInstance client = null;
try {
client = fact1.createComponentInstance(props);
} catch (Exception e) {
e.printStackTrace();
fail("Cannot instantiate the client : " + e.getMessage());
}
Factory fact2 = ipojoHelper.getFactory(sc2, "COMPO-FooProviderType-1");
Properties props2 = new Properties();
props2.put("instance.name", "provider");
ComponentInstance provider = null;
try {
provider = fact2.createComponentInstance(props2);
} catch (Exception e) {
fail("Cannot instantiate the provider : " + e.getMessage());
}
ServiceReference ref = sc2.getServiceReference(CheckService.class.getName());
assertNotNull("Check ref existency", ref);
CheckService check = (CheckService) sc2.getService(ref);
assertTrue("Check invocation", check.check());
client.dispose();
provider.dispose();
empty2.dispose();
}
Aggregations