use of javax.management.openmbean.CompositeData in project aries by apache.
the class FrameworkTest method testStopBundles.
@Test
public void testStopBundles() throws Exception {
Bundle bundle = Mockito.mock(Bundle.class);
Mockito.when(context.getBundle(5)).thenReturn(bundle);
CompositeData data = mbean.stopBundles(new long[] { 5 });
Mockito.verify(bundle).stop();
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.stopBundles(null);
BatchActionResult batch2 = BatchActionResult.from(data2);
Assert.assertNull(batch2.getCompleted());
Assert.assertFalse(batch2.isSuccess());
Assert.assertNotNull(batch2.getError());
Assert.assertNull(batch2.getRemainingItems());
}
use of javax.management.openmbean.CompositeData in project aries by apache.
the class FrameworkTest method testUpdateBundles.
@Test
public void testUpdateBundles() throws Exception {
Bundle bundle = Mockito.mock(Bundle.class);
Mockito.when(context.getBundle(5)).thenReturn(bundle);
CompositeData data = mbean.updateBundles(new long[] { 5 });
Mockito.verify(bundle).update();
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.updateBundles(null);
BatchActionResult batch2 = BatchActionResult.from(data2);
Assert.assertNull(batch2.getCompleted());
Assert.assertFalse(batch2.isSuccess());
Assert.assertNotNull(batch2.getError());
Assert.assertNull(batch2.getRemainingItems());
Mockito.reset(bundle);
CompositeData data3 = mbean.updateBundles(new long[] { 6 });
Mockito.when(context.getBundle(6)).thenReturn(bundle);
Mockito.doThrow(new BundleException("")).when(bundle).update();
BatchActionResult batch3 = BatchActionResult.from(data3);
Assert.assertEquals(0, batch3.getCompleted().length);
Assert.assertFalse(batch3.isSuccess());
Assert.assertNotNull(batch3.getError());
Assert.assertEquals(6, batch3.getBundleInError());
Bundle bundle6 = Mockito.mock(Bundle.class);
Bundle bundle8 = Mockito.mock(Bundle.class);
Bundle bundle7 = Mockito.mock(Bundle.class);
Mockito.when(context.getBundle(6)).thenReturn(bundle6);
Mockito.when(context.getBundle(8)).thenReturn(bundle8);
Mockito.when(context.getBundle(7)).thenReturn(bundle7);
Mockito.doThrow(new BundleException("")).when(bundle8).update();
CompositeData data4 = mbean.updateBundles(new long[] { 6, 8, 7 });
BatchActionResult batch4 = BatchActionResult.from(data4);
Mockito.verify(bundle6).update();
Assert.assertEquals(1, batch4.getCompleted().length);
// should contain only bundleid 6
Assert.assertEquals(6, batch4.getCompleted()[0]);
Assert.assertFalse(batch4.isSuccess());
Assert.assertNotNull(batch4.getError());
Assert.assertEquals(8, batch4.getBundleInError());
Assert.assertEquals(1, batch4.getRemainingItems().length);
// should contain only bundleid 7
Assert.assertEquals(7, batch4.getRemainingItems()[0]);
}
use of javax.management.openmbean.CompositeData in project aries by apache.
the class ProvisioningService method extractProvisioningDictionary.
@SuppressWarnings("unchecked")
protected Dictionary<String, Object> extractProvisioningDictionary(TabularData info) {
Dictionary<String, Object> provisioningInfo = new Hashtable<String, Object>();
if (info != null) {
Collection<CompositeData> compositeData = (Collection<CompositeData>) info.values();
for (CompositeData row : compositeData) {
PropertyData<? extends Class> propertyData = PropertyData.from(row);
provisioningInfo.put(propertyData.getKey(), propertyData.getValue());
}
}
return provisioningInfo;
}
use of javax.management.openmbean.CompositeData in project deltaspike by apache.
the class SimpleRegistrationTest method checkMBean.
@Test
public void checkMBean() throws Exception {
assertEquals(0, myMBean.getCounter());
myMBean.resetTo(2);
final ObjectName on = new ObjectName("org.apache.deltaspike:type=MBeans,name=" + MyMBean.class.getName());
assertTrue(server.isRegistered(on));
assertEquals(2, server.getAttribute(on, "counter"));
assertEquals(6, server.invoke(on, "multiply", new Object[] { 3 }, new String[0]));
myMBean.resetTo(5);
assertEquals(5, server.getAttribute(on, "counter"));
assertEquals(20, server.invoke(on, "multiply", new Object[] { 4 }, new String[0]));
server.setAttribute(on, new Attribute("counter", 10));
assertEquals(10, myMBean.getCounter());
final Collection<Notification> notifications = new ArrayList<Notification>();
server.addNotificationListener(on, new NotificationListener() {
@Override
public void handleNotification(final Notification notification, final Object handback) {
notifications.add(notification);
}
}, null, null);
myMBean.broadcast();
assertEquals(1, notifications.size());
assertEquals(10L, notifications.iterator().next().getSequenceNumber());
MBeanInfo mBeanInfo = server.getMBeanInfo(on);
Assert.assertNotNull(mBeanInfo);
MBeanOperationInfo[] operations = mBeanInfo.getOperations();
Assert.assertNotNull(operations);
Assert.assertTrue(operations.length > 0);
Assert.assertTrue("Empty Signature on operation: " + operations[1], operations[1].getSignature().length > 0);
MBeanParameterInfo parameterInfo = operations[1].getSignature()[0];
assertEquals("multiplier", parameterInfo.getName());
assertEquals("the multiplier", parameterInfo.getDescription());
{
// table support - through map
Object table = server.getAttribute(on, "table");
assertTrue(TabularData.class.isInstance(table));
final TabularData data = TabularData.class.cast(table);
assertEquals(1, data.size());
final CompositeData compositeData = CompositeData.class.cast(data.values().iterator().next());
assertEquals(2, compositeData.values().size());
assertEquals("value1", compositeData.get("key1"));
assertEquals("value2", compositeData.get("key2"));
}
{
// table support - through Table
Object table = server.getAttribute(on, "table2");
assertTrue(TabularData.class.isInstance(table));
final TabularData data = TabularData.class.cast(table);
assertEquals(2, data.size());
final Iterator<?> iterator = data.values().iterator();
{
final CompositeData compositeData = CompositeData.class.cast(iterator.next());
assertEquals(3, compositeData.values().size());
assertEquals("1", compositeData.get("a"));
assertEquals("2", compositeData.get("b"));
assertEquals("3", compositeData.get("c"));
}
{
final CompositeData compositeData = CompositeData.class.cast(iterator.next());
assertEquals(3, compositeData.values().size());
assertEquals("alpha", compositeData.get("a"));
assertEquals("beta", compositeData.get("b"));
assertEquals("gamma", compositeData.get("c"));
}
}
}
use of javax.management.openmbean.CompositeData in project geode by apache.
the class TableConverter method fromNonNullOpenValue.
public Object fromNonNullOpenValue(Object openValue) throws InvalidObjectException {
final TabularData table = (TabularData) openValue;
final Collection<CompositeData> rows = (Collection<CompositeData>) table.values();
final Map<Object, Object> valueMap = sortedMap ? OpenTypeUtil.newSortedMap() : OpenTypeUtil.newMap();
for (CompositeData row : rows) {
final Object key = keyConverter.fromOpenValue(row.get("key"));
final Object value = valueConverter.fromOpenValue(row.get("value"));
if (valueMap.put(key, value) != null) {
final String msg = "Duplicate entry in TabularData: key=" + key;
throw new InvalidObjectException(msg);
}
}
return valueMap;
}
Aggregations