Search in sources :

Example 76 with ModuleContainer

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

the class TestModuleContainer method testCompatReprovide.

@Test
public void testCompatReprovide() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    Module b1 = installDummyModule("compatReprovide1.MF", "b1", container);
    Module b2 = installDummyModule("compatReprovide2.MF", "b2", container);
    Module b3 = installDummyModule("compatReprovide3.MF", "b3", container);
    String b1Visibility = b1.getCurrentRevision().getRequirements(BundleNamespace.BUNDLE_NAMESPACE).iterator().next().getDirectives().get(BundleNamespace.REQUIREMENT_VISIBILITY_DIRECTIVE);
    String b2Visibility = b2.getCurrentRevision().getRequirements(BundleNamespace.BUNDLE_NAMESPACE).iterator().next().getDirectives().get(BundleNamespace.REQUIREMENT_VISIBILITY_DIRECTIVE);
    String b3Visibility = b3.getCurrentRevision().getRequirements(BundleNamespace.BUNDLE_NAMESPACE).iterator().next().getDirectives().get(BundleNamespace.REQUIREMENT_VISIBILITY_DIRECTIVE);
    Assert.assertEquals("Wrong visibility directive: " + b1, BundleNamespace.VISIBILITY_REEXPORT, b1Visibility);
    Assert.assertNull("Wrong visibility directive: ", b2Visibility);
    Assert.assertEquals("Wrong visibility directive: " + b2, BundleNamespace.VISIBILITY_REEXPORT, b3Visibility);
}
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)

Example 77 with ModuleContainer

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

the class TestModuleContainer method testUses4.

/*
	 * Test that fragments and uses constraints
	 */
@Test
public void testUses4() 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_h = installDummyModule("uses.h.MF", "h", container);
    Module uses_h_frag = installDummyModule("uses.h.frag.MF", "h.frag", container);
    container.resolve(null, false);
    Assert.assertEquals("h should resolve.", State.RESOLVED, uses_h.getState());
    Assert.assertEquals("h.frag should resolve.", State.RESOLVED, uses_h_frag.getState());
    Module uses_i = installDummyModule("uses.i.MF", "i", container);
    Module uses_j = installDummyModule("uses.j.MF", "j", container);
    container.resolve(null, false);
    Assert.assertEquals("i should resolve.", State.RESOLVED, uses_i.getState());
    Assert.assertEquals("j should resolve.", State.RESOLVED, uses_j.getState());
    List<BundleWire> requiredWires = uses_j.getCurrentRevision().getWiring().getRequiredWires(null);
    Assert.assertEquals("Wrong number of wires for j", 2, requiredWires.size());
    for (BundleWire wire : requiredWires) {
        Assert.assertEquals("Wrong provider", uses_i.getCurrentRevision(), wire.getProvider());
    }
    Module uses_j_dynamic = installDummyModule("uses.j.dynamic.MF", "j.dynamic", container);
    container.resolve(null, false);
    ModuleWire dynamicWire = container.resolveDynamic("uses2", uses_j_dynamic.getCurrentRevision());
    Assert.assertNotNull("Null dynamic wire.", dynamicWire);
    Assert.assertEquals("Wrong provider", uses_i.getCurrentRevision(), dynamicWire.getProvider());
}
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) BundleWire(org.osgi.framework.wiring.BundleWire) Test(org.junit.Test)

Example 78 with ModuleContainer

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

the class TestModuleContainer method testCompatSingleton.

@Test
public void testCompatSingleton() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    Module s1 = installDummyModule("compatSingleton1.MF", "s1", container);
    Module s2 = installDummyModule("compatSingleton2.MF", "s2", container);
    Module s3 = installDummyModule("compatSingleton3.MF", "s3", container);
    String s1Singleton = s1.getCurrentRevision().getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE).iterator().next().getDirectives().get(IdentityNamespace.CAPABILITY_SINGLETON_DIRECTIVE);
    String s2Singleton = s2.getCurrentRevision().getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE).iterator().next().getDirectives().get(IdentityNamespace.CAPABILITY_SINGLETON_DIRECTIVE);
    String s3Singleton = s3.getCurrentRevision().getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE).iterator().next().getDirectives().get(IdentityNamespace.CAPABILITY_SINGLETON_DIRECTIVE);
    Assert.assertEquals("Wrong singleton directive: " + s1, "true", s1Singleton);
    Assert.assertNull("Wrong singleton directive: " + s2, s2Singleton);
    Assert.assertEquals("Wrong singleton directive: " + s3, "true", s3Singleton);
}
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)

Example 79 with ModuleContainer

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

the class TestModuleContainer method testSystemBundleFragmentRequiresOtherFragmentFailResolution.

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

Example 80 with ModuleContainer

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

the class TestModuleContainer method testInvalidAttributes.

@Test
public void testInvalidAttributes() throws IOException, BundleException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    // install the system.bundle
    installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, Constants.SYSTEM_BUNDLE_SYMBOLICNAME, null, null, container);
    // provider with all supported types
    Map<String, String> invalidAttrManifest = new HashMap<String, String>();
    invalidAttrManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    invalidAttrManifest.put(Constants.BUNDLE_SYMBOLICNAME, "invalid");
    invalidAttrManifest.put(Constants.PROVIDE_CAPABILITY, "provider.cap; invalid:Boolean=true");
    checkInvalidManifest(invalidAttrManifest, container);
    invalidAttrManifest.put(Constants.PROVIDE_CAPABILITY, "provider.cap; invalid:Integer=1");
    checkInvalidManifest(invalidAttrManifest, container);
    invalidAttrManifest.put(Constants.PROVIDE_CAPABILITY, "provider.cap; invalid:List<Boolean>=true");
    checkInvalidManifest(invalidAttrManifest, container);
    invalidAttrManifest.put(Constants.PROVIDE_CAPABILITY, "provider.cap; invalid:List<Integer>=1");
    checkInvalidManifest(invalidAttrManifest, container);
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) HashMap(java.util.HashMap) 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