use of org.osgi.framework.wiring.BundleRequirement in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testSubstitutableExport.
@Test
public void testSubstitutableExport() throws BundleException, IOException {
DummyContainerAdaptor adaptor = createDummyAdaptor();
ModuleContainer container = adaptor.getContainer();
// install the system.bundle
Module systemBundle = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, Constants.SYSTEM_BUNDLE_SYMBOLICNAME, null, null, container);
ResolutionReport report = container.resolve(Arrays.asList(systemBundle), true);
Assert.assertNull("Failed to resolve system.bundle.", report.getResolutionException());
// install an exporter with substitutable export.
Map<String, String> exporterManifest = new HashMap<String, String>();
exporterManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
exporterManifest.put(Constants.BUNDLE_SYMBOLICNAME, "exporter");
exporterManifest.put(Constants.EXPORT_PACKAGE, "exporter");
exporterManifest.put(Constants.IMPORT_PACKAGE, "exporter");
Module moduleSubsExport = installDummyModule(exporterManifest, "exporter", container);
report = container.resolve(Arrays.asList(moduleSubsExport), true);
Assert.assertNull("Failed to resolve", report.getResolutionException());
List<BundleRequirement> reqs = moduleSubsExport.getCurrentRevision().getWiring().getRequirements(PackageNamespace.PACKAGE_NAMESPACE);
assertEquals("Wrong number of imports.", 0, reqs.size());
container.uninstall(moduleSubsExport);
exporterManifest = new HashMap<String, String>();
exporterManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
exporterManifest.put(Constants.BUNDLE_SYMBOLICNAME, "substitutableExporter");
exporterManifest.put(Constants.EXPORT_PACKAGE, "exporter");
exporterManifest.put(Constants.IMPORT_PACKAGE, "exporter; pickme=true");
moduleSubsExport = installDummyModule(exporterManifest, "substitutableExporter", container);
exporterManifest = new HashMap<String, String>();
exporterManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
exporterManifest.put(Constants.BUNDLE_SYMBOLICNAME, "exporter");
exporterManifest.put(Constants.EXPORT_PACKAGE, "exporter; pickme=true");
Module moduleExport = installDummyModule(exporterManifest, "exporter", container);
report = container.resolve(Arrays.asList(moduleSubsExport), true);
Assert.assertNull("Failed to resolve", report.getResolutionException());
List<BundleCapability> caps = moduleSubsExport.getCurrentRevision().getWiring().getCapabilities(PackageNamespace.PACKAGE_NAMESPACE);
assertEquals("Wrong number of capabilities.", 0, caps.size());
reqs = moduleSubsExport.getCurrentRevision().getWiring().getRequirements(PackageNamespace.PACKAGE_NAMESPACE);
assertEquals("Wrong number of imports.", 1, reqs.size());
ModuleWiring wiring = moduleSubsExport.getCurrentRevision().getWiring();
List<ModuleWire> packageWires = wiring.getRequiredModuleWires(PackageNamespace.PACKAGE_NAMESPACE);
Assert.assertEquals("Unexpected number of wires", 1, packageWires.size());
Assert.assertEquals("Wrong exporter", packageWires.get(0).getProviderWiring().getRevision(), moduleExport.getCurrentRevision());
}
use of org.osgi.framework.wiring.BundleRequirement in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testSingleton04.
@Test
public void testSingleton04() throws BundleException, IOException {
final Collection<BundleRevision> disabled = new ArrayList<BundleRevision>();
ResolverHookFactory resolverHookFactory = new ResolverHookFactory() {
@Override
public ResolverHook begin(Collection<BundleRevision> triggers) {
return new ResolverHook() {
@Override
public void filterSingletonCollisions(BundleCapability singleton, Collection<BundleCapability> collisionCandidates) {
// nothing
}
@Override
public void filterResolvable(Collection<BundleRevision> candidates) {
candidates.removeAll(disabled);
}
@Override
public void filterMatches(BundleRequirement requirement, Collection<BundleCapability> candidates) {
// nothing
}
@Override
public void end() {
// nothing
}
};
}
};
DummyContainerAdaptor adaptor = new DummyContainerAdaptor(new DummyCollisionHook(false), Collections.<String, String>emptyMap(), resolverHookFactory);
ModuleContainer container = adaptor.getContainer();
Module s1_v1 = installDummyModule("singleton1_v1.MF", "s1_v1", container);
Module s1_v2 = installDummyModule("singleton1_v2.MF", "s1_v2", container);
Module s1_v3 = installDummyModule("singleton1_v3.MF", "s1_v3", container);
Module s2_v1 = installDummyModule("singleton2_v1.MF", "s1_v1", container);
Module s2_v2 = installDummyModule("singleton2_v2.MF", "s1_v2", container);
Module s2_v3 = installDummyModule("singleton2_v3.MF", "s1_v3", container);
container.resolve(null, false);
Assert.assertFalse("Singleton v1 is resolved.", Module.RESOLVED_SET.contains(s1_v1.getState()));
Assert.assertFalse("Singleton v2 is resolved.", Module.RESOLVED_SET.contains(s1_v2.getState()));
Assert.assertTrue("Singleton v3 is not resolved.", Module.RESOLVED_SET.contains(s1_v3.getState()));
Assert.assertFalse("client v1 is resolved.", Module.RESOLVED_SET.contains(s2_v1.getState()));
Assert.assertFalse("client v2 is resolved.", Module.RESOLVED_SET.contains(s2_v2.getState()));
Assert.assertTrue("client v3 is not resolved.", Module.RESOLVED_SET.contains(s2_v3.getState()));
// now disable s1_v3
disabled.add(s1_v3.getCurrentRevision());
container.refresh(Arrays.asList(s1_v3));
Assert.assertFalse("Singleton v1 is resolved.", Module.RESOLVED_SET.contains(s1_v1.getState()));
Assert.assertTrue("Singleton v2 is not resolved.", Module.RESOLVED_SET.contains(s1_v2.getState()));
Assert.assertFalse("Singleton v3 is resolved.", Module.RESOLVED_SET.contains(s1_v3.getState()));
Assert.assertFalse("client v1 is resolved.", Module.RESOLVED_SET.contains(s2_v1.getState()));
Assert.assertTrue("client v2 is not resolved.", Module.RESOLVED_SET.contains(s2_v2.getState()));
Assert.assertFalse("client v3 is resolved.", Module.RESOLVED_SET.contains(s2_v3.getState()));
// now disable s1_v2
disabled.add(s1_v2.getCurrentRevision());
container.refresh(Arrays.asList(s1_v2));
Assert.assertTrue("Singleton v1 is not resolved.", Module.RESOLVED_SET.contains(s1_v1.getState()));
Assert.assertFalse("Singleton v2 is resolved.", Module.RESOLVED_SET.contains(s1_v2.getState()));
Assert.assertFalse("Singleton v3 is resolved.", Module.RESOLVED_SET.contains(s1_v3.getState()));
Assert.assertTrue("client v1 is not resolved.", Module.RESOLVED_SET.contains(s2_v1.getState()));
Assert.assertFalse("client v2 is resolved.", Module.RESOLVED_SET.contains(s2_v2.getState()));
Assert.assertFalse("client v3 is resolved.", Module.RESOLVED_SET.contains(s2_v3.getState()));
}
use of org.osgi.framework.wiring.BundleRequirement in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testDynamicWithOptionalImport.
@Test
public void testDynamicWithOptionalImport() throws BundleException, IOException {
DummyContainerAdaptor adaptor = createDummyAdaptor();
ModuleContainer container = adaptor.getContainer();
// install the system.bundle
Module systemBundle = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, Constants.SYSTEM_BUNDLE_SYMBOLICNAME, null, null, container);
ResolutionReport report = container.resolve(Arrays.asList(systemBundle), true);
Assert.assertNull("Failed to resolve system.bundle.", report.getResolutionException());
// install an importer
Map<String, String> optionalImporterManifest = new HashMap<String, String>();
optionalImporterManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
optionalImporterManifest.put(Constants.BUNDLE_SYMBOLICNAME, "importer");
optionalImporterManifest.put(Constants.IMPORT_PACKAGE, "exporter; resolution:=optional");
optionalImporterManifest.put(Constants.DYNAMICIMPORT_PACKAGE, "exporter");
Module optionalImporterModule = installDummyModule(optionalImporterManifest, "optionalImporter", container);
// unsatisfied optional and dynamic imports do not fail a resolve.
report = container.resolve(Arrays.asList(optionalImporterModule), true);
Assert.assertNull("Failed to resolve system.bundle.", report.getResolutionException());
// dynamic and optional imports are same. Optional import is not satisfied we should only see the dynamic import
List<BundleRequirement> importReqsList = optionalImporterModule.getCurrentRevision().getWiring().getRequirements(PackageNamespace.PACKAGE_NAMESPACE);
assertEquals("Wrong number of imports.", 1, importReqsList.size());
assertEquals("Import was not dynamic", PackageNamespace.RESOLUTION_DYNAMIC, importReqsList.get(0).getDirectives().get(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE));
// install a exporter to satisfy existing optional import
Map<String, String> exporterManifest = new HashMap<String, String>();
exporterManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
exporterManifest.put(Constants.BUNDLE_SYMBOLICNAME, "exporter");
exporterManifest.put(Constants.EXPORT_PACKAGE, "exporter");
installDummyModule(exporterManifest, "exporter", container);
ModuleWire dynamicWire = container.resolveDynamic("exporter", optionalImporterModule.getCurrentRevision());
Assert.assertNotNull("Expected to find a dynamic wire.", dynamicWire);
// re-resolve importer
container.refresh(Collections.singleton(optionalImporterModule));
report = container.resolve(Arrays.asList(optionalImporterModule), true);
Assert.assertNull("Failed to resolve system.bundle.", report.getResolutionException());
importReqsList = optionalImporterModule.getCurrentRevision().getWiring().getRequirements(PackageNamespace.PACKAGE_NAMESPACE);
assertEquals("Wrong number of imports.", 2, importReqsList.size());
}
use of org.osgi.framework.wiring.BundleRequirement in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testDynamicWithExport.
@Test
public void testDynamicWithExport() throws BundleException, IOException {
DummyContainerAdaptor adaptor = createDummyAdaptor();
ModuleContainer container = adaptor.getContainer();
// install the system.bundle
Module systemBundle = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, Constants.SYSTEM_BUNDLE_SYMBOLICNAME, null, null, container);
ResolutionReport report = container.resolve(Arrays.asList(systemBundle), true);
Assert.assertNull("Failed to resolve system.bundle.", report.getResolutionException());
// install an importer
Map<String, String> optionalImporterManifest = new HashMap<String, String>();
optionalImporterManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
optionalImporterManifest.put(Constants.BUNDLE_SYMBOLICNAME, "importer");
optionalImporterManifest.put(Constants.EXPORT_PACKAGE, "exporter");
optionalImporterManifest.put(Constants.DYNAMICIMPORT_PACKAGE, "exporter");
Module optionalImporterModule = installDummyModule(optionalImporterManifest, "optionalImporter", container);
// unsatisfied optional and dynamic imports do not fail a resolve.
report = container.resolve(Arrays.asList(optionalImporterModule), true);
Assert.assertNull("Failed to resolve system.bundle.", report.getResolutionException());
// dynamic and optional imports are same. Optional import is not satisfied we should only see the dynamic import
List<BundleRequirement> importReqsList = optionalImporterModule.getCurrentRevision().getWiring().getRequirements(PackageNamespace.PACKAGE_NAMESPACE);
assertEquals("Wrong number of imports.", 1, importReqsList.size());
assertEquals("Import was not dynamic", PackageNamespace.RESOLUTION_DYNAMIC, importReqsList.get(0).getDirectives().get(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE));
ModuleWire dynamicWire = container.resolveDynamic("exporter", optionalImporterModule.getCurrentRevision());
Assert.assertNull("Expected no dynamic wire.", dynamicWire);
}
use of org.osgi.framework.wiring.BundleRequirement in project aries by apache.
the class BundleWiringStateMBeanTest method testGetCurrentRevisionDeclaredRequirements.
@Test
public void testGetCurrentRevisionDeclaredRequirements() throws Exception {
Bundle a = getBundleByName("org.apache.aries.jmx.test.bundlea");
BundleRevision br = (BundleRevision) a.adapt(BundleRevision.class);
List<BundleRequirement> requirements = br.getDeclaredRequirements(BundleRevision.PACKAGE_NAMESPACE);
CompositeData[] jmxRequirements = brsMBean.getCurrentRevisionDeclaredRequirements(a.getBundleId(), BundleRevision.PACKAGE_NAMESPACE);
Assert.assertEquals(requirements.size(), jmxRequirements.length);
Map<Map<String, Object>, Map<String, String>> expectedRequirements = requirementsToMap(requirements);
Map<Map<String, Object>, Map<String, String>> actualRequirements = jmxCapReqToMap(jmxRequirements);
Assert.assertEquals(expectedRequirements, actualRequirements);
}
Aggregations