Search in sources :

Example 6 with BundleArchive

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"));
    }
}
Also used : BundleArchive(org.apache.felix.framework.cache.BundleArchive) HashMap(java.util.HashMap) BundleException(org.osgi.framework.BundleException) BundleArchiveRevision(org.apache.felix.framework.cache.BundleArchiveRevision)

Example 7 with BundleArchive

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());
}
Also used : BundleArchive(org.apache.felix.framework.cache.BundleArchive) HashMap(java.util.HashMap) BundleArchiveRevision(org.apache.felix.framework.cache.BundleArchiveRevision)

Aggregations

HashMap (java.util.HashMap)7 BundleArchive (org.apache.felix.framework.cache.BundleArchive)7 BundleArchiveRevision (org.apache.felix.framework.cache.BundleArchiveRevision)5 Bundle (org.osgi.framework.Bundle)5 BundleException (org.osgi.framework.BundleException)5 Collection (java.util.Collection)3 CollisionHook (org.osgi.framework.hooks.bundle.CollisionHook)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 AccessControlException (java.security.AccessControlException)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 WeakHashMap (java.util.WeakHashMap)2 StringMap (org.apache.felix.framework.util.StringMap)2 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)2 ServiceException (org.osgi.framework.ServiceException)2 ResolutionException (org.osgi.service.resolver.ResolutionException)2 ArrayList (java.util.ArrayList)1 BundleCache (org.apache.felix.framework.cache.BundleCache)1