Search in sources :

Example 1 with BatchActionResult

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");
    }
}
Also used : CompositeData(javax.management.openmbean.CompositeData) FileOutputStream(java.io.FileOutputStream) JarOutputStream(java.util.jar.JarOutputStream) Manifest(java.util.jar.Manifest) File(java.io.File) BatchActionResult(org.apache.aries.jmx.codec.BatchActionResult) BundleException(org.osgi.framework.BundleException) IOException(java.io.IOException) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.jmx.AbstractIntegrationTest)

Example 2 with BatchActionResult

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());
}
Also used : InputStream(java.io.InputStream) Bundle(org.osgi.framework.Bundle) CompositeData(javax.management.openmbean.CompositeData) BatchActionResult(org.apache.aries.jmx.codec.BatchActionResult) Test(org.junit.Test)

Example 3 with BatchActionResult

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());
}
Also used : Bundle(org.osgi.framework.Bundle) CompositeData(javax.management.openmbean.CompositeData) BatchActionResult(org.apache.aries.jmx.codec.BatchActionResult) Test(org.junit.Test)

Example 4 with BatchActionResult

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());
}
Also used : Bundle(org.osgi.framework.Bundle) CompositeData(javax.management.openmbean.CompositeData) BatchActionResult(org.apache.aries.jmx.codec.BatchActionResult) Test(org.junit.Test)

Example 5 with BatchActionResult

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());
}
Also used : Bundle(org.osgi.framework.Bundle) CompositeData(javax.management.openmbean.CompositeData) BatchActionResult(org.apache.aries.jmx.codec.BatchActionResult) Test(org.junit.Test)

Aggregations

BatchActionResult (org.apache.aries.jmx.codec.BatchActionResult)8 CompositeData (javax.management.openmbean.CompositeData)7 Test (org.junit.Test)7 Bundle (org.osgi.framework.Bundle)6 BundleException (org.osgi.framework.BundleException)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 JarOutputStream (java.util.jar.JarOutputStream)1 Manifest (java.util.jar.Manifest)1 AbstractIntegrationTest (org.apache.aries.jmx.AbstractIntegrationTest)1