use of org.apache.felix.ipojo.composite.CompositeInstanceDescription 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();
}
use of org.apache.felix.ipojo.composite.CompositeInstanceDescription in project felix by apache.
the class TestSimpleInstance method atestArchitecture.
public void atestArchitecture() {
// TODO fix and reactivate the method.
Properties props = new Properties();
props.put("instance.name", "under");
ComponentInstance under = null;
try {
under = compoFactory.createComponentInstance(props);
} catch (Exception e) {
fail("Cannot instantiate under : " + e.getMessage());
}
ServiceReference ref = osgiHelper.getServiceReference(Architecture.class.getName(), "(architecture.instance=under)");
assertNotNull("Check architecture availability", ref);
Architecture arch = (Architecture) getContext().getService(ref);
CompositeInstanceDescription id = (CompositeInstanceDescription) arch.getInstanceDescription();
assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
InstanceDescription[] contained = id.getContainedInstances();
assertEquals("Check contained instances count (" + contained.length + ")", contained.length, 1);
assertEquals("Check instance name", id.getName(), "under");
assertEquals("Check component type name", id.getComponentDescription().getName(), "composite.bar.1");
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);
ref = osgiHelper.getServiceReference(Architecture.class.getName(), "(architecture.instance=under)");
assertNotNull("Check architecture availability", ref);
arch = (Architecture) getContext().getService(ref);
// id = arch.getInstanceDescription();
assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
contained = id.getContainedInstances();
assertEquals("Check contained instances count", contained.length, 1);
assertEquals("Check instance name", id.getName(), "under");
assertEquals("Check component type name", id.getComponentDescription().getName(), "composite.bar.1");
fact2.stop();
assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);
ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "under");
assertNotNull("Check architecture availability", ref);
arch = (Architecture) getContext().getService(ref);
// id = arch.getInstanceDescription();
assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
contained = id.getContainedInstances();
assertEquals("Check contained instances count", contained.length, 1);
assertEquals("Check instance name", id.getName(), "under");
assertEquals("Check component type name", id.getComponentDescription().getName(), "composite.bar.1");
fact3.stop();
assertTrue("Check instance invalidity", under.getState() == ComponentInstance.INVALID);
ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "under");
assertNotNull("Check architecture availability", ref);
arch = (Architecture) getContext().getService(ref);
// id = arch.getInstanceDescription();
assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.INVALID);
contained = id.getContainedInstances();
assertEquals("Check contained instances count", contained.length, 0);
assertEquals("Check instance name", id.getName(), "under");
assertEquals("Check component type name", id.getComponentDescription().getName(), "composite.bar.1");
fact1.start();
assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);
ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "under");
assertNotNull("Check architecture availability", ref);
arch = (Architecture) getContext().getService(ref);
// id = arch.getInstanceDescription();
assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
contained = id.getContainedInstances();
assertEquals("Check contained instances count", contained.length, 1);
assertEquals("Check instance name", id.getName(), "under");
assertEquals("Check component type name", id.getComponentDescription().getName(), "composite.bar.1");
under.dispose();
fact2.start();
fact3.start();
}
use of org.apache.felix.ipojo.composite.CompositeInstanceDescription in project felix by apache.
the class TestSimpleInstantiation method testArchitecture.
@Test
public void testArchitecture() {
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());
}
ServiceReference ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "under");
assertNotNull("Check architecture availability", ref);
Architecture arch = (Architecture) getContext().getService(ref);
CompositeInstanceDescription id = (CompositeInstanceDescription) arch.getInstanceDescription();
assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
InstanceDescription[] contained = id.getContainedInstances();
assertEquals("Check contained instances count", contained.length, 1);
assertEquals("Check instance name", id.getName(), "under");
assertEquals("Check component type name", id.getComponentDescription().getName(), "composite.bar.1");
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);
ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "under");
assertNotNull("Check architecture availability", ref);
arch = (Architecture) getContext().getService(ref);
// id = arch.getInstanceDescription();
assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
contained = id.getContainedInstances();
assertEquals("Check contained instances count", contained.length, 1);
assertEquals("Check instance name", id.getName(), "under");
assertEquals("Check component type name", id.getComponentDescription().getName(), "composite.bar.1");
fact2.stop();
assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);
ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "under");
assertNotNull("Check architecture availability", ref);
arch = (Architecture) getContext().getService(ref);
// id = arch.getInstanceDescription();
assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
contained = id.getContainedInstances();
assertEquals("Check contained instances count", contained.length, 1);
assertEquals("Check instance name", id.getName(), "under");
assertEquals("Check component type name", id.getComponentDescription().getName(), "composite.bar.1");
fact3.stop();
assertTrue("Check instance invalidity", under.getState() == ComponentInstance.INVALID);
ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "under");
assertNotNull("Check architecture availability", ref);
arch = (Architecture) getContext().getService(ref);
// id = arch.getInstanceDescription();
assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.INVALID);
contained = id.getContainedInstances();
assertEquals("Check contained instances count", contained.length, 0);
assertEquals("Check instance name", id.getName(), "under");
assertEquals("Check component type name", id.getComponentDescription().getName(), "composite.bar.1");
fact1.start();
assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);
ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "under");
assertNotNull("Check architecture availability", ref);
arch = (Architecture) getContext().getService(ref);
// id = arch.getInstanceDescription();
assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
contained = id.getContainedInstances();
assertEquals("Check contained instances count", contained.length, 1);
assertEquals("Check instance name", id.getName(), "under");
assertEquals("Check component type name", id.getComponentDescription().getName(), "composite.bar.1");
under.dispose();
fact2.start();
fact3.start();
}
Aggregations