Search in sources :

Example 71 with DummyContainerAdaptor

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

the class TestModuleContainer method testResolveAlreadyResolvedBundles.

// Disabled @Test
public void testResolveAlreadyResolvedBundles() throws BundleException, IOException {
    setupModuleDatabase();
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    resolvedModuleDatabase.store(new DataOutputStream(bytes), true);
    bytes.close();
    adaptor.getDatabase().load(new DataInputStream(new ByteArrayInputStream(bytes.toByteArray())));
    adaptor.getContainer().resolve(new ArrayList<Module>(), false);
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) Module(org.eclipse.osgi.container.Module)

Example 72 with DummyContainerAdaptor

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

the class TestModuleContainer method testRemovalPending.

@Test
public void testRemovalPending() 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 c4 = installDummyModule("c4_v1.MF", "c4_v1", container);
    Module c6 = installDummyModule("c6_v1.MF", "c6_v1", container);
    Module c7 = installDummyModule("c7_v1.MF", "c7_v1", container);
    container.resolve(Arrays.asList(c7), true);
    // throw out installed and resolved events
    database.getModuleEvents();
    ModuleRevision c4Revision0 = c4.getCurrentRevision();
    // updating to identical content
    container.update(c4, OSGiManifestBuilderFactory.createBuilder(getManifest("c4_v1.MF")), null);
    container.resolve(Arrays.asList(c4), true);
    Collection<ModuleRevision> removalPending = container.getRemovalPending();
    Assert.assertEquals("Wrong number of removal pending", 1, removalPending.size());
    Assert.assertTrue("Wrong module removalPending: " + removalPending, removalPending.contains(c4Revision0));
    ModuleRevision c6Revision0 = c6.getCurrentRevision();
    // updating to identical content
    container.update(c6, OSGiManifestBuilderFactory.createBuilder(getManifest("c6_v1.MF")), null);
    container.resolve(Arrays.asList(c6), true);
    removalPending = container.getRemovalPending();
    Assert.assertEquals("Wrong number of removal pending", 2, removalPending.size());
    Assert.assertTrue("Wrong module removalPending: " + removalPending, removalPending.containsAll(Arrays.asList(c4Revision0, c6Revision0)));
    // update again with identical content
    container.update(c4, OSGiManifestBuilderFactory.createBuilder(getManifest("c4_v1.MF")), null);
    container.update(c6, OSGiManifestBuilderFactory.createBuilder(getManifest("c6_v1.MF")), null);
    container.resolve(Arrays.asList(c4, c6), true);
    // Again we only have two since the previous current revisions did not have any dependents
    removalPending = container.getRemovalPending();
    Assert.assertEquals("Wrong number of removal pending", 2, removalPending.size());
    Assert.assertTrue("Wrong module removalPending: " + removalPending, removalPending.containsAll(Arrays.asList(c4Revision0, c6Revision0)));
    container.refresh(null);
    removalPending = container.getRemovalPending();
    Assert.assertEquals("Wrong number of removal pending", 0, removalPending.size());
    List<DummyModuleEvent> actual = database.getModuleEvents();
    List<DummyModuleEvent> expected = new ArrayList<DummyModuleEvent>(Arrays.asList(new DummyModuleEvent(c4, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(c4, ModuleEvent.UPDATED, State.INSTALLED), new DummyModuleEvent(c4, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(c6, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(c6, ModuleEvent.UPDATED, State.INSTALLED), new DummyModuleEvent(c6, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(c4, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(c4, ModuleEvent.UPDATED, State.INSTALLED), new DummyModuleEvent(c6, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(c6, ModuleEvent.UPDATED, State.INSTALLED), new DummyModuleEvent(c4, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(c6, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(c4, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(c6, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(c7, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(c4, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(c6, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(c7, ModuleEvent.RESOLVED, State.RESOLVED)));
    assertEvents(expected, actual, false);
    // uninstall c4
    c4Revision0 = c4.getCurrentRevision();
    container.uninstall(c4);
    removalPending = container.getRemovalPending();
    Assert.assertEquals("Wrong number of removal pending", 1, removalPending.size());
    Assert.assertTrue("Wrong module removalPending: " + removalPending, removalPending.containsAll(Arrays.asList(c4Revision0)));
    container.refresh(null);
    actual = database.getModuleEvents();
    expected = new ArrayList<DummyModuleEvent>(Arrays.asList(new DummyModuleEvent(c4, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(c4, ModuleEvent.UNINSTALLED, State.UNINSTALLED), new DummyModuleEvent(c6, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(c7, ModuleEvent.UNRESOLVED, State.INSTALLED)));
    assertEvents(expected, actual, false);
    // Test bug 411833
    // install c4 again and resolve c6
    c4 = installDummyModule("c4_v1.MF", "c4_v1", container);
    container.resolve(Arrays.asList(c6), true);
    // throw out installed and resolved events
    database.getModuleEvents();
    removalPending = container.getRemovalPending();
    Assert.assertEquals("Wrong number of removal pending", 0, removalPending.size());
    c4Revision0 = c4.getCurrentRevision();
    // uninstall c4, but refresh c6 instead
    // this should result in removal pending c4 to be removed.
    container.uninstall(c4);
    removalPending = container.getRemovalPending();
    Assert.assertEquals("Wrong number of removal pending", 1, removalPending.size());
    Assert.assertTrue("Wrong module removalPending: " + removalPending, removalPending.containsAll(Arrays.asList(c4Revision0)));
    container.refresh(Collections.singletonList(c6));
    actual = database.getModuleEvents();
    expected = new ArrayList<DummyModuleEvent>(Arrays.asList(new DummyModuleEvent(c4, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(c4, ModuleEvent.UNINSTALLED, State.UNINSTALLED), new DummyModuleEvent(c6, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(c7, ModuleEvent.UNRESOLVED, State.INSTALLED)));
    assertEvents(expected, actual, false);
    removalPending = container.getRemovalPending();
    Assert.assertEquals("Wrong number of removal pending", 0, removalPending.size());
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) ArrayList(java.util.ArrayList) Module(org.eclipse.osgi.container.Module) DummyModuleEvent(org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase.DummyModuleEvent) ModuleRevision(org.eclipse.osgi.container.ModuleRevision) DummyModuleDatabase(org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase) Test(org.junit.Test)

Example 73 with DummyContainerAdaptor

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

the class TestModuleContainer method testDynamicImport03.

@Test
public void testDynamicImport03() 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("c1.a", dynamic3.getCurrentRevision());
    Assert.assertNull("Dynamic wire found.", dynamicWire);
    Module c1v1 = installDummyModule("c1_v1.MF", "c1_v1", container);
    database.getModuleEvents();
    dynamicWire = container.resolveDynamic("c1.a", dynamic3.getCurrentRevision());
    Assert.assertNotNull("Dynamic wire not found.", dynamicWire);
    Assert.assertEquals("Wrong package found.", "c1.a", dynamicWire.getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
    Assert.assertEquals("Wrong provider for the wire found.", c1v1.getCurrentRevision(), dynamicWire.getProvider());
    ModuleWiring c1v1Wiring = c1v1.getCurrentRevision().getWiring();
    Assert.assertNotNull("c1 wiring is null.", c1v1Wiring);
    Module c1v2 = installDummyModule("c1_v2.MF", "c1_v2", container);
    container.resolve(Arrays.asList(c1v2), true);
    database.getModuleEvents();
    dynamicWire = container.resolveDynamic("c1.b", dynamic3.getCurrentRevision());
    Assert.assertNotNull("Dynamic wire not found.", dynamicWire);
    Assert.assertEquals("Wrong package found.", "c1.b", dynamicWire.getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
    Assert.assertEquals("Wrong provider.", c1v1.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) 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 74 with DummyContainerAdaptor

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

the class TestModuleContainer method testPersistence.

@Test
public void testPersistence() throws BundleException, IOException {
    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);
    Map<String, Object> attrs = new HashMap<String, Object>();
    attrs.put("string", "sValue");
    attrs.put("string.list1", Arrays.asList("v1", "v2", "v3"));
    attrs.put("string.list2", Arrays.asList("v4", "v5", "v6"));
    attrs.put("version", Version.valueOf("1.1"));
    attrs.put("version.list", Arrays.asList(Version.valueOf("1.0"), Version.valueOf("2.0"), Version.valueOf("3.0")));
    attrs.put("long", Long.valueOf(12345));
    attrs.put("long.list", Arrays.asList(Long.valueOf(1), Long.valueOf(2), Long.valueOf(3)));
    attrs.put("double", Double.valueOf(1.2345));
    attrs.put("double.list", Arrays.asList(Double.valueOf(1.1), Double.valueOf(1.2), Double.valueOf(1.3)));
    attrs.put("uri", "some.uri");
    attrs.put("set", Arrays.asList("s1", "s2", "s3"));
    // provider with all supported types
    Map<String, String> providerManifest = new HashMap<String, String>();
    providerManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    providerManifest.put(Constants.BUNDLE_SYMBOLICNAME, "provider");
    providerManifest.put(Constants.EXPORT_PACKAGE, "provider; version=1.1; attr1=attr1; attr2=attr2; dir1:=dir1; dir2:=dir2");
    providerManifest.put(Constants.PROVIDE_CAPABILITY, // 
    "provider.cap;" + // 
    " string=sValue;" + // 
    " string.list1:List=\"v1,v2,v3\";" + // 
    " string.list2:List<String>=\"v4,v5,v6\";" + // 
    " version:Version=1.1;" + // 
    " version.list:List<Version>=\"1.0,2.0,3.0\";" + // 
    " long:Long=12345;" + // 
    " long.list:List<Long>=\"1,2,3\";" + // 
    " double:Double=1.2345;" + // 
    " double.list:List<Double>=\"1.1,1.2,1.3\";" + // 
    " uri:uri=some.uri;" + " set:set=\"s1,s2,s3\"");
    Module providerModule = installDummyModule(providerManifest, "provider", container);
    Map<String, Object> providerAttrs = providerModule.getCurrentRevision().getCapabilities("provider.cap").get(0).getAttributes();
    assertEquals("Wrong provider attrs", attrs, providerAttrs);
    Map<String, String> requirerManifest = new HashMap<String, String>();
    requirerManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    requirerManifest.put(Constants.BUNDLE_SYMBOLICNAME, "requirer");
    requirerManifest.put(Constants.IMPORT_PACKAGE, "provider; version=1.1; attr1=attr1; attr2=attr2; dir1:=dir1; dir2:=dir2");
    requirerManifest.put(Constants.REQUIRE_CAPABILITY, // 
    "optional;" + // 
    " resolution:=optional; " + // 
    " string=sValue;" + // 
    " string.list1:List=\"v1,v2,v3\";" + // 
    " string.list2:List<String>=\"v4,v5,v6\";" + // 
    " version:Version=1.1;" + // 
    " version.list:List<Version>=\"1.0,2.0,3.0\";" + // 
    " long:Long=12345;" + // 
    " long.list:List<Long>=\"1,2,3\";" + // 
    " double:Double=1.2345;" + // 
    " double.list:List<Double>=\"1.1,1.2,1.3\";" + // 
    " uri:uri=some.uri;" + // 
    " set:set=\"s1,s2,s3\"," + // 
    "provider.cap; filter:=\"(string=sValue)\"," + // 
    "provider.cap; filter:=\"(string.list1=v2)\"," + // 
    "provider.cap; filter:=\"(string.list2=v5)\"," + // 
    "provider.cap; filter:=\"(string.list2=v5)\"," + // 
    "provider.cap; filter:=\"(&(version>=1.1)(version<=1.1.1))\"," + // 
    "provider.cap; filter:=\"(&(version.list=1)(version.list=2))\"," + // 
    "provider.cap; filter:=\"(long>=12344)\"," + // 
    "provider.cap; filter:=\"(long.list=2)\"," + // 
    "provider.cap; filter:=\"(double>=1.2)\"," + // 
    "provider.cap; filter:=\"(double.list=1.2)\"," + // 
    "provider.cap; filter:=\"(uri=some.uri)\"," + // 
    "provider.cap; filter:=\"(set=s2)\"" + "");
    Module requirerModule = installDummyModule(requirerManifest, "requirer", container);
    Map<String, Object> requirerAttrs = requirerModule.getCurrentRevision().getRequirements("optional").get(0).getAttributes();
    assertEquals("Wrong requirer attrs", attrs, requirerAttrs);
    ResolutionReport report = container.resolve(Collections.singleton(requirerModule), true);
    assertNull("Error resolving.", report.getResolutionException());
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    DataOutputStream data = new DataOutputStream(bytes);
    adaptor.getDatabase().store(data, true);
    // reload into a new container
    adaptor = createDummyAdaptor();
    container = adaptor.getContainer();
    adaptor.getDatabase().load(new DataInputStream(new ByteArrayInputStream(bytes.toByteArray())));
    providerModule = container.getModule("provider");
    providerAttrs = providerModule.getCurrentRevision().getCapabilities("provider.cap").get(0).getAttributes();
    assertEquals("Wrong provider attrs", attrs, providerAttrs);
    assertNotNull("No provider found.", providerModule);
    requirerModule = container.getModule("requirer");
    assertNotNull("No requirer found.", requirerModule);
    requirerAttrs = requirerModule.getCurrentRevision().getRequirements("optional").get(0).getAttributes();
    assertEquals("Wrong requirer attrs", attrs, requirerAttrs);
}
Also used : ModuleContainer(org.eclipse.osgi.container.ModuleContainer) HashMap(java.util.HashMap) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ResolutionReport(org.eclipse.osgi.report.resolution.ResolutionReport) DataInputStream(java.io.DataInputStream) DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ByteArrayInputStream(java.io.ByteArrayInputStream) Module(org.eclipse.osgi.container.Module) Test(org.junit.Test)

Example 75 with DummyContainerAdaptor

use of org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor 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)

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