use of org.apache.felix.ipojo.architecture.HandlerDescription in project felix by apache.
the class TestProvidedServiceArchitecture method testProps.
@Test
public void testProps() {
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);
Properties props = new Properties();
props.put("instance.name", compName);
props.put("foo", "foo");
props.put("bar", "2");
props.put("baz", "baz");
ipojoHelper.createComponentInstance(factName, props);
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");
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(), 5);
assertEquals("Check instance.name property", prop.getProperty("instance.name"), compName);
assertEquals("Check factory.name property", prop.getProperty("factory.name"), factName);
assertEquals("Check foo property", prop.get("foo"), "foo");
assertEquals("Check bar property", prop.get("bar"), new Integer(2));
assertEquals("Check baz property", prop.get("baz"), "baz");
}
use of org.apache.felix.ipojo.architecture.HandlerDescription in project felix by apache.
the class TestProvidedServiceArchitecture method testDoubleProviding.
@Test
public void testDoubleProviding() {
String factName = "PS-FooBarProviderType-1";
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.FooBarProviderType1");
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, 2);
assertContains("Check provided service specs - 2", ps[0].getServiceSpecifications(), FooService.class.getName());
assertContains("Check provided service specs - 2", ps[0].getServiceSpecifications(), BarService.class.getName());
assertEquals("Check Provided Service availability", ps[0].getState(), ProvidedServiceDescription.REGISTERED);
}
use of org.apache.felix.ipojo.architecture.HandlerDescription in project felix by apache.
the class AutoHandlerTest method testInstanceCreation.
@Test
public void testInstanceCreation() throws Exception {
String v = "org.apache.felix.ipojo.test.handler.checkservice:check";
System.setProperty(ORG_APACHE_FELIX_IPOJO_HANDLER_AUTO_PRIMITIVE, v);
factory.stop();
factory.restart();
factory.start();
instance = factory.createComponentInstance(new Properties());
assertEquals(ComponentInstance.VALID, instance.getState());
HandlerDescription hd = instance.getInstanceDescription().getHandlerDescription(v);
assertNotNull(hd);
assertTrue(hd instanceof CheckServiceHandlerDescription);
System.setProperty(ORG_APACHE_FELIX_IPOJO_HANDLER_AUTO_PRIMITIVE, "");
factory.stop();
factory.restart();
factory.start();
}
use of org.apache.felix.ipojo.architecture.HandlerDescription in project felix by apache.
the class VersionConflictTest method deployBundlesAtRuntime.
@Test
public void deployBundlesAtRuntime() throws MalformedURLException, BundleException, InvalidSyntaxException {
if (isKF()) {
System.out.println("Test disabled on knopflerfish");
return;
}
Bundle b1 = context.installBundle(context.getProperty("url1"));
b1.start();
Bundle b3 = context.installBundle(context.getProperty("c1"));
b3.start();
Bundle b2 = context.installBundle(context.getProperty("url2"));
b2.start();
Bundle b4 = context.installBundle(context.getProperty("c2"));
b4.start();
Bundle b5 = context.installBundle(context.getProperty("cons"));
b5.start();
Stability.waitForStability(bc);
Bundle[] bundles = context.getBundles();
for (Bundle bundle : bundles) {
System.out.println("bundle " + bundle.getSymbolicName() + " : " + (bundle.getState() == Bundle.ACTIVE));
// Assert.assertEquals(bundles[i].getSymbolicName() + " is not active", Bundle.ACTIVE, bundles[i].getState());
}
// Bundle consBundle = osgiHelper.getBundle("MyCons");
// BundleWiring wiring = consBundle.adapt(BundleWiring.class);
// System.out.println("Bundle Wiring req: ");
// for (BundleWire wire : wiring.getRequiredWires(null)) {
// System.out.println(wire.getCapability().getAttributes() + " - " + wire.getCapability().getDirectives());
// }
osgiHelper.waitForService(Architecture.class.getName(), "(architecture.instance=mycons)", 2000);
// Check that the two services are provided.
ServiceReference[] refs = context.getAllServiceReferences("org.apache.felix.ipojo.core.tests.services.MyService", null);
Assert.assertNotNull(refs);
Assert.assertEquals(2, refs.length);
ServiceReference refv1 = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "mycons");
Assert.assertNotNull(refv1);
Architecture arch = (Architecture) osgiHelper.getRawServiceObject(refv1);
HandlerDescription desc = arch.getInstanceDescription().getHandlerDescription("org.apache.felix.ipojo:requires");
Assert.assertNotNull(desc);
DependencyHandlerDescription d = (DependencyHandlerDescription) desc;
Assert.assertNotNull(d.getDependencies());
Assert.assertEquals(1, d.getDependencies().length);
DependencyDescription dep = d.getDependencies()[0];
Assert.assertEquals(Dependency.RESOLVED, dep.getState());
Assert.assertEquals(1, dep.getServiceReferences().size());
ServiceReference r = dep.getServiceReferences().get(0);
Assert.assertEquals("provider", r.getProperty("factory.name"));
Assert.assertEquals("2.0", r.getProperty("factory.version"));
}
use of org.apache.felix.ipojo.architecture.HandlerDescription in project felix by apache.
the class VersionConflictTest method deployBundlesAtRuntimeV1.
@Test
@Ignore("Does not work anymore, but the scenario runs as expected in a regular framework. The check find the " + "version 2.0 of the service instead of the 1.0")
public void deployBundlesAtRuntimeV1() throws MalformedURLException, BundleException, InvalidSyntaxException {
Bundle b1 = context.installBundle(context.getProperty("url1"));
b1.start();
Bundle b3 = context.installBundle(context.getProperty("c1"));
b3.start();
Bundle b2 = context.installBundle(context.getProperty("url2"));
b2.start();
Bundle b4 = context.installBundle(context.getProperty("c2"));
b4.start();
Bundle b5 = context.installBundle(context.getProperty("consV1"));
b5.start();
Bundle[] bundles = context.getBundles();
for (int i = 0; i < bundles.length; i++) {
System.out.println("bundle " + bundles[i].getSymbolicName() + " : " + (bundles[i].getState() == Bundle.ACTIVE));
}
osgiHelper.waitForService(Architecture.class.getName(), "(architecture.instance=mycons)", 2000);
// Check that the two services are provided.
ServiceReference[] refs = context.getAllServiceReferences("org.apache.felix.ipojo.core.tests.services.MyService", null);
Assert.assertNotNull(refs);
Assert.assertEquals(2, refs.length);
ServiceReference refv1 = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "mycons");
Assert.assertNotNull(refv1);
Architecture arch = (Architecture) osgiHelper.getRawServiceObject(refv1);
HandlerDescription desc = arch.getInstanceDescription().getHandlerDescription("org.apache.felix.ipojo:requires");
Assert.assertNotNull(desc);
DependencyHandlerDescription d = (DependencyHandlerDescription) desc;
Assert.assertNotNull(d.getDependencies());
Assert.assertEquals(1, d.getDependencies().length);
DependencyDescription dep = d.getDependencies()[0];
Assert.assertEquals(Dependency.RESOLVED, dep.getState());
Assert.assertEquals(1, dep.getServiceReferences().size());
ServiceReference r = dep.getServiceReferences().get(0);
Assert.assertEquals("provider", r.getProperty("factory.name"));
Assert.assertEquals("1.0", r.getProperty("factory.version"));
}
Aggregations