use of org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testModuleIDSetting.
@Test
public void testModuleIDSetting() 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());
Map<String, String> manifest = new HashMap<String, String>();
// test by installing bundles with decreasing IDs
List<Module> modules = new ArrayList<Module>();
for (int i = 5; i > 0; i--) {
manifest.clear();
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
manifest.put(Constants.BUNDLE_SYMBOLICNAME, String.valueOf(i));
modules.add(installDummyModule(manifest, i, manifest.get(Constants.BUNDLE_SYMBOLICNAME), container));
}
// test that the modules have decreasing ID starting at 5
long id = 5;
for (Module module : modules) {
Assert.assertEquals("Wrong ID found.", id--, module.getId().longValue());
}
// test that error occurs when trying to use an existing ID
manifest.clear();
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
manifest.put(Constants.BUNDLE_SYMBOLICNAME, String.valueOf("test.dup.id"));
try {
installDummyModule(manifest, 5, manifest.get(Constants.BUNDLE_SYMBOLICNAME), container);
fail("Expected to fail installation with duplicate ID.");
} catch (IllegalStateException e) {
// expected
}
}
use of org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testUses6FragConflicts.
@Test
public void testUses6FragConflicts() throws BundleException, IOException {
DummyContainerAdaptor adaptor = createDummyAdaptor();
ModuleContainer container = adaptor.getContainer();
Module systemBundle = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, container);
container.resolve(Arrays.asList(systemBundle), true);
Module uses_n1 = installDummyModule("uses.n1.MF", "n1", container);
installDummyModule("uses.n2.MF", "n2", container);
Module uses_n2_frag = installDummyModule("uses.n2.frag.MF", "n2.frag", container);
Module uses_n3 = installDummyModule("uses.n3.MF", "n3", container);
ResolutionReport report = container.resolve(null, false);
Assert.assertNull("resolution report has a resolution exception.", report.getResolutionException());
Assert.assertEquals("n1 should resolve.", State.RESOLVED, uses_n1.getState());
// TODO The following should be true, but on the current resolver in Mars the host is thrown away also
// Assert.assertEquals("n2 should resolve.", State.RESOLVED, uses_n2.getState());
Assert.assertEquals("n2.frag should not resolve.", State.INSTALLED, uses_n2_frag.getState());
Assert.assertEquals("n3 should resolve.", State.RESOLVED, uses_n3.getState());
}
use of org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testStartLevelDeadlock.
@Test
public void testStartLevelDeadlock() throws BundleException, IOException {
DummyContainerAdaptor adaptor = createDummyAdaptor();
ModuleContainer container = adaptor.getContainer();
container.getFrameworkStartLevel().setInitialBundleStartLevel(2);
// 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());
systemBundle.start();
// install a module
Map<String, String> manifest = new HashMap<String, String>();
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "module.test");
Module module = installDummyModule(manifest, manifest.get(Constants.BUNDLE_SYMBOLICNAME), container);
adaptor.setSlowdownEvents(true);
module.setStartLevel(1);
module.start();
List<DummyContainerEvent> events = adaptor.getDatabase().getContainerEvents();
for (DummyContainerEvent event : events) {
Assert.assertNotEquals("Found an error: " + event.error, ContainerEvent.ERROR, event.type);
}
}
use of org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor 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.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testNativeWithFilterChars.
@Test
public void testNativeWithFilterChars() throws BundleException, IOException {
DummyContainerAdaptor adaptor = createDummyAdaptor();
ModuleContainer container = adaptor.getContainer();
// install the system.bundle
String extraCapabilities = "osgi.native; osgi.native.osname=\"Windows NT (unknown)\"";
Module systemBundle = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, Constants.SYSTEM_BUNDLE_SYMBOLICNAME, null, extraCapabilities, container);
ResolutionReport report = container.resolve(Arrays.asList(systemBundle), true);
Assert.assertNull("Failed to resolve system.bundle.", report.getResolutionException());
// install bundle with Bundle-NativeCode
Map<String, String> nativeCodeManifest = new HashMap<String, String>();
nativeCodeManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
nativeCodeManifest.put(Constants.BUNDLE_SYMBOLICNAME, "importer");
//
nativeCodeManifest.put(//
Constants.BUNDLE_NATIVECODE, //
"/lib/mylib.dll; osname=\"win32\"; osname=\"Windows NT (unknown)\"," + "/lib/mylib.lib; osname=\"Linux\"");
Module nativeCodeModule = installDummyModule(nativeCodeManifest, "nativeCodeBundle", container);
// unsatisfied optional and dynamic imports do not fail a resolve.
report = container.resolve(Arrays.asList(nativeCodeModule), true);
Assert.assertNull("Failed to resolve nativeCodeBundle.", report.getResolutionException());
}
Aggregations