Examples of BatchActionResult


Examples of org.apache.aries.jmx.codec.BatchActionResult

    /**
     * @see org.osgi.jmx.framework.FrameworkMBean#uninstallBundles(long[])
     */
    public CompositeData uninstallBundles(long[] bundleIdentifiers) throws IOException {
        if(bundleIdentifiers == null){
            return new BatchActionResult("Failed uninstall bundles, bundle id's can't be null").toCompositeData();
         }
        for (int i = 0; i < bundleIdentifiers.length; i++) {
            try {
                uninstallBundle(bundleIdentifiers[i]);
            } catch (Throwable t) {
                return createFailedBatchActionResult(bundleIdentifiers, i, t);
            }
        }
        return new BatchActionResult(bundleIdentifiers).toCompositeData();
    }
View Full Code Here

Examples of org.apache.aries.jmx.codec.BatchActionResult

    /**
     * @see org.osgi.jmx.framework.FrameworkMBean#updateBundles(long[])
     */
    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();
    }
View Full Code Here

Examples of org.apache.aries.jmx.codec.BatchActionResult

    /**
     * @see org.osgi.jmx.framework.FrameworkMBean#updateBundlesFromURL(long[], String[])
     */
    public CompositeData updateBundlesFromURL(long[] bundleIdentifiers, String[] urls) throws IOException {
        if(bundleIdentifiers == null || urls == null){
            return new BatchActionResult("Failed to update bundles arguments can't be null").toCompositeData();
        }
       
        if(bundleIdentifiers != null && urls != null && bundleIdentifiers.length != urls.length){
            return new BatchActionResult("Failed to update bundles size of arguments should be same").toCompositeData();
        }
        for (int i = 0; i < bundleIdentifiers.length; i++) {
            try {
                updateBundleFromURL(bundleIdentifiers[i], urls[i]);
            } catch (Throwable t) {
                return createFailedBatchActionResult(bundleIdentifiers, i, t);
            }
        }
        return new BatchActionResult(bundleIdentifiers).toCompositeData();
    }
View Full Code Here

Examples of org.apache.aries.jmx.codec.BatchActionResult

    private CompositeData createFailedBatchActionResult(long[] bundleIdentifiers, int i, Throwable t) {
        long[] completed = new long[i];
        System.arraycopy(bundleIdentifiers, 0, completed, 0, i);
        long[] remaining = new long[bundleIdentifiers.length - i - 1];
        System.arraycopy(bundleIdentifiers, i + 1, remaining, 0, remaining.length);
        return new BatchActionResult(completed, t.toString(), remaining, bundleIdentifiers[i]).toCompositeData();
    }
View Full Code Here

Examples of org.apache.aries.jmx.codec.BatchActionResult

    public void testSetBundleStartLevels() throws IOException {
        Bundle bundle = Mockito.mock(Bundle.class);
        Mockito.when(context.getBundle(2)).thenReturn(bundle);
        CompositeData data = mbean.setBundleStartLevels(new long[] { 2 }, new int[] { 2 });
        Mockito.verify(startLevel).setBundleStartLevel(bundle, 2);
        BatchActionResult batch = BatchActionResult.from(data);
        Assert.assertEquals(2, batch.getCompleted()[0]);
        Assert.assertTrue(batch.isSuccess());
        Assert.assertNull(batch.getError());
        Assert.assertNull(batch.getRemainingItems());

        CompositeData data2 = mbean.setBundleStartLevels(new long[] { 2 }, new int[] { 2, 4 });
        BatchActionResult batch2 = BatchActionResult.from(data2);
        Assert.assertNull(batch2.getCompleted());
        Assert.assertFalse(batch2.isSuccess());
        Assert.assertNotNull(batch2.getError());
        Assert.assertNull(batch2.getRemainingItems());

    }
View Full Code Here

Examples of org.apache.aries.jmx.codec.BatchActionResult

        Bundle bundle = Mockito.mock(Bundle.class);
        Mockito.when(context.getBundle(5)).thenReturn(bundle);
        CompositeData data = mbean.startBundles(new long[] { 5 });
        Mockito.verify(bundle).start();

        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.startBundles(null);

        BatchActionResult batch2 = BatchActionResult.from(data2);
        Assert.assertNull(batch2.getCompleted());
        Assert.assertFalse(batch2.isSuccess());
        Assert.assertNotNull(batch2.getError());
        Assert.assertNull(batch2.getRemainingItems());
    }
View Full Code Here

Examples of org.apache.aries.jmx.codec.BatchActionResult

        Bundle bundle = Mockito.mock(Bundle.class);
        Mockito.when(context.getBundle(5)).thenReturn(bundle);
        CompositeData data = mbean.stopBundles(new long[] { 5 });
        Mockito.verify(bundle).stop();

        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.stopBundles(null);

        BatchActionResult batch2 = BatchActionResult.from(data2);
        Assert.assertNull(batch2.getCompleted());
        Assert.assertFalse(batch2.isSuccess());
        Assert.assertNotNull(batch2.getError());
        Assert.assertNull(batch2.getRemainingItems());
    }
View Full Code Here

Examples of org.apache.aries.jmx.codec.BatchActionResult

    public void testUninstallBundles() throws Exception {
        Bundle bundle = Mockito.mock(Bundle.class);
        Mockito.when(context.getBundle(5)).thenReturn(bundle);
        CompositeData data = mbean.uninstallBundles(new long[] { 5 });
        Mockito.verify(bundle).uninstall();
        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.uninstallBundles(null);

        BatchActionResult batch2 = BatchActionResult.from(data2);
        Assert.assertNull(batch2.getCompleted());
        Assert.assertFalse(batch2.isSuccess());
        Assert.assertNotNull(batch2.getError());
        Assert.assertNull(batch2.getRemainingItems());
    }
View Full Code Here

Examples of org.apache.aries.jmx.codec.BatchActionResult

    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);
        // should contain only bundleid 6
        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);
        // should contain only bundleid 7
        Assert.assertEquals(7, batch4.getRemainingItems()[0]);
    }
View Full Code Here

Examples of org.apache.aries.jmx.codec.BatchActionResult

        Mockito.doReturn(stream).when(spiedMBean).createStream(Mockito.anyString());
        Bundle bundle = Mockito.mock(Bundle.class);
        Mockito.when(context.getBundle(5)).thenReturn(bundle);
        CompositeData data = spiedMBean.updateBundlesFromURL(new long[] { 5 }, new String[] { "file:test.jar" });
        Mockito.verify(bundle).update(stream);
        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 = spiedMBean.updateBundlesFromURL(new long[] { 2, 4 }, new String[] { "file:test.jar" });
        BatchActionResult batch2 = BatchActionResult.from(data2);
        Assert.assertFalse(batch2.isSuccess());
        Assert.assertNotNull(batch2.getError());
        Assert.assertNotNull(batch2.getError());
        Assert.assertNull(batch2.getRemainingItems());
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.