use of org.apache.felix.ipojo.handlers.dependency.DependencyDescription in project felix by apache.
the class TestDependencyIdDetection method testAddAndRemoveMethods.
@Test
public void testAddAndRemoveMethods() {
ComponentInstance instance = ipojoHelper.createComponentInstance(factory);
DependencyHandlerDescription dh = (DependencyHandlerDescription) instance.getInstanceDescription().getHandlerDescription("org.apache.felix.ipojo:requires");
DependencyDescription dd = findDependencyById(dh, "MyService");
assertThat(dd).isNotNull();
DependencyCallback[] callbacks = dd.getDependency().getDependencyCallbacks();
assertThat(callbacks).isNotNull();
DependencyCallback bind = getBindCallback(callbacks);
DependencyCallback unbind = getUnbindCallback(callbacks);
assertThat(bind).isNotNull();
assertThat(unbind).isNotNull();
assertThat(bind.getMethodName()).isEqualTo("addMyService");
assertThat(unbind.getMethodName()).isEqualTo("removeMyService");
}
use of org.apache.felix.ipojo.handlers.dependency.DependencyDescription in project felix by apache.
the class TestDependencyIdDetection method testSetAndUnSetMethods.
@Test
public void testSetAndUnSetMethods() {
ComponentInstance instance = ipojoHelper.createComponentInstance(factory);
DependencyHandlerDescription dh = (DependencyHandlerDescription) instance.getInstanceDescription().getHandlerDescription("org.apache.felix.ipojo:requires");
DependencyDescription dd = findDependencyById(dh, "MyOtherService");
assertThat(dd).isNotNull();
DependencyCallback[] callbacks = dd.getDependency().getDependencyCallbacks();
assertThat(callbacks).isNotNull();
DependencyCallback bind = getBindCallback(callbacks);
DependencyCallback unbind = getUnbindCallback(callbacks);
assertThat(bind).isNotNull();
assertThat(unbind).isNotNull();
assertThat(bind.getMethodName()).isEqualTo("setMyOtherService");
assertThat(unbind.getMethodName()).isEqualTo("unsetMyOtherService");
}
use of org.apache.felix.ipojo.handlers.dependency.DependencyDescription 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.handlers.dependency.DependencyDescription 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"));
}
use of org.apache.felix.ipojo.handlers.dependency.DependencyDescription in project felix by apache.
the class IPOJOPlugin method getRequiredServiceDetail.
/**
* Builds the JSON Array representing the required services.
* @param hd the dependency handler
* @return the array containing JSON object representing service
* dependencies, or null if there is no service dependency.
* @throws JSONException if the JSON array cannot be created.
*/
private void getRequiredServiceDetail(JSONWriter pw, HandlerDescription hd) throws IOException {
if (hd == null) {
return;
}
pw.key("reqs");
pw.array();
DependencyHandlerDescription desc = (DependencyHandlerDescription) hd;
for (DependencyDescription dep : desc.getDependencies()) {
pw.object();
pw.key("specification");
pw.value(dep.getSpecification());
pw.key("id");
pw.value(dep.getId());
pw.key("state");
pw.value(StateUtils.getDependencyState(dep.getState()));
pw.key("policy");
pw.value(StateUtils.getDependencyBindingPolicy(dep.getPolicy()));
pw.key("optional");
pw.value(dep.isOptional());
pw.key("aggregate");
pw.value(dep.isMultiple());
if (dep.getFilter() != null) {
pw.key("filter");
pw.value(dep.getFilter());
}
if (dep.getServiceReferences() != null && dep.getServiceReferences().size() != 0) {
pw.key("matching");
getServiceReferenceList(pw, dep.getServiceReferences());
}
if (dep.getUsedServices() != null && dep.getUsedServices().size() != 0) {
pw.key("used");
getServiceReferenceList(pw, dep.getUsedServices());
}
pw.endObject();
}
pw.endArray();
}
Aggregations