Search in sources :

Example 91 with Module

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

the class TestModuleContainer method testDynamicImport01.

@Test
public void testDynamicImport01() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    Module systemBundle = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, null, null, "osgi.ee; osgi.ee=JavaSE; version:Version=\"1.5.0\"", container);
    container.resolve(Arrays.asList(systemBundle), true);
    Module c1 = installDummyModule("c1_v1.MF", "c1_v1", container);
    Module dynamic1 = installDummyModule("dynamic1_v1.MF", "dynamic1_v1", container);
    container.resolve(Arrays.asList(c1, dynamic1), true);
    ModuleWire dynamicWire = container.resolveDynamic("org.osgi.framework", dynamic1.getCurrentRevision());
    Assert.assertNotNull("No dynamic wire found.", dynamicWire);
    Assert.assertEquals("Wrong package found.", "org.osgi.framework", dynamicWire.getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
    Assert.assertEquals("Wrong provider for the wire found.", systemBundle.getCurrentRevision(), dynamicWire.getProvider());
    dynamicWire = container.resolveDynamic("org.osgi.framework.wiring", dynamic1.getCurrentRevision());
    Assert.assertNotNull("No dynamic wire found.", dynamicWire);
    Assert.assertEquals("Wrong package found.", "org.osgi.framework.wiring", dynamicWire.getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
    Assert.assertEquals("Wrong provider for the wire found.", systemBundle.getCurrentRevision(), dynamicWire.getProvider());
    dynamicWire = container.resolveDynamic("c1.b", dynamic1.getCurrentRevision());
    Assert.assertNotNull("No dynamic wire found.", dynamicWire);
    Assert.assertEquals("Wrong package found.", "c1.b", dynamicWire.getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
    Assert.assertEquals("Wrong provider for the wire found.", c1.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) Test(org.junit.Test)

Example 92 with Module

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

the class TestModuleContainer method testSubstitutableExports01.

@Test
public void testSubstitutableExports01() 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 sub1 = installDummyModule("sub1_v1.MF", "sub1", container);
    Module sub2 = installDummyModule("sub2_v1.MF", "sub2", container);
    ModuleRevision sub1Revision0 = sub1.getCurrentRevision();
    container.resolve(Arrays.asList(sub2), true);
    container.update(sub1, OSGiManifestBuilderFactory.createBuilder(getManifest("sub1_v2.MF")), null);
    container.resolve(Arrays.asList(sub1), true);
    ModuleWiring sub1Wiring = sub1.getCurrentRevision().getWiring();
    List<BundleCapability> exportedPackages = sub1Wiring.getCapabilities(PackageNamespace.PACKAGE_NAMESPACE);
    Assert.assertEquals("Wrong number of exported packages: " + exportedPackages, 0, exportedPackages.size());
    List<BundleWire> requiredWires = sub1Wiring.getRequiredWires(PackageNamespace.PACKAGE_NAMESPACE);
    Assert.assertEquals("Wrong number of imported packages: ", 2, requiredWires.size());
    Assert.assertEquals("Wrong provider for package: " + requiredWires.get(1).getProvider(), sub1Revision0, requiredWires.get(1).getProvider());
    container.refresh(Arrays.asList(sub1));
    sub1Wiring = sub1.getCurrentRevision().getWiring();
    exportedPackages = sub1Wiring.getCapabilities(PackageNamespace.PACKAGE_NAMESPACE);
    Assert.assertEquals("Wrong number of exported packages: " + exportedPackages, 1, exportedPackages.size());
    requiredWires = sub1Wiring.getRequiredWires(PackageNamespace.PACKAGE_NAMESPACE);
    Assert.assertEquals("Wrong number of imported packages: ", 1, requiredWires.size());
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) ModuleWiring(org.eclipse.osgi.container.ModuleWiring) Module(org.eclipse.osgi.container.Module) BundleCapability(org.osgi.framework.wiring.BundleCapability) ModuleRevision(org.eclipse.osgi.container.ModuleRevision) BundleWire(org.osgi.framework.wiring.BundleWire) Test(org.junit.Test)

Example 93 with Module

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

the class TestModuleContainer method testFragments02.

@Test
public void testFragments02() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    Module systemModule = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, container);
    Module c1 = installDummyModule("c1_v1.MF", "c1_v1", container);
    Module h2 = installDummyModule("h2_v1.MF", "h2_v1", container);
    container.resolve(Arrays.asList(systemModule, c1, h2), true);
    ModuleWiring h2wiring = h2.getCurrentRevision().getWiring();
    Assert.assertNotNull("Wiring is null.", h2wiring);
    Module f2 = installDummyModule("f2_v1.MF", "f2_v1", container);
    Assert.assertEquals("Wrong state.", State.INSTALLED, f2.getState());
    container.resolve(Arrays.asList(f2), false);
    Assert.assertNull("Expected to not be able to resolve f2.", f2.getCurrentRevision().getWiring());
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) ModuleWiring(org.eclipse.osgi.container.ModuleWiring) Module(org.eclipse.osgi.container.Module) Test(org.junit.Test)

Example 94 with Module

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

the class TestModuleContainer method doTestEventsStartLevel.

private void doTestEventsStartLevel(int beginningStartLevel) throws BundleException, IOException {
    Map<String, String> configuration = new HashMap<String, String>();
    configuration.put(Constants.FRAMEWORK_BEGINNING_STARTLEVEL, String.valueOf(beginningStartLevel));
    DummyContainerAdaptor adaptor = new DummyContainerAdaptor(new DummyCollisionHook(false), configuration);
    ModuleContainer container = adaptor.getContainer();
    DummyModuleDatabase database = adaptor.getDatabase();
    Module systemBundle = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, container);
    container.resolve(Arrays.asList(systemBundle), true);
    Module c1 = installDummyModule("c1_v1.MF", "c1_v1", container);
    Module c2 = installDummyModule("c2_v1.MF", "c2_v1", container);
    Module c3 = installDummyModule("c3_v1.MF", "c3_v1", container);
    Module c4 = installDummyModule("c4_v1.MF", "c4_v1", container);
    Module c5 = installDummyModule("c5_v1.MF", "c5_v1", container);
    Module c6 = installDummyModule("c6_v1.MF", "c6_v1", container);
    Module c7 = installDummyModule("c7_v1.MF", "c7_v1", container);
    container.resolve(Arrays.asList(c1, c2, c3, c4, c5, c6, c7), true);
    database.getModuleEvents();
    c1.setStartLevel(70);
    c2.setStartLevel(60);
    c3.setStartLevel(50);
    c4.setStartLevel(40);
    c5.setStartLevel(30);
    c6.setStartLevel(20);
    c7.setStartLevel(10);
    c1.start();
    c2.start();
    c3.start();
    c4.start();
    c5.start();
    c6.start();
    c7.start();
    List<DummyModuleEvent> actualModuleEvents = database.getModuleEvents();
    Assert.assertEquals("Expecting no events.", 0, actualModuleEvents.size());
    systemBundle.start();
    if (beginningStartLevel == 1) {
        actualModuleEvents = database.getModuleEvents(2);
        List<DummyModuleEvent> expectedModuleEvents = new ArrayList<DummyModuleEvent>(Arrays.asList(new DummyModuleEvent(systemBundle, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(systemBundle, ModuleEvent.STARTED, State.ACTIVE)));
        assertEvents(expectedModuleEvents, actualModuleEvents, true);
        List<DummyContainerEvent> actualContainerEvents = database.getContainerEvents();
        List<DummyContainerEvent> expectedContainerEvents = new ArrayList<DummyContainerEvent>(Arrays.asList(new DummyContainerEvent(ContainerEvent.STARTED, systemBundle, null)));
        Assert.assertEquals("Wrong container events.", expectedContainerEvents, actualContainerEvents);
        container.getFrameworkStartLevel().setStartLevel(100);
        actualModuleEvents = database.getModuleEvents(14);
        expectedModuleEvents = new ArrayList<DummyModuleEvent>(Arrays.asList(new DummyModuleEvent(c7, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(c7, ModuleEvent.STARTED, State.ACTIVE), new DummyModuleEvent(c6, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(c6, ModuleEvent.STARTED, State.ACTIVE), new DummyModuleEvent(c5, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(c5, ModuleEvent.STARTED, State.ACTIVE), new DummyModuleEvent(c4, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(c4, ModuleEvent.STARTED, State.ACTIVE), new DummyModuleEvent(c3, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(c3, ModuleEvent.STARTED, State.ACTIVE), new DummyModuleEvent(c2, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(c2, ModuleEvent.STARTED, State.ACTIVE), new DummyModuleEvent(c1, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(c1, ModuleEvent.STARTED, State.ACTIVE)));
        actualContainerEvents = database.getContainerEvents(1);
        expectedContainerEvents = new ArrayList<DummyContainerEvent>(Arrays.asList(new DummyContainerEvent(ContainerEvent.START_LEVEL, systemBundle, null)));
        Assert.assertEquals("Wrong container events.", expectedContainerEvents, actualContainerEvents);
    } else {
        actualModuleEvents = database.getModuleEvents(16);
        List<DummyModuleEvent> expectedModuleEvents = new ArrayList<DummyModuleEvent>(Arrays.asList(new DummyModuleEvent(systemBundle, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(c7, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(c7, ModuleEvent.STARTED, State.ACTIVE), new DummyModuleEvent(c6, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(c6, ModuleEvent.STARTED, State.ACTIVE), new DummyModuleEvent(c5, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(c5, ModuleEvent.STARTED, State.ACTIVE), new DummyModuleEvent(c4, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(c4, ModuleEvent.STARTED, State.ACTIVE), new DummyModuleEvent(c3, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(c3, ModuleEvent.STARTED, State.ACTIVE), new DummyModuleEvent(c2, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(c2, ModuleEvent.STARTED, State.ACTIVE), new DummyModuleEvent(c1, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(c1, ModuleEvent.STARTED, State.ACTIVE), new DummyModuleEvent(systemBundle, ModuleEvent.STARTED, State.ACTIVE)));
        assertEvents(expectedModuleEvents, actualModuleEvents, true);
        List<DummyContainerEvent> actualContainerEvents = database.getContainerEvents();
        List<DummyContainerEvent> expectedContainerEvents = new ArrayList<DummyContainerEvent>(Arrays.asList(new DummyContainerEvent(ContainerEvent.STARTED, systemBundle, null)));
        Assert.assertEquals("Wrong container events.", expectedContainerEvents, actualContainerEvents);
    }
    if (beginningStartLevel == 1) {
        container.getFrameworkStartLevel().setStartLevel(1);
        actualModuleEvents = database.getModuleEvents(14);
        List<DummyModuleEvent> expectedModuleEvents = new ArrayList<DummyModuleEvent>(Arrays.asList(new DummyModuleEvent(c1, ModuleEvent.STOPPING, State.STOPPING), new DummyModuleEvent(c1, ModuleEvent.STOPPED, State.RESOLVED), new DummyModuleEvent(c2, ModuleEvent.STOPPING, State.STOPPING), new DummyModuleEvent(c2, ModuleEvent.STOPPED, State.RESOLVED), new DummyModuleEvent(c3, ModuleEvent.STOPPING, State.STOPPING), new DummyModuleEvent(c3, ModuleEvent.STOPPED, State.RESOLVED), new DummyModuleEvent(c4, ModuleEvent.STOPPING, State.STOPPING), new DummyModuleEvent(c4, ModuleEvent.STOPPED, State.RESOLVED), new DummyModuleEvent(c5, ModuleEvent.STOPPING, State.STOPPING), new DummyModuleEvent(c5, ModuleEvent.STOPPED, State.RESOLVED), new DummyModuleEvent(c6, ModuleEvent.STOPPING, State.STOPPING), new DummyModuleEvent(c6, ModuleEvent.STOPPED, State.RESOLVED), new DummyModuleEvent(c7, ModuleEvent.STOPPING, State.STOPPING), new DummyModuleEvent(c7, ModuleEvent.STOPPED, State.RESOLVED)));
        assertEvents(expectedModuleEvents, actualModuleEvents, true);
        List<DummyContainerEvent> actualContainerEvents = database.getContainerEvents(1);
        List<DummyContainerEvent> expectedContainerEvents = new ArrayList<DummyContainerEvent>(Arrays.asList(new DummyContainerEvent(ContainerEvent.START_LEVEL, systemBundle, null)));
        Assert.assertEquals("Wrong container events.", expectedContainerEvents, actualContainerEvents);
    }
    systemBundle.stop();
    if (beginningStartLevel == 1) {
        actualModuleEvents = database.getModuleEvents(2);
        List<DummyModuleEvent> expectedModuleEvents = new ArrayList<DummyModuleEvent>(Arrays.asList(new DummyModuleEvent(systemBundle, ModuleEvent.STOPPING, State.STOPPING), new DummyModuleEvent(systemBundle, ModuleEvent.STOPPED, State.RESOLVED)));
        assertEvents(expectedModuleEvents, actualModuleEvents, true);
    } else {
        actualModuleEvents = database.getModuleEvents(16);
        List<DummyModuleEvent> expectedModuleEvents = new ArrayList<DummyModuleEvent>(Arrays.asList(new DummyModuleEvent(systemBundle, ModuleEvent.STOPPING, State.STOPPING), new DummyModuleEvent(c1, ModuleEvent.STOPPING, State.STOPPING), new DummyModuleEvent(c1, ModuleEvent.STOPPED, State.RESOLVED), new DummyModuleEvent(c2, ModuleEvent.STOPPING, State.STOPPING), new DummyModuleEvent(c2, ModuleEvent.STOPPED, State.RESOLVED), new DummyModuleEvent(c3, ModuleEvent.STOPPING, State.STOPPING), new DummyModuleEvent(c3, ModuleEvent.STOPPED, State.RESOLVED), new DummyModuleEvent(c4, ModuleEvent.STOPPING, State.STOPPING), new DummyModuleEvent(c4, ModuleEvent.STOPPED, State.RESOLVED), new DummyModuleEvent(c5, ModuleEvent.STOPPING, State.STOPPING), new DummyModuleEvent(c5, ModuleEvent.STOPPED, State.RESOLVED), new DummyModuleEvent(c6, ModuleEvent.STOPPING, State.STOPPING), new DummyModuleEvent(c6, ModuleEvent.STOPPED, State.RESOLVED), new DummyModuleEvent(c7, ModuleEvent.STOPPING, State.STOPPING), new DummyModuleEvent(c7, ModuleEvent.STOPPED, State.RESOLVED), new DummyModuleEvent(systemBundle, ModuleEvent.STOPPED, State.RESOLVED)));
        assertEvents(expectedModuleEvents, actualModuleEvents, true);
    }
    List<DummyContainerEvent> actualContainerEvents = database.getContainerEvents();
    List<DummyContainerEvent> expectedContainerEvents = new ArrayList<DummyContainerEvent>(Arrays.asList(new DummyContainerEvent(ContainerEvent.STOPPED, systemBundle, null)));
    Assert.assertEquals("Wrong container events.", expectedContainerEvents, actualContainerEvents);
}
Also used : HashMap(java.util.HashMap) DummyCollisionHook(org.eclipse.osgi.tests.container.dummys.DummyCollisionHook) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) ArrayList(java.util.ArrayList) DummyContainerEvent(org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase.DummyContainerEvent) DummyModuleDatabase(org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase) DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) Module(org.eclipse.osgi.container.Module) DummyModuleEvent(org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase.DummyModuleEvent)

Example 95 with Module

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

the class TestModuleContainer method testMissingHost.

@Test
public void testMissingHost() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, container);
    Module f1v1 = installDummyModule("f1_v1.MF", "f1_v1", container);
    Module b3 = installDummyModule("b3_v1.MF", "b3_v1", container);
    ResolutionReport report = container.resolve(Arrays.asList(f1v1, b3), true);
    Assert.assertNotNull("Expected a resolution exception.", report.getResolutionException());
    Module h1v1 = installDummyModule("h1_v1.MF", "h1_v1", container);
    report = container.resolve(Arrays.asList(b3), true);
    Assert.assertNull("Expected no resolution exception.", report.getResolutionException());
    ModuleWiring wiring = b3.getCurrentRevision().getWiring();
    List<ModuleWire> packageWires = wiring.getRequiredModuleWires(PackageNamespace.PACKAGE_NAMESPACE);
    Assert.assertEquals("Expected 1 import.", 1, packageWires.size());
    ModuleWire pkgWire = packageWires.get(0);
    Assert.assertEquals("Wrong host exporter.", pkgWire.getProviderWiring().getRevision(), h1v1.getCurrentRevision());
}
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) ResolutionReport(org.eclipse.osgi.report.resolution.ResolutionReport) Test(org.junit.Test)

Aggregations

Module (org.eclipse.osgi.container.Module)119 ModuleContainer (org.eclipse.osgi.container.ModuleContainer)92 Test (org.junit.Test)84 DummyContainerAdaptor (org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor)79 ResolutionReport (org.eclipse.osgi.report.resolution.ResolutionReport)36 ModuleWire (org.eclipse.osgi.container.ModuleWire)32 HashMap (java.util.HashMap)23 ArrayList (java.util.ArrayList)22 ModuleWiring (org.eclipse.osgi.container.ModuleWiring)22 ModuleRevision (org.eclipse.osgi.container.ModuleRevision)21 DummyModuleDatabase (org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase)12 Generation (org.eclipse.osgi.storage.BundleInfo.Generation)10 BundleException (org.osgi.framework.BundleException)10 DummyModuleEvent (org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase.DummyModuleEvent)9 ModuleRevisionBuilder (org.eclipse.osgi.container.ModuleRevisionBuilder)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 DataInputStream (java.io.DataInputStream)6 ModuleCapability (org.eclipse.osgi.container.ModuleCapability)6 DummyCollisionHook (org.eclipse.osgi.tests.container.dummys.DummyCollisionHook)6