use of org.apache.aries.jmx.codec.BatchActionResult in project aries by apache.
the class FrameworkMBeanTest method testMBeanInterface.
@Test
public void testMBeanInterface() throws IOException {
long[] bundleIds = new long[] { 1, 2 };
int[] newlevels = new int[] { 1, 1 };
CompositeData compData = framework.setBundleStartLevels(bundleIds, newlevels);
assertNotNull(compData);
BatchActionResult batch2 = BatchActionResult.from(compData);
assertNotNull(batch2.getCompleted());
assertTrue(batch2.isSuccess());
assertNull(batch2.getError());
assertNull(batch2.getRemainingItems());
File file = File.createTempFile("bundletest", ".jar");
file.deleteOnExit();
Manifest man = new Manifest();
man.getMainAttributes().putValue("Manifest-Version", "1.0");
JarOutputStream jaros = new JarOutputStream(new FileOutputStream(file), man);
jaros.flush();
jaros.close();
long bundleId = 0;
try {
bundleId = framework.installBundleFromURL(file.getAbsolutePath(), file.toURI().toString());
} catch (Exception e) {
fail("Installation of test bundle shouldn't fail");
}
try {
framework.uninstallBundle(bundleId);
} catch (Exception e) {
fail("Uninstallation of test bundle shouldn't fail");
}
}
use of org.apache.aries.jmx.codec.BatchActionResult in project aries by apache.
the class FrameworkTest method testUpdateBundlesFromURL.
@Test
public void testUpdateBundlesFromURL() throws Exception {
Framework spiedMBean = Mockito.spy(mbean);
InputStream stream = Mockito.mock(InputStream.class);
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());
}
use of org.apache.aries.jmx.codec.BatchActionResult in project aries by apache.
the class FrameworkTest method testUninstallBundles.
@Test
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());
}
use of org.apache.aries.jmx.codec.BatchActionResult in project aries by apache.
the class FrameworkTest method testStartBundles.
@Test
public void testStartBundles() throws Exception {
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());
}
use of org.apache.aries.jmx.codec.BatchActionResult in project aries by apache.
the class FrameworkTest method testSetBundleStartLevels.
@Test
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());
}
Aggregations