Search in sources :

Example 26 with CompositeData

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

the class FileAuditor method getEvents.

/**
	 * {@inheritDoc}
	 */
@Override
public synchronized CompositeData[] getEvents(Integer eventCount) {
    if (eventType == null || eventCount == 0)
        return null;
    Vector<CompositeData> retVal = new Vector<CompositeData>();
    /*
		 * Save off the position
		 */
    long savePosition = -1;
    try {
        savePosition = auditFile.getFilePointer();
        long currentPosition = savePosition;
        // Get the last event
        CompositeData event = getLastEvent();
        if (event != null)
            retVal.add(event);
        // keep getting event until either we have reached the requested count
        // or there are no more records
        int cnt = 1;
        while (cnt < eventCount && event != null) {
            int size = getRecordSize(currentPosition);
            // move the file pointer to the last record
            currentPosition -= (RECORD_METADATA_SIZE + size + 4);
            auditFile.seek(currentPosition);
            event = getLastEvent();
            if (event != null)
                retVal.add(event);
            ++cnt;
        }
    } catch (IOException e) {
    /* no-op */
    } finally {
        try {
            // set the file point back to the orignal position
            if (savePosition > -1)
                auditFile.seek(savePosition);
        } catch (IOException e) {
        /* no-op */
        }
    }
    return (retVal.size() > 0) ? retVal.toArray(new CompositeData[retVal.size()]) : null;
}
Also used : CompositeData(javax.management.openmbean.CompositeData) IOException(java.io.IOException) Vector(java.util.Vector)

Example 27 with CompositeData

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

the class FileAuditorTest method testGetLastEvent_AssertRecordContentAndContext.

@Test
public void testGetLastEvent_AssertRecordContentAndContext() {
    FileAuditor auditor = new FileAuditor(auditFile);
    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");
    auditor.audit(PRINCIPAL, event1);
    auditor.audit(PRINCIPAL, event2, Arrays.asList(context1, context2));
    assertNotNull(auditor.getLastEvent());
    CompositeData lastMessage = auditor.getLastEvent();
    assertEquals(event2.getName(), lastMessage.get("Event Name"));
    assertEquals(event2.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 28 with CompositeData

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

the class FileAuditorTest method testGetEvents_RequestMoreThanAvailable_AssertGotAllAvailableRecords.

@Test
public void testGetEvents_RequestMoreThanAvailable_AssertGotAllAvailableRecords() {
    FileAuditor auditor = new FileAuditor(auditFile);
    auditor.clear();
    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");
    auditor.audit(PRINCIPAL, event1);
    auditor.audit(PRINCIPAL, event2, Arrays.asList(context1, context2));
    CompositeData[] events = auditor.getEvents(5);
    assertNotNull(events);
    assertEquals(2, events.length);
    CompositeData lastMessage = events[0];
    assertEquals(event2.getName(), lastMessage.get("Event Name"));
    assertEquals(event2.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 29 with CompositeData

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

the class RDBMSAuditor_getEventsTest method testGetEvents_RequestLessThanAvailable_AssertGotOnlyRecords.

@Test
public void testGetEvents_RequestLessThanAvailable_AssertGotOnlyRecords() {
    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(1);
    assertNotNull(events);
    assertEquals(1, events.length);
    CompositeData lastMessage = events[0];
    assertEquals(event2.getName(), lastMessage.get("Event Name"));
    assertEquals(event2.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 30 with CompositeData

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

the class RDBMSAuditor_getEventsTest method testGetEvents_AssertGotAllRecordsRequested.

@Test
public void testGetEvents_AssertGotAllRecordsRequested() {
    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(2);
    assertNotNull(events);
    assertEquals(2, events.length);
    CompositeData lastMessage = events[0];
    assertEquals(event2.getName(), lastMessage.get("Event Name"));
    assertEquals(event2.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)

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