use of org.nhindirect.common.audit.DefaultAuditContext in project nhin-d by DirectProject.
the class RDBMSAuditor_getEventsTest method testGetEvents_RequestMoreThanAvailable_AssertGotAllAvailableRecords.
@Test
public void testGetEvents_RequestMoreThanAvailable_AssertGotAllAvailableRecords() {
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(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]);
}
use of org.nhindirect.common.audit.DefaultAuditContext in project nhin-d by DirectProject.
the class RDBMSAuditor_getLastEventTest method testGetLastEventTest_withContexts_lastEventRetrieved.
@Test
public void testGetLastEventTest_withContexts_lastEventRetrieved() 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]);
}
Aggregations