use of org.apache.felix.ipojo.Factory 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);
}
use of org.apache.felix.ipojo.Factory in project felix by apache.
the class TestUnacceptableConfiguration method testUnicity2.
/**
* Check instance name unicity.
*/
@Test
public void testUnicity2() {
Factory f = ipojoHelper.getFactory("Factories-FooProviderType-2");
ComponentInstance ci1, ci2, ci3;
try {
Properties p1 = new Properties();
p1.put("instance.name", "name1");
ci1 = f.createComponentInstance(p1);
Properties p2 = new Properties();
p2.put("instance.name", "name2");
ci2 = f.createComponentInstance(p2);
Properties p3 = new Properties();
p3.put("instance.name", "name3");
ci3 = f.createComponentInstance(p3);
assertThat("Check name ci1, ci2", ci1.getInstanceName(), not(ci2.getInstanceName()));
assertThat("Check name ci1, ci3", ci1.getInstanceName(), not(ci3.getInstanceName()));
assertThat("Check name ci3, ci2", ci3.getInstanceName(), not(ci2.getInstanceName()));
ci1.dispose();
ci2.dispose();
ci3.dispose();
} catch (Exception e) {
fail("An acceptable configuration is refused");
}
}
use of org.apache.felix.ipojo.Factory in project felix by apache.
the class TestUnacceptableConfiguration method testEmptyConfiguration2.
/**
* Empty configuration (just the name).
*/
@Test
public void testEmptyConfiguration2() {
Factory f = ipojoHelper.getFactory("Factories-FooProviderType-Dyn2");
Properties p = new Properties();
p.put("instance.name", "ko");
ComponentInstance ci;
try {
ci = f.createComponentInstance(p);
ci.dispose();
} catch (Exception e) {
return;
}
fail("An unacceptable configuration is accepted");
}
use of org.apache.felix.ipojo.Factory in project felix by apache.
the class TestUnacceptableConfiguration method testNull.
/**
* Null configuration (accept).
*/
@Test
public void testNull() {
Factory f = ipojoHelper.getFactory("Factories-FooProviderType-2");
ComponentInstance ci;
try {
ci = f.createComponentInstance(null);
ci.dispose();
} catch (Exception e) {
fail("An acceptable configuration is refused");
}
}
use of org.apache.felix.ipojo.Factory in project felix by apache.
the class TestUnacceptableConfiguration method testWithoutName.
/**
* Configuration without the name property.
*/
@Test
public void testWithoutName() {
Factory f = ipojoHelper.getFactory("Factories-FooProviderType-2");
Properties p = new Properties();
p.put("int", 3);
p.put("long", (long) 42);
p.put("string", "absdir");
p.put("strAProp", new String[] { "a" });
p.put("intAProp", new int[] { 1, 2 });
ComponentInstance ci;
try {
ci = f.createComponentInstance(p);
ci.dispose();
} catch (Exception e) {
fail("an acceptable configuration is refused : " + e.getMessage());
e.printStackTrace();
}
}
Aggregations