use of org.apache.felix.ipojo.ServiceContext in project felix by apache.
the class TestConfiguration method testDefaultInstantiation.
@Test
public void testDefaultInstantiation() throws InvalidSyntaxException {
Properties props = new Properties();
props.put("instance.name", "under");
ComponentInstance under = null;
try {
under = compositeFactory.createComponentInstance(props);
} catch (Exception e) {
e.printStackTrace();
fail("Cannot instantiate under : " + e.getMessage());
}
assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
ServiceContext sc = getServiceContext(under);
ServiceReference[] refs = sc.getServiceReferences(FooService.class.getName(), null);
assertEquals(2, refs.length);
for (int i = 0; i < refs.length; i++) {
assertEquals(3, ((Integer) refs[i].getProperty("int")).intValue());
assertEquals("foo", (String) refs[i].getProperty("string"));
}
under.dispose();
}
use of org.apache.felix.ipojo.ServiceContext in project felix by apache.
the class TestConfiguration method testConfiguredInstantiation.
@Test
public void testConfiguredInstantiation() throws InvalidSyntaxException {
Properties props = new Properties();
props.put("instance.name", "under");
props.put("string", "bar");
props.put("int", "25");
ComponentInstance under = null;
try {
under = compositeFactory.createComponentInstance(props);
} catch (Exception e) {
e.printStackTrace();
fail("Cannot instantiate under : " + e.getMessage());
}
assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
ServiceContext sc = getServiceContext(under);
ServiceReference[] refs = sc.getServiceReferences(FooService.class.getName(), null);
assertEquals(2, refs.length);
for (int i = 0; i < refs.length; i++) {
assertEquals(25, ((Integer) refs[i].getProperty("int")).intValue());
assertEquals("bar", (String) refs[i].getProperty("string"));
}
under.dispose();
}
use of org.apache.felix.ipojo.ServiceContext in project felix by apache.
the class TestMultipleInstantiation method testServiceAvailability.
@Test
public void testServiceAvailability() {
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());
}
assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
ServiceContext sc = getServiceContext(under);
assertNotNull("Check service availability", sc.getServiceReference(BarService.class.getName()));
int count = ipojoHelper.getServiceReferences(sc, BarService.class.getName(), null).length;
assertEquals("Check service provider number : " + count, count, 3);
under.dispose();
}
use of org.apache.felix.ipojo.ServiceContext in project felix by apache.
the class TestMultipleInstantiation method testServiceAvailabilityLevel2.
@Test
public void testServiceAvailabilityLevel2() {
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);
ServiceContext sc2 = getServiceContext(under);
assertNotNull("Check service availability", sc2.getServiceReference(BarService.class.getName()));
assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc2, BarService.class.getName(), null).length, 3);
under.dispose();
}
use of org.apache.felix.ipojo.ServiceContext in project felix by apache.
the class TestMultipleInstantiation method testFactoryManagementLevel2.
@Test
public void testFactoryManagementLevel2() {
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 - 1", under.getState() == ComponentInstance.VALID);
ServiceContext sc2 = getServiceContext(under);
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(sc2, BarService.class.getName(), null).length, 2);
fact2.stop();
assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);
assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc2, BarService.class.getName(), null).length, 1);
fact3.stop();
assertTrue("Check instance invalidity", under.getState() == ComponentInstance.INVALID);
assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc2, BarService.class.getName(), null).length, 0);
fact1.start();
assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);
assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc2, BarService.class.getName(), null).length, 1);
under.dispose();
fact2.start();
fact3.start();
}
Aggregations