use of org.apache.felix.ipojo.ServiceContext in project felix by apache.
the class TestSimpleInstance method testServiceAvailability.
@Test
public void testServiceAvailability() {
Properties props = new Properties();
props.put("instance.name", "under");
ComponentInstance under = null;
try {
under = compoFactory.createComponentInstance(props);
} catch (Exception e) {
fail("Cannot instantiate under : " + e.getMessage());
}
assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
ServiceContext sc = getServiceContext(under);
assertNotNull("Check service availability", sc.getServiceReference(FooService.class.getName()));
assertEquals("Check service provider", ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null).length, 2);
under.dispose();
}
use of org.apache.felix.ipojo.ServiceContext in project felix by apache.
the class TestConfigurableInstantiation method testAccept.
@Test
public void testAccept() {
Properties props = new Properties();
props.put("instance.name", "under-A");
ComponentInstance under = null;
try {
under = acceptF.createComponentInstance(props);
} catch (Exception e) {
fail("Cannot instantiate under : " + e.getMessage());
}
assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
ServiceContext sc = getServiceContext(under);
ServiceReference ref = sc.getServiceReference(FooService.class.getName());
assertNotNull("Check refs not null", ref);
FooService foo = (FooService) sc.getService(ref);
Properties p = foo.fooProps();
boolean b = ((Boolean) p.get("boolProp")).booleanValue();
String s = (String) p.get("strProp");
int i = ((Integer) p.get("intProp")).intValue();
assertTrue("Test boolean", b);
assertEquals("Test string", s, "foo");
// TODO See why it fails...
// assertEquals("Test int", i, 5); // The code fix to 5.
under.dispose();
}
use of org.apache.felix.ipojo.ServiceContext in project felix by apache.
the class TestMultipleInstantiation method testFactoryManagement.
@Test
public void testFactoryManagement() {
Properties props = new Properties();
props.put("instance.name", "under");
ComponentInstance under = null;
try {
under = bar2Factory.createComponentInstance(props);
} catch (Exception e) {
fail("Cannot instantiate under : " + e.getMessage());
}
ServiceContext sc = getServiceContext(under);
assertTrue("Check instance validity - 1", under.getState() == ComponentInstance.VALID);
ComponentFactory fact1 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-1");
ComponentFactory fact2 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-2");
ComponentFactory fact3 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-3");
fact1.stop();
assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);
assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc, BarService.class.getName(), null).length, 2);
fact2.stop();
assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);
assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc, BarService.class.getName(), null).length, 1);
fact3.stop();
assertTrue("Check instance invalidity", under.getState() == ComponentInstance.INVALID);
assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc, BarService.class.getName(), null).length, 0);
fact1.start();
assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc, BarService.class.getName(), null).length, 1);
assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);
under.dispose();
fact2.start();
fact3.start();
}
use of org.apache.felix.ipojo.ServiceContext in project felix by apache.
the class TestMultipleInstantiation method testCreationLevel2.
@Test
public void testCreationLevel2() {
ServiceContext sc = getServiceContext(empty);
Properties props = new Properties();
props.put("instance.name", "under");
ComponentInstance under = null;
try {
under = bar2Factory.createComponentInstance(props, sc);
} catch (Exception e) {
fail("Cannot instantiate under : " + e.getMessage());
}
assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
under.dispose();
}
use of org.apache.felix.ipojo.ServiceContext in project felix by apache.
the class TestOptionalInstantiation method testServiceAvailabilityLevel2.
@Test
public void testServiceAvailabilityLevel2() {
ServiceContext sc = getServiceContext(empty);
Properties props = new Properties();
props.put("instance.name", "under");
ComponentInstance under = null;
try {
under = bar1Factory.createComponentInstance(props, sc);
} catch (Exception e) {
fail("Cannot instantiate under : " + e.getMessage());
}
assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
ServiceContext sc2 = getServiceContext(under);
assertNotNull("Check service availability", sc2.getServiceReference(BarService.class.getName()));
under.dispose();
}
Aggregations