use of org.cloudfoundry.identity.uaa.audit.AuditEventType in project uaa by cloudfoundry.
the class AuditCheckMockMvcTests method assertSingleClientAdminAuditEventFiredWith.
private void assertSingleClientAdminAuditEventFiredWith(AuditEventType expectedEventType, String[] expectedScopes, String[] expectedAuthorities) {
List<AbstractUaaEvent> events = testListener.getEvents().stream().filter(e -> e instanceof AbstractClientAdminEvent).collect(Collectors.toList());
assertNotNull(events);
assertEquals(1, events.size());
AbstractUaaEvent event = events.get(0);
assertEquals(expectedEventType, event.getAuditEvent().getType());
ArgumentCaptor<AuditEvent> captor = ArgumentCaptor.forClass(AuditEvent.class);
verify(mockAuditService, atLeast(1)).log(captor.capture(), anyString());
List<AuditEvent> auditEvents = captor.getAllValues().stream().filter(e -> e.getType() == expectedEventType).collect(Collectors.toList());
assertNotNull(auditEvents);
assertEquals(1, auditEvents.size());
AuditEvent auditEvent = auditEvents.get(0);
String auditEventData = auditEvent.getData();
assertNotNull(auditEventData);
Map<String, Object> map = JsonUtils.readValue(auditEventData, new TypeReference<Map<String, Object>>() {
});
List<String> auditScopes = (List<String>) map.get("scopes");
List<String> auditAuthorities = (List<String>) map.get("authorities");
assertNotNull(auditScopes);
assertNotNull(auditAuthorities);
assertThat(auditScopes, containsInAnyOrder(expectedScopes));
assertThat(auditAuthorities, containsInAnyOrder(expectedAuthorities));
}
Aggregations