Search in sources :

Example 11 with DefaultAuditContext

use of org.nhindirect.common.audit.DefaultAuditContext in project nhin-d by DirectProject.

the class FileAuditorTest method testGetEvents_RequestLessThanAvailable_AssertGotOnlyRecords.

@Test
public void testGetEvents_RequestLessThanAvailable_AssertGotOnlyRecords() {
    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(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 12 with DefaultAuditContext

use of org.nhindirect.common.audit.DefaultAuditContext in project nhin-d by DirectProject.

the class MultiProviderAuditorTest method testAuditWithContext.

@Test
public void testAuditWithContext() {
    Auditor auditor = new MultiProviderAuditor(Arrays.asList(new LoggingAuditor(), new NoOpAuditor()));
    Collection<? extends AuditContext> ctx = Arrays.asList(new DefaultAuditContext("name", "value"));
    auditor.audit(PRINCIPAL, UNIT_TEST_EVENT, ctx);
}
Also used : LoggingAuditor(org.nhindirect.common.audit.impl.LoggingAuditor) Auditor(org.nhindirect.common.audit.Auditor) MultiProviderAuditor(org.nhindirect.common.audit.impl.MultiProviderAuditor) NoOpAuditor(org.nhindirect.common.audit.impl.NoOpAuditor) DefaultAuditContext(org.nhindirect.common.audit.DefaultAuditContext) MultiProviderAuditor(org.nhindirect.common.audit.impl.MultiProviderAuditor) NoOpAuditor(org.nhindirect.common.audit.impl.NoOpAuditor) LoggingAuditor(org.nhindirect.common.audit.impl.LoggingAuditor) Test(org.junit.Test)

Example 13 with DefaultAuditContext

use of org.nhindirect.common.audit.DefaultAuditContext in project nhin-d by DirectProject.

the class FileAuditorTest method testGetEvents_NoRecordsRequested_ReturnedRecords.

@Test
public void testGetEvents_NoRecordsRequested_ReturnedRecords() {
    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(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 14 with DefaultAuditContext

use of org.nhindirect.common.audit.DefaultAuditContext in project nhin-d by DirectProject.

the class FileAuditorTest method testGetEvents_AssertGotAllRecordsRequested.

@Test
public void testGetEvents_AssertGotAllRecordsRequested() {
    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));
    CompositeData[] events = auditor.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 15 with DefaultAuditContext

use of org.nhindirect.common.audit.DefaultAuditContext in project nhin-d by DirectProject.

the class FileAuditorTest method testAuditCategoryWithContext.

@Test
public void testAuditCategoryWithContext() {
    FileAuditor auditor = new FileAuditor(auditFile);
    Collection<? extends AuditContext> ctx = Arrays.asList(new DefaultAuditContext("name", "value"));
    auditor.audit(PRINCIPAL, UNIT_TEST_EVENT, ctx);
}
Also used : DefaultAuditContext(org.nhindirect.common.audit.DefaultAuditContext) Test(org.junit.Test)

Aggregations

DefaultAuditContext (org.nhindirect.common.audit.DefaultAuditContext)17 Test (org.junit.Test)15 AuditEvent (org.nhindirect.common.audit.AuditEvent)13 CompositeData (javax.management.openmbean.CompositeData)11 LoggingAuditor (org.nhindirect.common.audit.impl.LoggingAuditor)2 NHINDAddress (org.nhindirect.stagent.NHINDAddress)2 OutgoingMessage (org.nhindirect.stagent.OutgoingMessage)2 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 MessagingException (javax.mail.MessagingException)1 MimeMessage (javax.mail.internet.MimeMessage)1 AuditContext (org.nhindirect.common.audit.AuditContext)1 Auditor (org.nhindirect.common.audit.Auditor)1 MultiProviderAuditor (org.nhindirect.common.audit.impl.MultiProviderAuditor)1 NoOpAuditor (org.nhindirect.common.audit.impl.NoOpAuditor)1 AgentException (org.nhindirect.stagent.AgentException)1 DefaultMessageEnvelope (org.nhindirect.stagent.DefaultMessageEnvelope)1 IncomingMessage (org.nhindirect.stagent.IncomingMessage)1