Framework implements FrameworkMBean { public CompositeData installBundles(String[] locations) throws IOException { if(locations == null){ return new BatchInstallResult("Failed to install bundles locations can't be null").toCompositeData(); } long[] ids = new long[locations.length]; for (int i = 0; i < locations.length; i++) { try { long id = installBundle(locations[i]); ids[i] = id; } catch (Throwable t) { long[] completed = new long[i]; System.arraycopy(ids, 0, completed, 0, i); String[] remaining = new String[locations.length - i - 1]; System.arraycopy(locations, i + 1, remaining, 0, remaining.length); return new BatchInstallResult(completed, t.toString(), remaining, locations[i]).toCompositeData(); } } return new BatchInstallResult(ids).toCompositeData(); } Framework(BundleContext context, StartLevel startLevel, PackageAdmin packageAdmin); long[] getDependencyClosure(long[] bundles); int getFrameworkStartLevel(); int getInitialBundleStartLevel(); String getProperty(String key); long[] getRemovalPendingBundles(); long installBundle(String location); long installBundleFromURL(String location, String url); InputStream createStream(String url); CompositeData installBundles(String[] locations); CompositeData installBundlesFromURL(String[] locations, String[] urls); void refreshBundle(long bundleIdentifier); boolean refreshBundleAndWait(long bundleIdentifier); void refreshBundles(long[] bundleIdentifiers); CompositeData refreshBundlesAndWait(long[] bundleIdentifiers); boolean resolveBundle(long bundleIdentifier); boolean resolveBundles(long[] bundleIdentifiers); CompositeData resolve(long[] bundleIdentifiers); void restartFramework(); void setBundleStartLevel(long bundleIdentifier, int newlevel); CompositeData setBundleStartLevels(long[] bundleIdentifiers, int[] newlevels); void setFrameworkStartLevel(int newlevel); void setInitialBundleStartLevel(int newlevel); void shutdownFramework(); void startBundle(long bundleIdentifier); CompositeData startBundles(long[] bundleIdentifiers); void stopBundle(long bundleIdentifier); CompositeData stopBundles(long[] bundleIdentifiers); void uninstallBundle(long bundleIdentifier); CompositeData uninstallBundles(long[] bundleIdentifiers); void updateBundle(long bundleIdentifier); void updateBundleFromURL(long bundleIdentifier, String url); CompositeData updateBundles(long[] bundleIdentifiers); CompositeData updateBundlesFromURL(long[] bundleIdentifiers, String[] urls); void updateFramework();  }
@Test public void testInstallBundles() throws Exception { String[] locations = new String[] { "file:test.jar" }; Bundle bundle = Mockito.mock(Bundle.class); Mockito.when(context.installBundle("file:test.jar")).thenReturn(bundle); Mockito.when(bundle.getBundleId()).thenReturn(Long.valueOf(2)); CompositeData data = mbean.installBundles(locations); BatchInstallResult batch = BatchInstallResult.from(data); Assert.assertNotNull(batch); Assert.assertEquals(2, batch.getCompleted()[0]); Assert.assertTrue(batch.isSuccess()); Assert.assertNull(batch.getError()); Assert.assertNull(batch.getRemainingLocationItems()); Mockito.reset(context); Mockito.when(context.installBundle("file:test.jar")).thenThrow(new BundleException("location doesn't exist")); CompositeData data2 = mbean.installBundles(locations); BatchInstallResult batch2 = BatchInstallResult.from(data2); Assert.assertNotNull(batch2); Assert.assertNotNull(batch2.getCompleted()); Assert.assertEquals(0, batch2.getCompleted().length); Assert.assertFalse(batch2.isSuccess()); Assert.assertNotNull(batch2.getError()); Assert.assertEquals("file:test.jar", batch2.getBundleInError()); Assert.assertNotNull(batch2.getRemainingLocationItems()); Assert.assertEquals(0, batch2.getRemainingLocationItems().length); }