use of org.nhindirect.common.audit.DefaultAuditContext 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);
}
use of org.nhindirect.common.audit.DefaultAuditContext in project nhin-d by DirectProject.
the class LoggingAuditorTest method testAuditWithContext.
@Test
public void testAuditWithContext() {
LoggingAuditor auditor = new LoggingAuditor();
Collection<? extends AuditContext> ctx = Arrays.asList(new DefaultAuditContext("name", "value"));
auditor.audit(PRINCIPAL, UNIT_TEST_EVENT, ctx);
}
use of org.nhindirect.common.audit.DefaultAuditContext in project nhin-d by DirectProject.
the class NoOpAuditorTest method testAuditWithContext.
@Test
public void testAuditWithContext() {
NoOpAuditor auditor = new NoOpAuditor();
Collection<? extends AuditContext> ctx = Arrays.asList(new DefaultAuditContext("name", "value"));
auditor.audit(PRINCIPAL, UNIT_TEST_EVENT, ctx);
}
use of org.nhindirect.common.audit.DefaultAuditContext in project nhin-d by DirectProject.
the class RDBMSAuditor_writeEventTest method testWriteEvent_withContexts_assertWritten.
@Test
public void testWriteEvent_withContexts_assertWritten() 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]);
}
use of org.nhindirect.common.audit.DefaultAuditContext 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);
}
Aggregations