Search in sources :

Example 21 with DummyContainerAdaptor

use of org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor in project rt.equinox.framework by eclipse.

the class TestModuleContainer method testDynamicImportMiss01.

@Test
public void testDynamicImportMiss01() 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);
    DummyResolverHookFactory factory = (DummyResolverHookFactory) adaptor.getResolverHookFactory();
    DummyResolverHook hook = (DummyResolverHook) factory.getHook();
    hook.getResolutionReports().clear();
    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());
    Assert.assertEquals("Wrong number of reports.", 1, hook.getResolutionReports().size());
    hook.getResolutionReports().clear();
    dynamicWire = container.resolveDynamic("does.not.exist", dynamic1.getCurrentRevision());
    Assert.assertNull("Unexpected Dynamic wire found.", dynamicWire);
    Assert.assertEquals("Wrong number of reports.", 1, hook.getResolutionReports().size());
    // Try again; no report should be generated a second time
    hook.getResolutionReports().clear();
    dynamicWire = container.resolveDynamic("does.not.exist", dynamic1.getCurrentRevision());
    Assert.assertNull("Unexpected Dynamic wire found.", dynamicWire);
    Assert.assertEquals("Wrong number of reports.", 0, hook.getResolutionReports().size());
}
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) DummyResolverHookFactory(org.eclipse.osgi.tests.container.dummys.DummyResolverHookFactory) DummyResolverHook(org.eclipse.osgi.tests.container.dummys.DummyResolverHook) Test(org.junit.Test)

Example 22 with DummyContainerAdaptor

use of org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor in project rt.equinox.framework by eclipse.

the class TestModuleContainer method testMultiHost.

@Test
public void testMultiHost() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, container);
    Module h1v1 = installDummyModule("h1_v1.MF", "h1_v1", container);
    Module h1v2 = installDummyModule("h1_v2.MF", "h1_v2", 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(h1v1, h1v2, f1v1, b3), true);
    Assert.assertNull("Expected no resolution exception.", report.getResolutionException());
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) Module(org.eclipse.osgi.container.Module) ResolutionReport(org.eclipse.osgi.report.resolution.ResolutionReport) Test(org.junit.Test)

Example 23 with DummyContainerAdaptor

use of org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor in project rt.equinox.framework by eclipse.

the class TestModuleContainer method testInstallCollision01.

@Test
public void testInstallCollision01() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, container);
    installDummyModule("b1_v1.MF", "b1_a", container);
    try {
        installDummyModule("b1_v1.MF", "b1_b", container);
        Assert.fail("Expected to fail installation because of a collision.");
    } catch (BundleException e) {
        // expected
        Assert.assertEquals("Wrong exception type.", BundleException.DUPLICATE_BUNDLE_ERROR, e.getType());
    }
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) BundleException(org.osgi.framework.BundleException) Test(org.junit.Test)

Example 24 with DummyContainerAdaptor

use of org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor in project rt.equinox.framework by eclipse.

the class TestModuleContainer method testDynamicWithExport.

@Test
public void testDynamicWithExport() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    // install the system.bundle
    Module systemBundle = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, Constants.SYSTEM_BUNDLE_SYMBOLICNAME, null, null, container);
    ResolutionReport report = container.resolve(Arrays.asList(systemBundle), true);
    Assert.assertNull("Failed to resolve system.bundle.", report.getResolutionException());
    // install an importer
    Map<String, String> optionalImporterManifest = new HashMap<String, String>();
    optionalImporterManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    optionalImporterManifest.put(Constants.BUNDLE_SYMBOLICNAME, "importer");
    optionalImporterManifest.put(Constants.EXPORT_PACKAGE, "exporter");
    optionalImporterManifest.put(Constants.DYNAMICIMPORT_PACKAGE, "exporter");
    Module optionalImporterModule = installDummyModule(optionalImporterManifest, "optionalImporter", container);
    // unsatisfied optional and dynamic imports do not fail a resolve.
    report = container.resolve(Arrays.asList(optionalImporterModule), true);
    Assert.assertNull("Failed to resolve system.bundle.", report.getResolutionException());
    // dynamic and optional imports are same. Optional import is not satisfied we should only see the dynamic import
    List<BundleRequirement> importReqsList = optionalImporterModule.getCurrentRevision().getWiring().getRequirements(PackageNamespace.PACKAGE_NAMESPACE);
    assertEquals("Wrong number of imports.", 1, importReqsList.size());
    assertEquals("Import was not dynamic", PackageNamespace.RESOLUTION_DYNAMIC, importReqsList.get(0).getDirectives().get(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE));
    ModuleWire dynamicWire = container.resolveDynamic("exporter", optionalImporterModule.getCurrentRevision());
    Assert.assertNull("Expected no dynamic wire.", dynamicWire);
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) 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) BundleRequirement(org.osgi.framework.wiring.BundleRequirement) Test(org.junit.Test)

Example 25 with DummyContainerAdaptor

use of org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor in project rt.equinox.framework by eclipse.

the class TestModuleContainer method testUpdateCollision01.

@Test
public void testUpdateCollision01() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    Module b1_v1 = installDummyModule("b1_v1.MF", "b1_v1", container);
    installDummyModule("b1_v2.MF", "b1_v2", container);
    try {
        container.update(b1_v1, OSGiManifestBuilderFactory.createBuilder(getManifest("b1_v2.MF")), null);
        Assert.fail("Expected to fail update because of a collision.");
    } catch (BundleException e) {
        // expected
        Assert.assertEquals("Wrong exception type.", BundleException.DUPLICATE_BUNDLE_ERROR, e.getType());
    }
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) BundleException(org.osgi.framework.BundleException) Module(org.eclipse.osgi.container.Module) Test(org.junit.Test)

Aggregations

DummyContainerAdaptor (org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor)85 ModuleContainer (org.eclipse.osgi.container.ModuleContainer)80 Module (org.eclipse.osgi.container.Module)79 Test (org.junit.Test)73 ModuleWire (org.eclipse.osgi.container.ModuleWire)25 ResolutionReport (org.eclipse.osgi.report.resolution.ResolutionReport)23 ModuleWiring (org.eclipse.osgi.container.ModuleWiring)20 HashMap (java.util.HashMap)18 ArrayList (java.util.ArrayList)15 DummyModuleDatabase (org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 DummyModuleEvent (org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase.DummyModuleEvent)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 DataInputStream (java.io.DataInputStream)8 DataOutputStream (java.io.DataOutputStream)8 ModuleRevision (org.eclipse.osgi.container.ModuleRevision)8 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