Search in sources :

Example 1 with EventDetails

use of uk.gov.ida.hub.shared.eventsink.EventDetails in project verify-hub by alphagov.

the class ExceptionAuditorTest method shouldAuditUnauditedException.

@Test
public void shouldAuditUnauditedException() {
    DateTime expectedTimestamp = DateTime.now();
    DateTimeFreezer.freezeTime(expectedTimestamp);
    final UUID errorId = UUID.randomUUID();
    ApplicationException exception = createUnauditedException(ExceptionType.DUPLICATE_SESSION, errorId, URI.create("/some-uri"));
    exceptionAuditor.auditException(exception, Optional.of(SESSION_ID));
    ArgumentCaptor<EventDetails> argumentCaptor = ArgumentCaptor.forClass(EventDetails.class);
    verify(eventSinkMessageSender).audit(eq(exception), eq(errorId), eq(SESSION_ID), argumentCaptor.capture());
    final EventDetails event = argumentCaptor.getValue();
    assertThat(event.getKey()).isEqualTo(downstream_uri);
    assertThat(event.getValue()).isEqualTo(exception.getUri().get().toASCIIString());
}
Also used : ApplicationException(uk.gov.ida.exceptions.ApplicationException) UUID(java.util.UUID) DateTime(org.joda.time.DateTime) EventDetails(uk.gov.ida.hub.shared.eventsink.EventDetails) Test(org.junit.jupiter.api.Test)

Example 2 with EventDetails

use of uk.gov.ida.hub.shared.eventsink.EventDetails in project verify-hub by alphagov.

the class ExceptionAuditor method auditException.

public boolean auditException(ApplicationException exception, Optional<SessionId> sessionId) {
    boolean isAudited = exception.isAudited();
    if (!isAudited && exception.requiresAuditing()) {
        EventDetails eventDetails = new EventDetails(downstream_uri, exception.getUri().orElse(URI.create("uri-not-present")).toASCIIString());
        eventSinkMessageSender.audit(exception, exception.getErrorId(), sessionId.orElse(SessionId.NO_SESSION_CONTEXT_IN_ERROR), eventDetails);
        isAudited = true;
    }
    return isAudited;
}
Also used : EventDetails(uk.gov.ida.hub.shared.eventsink.EventDetails)

Aggregations

EventDetails (uk.gov.ida.hub.shared.eventsink.EventDetails)2 UUID (java.util.UUID)1 DateTime (org.joda.time.DateTime)1 Test (org.junit.jupiter.api.Test)1 ApplicationException (uk.gov.ida.exceptions.ApplicationException)1