Search in sources :

Example 1 with AuditEvent

use of org.nhindirect.common.audit.AuditEvent 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 2 with AuditEvent

use of org.nhindirect.common.audit.AuditEvent 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 3 with AuditEvent

use of org.nhindirect.common.audit.AuditEvent 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 4 with AuditEvent

use of org.nhindirect.common.audit.AuditEvent 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)

Example 5 with AuditEvent

use of org.nhindirect.common.audit.AuditEvent 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)

Aggregations

AuditEvent (org.nhindirect.common.audit.AuditEvent)21 DefaultAuditContext (org.nhindirect.common.audit.DefaultAuditContext)15 CompositeData (javax.management.openmbean.CompositeData)14 Test (org.junit.Test)14 AuditContext (org.nhindirect.common.audit.AuditContext)5 IOException (java.io.IOException)2 UnknownHostException (java.net.UnknownHostException)2 MessagingException (javax.mail.MessagingException)2 AgentException (org.nhindirect.stagent.AgentException)2 DefaultMessageEnvelope (org.nhindirect.stagent.DefaultMessageEnvelope)2 IncomingMessage (org.nhindirect.stagent.IncomingMessage)2 MessageEnvelope (org.nhindirect.stagent.MessageEnvelope)2 NHINDAddress (org.nhindirect.stagent.NHINDAddress)2 NHINDException (org.nhindirect.stagent.NHINDException)2 OutgoingMessage (org.nhindirect.stagent.OutgoingMessage)2 NotificationMessage (org.nhindirect.stagent.mail.notifications.NotificationMessage)2 Transactional (org.springframework.transaction.annotation.Transactional)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Entry (java.util.Map.Entry)1