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]);
}
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());
}
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());
}
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());
}
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());
}
Aggregations