use of org.apache.felix.ipojo.ServiceContext in project felix by apache.
the class TestOptionalInstantiation method testFactoryManagementLevel2.
@Test
public void testFactoryManagementLevel2() {
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 - 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);
fact2.stop();
assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);
fact3.stop();
assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);
fact1.start();
assertTrue("Check instance validity - 5", under.getState() == ComponentInstance.VALID);
under.dispose();
fact2.start();
fact3.start();
}
use of org.apache.felix.ipojo.ServiceContext in project felix by apache.
the class TestOptionalInstantiation method testFactoryManagement.
@Test
public void testFactoryManagement() {
Properties props = new Properties();
props.put("instance.name", "under");
ComponentInstance under = null;
try {
under = bar1Factory.createComponentInstance(props);
} catch (Exception e) {
fail("Cannot instantiate under : " + e.getMessage());
}
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);
fact2.stop();
assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);
fact3.stop();
assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);
ServiceContext sc = getServiceContext(under);
assertNull("Check that no Bar Service is available", sc.getServiceReference(BarService.class.getName()));
fact1.start();
assertTrue("Check instance validity - 5", under.getState() == ComponentInstance.VALID);
under.dispose();
fact2.start();
fact3.start();
}
use of org.apache.felix.ipojo.ServiceContext in project felix by apache.
the class TestOptionalMultipleInstantiation 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 TestOptionalMultipleInstantiation 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 TestSimpleInstantiation method testFactoryManagementLevel2.
@Test
public void testFactoryManagementLevel2() {
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 - 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);
fact2.stop();
assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);
fact3.stop();
assertTrue("Check instance invalidity", under.getState() == ComponentInstance.INVALID);
fact1.start();
assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);
under.dispose();
fact2.start();
fact3.start();
}
Aggregations