Search in sources :

Example 26 with DummyContainerAdaptor

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

the class TestModuleContainer method testDynamicImport06.

@Test
public void testDynamicImport06() 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 dynamic3 = installDummyModule("dynamic2_v1.MF", "dynamic2_v1", container);
    container.resolve(Arrays.asList(systemBundle, dynamic3), true);
    Module f1 = installDummyModule("f1_v1.MF", "f1_v1", container);
    ModuleWire dynamicWire;
    dynamicWire = container.resolveDynamic("h1.a", dynamic3.getCurrentRevision());
    Assert.assertNull("Dynamic wire found.", dynamicWire);
    dynamicWire = container.resolveDynamic("f1.a", dynamic3.getCurrentRevision());
    Assert.assertNull("Dynamic wire found.", dynamicWire);
    Module h1 = installDummyModule("h1_v1.MF", "h1_v1", container);
    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 host revision 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 host revision 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) Test(org.junit.Test)

Example 27 with DummyContainerAdaptor

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

the class TestModuleContainer method testSettings01.

@Test
public void testSettings01() 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);
    // actually launch the container
    systemBundle.start();
    container.getFrameworkStartLevel().setInitialBundleStartLevel(2);
    Module c4 = installDummyModule("c4_v1.MF", "c4_v1", container);
    Module lazy1 = installDummyModule("lazy1_v1.MF", "lazy1", container);
    container.resolve(Arrays.asList(c4, lazy1), true);
    Assert.assertEquals("Wrong startlevel.", 2, c4.getStartLevel());
    Assert.assertEquals("Wrong startlevel.", 2, lazy1.getStartLevel());
    c4.setStartLevel(3);
    lazy1.setStartLevel(3);
    Assert.assertEquals("Wrong startlevel.", 3, c4.getStartLevel());
    Assert.assertEquals("Wrong startlevel.", 3, lazy1.getStartLevel());
    database.getModuleEvents();
    c4.start();
    lazy1.start(StartOptions.USE_ACTIVATION_POLICY);
    List<DummyModuleEvent> actual = database.getModuleEvents();
    Assert.assertEquals("Did not expect any events.", 0, actual.size());
    database.getContainerEvents();
    container.getFrameworkStartLevel().setStartLevel(3);
    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);
    actual = database.getModuleEvents(3);
    List<DummyModuleEvent> expected = new ArrayList<DummyModuleEvent>(Arrays.asList(new DummyModuleEvent(lazy1, ModuleEvent.LAZY_ACTIVATION, State.LAZY_STARTING), new DummyModuleEvent(c4, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(c4, ModuleEvent.STARTED, State.ACTIVE)));
    assertEvents(expected, actual, true);
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    DataOutputStream data = new DataOutputStream(bytes);
    database.store(data, true);
    systemBundle.stop();
    // reload into a new container
    adaptor = createDummyAdaptor();
    container = adaptor.getContainer();
    database = adaptor.getDatabase();
    database.load(new DataInputStream(new ByteArrayInputStream(bytes.toByteArray())));
    systemBundle = container.getModule(0);
    Assert.assertNotNull("System bundle is null.", systemBundle);
    Assert.assertTrue("System bundle should always use activation policy.", systemBundle.isActivationPolicyUsed());
    Assert.assertTrue("System bundle should always have its auto-start flag set.", systemBundle.isPersistentlyStarted());
    c4 = container.getModule(c4.getId());
    Assert.assertNotNull("c4 is null", c4);
    lazy1 = container.getModule(lazy1.getId());
    Assert.assertNotNull("lazy1 is null", lazy1);
    Assert.assertFalse("c4 has activation policy set.", c4.isActivationPolicyUsed());
    Assert.assertTrue("c4 is not auto started.", c4.isPersistentlyStarted());
    Assert.assertEquals("c4 has wrong start-level", 3, c4.getStartLevel());
    Assert.assertTrue("lazy1 is using activation policy.", lazy1.isActivationPolicyUsed());
    Assert.assertTrue("lazy1 is not auto started.", lazy1.isPersistentlyStarted());
    Assert.assertEquals("lazy1 has wrong start-level", 3, lazy1.getStartLevel());
    // relaunch the container
    systemBundle.start();
    actualContainerEvents = database.getContainerEvents();
    expectedContainerEvents = new ArrayList<DummyContainerEvent>(Arrays.asList(new DummyContainerEvent(ContainerEvent.START_LEVEL, systemBundle, null), new DummyContainerEvent(ContainerEvent.STARTED, systemBundle, null)));
    actual = database.getModuleEvents(2);
    expected = new ArrayList<DummyModuleEvent>(Arrays.asList(new DummyModuleEvent(systemBundle, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(systemBundle, ModuleEvent.STARTED, State.ACTIVE)));
    assertEvents(expected, actual, true);
    container.getFrameworkStartLevel().setStartLevel(3);
    actualContainerEvents = database.getContainerEvents(1);
    expectedContainerEvents = new ArrayList<DummyContainerEvent>(Arrays.asList(new DummyContainerEvent(ContainerEvent.START_LEVEL, systemBundle, null)));
    Assert.assertEquals("Wrong container events.", expectedContainerEvents, actualContainerEvents);
    actual = database.getModuleEvents(3);
    expected = new ArrayList<DummyModuleEvent>(Arrays.asList(new DummyModuleEvent(lazy1, ModuleEvent.LAZY_ACTIVATION, State.LAZY_STARTING), new DummyModuleEvent(c4, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(c4, ModuleEvent.STARTED, State.ACTIVE)));
    assertEvents(expected, actual, true);
}
Also used : ModuleContainer(org.eclipse.osgi.container.ModuleContainer) DataOutputStream(java.io.DataOutputStream) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) 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) ByteArrayInputStream(java.io.ByteArrayInputStream) Module(org.eclipse.osgi.container.Module) DummyModuleEvent(org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase.DummyModuleEvent) Test(org.junit.Test)

Example 28 with DummyContainerAdaptor

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

the class TestModuleContainer method testMultiCardinalityUses.

@Test
public void testMultiCardinalityUses() 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 p5v100 = installDummyModule("p5_v100.MF", "p5_v100", container);
    Module p5v101 = installDummyModule("p5_v101.MF", "p5_v101", container);
    Module p5v110 = installDummyModule("p5_v110.MF", "p5_v110", container);
    Module p5v111 = installDummyModule("p5_v111.MF", "p5_v111", container);
    installDummyModule("p6_v100.MF", "p6_v100", container);
    installDummyModule("p6_v110.MF", "p6_v110", container);
    installDummyModule("p7_v100.MF", "p7_v100", container);
    installDummyModule("p7_v110.MF", "p7_v110", container);
    container.resolve(null, false);
    Module c6v100 = installDummyModule("c6_v100.MF", "c6_v100", container);
    Module c6v110 = installDummyModule("c6_v110.MF", "c6_v110", container);
    Module c6v130 = installDummyModule("c6_v130.MF", "c6_v130", container);
    Module c6v140 = installDummyModule("c6_v140.MF", "c6_v140", container);
    Module c6v150 = installDummyModule("c6_v150.MF", "c6_v150", container);
    Module c6v170 = installDummyModule("c6_v170.MF", "c6_v170", container);
    // Module c6v180 = installDummyModule("c6_v180.MF", "c6_v180", container);
    // Module c6v120 = installDummyModule("c6_v120.MF", "c6_v120", container);
    container.resolve(null, false);
    final String namespace5 = "namespace.5";
    List<ModuleWire> p5v100Provided = p5v100.getCurrentRevision().getWiring().getProvidedModuleWires(namespace5);
    List<ModuleWire> p5v101Provided = p5v101.getCurrentRevision().getWiring().getProvidedModuleWires(namespace5);
    List<ModuleWire> p5v110Provided = p5v110.getCurrentRevision().getWiring().getProvidedModuleWires(namespace5);
    List<ModuleWire> p5v111Provided = p5v111.getCurrentRevision().getWiring().getProvidedModuleWires(namespace5);
    ModuleWiring c6v100Wiring = c6v100.getCurrentRevision().getWiring();
    List<ModuleWire> c6v100Required = c6v100Wiring.getRequiredModuleWires(namespace5);
    Assert.assertEquals("Wrong number of capabilities", 2, c6v100Required.size());
    assertWires(c6v100Required, p5v100Provided, p5v101Provided);
    ModuleWiring c6v110Wiring = c6v110.getCurrentRevision().getWiring();
    List<ModuleWire> c6v110Required = c6v110Wiring.getRequiredModuleWires(namespace5);
    Assert.assertEquals("Wrong number of capabilities", 2, c6v110Required.size());
    assertWires(c6v110Required, p5v100Provided, p5v101Provided);
    ModuleWiring c6v130Wiring = c6v130.getCurrentRevision().getWiring();
    List<ModuleWire> c6v130Required = c6v130Wiring.getRequiredModuleWires(namespace5);
    Assert.assertEquals("Wrong number of capabilities", 2, c6v130Required.size());
    assertWires(c6v130Required, p5v100Provided, p5v101Provided);
    ModuleWiring c6v140Wiring = c6v140.getCurrentRevision().getWiring();
    List<ModuleWire> c6v140Required = c6v140Wiring.getRequiredModuleWires(namespace5);
    Assert.assertEquals("Wrong number of capabilities", 2, c6v140Required.size());
    assertWires(c6v140Required, p5v100Provided, p5v101Provided);
    ModuleWiring c6v150Wiring = c6v150.getCurrentRevision().getWiring();
    List<ModuleWire> c6v150Required = c6v150Wiring.getRequiredModuleWires(namespace5);
    Assert.assertEquals("Wrong number of capabilities", 2, c6v150Required.size());
    assertWires(c6v150Required, p5v110Provided, p5v111Provided);
    ModuleWiring c6v170Wiring = c6v170.getCurrentRevision().getWiring();
    List<ModuleWire> c6v170Required = c6v170Wiring.getRequiredModuleWires(namespace5);
    Assert.assertEquals("Wrong number of capabilities", 2, c6v170Required.size());
    assertWires(c6v170Required, p5v110Provided, p5v111Provided);
    Module c6v160 = installDummyModule("c6_v160.MF", "c6_v160", container);
    container.resolve(null, false);
    Assert.assertNull("Bundle should not be resolved: " + c6v160, c6v160.getCurrentRevision().getWiring());
    container.uninstall(c6v160);
    Module c6v180 = installDummyModule("c6_v180.MF", "c6_v180", container);
    container.resolve(null, false);
    Assert.assertNull("Bundle should not be resolved: " + c6v180, c6v180.getCurrentRevision().getWiring());
    container.uninstall(c6v180);
}
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) Test(org.junit.Test)

Example 29 with DummyContainerAdaptor

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

the class TestModuleContainer method doTestUses5.

public void doTestUses5(String kManifest) 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_k = installDummyModule(kManifest, "k", container);
    Module uses_l = installDummyModule("uses.l.MF", "l", container);
    Module uses_m_conflict1 = installDummyModule("uses.m.conflict1.MF", "m.conflict1", container);
    Module uses_m_conflict2 = installDummyModule("uses.m.conflict2.MF", "m.conflict2", container);
    container.resolve(null, false);
    Assert.assertEquals("k should resolve.", State.RESOLVED, uses_k.getState());
    Assert.assertEquals("l should resolve.", State.RESOLVED, uses_l.getState());
    Assert.assertEquals("m.conflict1 should resolve.", State.RESOLVED, uses_m_conflict1.getState());
    Assert.assertEquals("m.conflict2 should resolve.", State.RESOLVED, uses_m_conflict2.getState());
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) Module(org.eclipse.osgi.container.Module)

Example 30 with DummyContainerAdaptor

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

the class TestModuleContainer method testDynamicImport07.

@Test
public void testDynamicImport07() 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 dynamic3 = installDummyModule("dynamic2_v1.MF", "dynamic2_v1", container);
    Assert.assertNull("Expected no resolution exception.", container.resolve(Arrays.asList(systemBundle, dynamic3), true).getResolutionException());
    installDummyModule("c6_v1.MF", "c6_v1", container);
    ModuleWire dynamicWire = container.resolveDynamic("c6", dynamic3.getCurrentRevision());
    Assert.assertNull("Dynamic wire found.", dynamicWire);
}
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