Search in sources :

Example 31 with CompositeData

use of javax.management.openmbean.CompositeData in project nhin-d by DirectProject.

the class RDBMSAuditor_getEventsTest method testGetEvents_NoRecordsRequested_ReturnedRecords.

@Test
public void testGetEvents_NoRecordsRequested_ReturnedRecords() {
    AuditEvent event1 = new AuditEvent("Category" + UUID.randomUUID(), "type");
    AuditEvent event2 = new AuditEvent("Category" + UUID.randomUUID(), "type");
    DefaultAuditContext context1 = new DefaultAuditContext("name1", "value1");
    DefaultAuditContext context2 = new DefaultAuditContext("name2", "value2");
    auditorImpl.audit(PRINCIPAL, event1);
    auditorImpl.audit(PRINCIPAL, event2, Arrays.asList(context1, context2));
    CompositeData[] events = auditorImpl.getEvents(0);
    assertNull(events);
}
Also used : DefaultAuditContext(org.nhindirect.common.audit.DefaultAuditContext) CompositeData(javax.management.openmbean.CompositeData) AuditEvent(org.nhindirect.common.audit.AuditEvent) Test(org.junit.Test)

Example 32 with CompositeData

use of javax.management.openmbean.CompositeData in project nhin-d by DirectProject.

the class RDBMSAuditor_writeEventTest method testWriteEvent_noContexts_assertWritten.

@Test
public void testWriteEvent_noContexts_assertWritten() throws Exception {
    final AuditEvent auditEvent = new AuditEvent("name1", "value1");
    this.auditorImpl.audit("testPin", auditEvent, null);
    final CompositeData lastMessage = auditorImpl.getLastEvent();
    assertNotNull(lastMessage);
    assertEquals(auditEvent.getName(), lastMessage.get("Event Name"));
    assertEquals(auditEvent.getType(), lastMessage.get("Event Type"));
    assertTrue(lastMessage.get("Event Id").toString().length() > 0);
    assertTrue(lastMessage.get("Event Time").toString().length() > 0);
    assertNotNull(lastMessage.get("Contexts"));
    String[] contexts = (String[]) lastMessage.get("Contexts");
    assertEquals(1, contexts.length);
}
Also used : CompositeData(javax.management.openmbean.CompositeData) AuditEvent(org.nhindirect.common.audit.AuditEvent) Test(org.junit.Test)

Example 33 with CompositeData

use of javax.management.openmbean.CompositeData in project nhin-d by DirectProject.

the class RDBMSAuditor_writeEventTest method testWriteEvent_withContexts_assertWritten.

@Test
public void testWriteEvent_withContexts_assertWritten() throws Exception {
    final AuditEvent auditEvent = new AuditEvent("name1", "value1");
    final DefaultAuditContext context1 = new DefaultAuditContext("name1", "value1");
    final DefaultAuditContext context2 = new DefaultAuditContext("name2", "value2");
    this.auditorImpl.audit("testPin", auditEvent, Arrays.asList(context1, context2));
    final CompositeData lastMessage = auditorImpl.getLastEvent();
    assertNotNull(lastMessage);
    assertEquals(auditEvent.getName(), lastMessage.get("Event Name"));
    assertEquals(auditEvent.getType(), lastMessage.get("Event Type"));
    assertTrue(lastMessage.get("Event Id").toString().length() > 0);
    assertTrue(lastMessage.get("Event Time").toString().length() > 0);
    assertNotNull(lastMessage.get("Contexts"));
    String[] contexts = (String[]) lastMessage.get("Contexts");
    assertEquals(2, contexts.length);
    assertEquals("name1:value1", contexts[0]);
    assertEquals("name2:value2", contexts[1]);
}
Also used : DefaultAuditContext(org.nhindirect.common.audit.DefaultAuditContext) CompositeData(javax.management.openmbean.CompositeData) AuditEvent(org.nhindirect.common.audit.AuditEvent) Test(org.junit.Test)

Example 34 with CompositeData

use of javax.management.openmbean.CompositeData in project midpoint by Evolveum.

the class SystemInfoPanel method fillMemoryUsage.

private void fillMemoryUsage(SystemInfoDto dto) throws Exception {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    ObjectName name = ObjectName.getInstance("java.lang:type=Memory");
    CompositeData cd = (CompositeData) mbs.getAttribute(name, "HeapMemoryUsage");
    dto.heapMemory[0] = (Long) cd.get("used");
    dto.heapMemory[1] = (Long) cd.get("committed");
    dto.heapMemory[2] = (Long) cd.get("max");
    cd = (CompositeData) mbs.getAttribute(name, "NonHeapMemoryUsage");
    dto.nonHeapMemory[0] = (Long) cd.get("used");
    dto.nonHeapMemory[1] = (Long) cd.get("committed");
    dto.nonHeapMemory[2] = (Long) cd.get("max");
}
Also used : CompositeData(javax.management.openmbean.CompositeData) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 35 with CompositeData

use of javax.management.openmbean.CompositeData in project jdk8u_jdk by JetBrains.

the class MXBeanTest method proxyEqual.

// Also needed for 5095277
private static boolean proxyEqual(Object proxy1, Object proxy2, NamedMXBeans namedMXBeans) {
    if (proxy1.getClass() != proxy2.getClass())
        return proxy1.equals(proxy2);
    InvocationHandler ih1 = Proxy.getInvocationHandler(proxy1);
    InvocationHandler ih2 = Proxy.getInvocationHandler(proxy2);
    if (!(ih1 instanceof CompositeDataInvocationHandler) || !(ih2 instanceof CompositeDataInvocationHandler))
        return proxy1.equals(proxy2);
    CompositeData cd1 = ((CompositeDataInvocationHandler) ih1).getCompositeData();
    CompositeData cd2 = ((CompositeDataInvocationHandler) ih2).getCompositeData();
    return compositeDataEqual(cd1, cd2, namedMXBeans);
}
Also used : CompositeData(javax.management.openmbean.CompositeData) CompositeDataInvocationHandler(javax.management.openmbean.CompositeDataInvocationHandler) CompositeDataInvocationHandler(javax.management.openmbean.CompositeDataInvocationHandler) MBeanServerInvocationHandler(javax.management.MBeanServerInvocationHandler) InvocationHandler(java.lang.reflect.InvocationHandler)

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