Search in sources :

Example 76 with CompositeData

use of javax.management.openmbean.CompositeData in project aries by apache.

the class PropertyDataTest method testToFromCompositeDataForList.

@Test
public void testToFromCompositeDataForList() {
    List<String> sl = new ArrayList<String>();
    sl.add("A");
    sl.add("B");
    PropertyData<List<String>> pd = PropertyData.newInstance("test", sl);
    CompositeData cd = pd.toCompositeData();
    assertEquals("test", cd.get(KEY));
    assertEquals("A,B", cd.get(VALUE));
    assertEquals("Array of String", cd.get(TYPE));
    PropertyData<String[]> pd2 = PropertyData.from(cd);
    assertEquals("test", pd2.getKey());
    assertEquals("Array of String", pd2.getEncodedType());
    assertArrayEquals(new String[] { "A", "B" }, pd2.getValue());
}
Also used : CompositeData(javax.management.openmbean.CompositeData) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 77 with CompositeData

use of javax.management.openmbean.CompositeData in project aries by apache.

the class PropertyDataTest method testToFromCompositeDataForArrayTypes.

@Test
public void testToFromCompositeDataForArrayTypes() {
    //long[]
    long[] primitiveLongValues = new long[] { 1, 2, 3 };
    PropertyData<long[]> primitiveLongArrayData = PropertyData.newInstance("test", primitiveLongValues);
    CompositeData primitiveLongArrayCData = primitiveLongArrayData.toCompositeData();
    assertEquals("test", primitiveLongArrayCData.get(KEY));
    assertEquals("1,2,3", primitiveLongArrayCData.get(VALUE));
    assertEquals("Array of long", primitiveLongArrayCData.get(TYPE));
    primitiveLongArrayData = PropertyData.from(primitiveLongArrayCData);
    assertEquals("test", primitiveLongArrayData.getKey());
    assertEquals("Array of long", primitiveLongArrayData.getEncodedType());
    assertArrayEquals(primitiveLongValues, primitiveLongArrayData.getValue());
    //Long[]
    Long[] longValues = new Long[] { new Long(4), new Long(5), new Long(6) };
    PropertyData<Long[]> longArrayData = PropertyData.newInstance("test", longValues);
    CompositeData longArrayCData = longArrayData.toCompositeData();
    assertEquals("test", longArrayCData.get(KEY));
    assertEquals("4,5,6", longArrayCData.get(VALUE));
    assertEquals("Array of Long", longArrayCData.get(TYPE));
    longArrayData = PropertyData.from(longArrayCData);
    assertEquals("test", longArrayData.getKey());
    assertEquals("Array of Long", longArrayData.getEncodedType());
    assertArrayEquals(longValues, longArrayData.getValue());
    //char[]
    char[] primitiveCharValues = new char[] { 'a', 'b', 'c' };
    PropertyData<char[]> primitiveCharArrayData = PropertyData.newInstance("test", primitiveCharValues);
    CompositeData primitiveCharArrayCData = primitiveCharArrayData.toCompositeData();
    assertEquals("test", primitiveCharArrayCData.get(KEY));
    assertEquals("a,b,c", primitiveCharArrayCData.get(VALUE));
    assertEquals("Array of char", primitiveCharArrayCData.get(TYPE));
    primitiveCharArrayData = PropertyData.from(primitiveCharArrayCData);
    assertEquals("test", primitiveCharArrayData.getKey());
    assertEquals("Array of char", primitiveCharArrayData.getEncodedType());
    assertArrayEquals(primitiveCharValues, primitiveCharArrayData.getValue());
    //Character[]
    Character[] charValues = new Character[] { 'a', 'b', 'c' };
    PropertyData<Character[]> charArrayData = PropertyData.newInstance("test", charValues);
    CompositeData charArrayCData = charArrayData.toCompositeData();
    assertEquals("test", charArrayCData.get(KEY));
    assertEquals("a,b,c", charArrayCData.get(VALUE));
    assertEquals("Array of Character", charArrayCData.get(TYPE));
    charArrayData = PropertyData.from(charArrayCData);
    assertEquals("test", charArrayData.getKey());
    assertEquals("Array of Character", charArrayData.getEncodedType());
    assertArrayEquals(charValues, charArrayData.getValue());
}
Also used : CompositeData(javax.management.openmbean.CompositeData) Test(org.junit.Test)

Example 78 with CompositeData

use of javax.management.openmbean.CompositeData in project aries by apache.

the class PropertyDataTest method testToCompositeDataForPrimitiveTypes.

@Test
public void testToCompositeDataForPrimitiveTypes() throws Exception {
    PropertyData<Integer> intData = PropertyData.newInstance("test", 1);
    CompositeData intCData = intData.toCompositeData();
    assertEquals("test", intCData.get(KEY));
    assertEquals("1", intCData.get(VALUE));
    assertEquals(P_INT, intCData.get(TYPE));
    PropertyData<Double> doubleData = PropertyData.newInstance("test", 1.0);
    CompositeData doubleCData = doubleData.toCompositeData();
    assertEquals("test", doubleCData.get(KEY));
    assertEquals("1.0", doubleCData.get(VALUE));
    assertEquals(P_DOUBLE, doubleCData.get(TYPE));
    PropertyData<Character> charData = PropertyData.newInstance("test", 'c');
    CompositeData charCData = charData.toCompositeData();
    assertEquals("test", charCData.get(KEY));
    assertEquals("c", charCData.get(VALUE));
    assertEquals(P_CHAR, charCData.get(TYPE));
    PropertyData<Boolean> booleanData = PropertyData.newInstance("test", true);
    CompositeData booleanCData = booleanData.toCompositeData();
    assertEquals("test", booleanCData.get(KEY));
    assertEquals("true", booleanCData.get(VALUE));
    assertEquals(P_BOOLEAN, booleanCData.get(TYPE));
}
Also used : BigInteger(java.math.BigInteger) CompositeData(javax.management.openmbean.CompositeData) Test(org.junit.Test)

Example 79 with CompositeData

use of javax.management.openmbean.CompositeData in project aries by apache.

the class FrameworkTest method testInstallBundles.

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

Example 80 with CompositeData

use of javax.management.openmbean.CompositeData 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)

Aggregations

CompositeData (javax.management.openmbean.CompositeData)229 TabularData (javax.management.openmbean.TabularData)91 Test (org.junit.Test)73 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)68 TabularDataSupport (javax.management.openmbean.TabularDataSupport)51 CompositeType (javax.management.openmbean.CompositeType)50 HashMap (java.util.HashMap)31 ArrayList (java.util.ArrayList)27 Map (java.util.Map)27 Bundle (org.osgi.framework.Bundle)24 ObjectName (javax.management.ObjectName)21 OpenDataException (javax.management.openmbean.OpenDataException)18 IOException (java.io.IOException)17 Collection (java.util.Collection)16 AbstractIntegrationTest (org.apache.aries.jmx.AbstractIntegrationTest)16 AuditEvent (org.nhindirect.common.audit.AuditEvent)15 TabularType (javax.management.openmbean.TabularType)13 MBeanServer (javax.management.MBeanServer)12 DefaultAuditContext (org.nhindirect.common.audit.DefaultAuditContext)11 MBeanException (javax.management.MBeanException)8