Search in sources :

Example 71 with CompositeData

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

the class ServiceStateTest method testNotificationsForServiceEvents.

@Test
public void testNotificationsForServiceEvents() throws Exception {
    StateConfig stateConfig = new StateConfig();
    //holders for Notifications captured
    List<Notification> received = new LinkedList<Notification>();
    List<AttributeChangeNotification> attributeChanges = new LinkedList<AttributeChangeNotification>();
    createService(stateConfig, received, attributeChanges);
    assertEquals(2, received.size());
    Notification registered = received.get(0);
    assertEquals(1, registered.getSequenceNumber());
    CompositeData data = (CompositeData) registered.getUserData();
    assertEquals(new Long(44), data.get(IDENTIFIER));
    assertEquals(new Long(9), data.get(BUNDLE_IDENTIFIER));
    assertEquals("file:/location", data.get(BUNDLE_LOCATION));
    assertEquals("bundle", data.get(BUNDLE_SYMBOLIC_NAME));
    assertArrayEquals(new String[] { "org.apache.aries.jmx.Mock" }, (String[]) data.get(OBJECT_CLASS));
    assertEquals(ServiceEvent.REGISTERED, data.get(EVENT));
    Notification modified = received.get(1);
    assertEquals(2, modified.getSequenceNumber());
    data = (CompositeData) modified.getUserData();
    assertEquals(new Long(44), data.get(IDENTIFIER));
    assertEquals(new Long(9), data.get(BUNDLE_IDENTIFIER));
    assertEquals("file:/location", data.get(BUNDLE_LOCATION));
    assertEquals("bundle", data.get(BUNDLE_SYMBOLIC_NAME));
    assertArrayEquals(new String[] { "org.apache.aries.jmx.Mock" }, (String[]) data.get(OBJECT_CLASS));
    assertEquals(ServiceEvent.MODIFIED, data.get(EVENT));
    assertEquals(1, attributeChanges.size());
    AttributeChangeNotification ac = attributeChanges.get(0);
    assertEquals("ServiceIds", ac.getAttributeName());
    assertEquals(0, ((long[]) ac.getOldValue()).length);
    assertEquals(1, ((long[]) ac.getNewValue()).length);
    assertEquals(44L, ((long[]) ac.getNewValue())[0]);
}
Also used : AttributeChangeNotification(javax.management.AttributeChangeNotification) CompositeData(javax.management.openmbean.CompositeData) LinkedList(java.util.LinkedList) AttributeChangeNotification(javax.management.AttributeChangeNotification) Notification(javax.management.Notification) Test(org.junit.Test)

Example 72 with CompositeData

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

the class BundleEventDataTest method testFrom.

@Test
public void testFrom() throws Exception {
    Map<String, Object> items = new HashMap<String, Object>();
    items.put(IDENTIFIER, new Long(7));
    items.put(SYMBOLIC_NAME, "t");
    items.put(LOCATION, "l");
    items.put(EVENT, BundleEvent.RESOLVED);
    CompositeData compositeData = new CompositeDataSupport(BUNDLE_EVENT_TYPE, items);
    BundleEventData event = BundleEventData.from(compositeData);
    assertEquals(7, event.getBundleId());
    assertEquals("t", event.getBundleSymbolicName());
    assertEquals("l", event.getLocation());
    assertEquals(BundleEvent.RESOLVED, event.getEventType());
}
Also used : HashMap(java.util.HashMap) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) Test(org.junit.Test)

Example 73 with CompositeData

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

the class PropertyDataTest method testToFromCompositeDataForList2.

@Test
public void testToFromCompositeDataForList2() {
    List<Long> sl = new ArrayList<Long>();
    sl.add(Long.MAX_VALUE);
    PropertyData<List<Long>> pd = PropertyData.newInstance("test", sl);
    CompositeData cd = pd.toCompositeData();
    assertEquals("test", cd.get(KEY));
    assertEquals(new Long(Long.MAX_VALUE).toString(), cd.get(VALUE));
    assertEquals("Array of Long", cd.get(TYPE));
    PropertyData<Long[]> pd2 = PropertyData.from(cd);
    assertEquals("test", pd2.getKey());
    assertEquals("Array of Long", pd2.getEncodedType());
    assertArrayEquals(new Long[] { Long.MAX_VALUE }, 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 74 with CompositeData

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

the class PropertyDataTest method testFromCompositeDataForWrapperTypes.

@Test
public void testFromCompositeDataForWrapperTypes() throws Exception {
    Map<String, Object> items = new HashMap<String, Object>();
    items.put(KEY, "key");
    items.put(VALUE, "1");
    items.put(TYPE, INTEGER);
    CompositeData compositeData = new CompositeDataSupport(PROPERTY_TYPE, items);
    PropertyData<Integer> intData = PropertyData.from(compositeData);
    assertEquals("key", intData.getKey());
    assertEquals(new Integer(1), intData.getValue());
    assertEquals(INTEGER, intData.getEncodedType());
    assertFalse(intData.isEncodingPrimitive());
    items.clear();
    items.put(KEY, "key");
    items.put(VALUE, "1.0");
    items.put(TYPE, DOUBLE);
    compositeData = new CompositeDataSupport(PROPERTY_TYPE, items);
    PropertyData<Double> doubleData = PropertyData.from(compositeData);
    assertEquals("key", doubleData.getKey());
    assertEquals(Double.valueOf(1.0), doubleData.getValue());
    assertEquals(DOUBLE, doubleData.getEncodedType());
    assertFalse(doubleData.isEncodingPrimitive());
    items.clear();
    items.put(KEY, "key");
    items.put(VALUE, "a");
    items.put(TYPE, CHARACTER);
    compositeData = new CompositeDataSupport(PROPERTY_TYPE, items);
    PropertyData<Character> charData = PropertyData.from(compositeData);
    assertEquals("key", charData.getKey());
    assertEquals(Character.valueOf('a'), charData.getValue());
    assertEquals(CHARACTER, charData.getEncodedType());
    assertFalse(charData.isEncodingPrimitive());
    items.clear();
    items.put(KEY, "key");
    items.put(VALUE, "true");
    items.put(TYPE, BOOLEAN);
    compositeData = new CompositeDataSupport(PROPERTY_TYPE, items);
    PropertyData<Boolean> booleanData = PropertyData.from(compositeData);
    assertEquals("key", booleanData.getKey());
    assertTrue(booleanData.getValue());
    assertEquals(BOOLEAN, booleanData.getEncodedType());
    assertFalse(booleanData.isEncodingPrimitive());
}
Also used : HashMap(java.util.HashMap) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Example 75 with CompositeData

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

the class PropertyDataTest method testToFromCompositeDataForAdditionalTypes.

@Test
public void testToFromCompositeDataForAdditionalTypes() {
    PropertyData<String> stringData = PropertyData.newInstance("test", "value");
    CompositeData stringCData = stringData.toCompositeData();
    assertEquals("test", stringCData.get(KEY));
    assertEquals("value", stringCData.get(VALUE));
    assertEquals(STRING, stringCData.get(TYPE));
    stringData = PropertyData.from(stringCData);
    assertEquals("test", stringData.getKey());
    assertEquals("value", stringData.getValue());
    assertEquals(STRING, stringData.getEncodedType());
    PropertyData<BigInteger> bigIntData = PropertyData.newInstance("test", new BigInteger("1"));
    CompositeData bigIntCData = bigIntData.toCompositeData();
    assertEquals("test", bigIntCData.get(KEY));
    assertEquals("1", bigIntCData.get(VALUE));
    assertEquals(BIGINTEGER, bigIntCData.get(TYPE));
    bigIntData = PropertyData.from(bigIntCData);
    assertEquals("test", bigIntData.getKey());
    assertEquals(new BigInteger("1"), bigIntData.getValue());
    assertEquals(BIGINTEGER, bigIntData.getEncodedType());
}
Also used : CompositeData(javax.management.openmbean.CompositeData) BigInteger(java.math.BigInteger) 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