fail("Fail to instantiate the foo2 component " + e.getMessage());
}
// The foo service is available => import1 must be valid
assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
ServiceContext sc = Utils.getServiceContext(import2);
ServiceReference[] refs = Utils.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+")", refs.length, 2);
FooService fs = (FooService) sc.getService(refs[0]);
assertTrue("Test foo invocation", fs.foo());
FooService fs2 = (FooService) sc.getService(refs[1]);
assertTrue("Test foo invocation", fs2.foo());
sc.ungetService(refs[0]);
sc.ungetService(refs[1]);
// Stop the first provider
foo1.stop();
assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
sc = Utils.getServiceContext(import2);
refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
assertNotNull("Test foo availability inside the composite - 2", refs);
assertEquals("Test foo availability inside the composite - 2.1 ("+refs.length+")", refs.length, 1);
fs = (FooService) sc.getService(refs[0]);
assertTrue("Test foo invocation", fs.foo());
sc.ungetService(refs[0]);
// stop the second foo provider
foo2.dispose();
// No provider -> Invalid
assertTrue("Test component validity - 2", import2.getState() == ComponentInstance.VALID);
sc = Utils.getServiceContext(import2);
refs = Utils.getServiceReferences(sc, FooService.class.getName(), null);
assertEquals("Test foo non-availability inside the composite - 1", refs.length, 0);
foo1.start();
assertTrue("Test component validity", import2.getState() == ComponentInstance.VALID);
sc = Utils.getServiceContext(import2);
refs = Utils.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]);
foo1.dispose();
// No provider -> Invalid
assertTrue("Test component invalidity - 3", import2.getState() == ComponentInstance.VALID);
sc = Utils.getServiceContext(import2);