Framework implements FrameworkMBean { public CompositeData updateBundles(long[] bundleIdentifiers) throws IOException { if (bundleIdentifiers == null) { return new BatchActionResult("Failed to update bundles, bundle id's can't be null").toCompositeData(); } for (int i = 0; i < bundleIdentifiers.length; i++) { try { updateBundle(bundleIdentifiers[i]); } catch (Throwable t) { return createFailedBatchActionResult(bundleIdentifiers, i, t); } } return new BatchActionResult(bundleIdentifiers).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 testUpdateBundles() throws Exception { Bundle bundle = Mockito.mock(Bundle.class); Mockito.when(context.getBundle(5)).thenReturn(bundle); CompositeData data = mbean.updateBundles(new long[] { 5 }); Mockito.verify(bundle).update(); BatchActionResult batch = BatchActionResult.from(data); Assert.assertEquals(5, batch.getCompleted()[0]); Assert.assertTrue(batch.isSuccess()); Assert.assertNull(batch.getError()); Assert.assertNull(batch.getRemainingItems()); CompositeData data2 = mbean.updateBundles(null); BatchActionResult batch2 = BatchActionResult.from(data2); Assert.assertNull(batch2.getCompleted()); Assert.assertFalse(batch2.isSuccess()); Assert.assertNotNull(batch2.getError()); Assert.assertNull(batch2.getRemainingItems()); Mockito.reset(bundle); CompositeData data3 = mbean.updateBundles(new long[] { 6 }); Mockito.when(context.getBundle(6)).thenReturn(bundle); Mockito.doThrow(new BundleException("")).when(bundle).update(); BatchActionResult batch3 = BatchActionResult.from(data3); Assert.assertEquals(0, batch3.getCompleted().length); Assert.assertFalse(batch3.isSuccess()); Assert.assertNotNull(batch3.getError()); Assert.assertEquals(6, batch3.getBundleInError()); Bundle bundle6 = Mockito.mock(Bundle.class); Bundle bundle8 = Mockito.mock(Bundle.class); Bundle bundle7 = Mockito.mock(Bundle.class); Mockito.when(context.getBundle(6)).thenReturn(bundle6); Mockito.when(context.getBundle(8)).thenReturn(bundle8); Mockito.when(context.getBundle(7)).thenReturn(bundle7); Mockito.doThrow(new BundleException("")).when(bundle8).update(); CompositeData data4 = mbean.updateBundles(new long[] { 6, 8, 7 }); BatchActionResult batch4 = BatchActionResult.from(data4); Mockito.verify(bundle6).update(); Assert.assertEquals(1, batch4.getCompleted().length); Assert.assertEquals(6, batch4.getCompleted()[0]); Assert.assertFalse(batch4.isSuccess()); Assert.assertNotNull(batch4.getError()); Assert.assertEquals(8, batch4.getBundleInError()); Assert.assertEquals(1, batch4.getRemainingItems().length); Assert.assertEquals(7, batch4.getRemainingItems()[0]); }