Search in sources :

Example 26 with ModuleContainer

use of org.eclipse.osgi.container.ModuleContainer in project rt.equinox.framework by eclipse.

the class TestModuleContainer method testSystemBundleFragmentRequiresOtherFragment.

@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);
}
Also used : ModuleWire(org.eclipse.osgi.container.ModuleWire) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) HashMap(java.util.HashMap) Module(org.eclipse.osgi.container.Module) ResolutionReport(org.eclipse.osgi.report.resolution.ResolutionReport) Test(org.junit.Test)

Example 27 with ModuleContainer

use of org.eclipse.osgi.container.ModuleContainer in project rt.equinox.framework by eclipse.

the class TestModuleContainer method testMultiCardinalityUses.

@Test
public void testMultiCardinalityUses() 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 p5v100 = installDummyModule("p5_v100.MF", "p5_v100", container);
    Module p5v101 = installDummyModule("p5_v101.MF", "p5_v101", container);
    Module p5v110 = installDummyModule("p5_v110.MF", "p5_v110", container);
    Module p5v111 = installDummyModule("p5_v111.MF", "p5_v111", container);
    installDummyModule("p6_v100.MF", "p6_v100", container);
    installDummyModule("p6_v110.MF", "p6_v110", container);
    installDummyModule("p7_v100.MF", "p7_v100", container);
    installDummyModule("p7_v110.MF", "p7_v110", container);
    container.resolve(null, false);
    Module c6v100 = installDummyModule("c6_v100.MF", "c6_v100", container);
    Module c6v110 = installDummyModule("c6_v110.MF", "c6_v110", container);
    Module c6v130 = installDummyModule("c6_v130.MF", "c6_v130", container);
    Module c6v140 = installDummyModule("c6_v140.MF", "c6_v140", container);
    Module c6v150 = installDummyModule("c6_v150.MF", "c6_v150", container);
    Module c6v170 = installDummyModule("c6_v170.MF", "c6_v170", container);
    // Module c6v180 = installDummyModule("c6_v180.MF", "c6_v180", container);
    // Module c6v120 = installDummyModule("c6_v120.MF", "c6_v120", container);
    container.resolve(null, false);
    final String namespace5 = "namespace.5";
    List<ModuleWire> p5v100Provided = p5v100.getCurrentRevision().getWiring().getProvidedModuleWires(namespace5);
    List<ModuleWire> p5v101Provided = p5v101.getCurrentRevision().getWiring().getProvidedModuleWires(namespace5);
    List<ModuleWire> p5v110Provided = p5v110.getCurrentRevision().getWiring().getProvidedModuleWires(namespace5);
    List<ModuleWire> p5v111Provided = p5v111.getCurrentRevision().getWiring().getProvidedModuleWires(namespace5);
    ModuleWiring c6v100Wiring = c6v100.getCurrentRevision().getWiring();
    List<ModuleWire> c6v100Required = c6v100Wiring.getRequiredModuleWires(namespace5);
    Assert.assertEquals("Wrong number of capabilities", 2, c6v100Required.size());
    assertWires(c6v100Required, p5v100Provided, p5v101Provided);
    ModuleWiring c6v110Wiring = c6v110.getCurrentRevision().getWiring();
    List<ModuleWire> c6v110Required = c6v110Wiring.getRequiredModuleWires(namespace5);
    Assert.assertEquals("Wrong number of capabilities", 2, c6v110Required.size());
    assertWires(c6v110Required, p5v100Provided, p5v101Provided);
    ModuleWiring c6v130Wiring = c6v130.getCurrentRevision().getWiring();
    List<ModuleWire> c6v130Required = c6v130Wiring.getRequiredModuleWires(namespace5);
    Assert.assertEquals("Wrong number of capabilities", 2, c6v130Required.size());
    assertWires(c6v130Required, p5v100Provided, p5v101Provided);
    ModuleWiring c6v140Wiring = c6v140.getCurrentRevision().getWiring();
    List<ModuleWire> c6v140Required = c6v140Wiring.getRequiredModuleWires(namespace5);
    Assert.assertEquals("Wrong number of capabilities", 2, c6v140Required.size());
    assertWires(c6v140Required, p5v100Provided, p5v101Provided);
    ModuleWiring c6v150Wiring = c6v150.getCurrentRevision().getWiring();
    List<ModuleWire> c6v150Required = c6v150Wiring.getRequiredModuleWires(namespace5);
    Assert.assertEquals("Wrong number of capabilities", 2, c6v150Required.size());
    assertWires(c6v150Required, p5v110Provided, p5v111Provided);
    ModuleWiring c6v170Wiring = c6v170.getCurrentRevision().getWiring();
    List<ModuleWire> c6v170Required = c6v170Wiring.getRequiredModuleWires(namespace5);
    Assert.assertEquals("Wrong number of capabilities", 2, c6v170Required.size());
    assertWires(c6v170Required, p5v110Provided, p5v111Provided);
    Module c6v160 = installDummyModule("c6_v160.MF", "c6_v160", container);
    container.resolve(null, false);
    Assert.assertNull("Bundle should not be resolved: " + c6v160, c6v160.getCurrentRevision().getWiring());
    container.uninstall(c6v160);
    Module c6v180 = installDummyModule("c6_v180.MF", "c6_v180", container);
    container.resolve(null, false);
    Assert.assertNull("Bundle should not be resolved: " + c6v180, c6v180.getCurrentRevision().getWiring());
    container.uninstall(c6v180);
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleWire(org.eclipse.osgi.container.ModuleWire) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) ModuleWiring(org.eclipse.osgi.container.ModuleWiring) Module(org.eclipse.osgi.container.Module) Test(org.junit.Test)

Example 28 with ModuleContainer

use of org.eclipse.osgi.container.ModuleContainer in project rt.equinox.framework by eclipse.

the class TestModuleContainer method doTestUses5.

public void doTestUses5(String kManifest) 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_k = installDummyModule(kManifest, "k", container);
    Module uses_l = installDummyModule("uses.l.MF", "l", container);
    Module uses_m_conflict1 = installDummyModule("uses.m.conflict1.MF", "m.conflict1", container);
    Module uses_m_conflict2 = installDummyModule("uses.m.conflict2.MF", "m.conflict2", container);
    container.resolve(null, false);
    Assert.assertEquals("k should resolve.", State.RESOLVED, uses_k.getState());
    Assert.assertEquals("l should resolve.", State.RESOLVED, uses_l.getState());
    Assert.assertEquals("m.conflict1 should resolve.", State.RESOLVED, uses_m_conflict1.getState());
    Assert.assertEquals("m.conflict2 should resolve.", State.RESOLVED, uses_m_conflict2.getState());
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) Module(org.eclipse.osgi.container.Module)

Example 29 with ModuleContainer

use of org.eclipse.osgi.container.ModuleContainer in project rt.equinox.framework by eclipse.

the class TestModuleContainer method testDynamicImport07.

@Test
public void testDynamicImport07() 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 dynamic3 = installDummyModule("dynamic2_v1.MF", "dynamic2_v1", container);
    Assert.assertNull("Expected no resolution exception.", container.resolve(Arrays.asList(systemBundle, dynamic3), true).getResolutionException());
    installDummyModule("c6_v1.MF", "c6_v1", container);
    ModuleWire dynamicWire = container.resolveDynamic("c6", dynamic3.getCurrentRevision());
    Assert.assertNull("Dynamic wire found.", dynamicWire);
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleWire(org.eclipse.osgi.container.ModuleWire) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) Module(org.eclipse.osgi.container.Module) Test(org.junit.Test)

Example 30 with ModuleContainer

use of org.eclipse.osgi.container.ModuleContainer in project rt.equinox.framework by eclipse.

the class TestModuleContainer method testUses3.

/*
	 * Test that split packages are handled ok with uses constraints
	 */
@Test
public void testUses3() 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_a = installDummyModule("uses.a.MF", "a", container);
    Module uses_b = installDummyModule("uses.b.MF", "b", container);
    Module uses_e = installDummyModule("uses.e.MF", "e", container);
    Module uses_f = installDummyModule("uses.f.MF", "f", container);
    Module uses_g = installDummyModule("uses.g.MF", "g", container);
    container.resolve(null, false);
    Assert.assertEquals("a should resolve.", State.RESOLVED, uses_a.getState());
    Assert.assertEquals("b should resolve.", State.RESOLVED, uses_b.getState());
    Assert.assertEquals("e should resolve.", State.RESOLVED, uses_e.getState());
    Assert.assertEquals("f should resolve.", State.RESOLVED, uses_f.getState());
    Assert.assertEquals("g should not resolve.", State.INSTALLED, uses_g.getState());
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) Module(org.eclipse.osgi.container.Module) Test(org.junit.Test)

Aggregations

ModuleContainer (org.eclipse.osgi.container.ModuleContainer)95 Module (org.eclipse.osgi.container.Module)92 Test (org.junit.Test)87 DummyContainerAdaptor (org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor)80 ResolutionReport (org.eclipse.osgi.report.resolution.ResolutionReport)36 ModuleWire (org.eclipse.osgi.container.ModuleWire)31 HashMap (java.util.HashMap)24 ModuleWiring (org.eclipse.osgi.container.ModuleWiring)20 ArrayList (java.util.ArrayList)15 DummyModuleDatabase (org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase)12 ModuleRevision (org.eclipse.osgi.container.ModuleRevision)9 DummyModuleEvent (org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase.DummyModuleEvent)9 DummyCollisionHook (org.eclipse.osgi.tests.container.dummys.DummyCollisionHook)7 BundleException (org.osgi.framework.BundleException)7 BundleRequirement (org.osgi.framework.wiring.BundleRequirement)6 DummyContainerEvent (org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase.DummyContainerEvent)5 BundleCapability (org.osgi.framework.wiring.BundleCapability)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 ModuleCapability (org.eclipse.osgi.container.ModuleCapability)4 DummyResolverHookFactory (org.eclipse.osgi.tests.container.dummys.DummyResolverHookFactory)4