use of org.apache.felix.ipojo.ComponentFactory in project felix by apache.
the class TestOptionalMultipleInstantiation method testFactoryManagementLevel2.
@Test
public void testFactoryManagementLevel2() {
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 - 1", under.getState() == ComponentInstance.VALID);
ServiceContext sc2 = getServiceContext(under);
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);
assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc2, BarService.class.getName(), null).length, 2);
fact2.stop();
assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);
assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc2, BarService.class.getName(), null).length, 1);
fact3.stop();
assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);
assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc2, BarService.class.getName(), null).length, 0);
fact1.start();
assertTrue("Check instance validity - 5", under.getState() == ComponentInstance.VALID);
assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc2, BarService.class.getName(), null).length, 1);
under.dispose();
fact2.start();
fact3.start();
}
use of org.apache.felix.ipojo.ComponentFactory in project felix by apache.
the class TestSimpleInstantiation method setUp.
@Before
public void setUp() {
bar1Factory = (ComponentFactory) ipojoHelper.getFactory("composite.bar.1");
Factory fact = ipojoHelper.getFactory("composite.empty");
Properties props = new Properties();
props.put("instance.name", "empty-X");
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 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 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 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();
}
use of org.apache.felix.ipojo.ComponentFactory in project felix by apache.
the class DependencyPropertiesTest method setup.
@Before
public void setup() {
Bundle bundle = mock(Bundle.class);
when(bundle.getSymbolicName()).thenReturn("test-bundle");
when(bundle.getVersion()).thenReturn(new Version(1, 0, 0));
BundleContext context = mock(BundleContext.class);
when(context.getBundle()).thenReturn(bundle);
ComponentFactory factory = mock(ComponentFactory.class);
when(factory.getFactoryName()).thenReturn("FooFactory");
ComponentInstance instance = mock(ComponentInstance.class);
when(instance.getInstanceName()).thenReturn("FooConsumer");
when(instance.getState()).thenReturn(2);
when(instance.getFactory()).thenReturn(factory);
this.dependency = mock(DependencyModel.class);
when(dependency.getId()).thenReturn("foo");
when(dependency.getSpecification()).thenReturn(List.class);
when(dependency.getBundleContext()).thenReturn(context);
when(dependency.getComponentInstance()).thenReturn(instance);
when(dependency.getState()).thenReturn(0);
}
Aggregations