use of org.apache.felix.ipojo.ServiceContext in project felix by apache.
the class TestSimpleInstantiation method testServiceAvailabilityLevel2.
@Test
public void testServiceAvailabilityLevel2() {
ServiceContext sc = getServiceContext(empty);
Properties props = new Properties();
props.put("instance.name", "under-X");
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();
}
use of org.apache.felix.ipojo.ServiceContext in project felix by apache.
the class TestDelayedFilteredImport method testSimple2.
@Test
public void testSimple2() {
import1.start();
// Two providers
assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
ServiceContext sc = getServiceContext(import1);
ServiceReference[] refs = ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null);
assertNotNull("Test foo availability inside the composite - 1", refs);
assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
FooService fs = (FooService) sc.getService(refs[0]);
assertTrue("Test foo invocation", fs.foo());
sc.ungetService(refs[0]);
foo2.stop();
assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
sc = getServiceContext(import1);
refs = ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null);
assertNotNull("Test foo availability inside the composite - 1", refs);
assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
fs = (FooService) sc.getService(refs[0]);
assertTrue("Test foo invocation", fs.foo());
sc.ungetService(refs[0]);
// Stop the second provider
foo1.stop();
assertTrue("Test component invalidity - 2", import1.getState() == ComponentInstance.INVALID);
foo1.start();
assertTrue("Test component validity", import1.getState() == ComponentInstance.VALID);
sc = getServiceContext(import1);
refs = ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null);
assertNotNull("Test foo availability inside the composite - 3", refs);
assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
fs = (FooService) sc.getService(refs[0]);
assertTrue("Test foo invocation", fs.foo());
sc.ungetService(refs[0]);
}
use of org.apache.felix.ipojo.ServiceContext in project felix by apache.
the class TestDelayedMultipleImport method testSimple.
@Test
public void testSimple() {
import2.start();
// Two providers
assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
ServiceContext sc = getServiceContext(import2);
ServiceReference[] refs = ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null);
assertNotNull("Test foo availability inside the composite - 1", refs);
assertEquals("Test foo availability inside the composite - 1.2", refs.length, 2);
FooService fs = (FooService) sc.getService(refs[0]);
assertTrue("Test foo invocation", fs.foo());
sc.ungetService(refs[0]);
fs = (FooService) sc.getService(refs[1]);
assertTrue("Test foo invocation (2)", fs.foo());
sc.ungetService(refs[1]);
foo1.stop();
assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
sc = getServiceContext(import2);
refs = ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null);
assertNotNull("Test foo availability inside the composite - 1", refs);
assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
fs = (FooService) sc.getService(refs[0]);
assertTrue("Test foo invocation", fs.foo());
sc.ungetService(refs[0]);
// Stop the second provider
foo2.stop();
assertTrue("Test component invalidity - 2", import2.getState() == ComponentInstance.INVALID);
foo2.start();
assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
sc = getServiceContext(import2);
refs = ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null);
assertNotNull("Test foo availability inside the composite - 3", refs);
assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
fs = (FooService) sc.getService(refs[0]);
assertTrue("Test foo invocation", fs.foo());
sc.ungetService(refs[0]);
}
use of org.apache.felix.ipojo.ServiceContext in project felix by apache.
the class TestDelayedMultipleImport method testSimple2.
@Test
public void testSimple2() {
import2.start();
// Two providers
assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
ServiceContext sc = getServiceContext(import2);
ServiceReference[] refs = ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null);
assertNotNull("Test foo availability inside the composite - 1", refs);
assertEquals("Test foo availability inside the composite - 1.2", refs.length, 2);
FooService fs = (FooService) sc.getService(refs[0]);
assertTrue("Test foo invocation", fs.foo());
sc.ungetService(refs[0]);
fs = (FooService) sc.getService(refs[1]);
assertTrue("Test foo invocation", fs.foo());
sc.ungetService(refs[1]);
foo2.stop();
assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
sc = getServiceContext(import2);
refs = ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null);
assertNotNull("Test foo availability inside the composite - 1", refs);
assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
fs = (FooService) sc.getService(refs[0]);
assertTrue("Test foo invocation", fs.foo());
sc.ungetService(refs[0]);
// Stop the second provider
foo1.stop();
assertTrue("Test component invalidity - 2", import2.getState() == ComponentInstance.INVALID);
foo1.start();
assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
sc = getServiceContext(import2);
refs = ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null);
assertNotNull("Test foo availability inside the composite - 3", refs);
assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
fs = (FooService) sc.getService(refs[0]);
assertTrue("Test foo invocation", fs.foo());
sc.ungetService(refs[0]);
}
use of org.apache.felix.ipojo.ServiceContext in project felix by apache.
the class TestDelayedOptionalImport method testSimple.
@Test
public void testSimple() {
import3.start();
// Two providers
assertTrue("Test component validity", import3.getState() == ComponentInstance.VALID);
ServiceContext sc = getServiceContext(import3);
ServiceReference[] refs = ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null);
assertNotNull("Test foo availability inside the composite - 1", refs);
assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
FooService fs = (FooService) sc.getService(refs[0]);
assertTrue("Test foo invocation", fs.foo());
sc.ungetService(refs[0]);
foo1.stop();
assertTrue("Test component validity", import3.getState() == ComponentInstance.VALID);
sc = getServiceContext(import3);
refs = ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null);
assertNotNull("Test foo availability inside the composite - 1", refs);
assertEquals("Test foo availability inside the composite - 1.2", refs.length, 1);
fs = (FooService) sc.getService(refs[0]);
assertTrue("Test foo invocation", fs.foo());
sc.ungetService(refs[0]);
// Stop the second provider
foo2.stop();
assertTrue("Test component validity - 2", import3.getState() == ComponentInstance.VALID);
sc = getServiceContext(import3);
refs = ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null);
assertEquals("Test foo non-availability inside the composite - 3.1", refs.length, 0);
foo2.start();
assertTrue("Test component validity", import3.getState() == ComponentInstance.VALID);
sc = getServiceContext(import3);
refs = ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null);
assertNotNull("Test foo availability inside the composite - 3", refs);
assertEquals("Test foo availability inside the composite - 3.1", refs.length, 1);
fs = (FooService) sc.getService(refs[0]);
assertTrue("Test foo invocation", fs.foo());
sc.ungetService(refs[0]);
}
Aggregations