Search in sources :

Example 91 with ModuleContainer

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

the class TestModuleContainer method testSingleton02.

@Test
public void testSingleton02() throws BundleException, IOException {
    ResolverHookFactory resolverHookFactory = new ResolverHookFactory() {

        @Override
        public ResolverHook begin(Collection<BundleRevision> triggers) {
            return new ResolverHook() {

                @Override
                public void filterSingletonCollisions(BundleCapability singleton, Collection<BundleCapability> collisionCandidates) {
                    collisionCandidates.clear();
                }

                @Override
                public void filterResolvable(Collection<BundleRevision> candidates) {
                // nothing
                }

                @Override
                public void filterMatches(BundleRequirement requirement, Collection<BundleCapability> candidates) {
                // nothing
                }

                @Override
                public void end() {
                // nothing
                }
            };
        }
    };
    DummyContainerAdaptor adaptor = new DummyContainerAdaptor(new DummyCollisionHook(false), Collections.<String, String>emptyMap(), resolverHookFactory);
    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.assertTrue("Singleton v1 is not resolved.", Module.RESOLVED_SET.contains(s1.getState()));
    Assert.assertTrue("Singleton v2 is not resolved.", Module.RESOLVED_SET.contains(s2.getState()));
    Assert.assertTrue("Singleton v3 is not resolved.", Module.RESOLVED_SET.contains(s3.getState()));
}
Also used : ResolverHookFactory(org.osgi.framework.hooks.resolver.ResolverHookFactory) DummyResolverHookFactory(org.eclipse.osgi.tests.container.dummys.DummyResolverHookFactory) DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) DummyResolverHook(org.eclipse.osgi.tests.container.dummys.DummyResolverHook) ResolverHook(org.osgi.framework.hooks.resolver.ResolverHook) DummyCollisionHook(org.eclipse.osgi.tests.container.dummys.DummyCollisionHook) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) Collection(java.util.Collection) BundleCapability(org.osgi.framework.wiring.BundleCapability) Module(org.eclipse.osgi.container.Module) BundleRequirement(org.osgi.framework.wiring.BundleRequirement) Test(org.junit.Test)

Example 92 with ModuleContainer

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

the class TestModuleContainer method testStoreInvalidAttributes.

@Test
public void testStoreInvalidAttributes() 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);
    Integer testInt = Integer.valueOf(1);
    List<Integer> testIntList = Collections.singletonList(testInt);
    ModuleRevisionBuilder builder = new ModuleRevisionBuilder();
    builder.setSymbolicName("invalid.attr");
    builder.setVersion(Version.valueOf("1.0.0"));
    builder.addCapability("test", Collections.<String, String>emptyMap(), Collections.singletonMap("test", (Object) testInt));
    builder.addCapability("test.list", Collections.<String, String>emptyMap(), Collections.singletonMap("test.list", (Object) testIntList));
    Module invalid = container.install(null, builder.getSymbolicName(), builder, null);
    Object testAttr = invalid.getCurrentRevision().getCapabilities("test").get(0).getAttributes().get("test");
    assertEquals("Wrong test attr", testInt, testAttr);
    Object testAttrList = invalid.getCurrentRevision().getCapabilities("test.list").get(0).getAttributes().get("test.list");
    assertEquals("Wrong test list attr", testIntList, testAttrList);
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    DataOutputStream data = new DataOutputStream(bytes);
    adaptor.getDatabase().store(data, true);
    List<DummyContainerEvent> events = adaptor.getDatabase().getContainerEvents();
    // make sure we see the errors
    assertEquals("Wrong number of events.", 2, events.size());
    for (DummyContainerEvent event : events) {
        assertEquals("Wrong type of event.", ContainerEvent.ERROR, event.type);
        assertTrue("Wrong type of exception.", event.error instanceof BundleException);
    }
    // reload into a new container
    adaptor = createDummyAdaptor();
    container = adaptor.getContainer();
    adaptor.getDatabase().load(new DataInputStream(new ByteArrayInputStream(bytes.toByteArray())));
    invalid = container.getModule("invalid.attr");
    assertNotNull("Could not find module.", invalid);
    String testIntString = String.valueOf(testInt);
    List<String> testIntStringList = Collections.singletonList(testIntString);
    testAttr = invalid.getCurrentRevision().getCapabilities("test").get(0).getAttributes().get("test");
    assertEquals("Wrong test attr", testIntString, testAttr);
    testAttrList = invalid.getCurrentRevision().getCapabilities("test.list").get(0).getAttributes().get("test.list");
    assertEquals("Wrong test list attr", testIntStringList, testAttrList);
}
Also used : ModuleContainer(org.eclipse.osgi.container.ModuleContainer) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) DummyContainerEvent(org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase.DummyContainerEvent) DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ByteArrayInputStream(java.io.ByteArrayInputStream) ModuleRevisionBuilder(org.eclipse.osgi.container.ModuleRevisionBuilder) BundleException(org.osgi.framework.BundleException) Module(org.eclipse.osgi.container.Module) Test(org.junit.Test)

Example 93 with ModuleContainer

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

the class TestModuleContainer method testSimpleResolve.

@Test
public void testSimpleResolve() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    Module systemBundle = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, container);
    ModuleRevision systemRevision = systemBundle.getCurrentRevision();
    container.resolve(Arrays.asList(systemBundle), true);
    ModuleWiring systemWiring = systemRevision.getWiring();
    Assert.assertNotNull("system wiring is null", systemWiring);
    Module b1 = installDummyModule("b1_v1.MF", "b1", container);
    ModuleRevision b1Revision = b1.getCurrentRevision();
    container.resolve(Arrays.asList(b1), true);
    ModuleWiring b1Wiring = b1Revision.getWiring();
    Assert.assertNotNull("b1 wiring is null", b1Wiring);
}
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) ModuleRevision(org.eclipse.osgi.container.ModuleRevision) Test(org.junit.Test)

Example 94 with ModuleContainer

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

the class TestModuleContainer method testEventsResolved.

@Test
public void testEventsResolved() 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 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);
    // throw away installed events
    database.getModuleEvents();
    container.resolve(Arrays.asList(c1, c2, c3, c4, c5, c6, c7), true);
    List<DummyModuleEvent> actual = database.getModuleEvents();
    List<DummyModuleEvent> expected = new ArrayList<DummyModuleEvent>(Arrays.asList(new DummyModuleEvent(c1, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(c2, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(c3, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(c4, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(c5, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(c6, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(c7, ModuleEvent.RESOLVED, State.RESOLVED)));
    assertEvents(expected, actual, false);
}
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) DummyModuleDatabase(org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase) Test(org.junit.Test)

Example 95 with ModuleContainer

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

the class TestModuleContainer method testUses2.

/*
	 * Test that split packages are handled ok with uses constraints
	 */
@Test
public void testUses2() 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_a = installDummyModule("uses.a.MF", "a", container);
    Module uses_b = installDummyModule("uses.b.MF", "b", container);
    Module uses_d = installDummyModule("uses.d.MF", "d", container);
    container.resolve(null, false);
    Assert.assertEquals("a should resolve.", State.RESOLVED, uses_a.getState());
    Assert.assertEquals("b should resolve.", State.RESOLVED, uses_b.getState());
    Assert.assertEquals("d should resolve.", State.RESOLVED, uses_d.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)

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