use of org.apache.felix.framework.cache.BundleArchive in project felix by apache.
the class CollisionHookTest method testNoCollisionHook.
public void testNoCollisionHook() throws Exception {
BundleImpl identicalBundle = mockBundleImpl(1L, "foo", "1.2.1.a");
BundleImpl differentBundle = mockBundleImpl(2L, "bar", "1.2.1.a");
// Mock the framework
StatefulResolver mockResolver = Mockito.mock(StatefulResolver.class);
Felix felixMock = Mockito.mock(Felix.class);
HookRegistry hReg = Mockito.mock(HookRegistry.class);
Mockito.when(felixMock.getHookRegistry()).thenReturn(hReg);
Mockito.when(felixMock.getResolver()).thenReturn(mockResolver);
Mockito.when(felixMock.getBundles()).thenReturn(new Bundle[] { differentBundle, identicalBundle });
// Mock the archive of the bundle being installed
Map<String, Object> headerMap = new HashMap<String, Object>();
headerMap.put(Constants.BUNDLE_SYMBOLICNAME, "foo");
headerMap.put(Constants.BUNDLE_VERSION, "1.2.1.a");
headerMap.put(Constants.BUNDLE_MANIFESTVERSION, "2");
BundleArchiveRevision archiveRevision = Mockito.mock(BundleArchiveRevision.class);
Mockito.when(archiveRevision.getManifestHeader()).thenReturn(headerMap);
BundleArchive archive = Mockito.mock(BundleArchive.class);
Mockito.when(archive.getCurrentRevision()).thenReturn(archiveRevision);
Mockito.when(archive.getId()).thenReturn(3L);
try {
new BundleImpl(felixMock, null, archive);
fail("Should have thrown a BundleException because the installed bundle is not unique");
} catch (BundleException be) {
// good
assertTrue(be.getMessage().contains("not unique"));
}
}
use of org.apache.felix.framework.cache.BundleArchive in project felix by apache.
the class CollisionHookTest method testAllowMultiple.
public void testAllowMultiple() throws Exception {
BundleImpl identicalBundle = mockBundleImpl(1L, "foo", "1.2.1.a");
BundleImpl differentBundle = mockBundleImpl(2L, "bar", "1.2.1.a");
Map<String, Object> config = new HashMap<String, Object>();
config.put(Constants.FRAMEWORK_BSNVERSION, Constants.FRAMEWORK_BSNVERSION_MULTIPLE);
// Mock the framework
StatefulResolver mockResolver = Mockito.mock(StatefulResolver.class);
Felix felixMock = Mockito.mock(Felix.class);
Mockito.when(felixMock.getConfig()).thenReturn(config);
Mockito.when(felixMock.getResolver()).thenReturn(mockResolver);
Mockito.when(felixMock.getBundles()).thenReturn(new Bundle[] { differentBundle, identicalBundle });
// Mock the archive of the bundle being installed
Map<String, Object> headerMap = new HashMap<String, Object>();
headerMap.put(Constants.BUNDLE_SYMBOLICNAME, "foo");
headerMap.put(Constants.BUNDLE_VERSION, "1.2.1.a");
headerMap.put(Constants.BUNDLE_MANIFESTVERSION, "2");
BundleArchiveRevision archiveRevision = Mockito.mock(BundleArchiveRevision.class);
Mockito.when(archiveRevision.getManifestHeader()).thenReturn(headerMap);
BundleArchive archive = Mockito.mock(BundleArchive.class);
Mockito.when(archive.getCurrentRevision()).thenReturn(archiveRevision);
Mockito.when(archive.getId()).thenReturn(3L);
BundleImpl bi = new BundleImpl(felixMock, null, archive);
assertEquals(3L, bi.getBundleId());
}
Aggregations