Search in sources :

Example 51 with ModuleContainer

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

the class TestModuleContainer method testSingleton01.

@Test
public void testSingleton01() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    Module s1 = installDummyModule("singleton1_v1.MF", "s1_v1", container);
    Module s2 = installDummyModule("singleton1_v2.MF", "s1_v2", container);
    Module s3 = installDummyModule("singleton1_v3.MF", "s1_v3", container);
    container.resolve(null, false);
    Assert.assertFalse("Singleton v1 is resolved.", Module.RESOLVED_SET.contains(s1.getState()));
    Assert.assertFalse("Singleton v2 is resolved.", Module.RESOLVED_SET.contains(s2.getState()));
    Assert.assertTrue("Singleton v3 is not resolved.", Module.RESOLVED_SET.contains(s3.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)

Example 52 with ModuleContainer

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

the class TestModuleContainer method testEventsInstall.

@Test
public void testEventsInstall() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    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);
    List<DummyModuleEvent> actual = adaptor.getDatabase().getModuleEvents();
    List<DummyModuleEvent> expected = Arrays.asList(new DummyModuleEvent(c1, ModuleEvent.INSTALLED, State.INSTALLED), new DummyModuleEvent(c2, ModuleEvent.INSTALLED, State.INSTALLED), new DummyModuleEvent(c3, ModuleEvent.INSTALLED, State.INSTALLED), new DummyModuleEvent(c4, ModuleEvent.INSTALLED, State.INSTALLED), new DummyModuleEvent(c5, ModuleEvent.INSTALLED, State.INSTALLED), new DummyModuleEvent(c6, ModuleEvent.INSTALLED, State.INSTALLED), new DummyModuleEvent(c7, ModuleEvent.INSTALLED, State.INSTALLED));
    Assert.assertEquals("Wrong install events.", expected, actual);
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) Module(org.eclipse.osgi.container.Module) DummyModuleEvent(org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase.DummyModuleEvent) Test(org.junit.Test)

Example 53 with ModuleContainer

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

the class TestModuleContainer method testMultiHostFragmentWithOverlapImport.

@Test
public void testMultiHostFragmentWithOverlapImport() throws BundleException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    // install an exporter
    Map<String, String> exporterManifest = new HashMap<String, String>();
    exporterManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    exporterManifest.put(Constants.BUNDLE_SYMBOLICNAME, "exporter");
    exporterManifest.put(Constants.BUNDLE_VERSION, "1.0");
    exporterManifest.put(Constants.EXPORT_PACKAGE, "exporter");
    installDummyModule(exporterManifest, "exporter", container);
    // install a fragment to the exporter
    Map<String, String> exporterFragManifest = new HashMap<String, String>();
    exporterFragManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    exporterFragManifest.put(Constants.BUNDLE_SYMBOLICNAME, "exporter.frag");
    exporterFragManifest.put(Constants.EXPORT_PACKAGE, "exporter.frag");
    exporterFragManifest.put(Constants.FRAGMENT_HOST, "exporter");
    installDummyModule(exporterFragManifest, "exporter.frag", container);
    // install a host that imports the exporter
    Map<String, String> hostManifest = new HashMap<String, String>();
    hostManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    hostManifest.put(Constants.BUNDLE_SYMBOLICNAME, "host");
    hostManifest.put(Constants.BUNDLE_VERSION, "1.0");
    hostManifest.put(Constants.IMPORT_PACKAGE, "exporter");
    installDummyModule(hostManifest, "host10", container);
    hostManifest.put(Constants.BUNDLE_VERSION, "1.1");
    installDummyModule(hostManifest, "host11", container);
    hostManifest.put(Constants.BUNDLE_VERSION, "1.2");
    installDummyModule(hostManifest, "host12", container);
    // install a fragment that also imports the exporter
    Map<String, String> hostFragManifest = new HashMap<String, String>();
    hostFragManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    hostFragManifest.put(Constants.BUNDLE_SYMBOLICNAME, "host.frag");
    hostFragManifest.put(Constants.FRAGMENT_HOST, "host");
    hostFragManifest.put(Constants.IMPORT_PACKAGE, "exporter; version=0.0");
    Module hostFrag = installDummyModule(hostFragManifest, "host.frag", container);
    ResolutionReport report = container.resolve(Arrays.asList(hostFrag), true);
    Assert.assertNull("Failed to resolve test.", report.getResolutionException());
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) 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 54 with ModuleContainer

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

the class TestModuleContainer method testDynamicImport04.

@Test
public void testDynamicImport04() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    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 dynamic3 = installDummyModule("dynamic2_v1.MF", "dynamic2_v1", container);
    container.resolve(Arrays.asList(systemBundle, dynamic3), true);
    ModuleWire dynamicWire = container.resolveDynamic("h1.a", dynamic3.getCurrentRevision());
    Assert.assertNull("Dynamic wire found.", dynamicWire);
    Module h1 = installDummyModule("h1_v1.MF", "h1_v1", container);
    Module f1 = installDummyModule("f1_v1.MF", "f1_v1", container);
    database.getModuleEvents();
    dynamicWire = container.resolveDynamic("h1.a", dynamic3.getCurrentRevision());
    Assert.assertNotNull("Dynamic wire not found.", dynamicWire);
    Assert.assertEquals("Wrong package found.", "h1.a", dynamicWire.getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
    Assert.assertEquals("Wrong provider for the wire found.", h1.getCurrentRevision(), dynamicWire.getProvider());
    dynamicWire = container.resolveDynamic("f1.a", dynamic3.getCurrentRevision());
    Assert.assertNotNull("Dynamic wire not found.", dynamicWire);
    Assert.assertEquals("Wrong package found.", "f1.a", dynamicWire.getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
    Assert.assertEquals("Wrong provider for the wire found.", h1.getCurrentRevision(), dynamicWire.getProvider());
    ModuleWiring h1Wiring = h1.getCurrentRevision().getWiring();
    Assert.assertNotNull("h1 wiring is null.", h1Wiring);
    ModuleWiring f1Wiring = f1.getCurrentRevision().getWiring();
    Assert.assertNotNull("f1 wiring is null.", f1Wiring);
}
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) DummyModuleDatabase(org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase) Test(org.junit.Test)

Example 55 with ModuleContainer

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

the class TestModuleContainer method testDynamicImport08.

@Test
public void testDynamicImport08() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    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 dynamic2 = installDummyModule("dynamic2_v1.MF", "dynamic2_v1", container);
    container.resolve(Arrays.asList(systemBundle, dynamic2), true);
    Module h1 = installDummyModule("h1_v1.MF", "h1_v1", container);
    Module f1 = installDummyModule("f1_v1.MF", "f1_v1", container);
    database.getModuleEvents();
    // make sure h1 is not resolved
    ModuleWiring h1Wiring = h1.getCurrentRevision().getWiring();
    Assert.assertNull("h1 got resolved somehow.", h1Wiring);
    // do not resolve the host first; make sure it gets pulled in while attempting to resolve
    // to a fragment capability.
    ModuleWire dynamicWire = container.resolveDynamic("f1.a", dynamic2.getCurrentRevision());
    Assert.assertNotNull("Dynamic wire not found.", dynamicWire);
    Assert.assertEquals("Wrong package found.", "f1.a", dynamicWire.getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
    Assert.assertEquals("Wrong provider for the wire found.", h1.getCurrentRevision(), dynamicWire.getProvider());
    h1Wiring = h1.getCurrentRevision().getWiring();
    Assert.assertNotNull("h1 wiring is null.", h1Wiring);
    ModuleWiring f1Wiring = f1.getCurrentRevision().getWiring();
    Assert.assertNotNull("f1 wiring is null.", f1Wiring);
}
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) DummyModuleDatabase(org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase) 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