use of org.nhindirect.common.audit.AuditEvent in project nhin-d by DirectProject.
the class DefaultSmtpAgent method postProcessMessage.
private void postProcessMessage(MessageProcessResult result) {
boolean isOutgoing = (result.getProcessedMessage() instanceof OutgoingMessage);
// check for rejected recipients
if (auditor != null && result.getProcessedMessage().getRejectedRecipients() != null && result.getProcessedMessage().getRejectedRecipients().size() > 0) {
Collection<AuditContext> contexts = createContextCollectionFromMessage(result.getProcessedMessage(), Arrays.asList(AuditEvents.DEFAULT_HEADER_CONTEXT));
StringBuffer rejectedRecips = new StringBuffer();
int cnt = 0;
for (NHINDAddress address : result.getProcessedMessage().getRejectedRecipients()) {
rejectedRecips.append(address.getAddress());
if (++cnt < result.getProcessedMessage().getRejectedRecipients().size())
rejectedRecips.append(", ");
}
contexts.add(new DefaultAuditContext(AuditEvents.REJECTED_RECIPIENTS_CONTEXT, rejectedRecips.toString()));
auditor.audit(PRINICPAL, new AuditEvent(AuditEvents.REJECTED_RECIP_NAME, AuditEvents.EVENT_TYPE), contexts);
}
if (isOutgoing)
postProcessOutgoingMessage(result);
else
postProcessIncomingMessage(result);
}
use of org.nhindirect.common.audit.AuditEvent in project nhin-d by DirectProject.
the class DefaultSmtpAgent_AuditMessage_Test method testAuditIncomingMessage_AssertEventsAudited.
public void testAuditIncomingMessage_AssertEventsAudited() throws Exception {
new TestPlan() {
protected String getMessageToProcess() throws Exception {
return TestUtils.readMessageResource("PlainIncomingMessage.txt");
}
@Override
protected void doAssertions(MessageProcessResult result) throws Exception {
DefaultSmtpAgent smtpAgent = (DefaultSmtpAgent) agent;
assertNotNull(smtpAgent.getAuditor());
assertTrue(smtpAgent.getAuditor() instanceof MockAuditor);
assertTrue(auditor.getEvents().size() > 0);
boolean foundIncomingType = false;
boolean foundMDNType = false;
for (Entry<AuditEvent, Collection<? extends AuditContext>> entry : auditor.getEvents().entrySet()) {
AuditEvent event = entry.getKey();
assertEquals(event.getType(), "SMTP Direct Message Processing");
if (event.getName().equals(AuditEvents.INCOMING_MESSAGE_NAME))
foundIncomingType = true;
else if (event.getName().equals(AuditEvents.PRODUCE_MDN_NAME)) {
boolean foundFinalRecip = false;
boolean foundOrigMsgId = false;
boolean foundDisp = false;
for (AuditContext ctx : entry.getValue()) {
if (ctx.getContextName().equals(MDNStandard.Headers.FinalRecipient)) {
foundFinalRecip = true;
} else if (ctx.getContextName().equals(MDNStandard.Headers.OriginalMessageID)) {
foundOrigMsgId = true;
} else if (ctx.getContextName().equals(MDNStandard.Headers.Disposition)) {
assertEquals("automatic-action/MDN-sent-automatically;processed", ctx.getContextValue());
foundDisp = true;
}
}
assertTrue(foundFinalRecip);
assertTrue(foundOrigMsgId);
assertTrue(foundDisp);
foundMDNType = true;
// assert attributes of the event
}
}
assertTrue(foundIncomingType);
assertTrue(foundMDNType);
}
}.perform();
}
use of org.nhindirect.common.audit.AuditEvent 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]);
}
use of org.nhindirect.common.audit.AuditEvent 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);
}
use of org.nhindirect.common.audit.AuditEvent in project nhin-d by DirectProject.
the class FileAuditorTest method testGetLastEvent_AssertRecordContent.
@Test
public void testGetLastEvent_AssertRecordContent() {
FileAuditor auditor = new FileAuditor(auditFile);
AuditEvent event1 = new AuditEvent("Category" + UUID.randomUUID(), "type");
AuditEvent event2 = new AuditEvent("Category" + UUID.randomUUID(), "type");
auditor.audit(PRINCIPAL, event1);
auditor.audit(PRINCIPAL, event2);
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"));
}
Aggregations