use of org.apache.felix.ipojo.ComponentFactory 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.ComponentFactory in project felix by apache.
the class TestOptionalInstantiation 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);
assertNotNull("Check architecture", arch);
CompositeInstanceDescription id = (CompositeInstanceDescription) arch.getInstanceDescription();
assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
InstanceDescription[] contained = id.getContainedInstances();
assertNotNull("Check contained not null", contained);
assertEquals("Check contained instances count (" + contained.length + ") - 1", contained.length, 1);
assertEquals("Check instance name", id.getName(), "under");
assertEquals("Check component type name", id.getComponentDescription().getName(), "composite.bar.3");
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.3");
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.3");
fact3.stop();
assertTrue("Check instance invalidity", 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, 0);
assertEquals("Check instance name", id.getName(), "under");
assertEquals("Check component type name", id.getComponentDescription().getName(), "composite.bar.3");
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.3");
getContext().ungetService(ref);
under.dispose();
fact2.start();
fact3.start();
}
use of org.apache.felix.ipojo.ComponentFactory in project felix by apache.
the class TestOptionalMultipleInstantiation method setUp.
@Before
public void setUp() {
bar2Factory = (ComponentFactory) ipojoHelper.getFactory("composite.bar.4");
assertNotNull("Check bar2factory availability", bar2Factory);
Factory fact = ipojoHelper.getFactory("composite.empty");
Properties props = new Properties();
props.put("instance.name", "empty");
try {
empty = fact.createComponentInstance(props);
} catch (Exception e) {
fail("Cannot create the empty composite : " + e.getMessage());
}
}
use of org.apache.felix.ipojo.ComponentFactory 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();
}
use of org.apache.felix.ipojo.ComponentFactory in project felix by apache.
the class TestObedience method testObedience.
@Test
public void testObedience() {
assertNull("Check no foo service", osgiHelper.getServiceReference(FooService.class.getName()));
ComponentFactory factory = (ComponentFactory) ipojoHelper.getFactory("Factories-FooProviderType-1");
assertNotNull("Check factory existing", factory);
Properties props1 = new Properties();
props1.put("instance.name", "foo1");
Properties props2 = new Properties();
props2.put("instance.name", "foo2");
ComponentInstance ci1 = null, ci2 = null;
try {
ci1 = factory.createComponentInstance(props1);
ci2 = factory.createComponentInstance(props2);
} catch (Exception e) {
fail("Cannot instantiate foo providers : " + e.getMessage());
}
assertTrue("Check foo1 validity", ci1.getState() == ComponentInstance.VALID);
assertTrue("Check foo2 validity", ci2.getState() == ComponentInstance.VALID);
assertNotNull("Check foo service", osgiHelper.getServiceReference(FooService.class.getName()));
assertEquals("Check the number of Foo", osgiHelper.getServiceReferences(FooService.class.getName(), null).length, 2);
factory.stop();
assertTrue("Check foo1 invalidity (" + ci1.getState() + ")", ci1.getState() == ComponentInstance.DISPOSED);
assertTrue("Check foo2 invalidity (" + ci1.getState() + ")", ci2.getState() == ComponentInstance.DISPOSED);
assertNull("Check no foo service", osgiHelper.getServiceReference(FooService.class.getName()));
factory.start();
assertNull("Check no foo service", osgiHelper.getServiceReference(FooService.class.getName()));
}
Aggregations