use of org.apache.felix.ipojo.architecture.HandlerDescription in project felix by apache.
the class IgnoreCaseHandlerSelectionTest method testCreationOfIgnoreCase1.
/**
* Check that the instance is correctly created with "empty".
*/
@Test
public void testCreationOfIgnoreCase1() {
ServiceReference refv1 = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "IgnoreCase-1");
Assert.assertNotNull(refv1);
Architecture arch = (Architecture) osgiHelper.getRawServiceObject(refv1);
Assert.assertEquals(ComponentInstance.VALID, arch.getInstanceDescription().getState());
HandlerDescription desc = arch.getInstanceDescription().getHandlerDescription(// Check with the declared name.
"orG.apAche.feliX.iPOJO.tests.CORE.hAnDlEr:EmPtY");
Assert.assertNotNull(desc);
Assert.assertTrue(desc.isValid());
}
use of org.apache.felix.ipojo.architecture.HandlerDescription in project felix by apache.
the class ExternalHandlerTest method createAHost.
@Test
public void createAHost() throws Exception {
PrimitiveComponentType type = createAWhiteboardHost();
ComponentInstance ci = type.createInstance();
assertThat(ci.getState(), is(ComponentInstance.VALID));
HandlerDescription hd = ci.getInstanceDescription().getHandlerDescription(Whiteboard.NAMESPACE + ":" + Whiteboard.NAME);
assertThat(hd, is(notNullValue()));
}
use of org.apache.felix.ipojo.architecture.HandlerDescription in project felix by apache.
the class ExternalHandlerTest method createDoubleHost.
@Test
public void createDoubleHost() throws Exception {
PrimitiveComponentType type = createASecondWhiteboardHost();
ComponentInstance ci = type.createInstance();
assertThat(ci.getState(), is(ComponentInstance.VALID));
HandlerDescription hd = ci.getInstanceDescription().getHandlerDescription(Whiteboard.NAMESPACE + ":" + Whiteboard.NAME);
assertThat(hd, is(notNullValue()));
}
use of org.apache.felix.ipojo.architecture.HandlerDescription in project felix by apache.
the class TestProvidedServiceArchitecture method testExposition.
@Test
public void testExposition() {
String factName = "PS-FooProviderType-1";
String compName = "FooProvider-1";
// Get the factory to create a component instance
Factory fact = ipojoHelper.getFactory(factName);
assertNotNull("Cannot find the factory FooProvider-1", fact);
ipojoHelper.createComponentInstance(factName, compName);
ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), compName);
assertNotNull("Architecture not available", arch_ref);
Architecture arch = (Architecture) osgiHelper.getRawServiceObject(arch_ref);
InstanceDescription id = arch.getInstanceDescription();
assertEquals("Check component instance name (" + id.getName() + ")", id.getName(), compName);
assertEquals("Check component type implementation class", id.getComponentDescription().getClassName(), "org.apache.felix.ipojo.runtime.core.components.FooProviderType1");
HandlerDescription[] handlers = id.getHandlers();
assertEquals("Number of handlers", handlers.length, 2);
// Look for the ProvidedService Handler
ProvidedServiceHandlerDescription pshd = null;
pshd = (ProvidedServiceHandlerDescription) id.getHandlerDescription("org.apache.felix.ipojo:provides");
// for(int i = 0; i < handlers.length; i++) {
// if(handlers[i].getHandlerName().equals("org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandler")) {
// pshd = (ProvidedServiceHandlerDescription) handlers[i];
// }
// }
//
assertNotNull("Check ProvidedServiceHandlerDescription", pshd);
ProvidedServiceDescription[] ps = pshd.getProvidedServices();
assertEquals("Check ProvidedService number", ps.length, 1);
assertEquals("Check Provided Service Specs - 1", ps[0].getServiceSpecifications().length, 1);
assertEquals("Check Provided Service Specs - 2", ps[0].getServiceSpecifications()[0], FooService.class.getName());
assertEquals("Check Provided Service availability", ps[0].getState(), ProvidedServiceDescription.REGISTERED);
Properties prop = ps[0].getProperties();
assertNotNull("Check Props", prop);
assertEquals("Check service properties number", prop.size(), 2);
assertEquals("Check instance.name property", prop.getProperty("instance.name"), compName);
assertEquals("Check factory.name property", prop.getProperty("factory.name"), factName);
}
use of org.apache.felix.ipojo.architecture.HandlerDescription in project felix by apache.
the class TestProvidedServiceArchitecture method testPropsNoValue.
@Test
public void testPropsNoValue() {
String factName = "PS-FooProviderType-3";
String compName = "FooProvider";
// Get the factory to create a component instance
Factory fact = ipojoHelper.getFactory(factName);
assertNotNull("Cannot find the factory FooProvider", fact);
ipojoHelper.createComponentInstance(factName, compName);
ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), compName);
assertNotNull("Architecture not available", arch_ref);
Architecture arch = (Architecture) osgiHelper.getRawServiceObject(arch_ref);
InstanceDescription id = arch.getInstanceDescription();
assertEquals("Check component instance name (" + id.getName() + ")", id.getName(), compName);
assertEquals("Check component type implementation class", id.getComponentDescription().getClassName(), "org.apache.felix.ipojo.runtime.core.components.FooProviderType1");
HandlerDescription[] handlers = id.getHandlers();
assertEquals("Number of handlers", handlers.length, 3);
// Look for the ProvidedService Handler
ProvidedServiceHandlerDescription pshd = null;
pshd = (ProvidedServiceHandlerDescription) id.getHandlerDescription("org.apache.felix.ipojo:provides");
// for(int i = 0; i < handlers.length; i++) {
// if(handlers[i].getHandlerName().equals("org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandler")) {
// pshd = (ProvidedServiceHandlerDescription) handlers[i];
// }
// }
assertNotNull("Check ProvidedServiceHandlerDescription", pshd);
ProvidedServiceDescription[] ps = pshd.getProvidedServices();
assertEquals("Check ProvidedService number", ps.length, 1);
assertEquals("Check Provided Service Specs - 1", ps[0].getServiceSpecifications().length, 1);
assertEquals("Check Provided Service Specs - 2", ps[0].getServiceSpecifications()[0], FooService.class.getName());
assertEquals("Check Provided Service availability", ps[0].getState(), ProvidedServiceDescription.REGISTERED);
Properties prop = ps[0].getProperties();
assertNotNull("Check Props", prop);
assertEquals("Check service properties number (#" + prop + "?=5)", prop.size(), 2);
assertEquals("Check instance.name property", prop.getProperty("instance.name"), compName);
assertEquals("Check factory.name property", prop.getProperty("factory.name"), factName);
}
Aggregations