use of org.apache.felix.ipojo.architecture.Architecture 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.Architecture 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.architecture.Architecture 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.Architecture in project felix by apache.
the class TestImmediateCallbackSeveralFactories method testCallback.
@Test
public void testCallback() {
// Check instance is invalid
ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance.getInstanceName());
assertNotNull("Check architecture availability", arch_ref);
PrimitiveInstanceDescription id_dep = (PrimitiveInstanceDescription) ((Architecture) osgiHelper.getRawServiceObject(arch_ref)).getInstanceDescription();
assertTrue("Check instance invalidity - 1", id_dep.getState() == ComponentInstance.INVALID);
assertEquals("Check pojo count - 1", id_dep.getCreatedObjects().length, 0);
// Start fooprovider
fooProvider.start();
// Check instance validity
// id_dep = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
assertTrue("Check instance validity - 1", id_dep.getState() == ComponentInstance.VALID);
// Check service providing
ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance.getInstanceName());
assertNotNull("Check CheckService availability", cs_ref);
CheckService cs = (CheckService) osgiHelper.getRawServiceObject(cs_ref);
assertTrue("check CheckService invocation", cs.check());
assertEquals("Check pojo count - 2", id_dep.getCreatedObjects().length, 1);
// Check int property
Integer index = (Integer) (cs.getProps().get("int"));
Integer count = (Integer) (cs.getProps().get("count"));
assertEquals("Check int property - 1 (" + index + ")", index.intValue(), 1);
assertEquals("Check count property - 1 (" + count + ")", count.intValue(), 1);
fooProvider.stop();
// id_dep = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.INVALID);
assertEquals("Check pojo count - 3", id_dep.getCreatedObjects().length, 1);
fooProvider.start();
// Check instance validity
// id_dep = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
assertTrue("Check instance validity - 2", id_dep.getState() == ComponentInstance.VALID);
// Check service providing
cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance.getInstanceName());
assertNotNull("Check CheckService availability", cs_ref);
cs = (CheckService) osgiHelper.getRawServiceObject(cs_ref);
assertTrue("check CheckService invocation", cs.check());
// Check int property
index = (Integer) (cs.getProps().get("int"));
count = (Integer) (cs.getProps().get("count"));
assertEquals("Check int property - 2 (" + index + ")", index.intValue(), 3);
assertEquals("Check count property - 2 (" + count + ")", count.intValue(), 1);
assertEquals("Check pojo count - 4 ", id_dep.getCreatedObjects().length, 1);
}
use of org.apache.felix.ipojo.architecture.Architecture in project felix by apache.
the class TestParentCallback method testCallback.
@Test
public void testCallback() {
// Check instance is invalid
ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance.getInstanceName());
assertNotNull("Check architecture availability", arch_ref);
PrimitiveInstanceDescription id_dep = (PrimitiveInstanceDescription) ((Architecture) osgiHelper.getRawServiceObject(arch_ref)).getInstanceDescription();
assertTrue("Check instance invalidity - 1", id_dep.getState() == ComponentInstance.INVALID);
// Start fooprovider
fooProvider.start();
// Check instance validity
// id_dep = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
assertTrue("Check instance validity - 1", id_dep.getState() == ComponentInstance.VALID);
// Check service providing
ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance.getInstanceName());
assertNotNull("Check CheckService availability", cs_ref);
// Check int property
assertEquals("Check pojo count - 2", id_dep.getCreatedObjects().length, 1);
fooProvider.stop();
// id_dep = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.INVALID);
fooProvider.start();
// Check instance validity
// id_dep = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
assertTrue("Check instance validity - 2", id_dep.getState() == ComponentInstance.VALID);
// Check service providing
cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance.getInstanceName());
assertNotNull("Check CheckService availability", cs_ref);
CheckService cs = (CheckService) osgiHelper.getRawServiceObject(cs_ref);
assertTrue("check CheckService invocation", cs.check());
// Clean up
bc.ungetService(arch_ref);
bc.ungetService(cs_ref);
}
Aggregations