use of org.apache.felix.ipojo.composite.CompositeManager 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.composite.CompositeManager 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.composite.CompositeManager in project felix by apache.
the class EmptyCompositeTest method testInstanceCreation2.
@Test
public void testInstanceCreation2() {
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);
} 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.composite.CompositeManager in project felix by apache.
the class EmptyCompositeTest method testInstanceCreation1.
@Test
public void testInstanceCreation1() {
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());
}
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());
}
Properties props2 = new Properties();
props2.put("instance.name", "empty2");
ComponentInstance ci2 = null;
try {
ci2 = factory.createComponentInstance(props2, sc);
} catch (Exception e) {
e.printStackTrace();
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();
}
Aggregations