### Question:
AbstractRestletAccessAuditFilter extends Filter { @Override protected int beforeHandle(Request request, Response response) { try { Representation representation = request.getEntity(); if (representation.isTransient()) { request.setEntity(new BufferingRepresentation(request.getEntity())); } auditAccessAttempt(request); } catch (AuditException e) { debug.error("Unable to publish {} audit event '{}' due to error: {} [{}]", ACCESS_TOPIC, EventName.AM_ACCESS_ATTEMPT, e.getMessage(), e); } return CONTINUE; } AbstractRestletAccessAuditFilter(Component component, Restlet restlet,
            AuditEventPublisher auditEventPublisher, AuditEventFactory auditEventFactory,
            RestletBodyAuditor<?> requestDetailCreator, RestletBodyAuditor<?> responseDetailCreator);   }### Answer:
@Test public void shouldCaptureRequestBodyProperties() throws Exception { auditFilter = new RestletAccessAuditFilterTest(restlet, eventPublisher, eventFactory, RestletBodyAuditor.jsonAuditor("fred"), RestletBodyAuditor.jsonAuditor("gary")); Request request = new Request(); request.setDate(newDate()); Response response = new Response(request); request.setEntity(new JsonRepresentation((Map<String, Object>) object(field("fred", "v"), field("gary", 7)))); when(eventPublisher.isAuditing(nullable(String.class), nullable(String.class), nullable(EventName.class))).thenReturn(true); auditFilter.beforeHandle(request, response); ArgumentCaptor<AuditEvent> captor = ArgumentCaptor.forClass(AuditEvent.class); verify(eventPublisher).tryPublish(nullable(String.class), captor.capture()); assertThat(captor.getValue().getValue()).isObject() .hasObject("request") .hasObject("detail") .contains("fred", "v"); }
@Test public void shouldCaptureRequestBodyProperties() throws Exception { auditFilter = new RestletAccessAuditFilterTest(restlet, eventPublisher, eventFactory, RestletBodyAuditor.jsonAuditor("fred"), RestletBodyAuditor.jsonAuditor("gary")); Request request = new Request(); request.setDate(new Date()); Response response = new Response(request); request.setEntity(new JsonRepresentation((Map<String, Object>) object(field("fred", "v"), field("gary", 7)))); when(eventPublisher.isAuditing(anyString(), anyString(), any(EventName.class))).thenReturn(true); auditFilter.beforeHandle(request, response); ArgumentCaptor<AuditEvent> captor = ArgumentCaptor.forClass(AuditEvent.class); verify(eventPublisher).tryPublish(anyString(), captor.capture()); assertThat(captor.getValue().getValue()).isObject() .hasObject("request") .hasObject("detail") .contains("fred", "v"); }