diff options
Diffstat (limited to 'bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java')
-rw-r--r-- | bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java | 302 |
1 files changed, 302 insertions, 0 deletions
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java index 1bab9f5b5..96b67023b 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java @@ -2839,6 +2839,308 @@ public class TestModuleContainer extends AbstractTest { } @Test + public void testSystemBundleFragmentsPackageImport() throws BundleException, IOException { + // install the system.bundle + Module systemBundle = createContainerWithSystemBundle(true); + ModuleContainer container = systemBundle.getContainer(); + + // install an system.bundle fragment that imports framework package + Map<String, String> systemFragManifest = new HashMap<String, String>(); + systemFragManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2"); + systemFragManifest.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag"); + systemFragManifest.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME); + systemFragManifest.put(Constants.IMPORT_PACKAGE, "org.osgi.framework"); + + Module systemFrag = installDummyModule(systemFragManifest, "systemFrag", container); + + ResolutionReport report = container.resolve(Arrays.asList(systemFrag), true); + Assert.assertNull("Failed to resolve system.bundle.", report.getResolutionException()); + + List<ModuleWire> hostWires = systemBundle.getCurrentRevision().getWiring().getProvidedModuleWires(HostNamespace.HOST_NAMESPACE); + assertEquals("Wrong number of fragments.", 1, hostWires.size()); + Assert.assertEquals("Unexpected fragment revision: " + hostWires, systemFrag.getCurrentRevision(), hostWires.get(0).getRequirer()); + + List<ModuleWire> systemBundleRequiredWires = systemBundle.getCurrentRevision().getWiring().getRequiredModuleWires(null); + assertEquals("No required wires expected.", 0, systemBundleRequiredWires.size()); + } + + @Test + public void testSystemBundleFragmentsNonPayloadRequirements() throws BundleException, IOException { + // install the system.bundle + Module systemBundle = createContainerWithSystemBundle(true); + ModuleContainer container = systemBundle.getContainer(); + + // install an system.bundle fragment that imports framework package + Map<String, String> systemFragManifest = new HashMap<String, String>(); + systemFragManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2"); + systemFragManifest.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag"); + systemFragManifest.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME); + systemFragManifest.put(Constants.REQUIRE_CAPABILITY, "osgi.ee; filter:=\"(osgi.ee=JavaSE)\""); + + Module systemFrag = installDummyModule(systemFragManifest, "systemFrag", container); + + ResolutionReport report = container.resolve(Arrays.asList(systemFrag), true); + Assert.assertNull("Failed to resolve system.bundle.", report.getResolutionException()); + + List<ModuleWire> hostWires = systemBundle.getCurrentRevision().getWiring().getProvidedModuleWires(HostNamespace.HOST_NAMESPACE); + assertEquals("Wrong number of fragments.", 1, hostWires.size()); + Assert.assertEquals("Unexpected fragment revision: " + hostWires, systemFrag.getCurrentRevision(), hostWires.get(0).getRequirer()); + + List<ModuleWire> systemBundleRequiredWires = systemBundle.getCurrentRevision().getWiring().getRequiredModuleWires(null); + assertEquals("No required wires expected.", 0, systemBundleRequiredWires.size()); + + List<ModuleWire> fragRequiredWires = systemFrag.getCurrentRevision().getWiring().getRequiredModuleWires(null); + assertEquals("Wrong number of required wires.", 2, fragRequiredWires.size()); + assertWires(fragRequiredWires, systemBundle.getCurrentRevision().getWiring().getProvidedModuleWires(null)); + } + + @Test + public void testSystemBundleFragmentsWithPayloadRequirements() throws BundleException, IOException { + // install the system.bundle + Module systemBundle = createContainerWithSystemBundle(true); + ModuleContainer container = systemBundle.getContainer(); + + // install an system.bundle fragment that requires a payload requirement from system.bundle + Map<String, String> systemFragManifest = new HashMap<String, String>(); + systemFragManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2"); + systemFragManifest.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag"); + systemFragManifest.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME); + systemFragManifest.put(Constants.REQUIRE_CAPABILITY, "equinox.test; filter:=\"(equinox.test=system)\""); + + Module systemFrag = installDummyModule(systemFragManifest, "systemFrag", container); + + ResolutionReport report = container.resolve(Arrays.asList(systemFrag), true); + Assert.assertNull("Failed to resolve system.bundle.", report.getResolutionException()); + + List<ModuleWire> hostWires = systemBundle.getCurrentRevision().getWiring().getProvidedModuleWires(HostNamespace.HOST_NAMESPACE); + assertEquals("Wrong number of fragments.", 1, hostWires.size()); + Assert.assertEquals("Unexpected fragment revision: " + hostWires, systemFrag.getCurrentRevision(), hostWires.get(0).getRequirer()); + + List<ModuleWire> systemBundleRequiredWires = systemBundle.getCurrentRevision().getWiring().getRequiredModuleWires(null); + assertEquals("Wrong number of wires.", 1, systemBundleRequiredWires.size()); + assertEquals("Wrong requirer.", systemBundle.getCurrentRevision(), systemBundleRequiredWires.get(0).getRequirer()); + assertEquals("Wrong requirement.", systemFrag.getCurrentRevision(), systemBundleRequiredWires.get(0).getRequirement().getRevision()); + + List<ModuleWire> fragRequiredWires = systemFrag.getCurrentRevision().getWiring().getRequiredModuleWires(null); + assertEquals("Wrong number of required wires.", 1, fragRequiredWires.size()); + assertWires(fragRequiredWires, hostWires); + } + + @Test + public void testSystemBundleFragmentRequiresOtherFragment() throws BundleException, IOException { + // install the system.bundle + Module systemBundle = createContainerWithSystemBundle(true); + ModuleContainer container = systemBundle.getContainer(); + + // install an system.bundle fragment that provides a capability + Map<String, String> systemFragManifest1 = new HashMap<String, String>(); + systemFragManifest1.put(Constants.BUNDLE_MANIFESTVERSION, "2"); + systemFragManifest1.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag1"); + systemFragManifest1.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME); + systemFragManifest1.put(Constants.PROVIDE_CAPABILITY, "fragment.capability; fragment.capability=test"); + Module systemFrag1 = installDummyModule(systemFragManifest1, "systemFrag1", container); + + // install an system.bundle fragment that requires a fragment capability + Map<String, String> systemFragManifest2 = new HashMap<String, String>(); + systemFragManifest2.put(Constants.BUNDLE_MANIFESTVERSION, "2"); + systemFragManifest2.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag2"); + systemFragManifest2.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME); + systemFragManifest2.put(Constants.REQUIRE_CAPABILITY, "fragment.capability; filter:=\"(fragment.capability=test)\""); + Module systemFrag2 = installDummyModule(systemFragManifest2, "systemFrag2", container); + + ResolutionReport report = container.resolve(Arrays.asList(systemFrag2), true); + Assert.assertNull("Failed to resolve system.bundle.", report.getResolutionException()); + + List<ModuleWire> hostWires = systemBundle.getCurrentRevision().getWiring().getProvidedModuleWires(HostNamespace.HOST_NAMESPACE); + assertEquals("Wrong number of fragments.", 2, hostWires.size()); + + List<ModuleWire> systemBundleRequiredWires = systemBundle.getCurrentRevision().getWiring().getRequiredModuleWires(null); + assertEquals("Wrong number of wires.", 1, systemBundleRequiredWires.size()); + assertEquals("Wrong requirer.", systemBundle.getCurrentRevision(), systemBundleRequiredWires.get(0).getRequirer()); + assertEquals("Wrong requirement.", systemFrag2.getCurrentRevision(), systemBundleRequiredWires.get(0).getRequirement().getRevision()); + assertEquals("Wrong provider.", systemBundle.getCurrentRevision(), systemBundleRequiredWires.get(0).getProvider()); + assertEquals("Wrong capability.", systemFrag1.getCurrentRevision(), systemBundleRequiredWires.get(0).getCapability().getRevision()); + + List<ModuleWire> fragRequiredWires = systemFrag2.getCurrentRevision().getWiring().getRequiredModuleWires(null); + assertEquals("Wrong number of required wires.", 1, fragRequiredWires.size()); + assertWires(fragRequiredWires, hostWires); + } + + @Test + public void testSystemBundleFragmentRequiresOtherFragmentFailResolution() throws BundleException, IOException { + // install the system.bundle + Module systemBundle = createContainerWithSystemBundle(true); + ModuleContainer container = systemBundle.getContainer(); + + // install an system.bundle fragment that provides a capability + Map<String, String> systemFragManifest1 = new HashMap<String, String>(); + systemFragManifest1.put(Constants.BUNDLE_MANIFESTVERSION, "2"); + systemFragManifest1.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag1"); + systemFragManifest1.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME); + systemFragManifest1.put(Constants.PROVIDE_CAPABILITY, "fragment.capability; fragment.capability=test1"); + Module systemFrag1 = installDummyModule(systemFragManifest1, "systemFrag1", container); + + // install an system.bundle fragment that requires a fragment capability, but fails to match + Map<String, String> systemFragManifest2 = new HashMap<String, String>(); + systemFragManifest2.put(Constants.BUNDLE_MANIFESTVERSION, "2"); + systemFragManifest2.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag2"); + systemFragManifest2.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME); + systemFragManifest2.put(Constants.REQUIRE_CAPABILITY, "fragment.capability; filter:=\"(fragment.capability=test4)\""); + systemFragManifest2.put(Constants.PROVIDE_CAPABILITY, "fragment.capability; fragment.capability=test2"); + Module systemFrag2 = installDummyModule(systemFragManifest2, "systemFrag2", container); + + // install an system.bundle fragment that requires a fragment capability from a fragment that fails to resolve + Map<String, String> systemFragManifest3 = new HashMap<String, String>(); + systemFragManifest3.put(Constants.BUNDLE_MANIFESTVERSION, "2"); + systemFragManifest3.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag3"); + systemFragManifest3.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME); + systemFragManifest3.put(Constants.REQUIRE_CAPABILITY, "fragment.capability; filter:=\"(fragment.capability=test2)\""); + systemFragManifest3.put(Constants.PROVIDE_CAPABILITY, "fragment.capability; fragment.capability=test3"); + Module systemFrag3 = installDummyModule(systemFragManifest3, "systemFrag3", container); + + ResolutionReport report = container.resolve(Arrays.asList(systemFrag3), true); + Assert.assertNotNull("Expected failure message", report.getResolutionException()); + + List<ModuleWire> hostWires = systemBundle.getCurrentRevision().getWiring().getProvidedModuleWires(HostNamespace.HOST_NAMESPACE); + assertEquals("Wrong number of fragments.", 1, hostWires.size()); + List<ModuleWire> systemFrag1HostWires = systemFrag1.getCurrentRevision().getWiring().getRequiredModuleWires(HostNamespace.HOST_NAMESPACE); + assertWires(systemFrag1HostWires, hostWires); + + // install a bundle that can satisfy the failed requirement, but it should not be allowed since it is not a fragment + Map<String, String> provideCapabilityManifest1 = new HashMap<String, String>(); + provideCapabilityManifest1.put(Constants.BUNDLE_MANIFESTVERSION, "2"); + provideCapabilityManifest1.put(Constants.BUNDLE_SYMBOLICNAME, "provideCapabilityBundle1"); + provideCapabilityManifest1.put(Constants.PROVIDE_CAPABILITY, "fragment.capability; fragment.capability=test4"); + installDummyModule(provideCapabilityManifest1, "provideCapabilityBundle1", container); + + hostWires = systemBundle.getCurrentRevision().getWiring().getProvidedModuleWires(HostNamespace.HOST_NAMESPACE); + assertEquals("Wrong number of fragments.", 1, hostWires.size()); + systemFrag1HostWires = systemFrag1.getCurrentRevision().getWiring().getRequiredModuleWires(HostNamespace.HOST_NAMESPACE); + assertWires(systemFrag1HostWires, hostWires); + + // install a fragment that satisfies the failed requirement + Map<String, String> systemFragManifest4 = new HashMap<String, String>(); + systemFragManifest4.put(Constants.BUNDLE_MANIFESTVERSION, "2"); + systemFragManifest4.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag4"); + systemFragManifest4.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME); + systemFragManifest4.put(Constants.PROVIDE_CAPABILITY, "fragment.capability; fragment.capability=test4"); + Module systemFrag4 = installDummyModule(systemFragManifest4, "systemFrag4", container); + + report = container.resolve(Arrays.asList(systemFrag3), true); + Assert.assertNull("Failed to resolve.", report.getResolutionException()); + + hostWires = systemBundle.getCurrentRevision().getWiring().getProvidedModuleWires(HostNamespace.HOST_NAMESPACE); + assertEquals("Wrong number of fragments.", 4, hostWires.size()); + systemFrag1HostWires = systemFrag1.getCurrentRevision().getWiring().getRequiredModuleWires(HostNamespace.HOST_NAMESPACE); + List<ModuleWire> systemFrag2HostWires = systemFrag2.getCurrentRevision().getWiring().getRequiredModuleWires(HostNamespace.HOST_NAMESPACE); + List<ModuleWire> systemFrag3HostWires = systemFrag3.getCurrentRevision().getWiring().getRequiredModuleWires(HostNamespace.HOST_NAMESPACE); + List<ModuleWire> systemFrag4HostWires = systemFrag4.getCurrentRevision().getWiring().getRequiredModuleWires(HostNamespace.HOST_NAMESPACE); + assertWires(systemFrag1HostWires, hostWires); + assertWires(systemFrag2HostWires, hostWires); + assertWires(systemFrag3HostWires, hostWires); + assertWires(systemFrag4HostWires, hostWires); + + List<ModuleCapability> fragmentCapabilities = systemBundle.getCurrentRevision().getWiring().getModuleCapabilities("fragment.capability"); + assertEquals("Wrong number of fragment capabilities.", 4, fragmentCapabilities.size()); + // Use set since the order of required and provided wires will be different + Set<ModuleWire> hostRequiredFragmentCapWires = new HashSet<ModuleWire>(systemBundle.getCurrentRevision().getWiring().getRequiredModuleWires("fragment.capability")); + Set<ModuleWire> hostProvidedFragmentCapWires = new HashSet<ModuleWire>(systemBundle.getCurrentRevision().getWiring().getProvidedModuleWires("fragment.capability")); + assertEquals("Wrong number of wires.", 2, hostProvidedFragmentCapWires.size()); + assertEquals("Wrong wires found from host.", hostRequiredFragmentCapWires, hostProvidedFragmentCapWires); + } + + @Test + public void testMultipleSystemBundleFragmentsWithSameName() throws BundleException, IOException { + // install the system.bundle + Module systemBundle = createContainerWithSystemBundle(true); + ModuleContainer container = systemBundle.getContainer(); + + // install multiple versions of the same fragment + Map<String, String> systemFragManifest1 = new HashMap<String, String>(); + systemFragManifest1.put(Constants.BUNDLE_MANIFESTVERSION, "2"); + systemFragManifest1.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag"); + systemFragManifest1.put(Constants.BUNDLE_VERSION, "1.0"); + systemFragManifest1.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME); + Module systemFrag1 = installDummyModule(systemFragManifest1, "systemFrag1", container); + + // first attempt to resolve the lowest version before installing the others + ResolutionReport report = container.resolve(Arrays.asList(systemFrag1), true); + Assert.assertNull("Unexpected failure message", report.getResolutionException()); + + List<ModuleWire> hostWires = systemBundle.getCurrentRevision().getWiring().getProvidedModuleWires(HostNamespace.HOST_NAMESPACE); + assertEquals("Wrong number of fragments.", 1, hostWires.size()); + List<ModuleWire> systemFrag1HostWires = systemFrag1.getCurrentRevision().getWiring().getRequiredModuleWires(HostNamespace.HOST_NAMESPACE); + assertWires(systemFrag1HostWires, hostWires); + + Map<String, String> systemFragManifest2 = new HashMap<String, String>(); + systemFragManifest2.put(Constants.BUNDLE_MANIFESTVERSION, "2"); + systemFragManifest2.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag"); + systemFragManifest2.put(Constants.BUNDLE_VERSION, "2.0"); + systemFragManifest2.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME); + Module systemFrag2 = installDummyModule(systemFragManifest2, "systemFrag2", container); + + Map<String, String> systemFragManifest3 = new HashMap<String, String>(); + systemFragManifest3.put(Constants.BUNDLE_MANIFESTVERSION, "2"); + systemFragManifest3.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag"); + systemFragManifest3.put(Constants.BUNDLE_VERSION, "3.0"); + systemFragManifest3.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME); + Module systemFrag3 = installDummyModule(systemFragManifest3, "systemFrag3", container); + + report = container.resolve(Arrays.asList(systemFrag2), true); + Assert.assertNotNull("Expected failure message", report.getResolutionException()); + report = container.resolve(Arrays.asList(systemFrag3), true); + Assert.assertNotNull("Expected failure message", report.getResolutionException()); + + hostWires = systemBundle.getCurrentRevision().getWiring().getProvidedModuleWires(HostNamespace.HOST_NAMESPACE); + assertEquals("Wrong number of fragments.", 1, hostWires.size()); + systemFrag1HostWires = systemFrag1.getCurrentRevision().getWiring().getRequiredModuleWires(HostNamespace.HOST_NAMESPACE); + assertWires(systemFrag1HostWires, hostWires); + + // uninstall the fragments so we can start over + container.uninstall(systemFrag1); + container.uninstall(systemFrag2); + container.uninstall(systemFrag3); + + // refresh the system bundle to get only it resolved + report = container.refresh(Collections.singleton(systemBundle)); + Assert.assertNull("Unexpected failure message", report.getResolutionException()); + hostWires = systemBundle.getCurrentRevision().getWiring().getProvidedModuleWires(HostNamespace.HOST_NAMESPACE); + assertEquals("Wrong number of fragments.", 0, hostWires.size()); + + // install the fragments again + systemFrag1 = installDummyModule(systemFragManifest1, "systemFrag1", container); + systemFrag2 = installDummyModule(systemFragManifest2, "systemFrag2", container); + systemFrag3 = installDummyModule(systemFragManifest3, "systemFrag3", container); + + report = container.resolve(Arrays.asList(systemFrag1), true); + Assert.assertNotNull("Expected failure message", report.getResolutionException()); + report = container.resolve(Arrays.asList(systemFrag2), true); + Assert.assertNotNull("Expected failure message", report.getResolutionException()); + report = container.resolve(Arrays.asList(systemFrag3), true); + Assert.assertNull("Unexpected failure message", report.getResolutionException()); + + hostWires = systemBundle.getCurrentRevision().getWiring().getProvidedModuleWires(HostNamespace.HOST_NAMESPACE); + List<ModuleWire> systemFrag3HostWires = systemFrag3.getCurrentRevision().getWiring().getRequiredModuleWires(HostNamespace.HOST_NAMESPACE); + assertWires(systemFrag3HostWires, hostWires); + } + + private Module createContainerWithSystemBundle(boolean resolveSystemBundle) throws BundleException, IOException { + DummyContainerAdaptor adaptor = createDummyAdaptor(); + ModuleContainer container = adaptor.getContainer(); + + // install the system.bundle + String systemCapability = "osgi.ee; osgi.ee=\"JavaSE\"; version:List<Version>=\"1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6\", equinox.test; equinox.test=system, osgi.native; osgi.native.osname=test"; + Module systemBundle = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, Constants.SYSTEM_BUNDLE_SYMBOLICNAME, null, systemCapability, container); + if (resolveSystemBundle) { + ResolutionReport report = container.resolve(Collections.singleton(systemBundle), true); + Assert.assertNull("Found resolution exception.", report.getResolutionException()); + Assert.assertEquals("System is not resolved.", State.RESOLVED, systemBundle.getState()); + } + + return systemBundle; + } + + @Test public void testSplitPackageUses01() throws BundleException { DummyContainerAdaptor adaptor = createDummyAdaptor(); ModuleContainer container = adaptor.getContainer(); |