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()));
}
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);
}
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);
}
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);
}
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());
}
Aggregations