use of org.apache.felix.ipojo.ServiceContext in project felix by apache.
the class TestSimpleInstantiation method testServiceAvailability.
@Test
public void testServiceAvailability() {
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", under.getState() == ComponentInstance.VALID);
ServiceContext sc = getServiceContext(under);
assertNotNull("Check service availability", sc.getServiceReference(BarService.class.getName()));
under.dispose();
}
use of org.apache.felix.ipojo.ServiceContext in project felix by apache.
the class TestSimpleInstantiation method testCreationLevel2.
@Test
public void testCreationLevel2() {
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);
under.dispose();
}
use of org.apache.felix.ipojo.ServiceContext in project felix by apache.
the class EmptyCompositeTest method testEmptyCompositeCreation.
@Test
public void testEmptyCompositeCreation() {
Factory factory = ipojoHelper.getFactory("composite.empty");
Properties props = new Properties();
props.put("instance.name", "empty");
ComponentInstance ci = null;
try {
ci = factory.createComponentInstance(props);
} catch (Exception e) {
e.printStackTrace();
fail("Unacceptable configuration : " + e.getMessage());
}
ComponentTypeDescription cd = ci.getFactory().getComponentDescription();
assertEquals("Check component type name", cd.getName(), "composite.empty");
// assertEquals("Check class name (" + cd.getClassName() + ")", cd.getClassName(), "composite");
assertEquals("Check offered service", cd.getprovidedServiceSpecification().length, 0);
assertEquals("Check configurable properties", cd.getProperties().length, 0);
CompositeInstanceDescription id = (CompositeInstanceDescription) ci.getInstanceDescription();
assertEquals("Check composite instance name", id.getName(), "empty");
assertEquals("Check composite instance state (" + id.getState() + ")", id.getState(), ComponentInstance.VALID);
assertEquals("Check contained instance", id.getContainedInstances().length, 0);
assertTrue("Check composite manager", ci instanceof CompositeManager);
CompositeManager cm = (CompositeManager) ci;
ServiceContext sc = cm.getServiceContext();
try {
assertEquals("Check number of factories imported", sc.getServiceReferences(Factory.class.getName(), null).length, getContext().getServiceReferences(Factory.class.getName(), null).length);
} catch (InvalidSyntaxException e) {
fail("Invalid filter : " + e.getMessage());
}
ci.dispose();
}
use of org.apache.felix.ipojo.ServiceContext in project felix by apache.
the class EmptyCompositeTest method testInstanceCreation3.
@Test
public void testInstanceCreation3() {
Factory factory = ipojoHelper.getFactory("composite.empty");
Properties props = new Properties();
props.put("instance.name", "empty");
ComponentInstance ci = null;
try {
ci = factory.createComponentInstance(props);
} catch (Exception e) {
fail("Unacceptable configuration : " + e.getMessage());
}
assertTrue("Check composite manager", ci instanceof CompositeManager);
CompositeManager cm = (CompositeManager) ci;
ServiceContext sc = cm.getServiceContext();
try {
assertEquals("Check number of factories imported", sc.getServiceReferences(Factory.class.getName(), null).length, getContext().getServiceReferences(Factory.class.getName(), null).length);
} catch (InvalidSyntaxException e) {
fail("Invalid filter : " + e.getMessage());
}
Factory factory2 = ipojoHelper.getFactory(sc, "composite.empty");
assertNotNull("Check factory2 not null", factory2);
Properties props2 = new Properties();
props2.put("instance.name", "empty2");
ComponentInstance ci2 = null;
try {
ci2 = factory2.createComponentInstance(props2, sc);
} catch (Exception e) {
fail("Unacceptable configuration : " + e.getMessage());
}
CompositeInstanceDescription id = (CompositeInstanceDescription) ci.getInstanceDescription();
assertEquals("Check composite instance name", id.getName(), "empty");
assertEquals("Check composite instance state", id.getState(), ComponentInstance.VALID);
assertEquals("Check contained instance", id.getContainedInstances().length, 1);
CompositeInstanceDescription id2 = (CompositeInstanceDescription) id.getContainedInstances()[0];
assertEquals("Check composite instance name", id2.getName(), "empty2");
assertEquals("Check composite instance state", id2.getState(), ComponentInstance.VALID);
assertEquals("Check contained instance", id2.getContainedInstances().length, 0);
ci2.dispose();
// id = ci.getInstanceDescription();
assertEquals("Check composite instance name", id.getName(), "empty");
assertEquals("Check composite instance state", id.getState(), ComponentInstance.VALID);
assertEquals("Check contained instance", id.getContainedInstances().length, 0);
ci.dispose();
}
use of org.apache.felix.ipojo.ServiceContext in project felix by apache.
the class ServiceRangeTest method testLevelOne2.
@Test
public void testLevelOne2() {
ServiceContext sc2 = getServiceContext(empty);
Factory fact1 = ipojoHelper.getFactory(sc2, "COMPO-SimpleCheckServiceProvider");
Properties props = new Properties();
props.put("instance.name", "client");
ComponentInstance client = null;
try {
client = fact1.createComponentInstance(props, sc2);
} catch (Exception e) {
fail("Cannot instantiate the client : " + e.getMessage());
}
Factory fact2 = ipojoHelper.getFactory(sc2, "COMPO-FooProviderType-1");
Properties props2 = new Properties();
props2.put("instance.name", "provider");
ComponentInstance provider = null;
try {
provider = fact2.createComponentInstance(props2, sc2);
} catch (Exception e) {
fail("Cannot instantiate the provider : " + e.getMessage());
}
ServiceReference ref = sc2.getServiceReference(CheckService.class.getName());
CheckService check = (CheckService) sc2.getService(ref);
assertTrue("Check invocation", check.check());
sc2.ungetService(ref);
// Check visibility
assertNotNull("Check foo service visible inside the composite", sc2.getServiceReference(FooService.class.getName()));
assertNotNull("Check check service visible inside the composite", sc2.getServiceReference(CheckService.class.getName()));
// Check invisibilty
assertNull("Check foo service invisible inside the context", getContext().getServiceReference(FooService.class.getName()));
try {
assertNull("Check check service invisible inside the context", getContext().getServiceReferences(CheckService.class.getName(), "(instance.name=client)"));
} catch (InvalidSyntaxException e) {
fail("Invalid filter : " + e);
}
client.dispose();
provider.dispose();
assertNull("Check foo service visible inside the composite 2", sc2.getServiceReference(FooService.class.getName()));
assertNull("Check check service visible inside the composite 2", sc2.getServiceReference(CheckService.class.getName()));
assertNull("Check foo service invisible inside the global", getContext().getServiceReference(FooService.class.getName()));
try {
assertNull("Check check service invisible inside the context", getContext().getServiceReferences(CheckService.class.getName(), "(instance.name=client)"));
} catch (InvalidSyntaxException e) {
fail("Invalid filter : " + e);
}
}
Aggregations