use of org.apache.felix.ipojo.Factory in project felix by apache.
the class TestComp5 method setUp.
@Before
public void setUp() {
tataFactory = (ComponentFactory) ipojoHelper.getFactory("tata");
totoFactory = (ComponentFactory) ipojoHelper.getFactory("toto");
tataFactory2 = (ComponentFactory) ipojoHelper.getFactory("comp-6");
tataFactory2.stop();
tataFactory.stop();
Properties props = new Properties();
props.put("instance.name", "toto provider");
try {
totoProv = totoFactory.createComponentInstance(props);
} catch (Exception e) {
e.printStackTrace();
}
Properties props3 = new Properties();
props3.put("instance.name", "toto provider 2");
try {
totoProv2 = totoFactory.createComponentInstance(props3);
} catch (Exception e) {
e.printStackTrace();
}
totoProv.stop();
totoProv2.stop();
Factory factory = ipojoHelper.getFactory("comp-5");
Properties props2 = new Properties();
props2.put("instance.name", "ff");
try {
under = factory.createComponentInstance(props2);
} catch (Exception e) {
e.printStackTrace();
fail("Cannot create an instance from comp-5 : " + e.getMessage());
}
}
use of org.apache.felix.ipojo.Factory in project felix by apache.
the class TestComp6 method setUp.
@Before
public void setUp() {
tataFactory = (ComponentFactory) ipojoHelper.getFactory("tata");
totoFactory = (ComponentFactory) ipojoHelper.getFactory("toto");
tataFactory.stop();
Properties props = new Properties();
props.put("instance.name", "toto provider");
try {
totoProv = totoFactory.createComponentInstance(props);
} catch (Exception e) {
e.printStackTrace();
}
Properties props3 = new Properties();
props3.put("instance.name", "toto provider 2");
try {
totoProv2 = totoFactory.createComponentInstance(props3);
} catch (Exception e) {
e.printStackTrace();
}
totoProv.stop();
totoProv2.stop();
Factory factory = ipojoHelper.getFactory("comp-6");
Properties props2 = new Properties();
props2.put("instance.name", "ff");
try {
under = factory.createComponentInstance(props2);
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.apache.felix.ipojo.Factory in project felix by apache.
the class TestComp7 method setUp.
@Before
public void setUp() {
tataFactory = (ComponentFactory) ipojoHelper.getFactory("tata");
totoFactory = (ComponentFactory) ipojoHelper.getFactory("toto");
tataFactory2 = (ComponentFactory) ipojoHelper.getFactory("comp-6");
tataFactory2.stop();
Properties props = new Properties();
props.put("instance.name", "toto provider");
try {
totoProv = totoFactory.createComponentInstance(props);
} catch (Exception e) {
e.printStackTrace();
}
Properties props3 = new Properties();
props3.put("instance.name", "toto provider 2");
try {
totoProv2 = totoFactory.createComponentInstance(props3);
} catch (Exception e) {
e.printStackTrace();
}
totoProv.stop();
totoProv2.stop();
Factory factory = ipojoHelper.getFactory("comp-7");
Properties props2 = new Properties();
props2.put("instance.name", "ff");
try {
under = factory.createComponentInstance(props2);
} catch (Exception e) {
e.printStackTrace();
}
tataFactory.stop();
}
use of org.apache.felix.ipojo.Factory in project felix by apache.
the class TestGetComponentInstance method testGetComponentInstance.
/**
* Check if a pojo can correctly be cast in POJO.
* Check the getComponentInstance method.
*/
@Test
public void testGetComponentInstance() throws NoSuchFieldException, IllegalAccessException, NoSuchMethodException {
String factName = "Manipulation-FooProviderType-1";
String compName = "FooProvider-1";
ServiceReference ref = null;
// Get the factory to create a component instance
Factory fact = ipojoHelper.getFactory(factName);
assertNotNull("Cannot find the factory FooProvider-1", fact);
Properties props = new Properties();
props.put("instance.name", compName);
ComponentInstance ci = null;
try {
ci = fact.createComponentInstance(props);
} catch (Exception e1) {
fail(e1.getMessage());
}
assertEquals("Check instance name", compName, ci.getInstanceName());
// Get a FooService provider
ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), compName);
assertNotNull("FS not available", ref);
// Get foo object
FooService fs = (FooService) osgiHelper.getServiceObject(ref);
// Cast to POJO
Pojo pojo = (Pojo) fs;
Field im = fs.getClass().getDeclaredField("__IM");
assertNotNull(im);
im.setAccessible(true);
assertNotNull(im.get(fs));
Method method = fs.getClass().getMethod("getComponentInstance");
assertNotNull(method);
// GetComponentInstance
ComponentInstance instance = pojo.getComponentInstance();
assertNotNull(instance);
assertEquals("Check component instance name", instance.getInstanceName(), compName);
assertEquals("Check component factory name", instance.getFactory().getName(), factName);
assertNotNull("Instance description not null", instance.getInstanceDescription());
PrimitiveInstanceDescription id = (PrimitiveInstanceDescription) instance.getInstanceDescription();
assertTrue("Check instance state", id.getState() == ComponentInstance.VALID);
assertEquals("Check created pojo count", id.getCreatedObjects().length, 1);
assertEquals("Check instance description name", id.getName(), compName);
ci.dispose();
// Check that there is no more FooService
ref = osgiHelper.getServiceReference(FooService.class.getName());
assertNull("FS available, but component instance stopped", ref);
}
use of org.apache.felix.ipojo.Factory in project felix by apache.
the class TestHandlerBindingAndIgnoreAnnotation method testFooHandlerBinding.
@Test
public void testFooHandlerBinding() {
/*
HandlerFactory handlerFactory = ipojoHelper.getHandlerFactory("com.acme:foo");
assertNotNull(handlerFactory);
assertEquals(Factory.VALID, handlerFactory.getState());
*/
// verify component's factory is here
// verify BazService has been published
// --> verify instance has been created
Factory factory = ipojoHelper.getFactory(FACTORY_NAME);
assertNotNull(factory);
assertEquals(Factory.VALID, factory.getState());
List<HandlerBindingTestService> services = osgiHelper.getServiceObjects(HandlerBindingTestService.class);
assertEquals(1, services.size());
HandlerBindingTestService baz = services.get(0);
assertEquals("Bonjour", baz.get("greeting"));
assertEquals("Welcome", baz.get("welcome"));
assertNull(baz.get("ignored"));
ipojoHelper.dispose();
}
Aggregations