DefaultAuditService implements AuditService { @Override public void audit(final JsonEnvelope envelope, final String component) { final String actionName = envelope.metadata().name(); if (auditBlacklistPattern.matcher(actionName).matches()) { logger.info(format("Skipping auditing of action %s due to configured blacklist pattern %s.", actionName, auditBlacklist)); } else { auditClient.auditEntry(envelope, component); } }  @PostConstruct void initialise(); @Override void audit(final JsonEnvelope envelope, final String component);  }
@Test public void shouldAuditWithDefaultEmptyBlacklist() throws Exception { initialisePattern(""); auditService.audit(jsonEnvelope, COMPONENT); verify(auditClient, times(1)).auditEntry(jsonEnvelope, COMPONENT); }
@Test public void shouldAuditNonBlacklistedAction() throws Exception { initialisePattern(".*\\.action"); when(metadata.name()).thenReturn("some-action"); auditService.audit(jsonEnvelope, COMPONENT); verify(auditClient, times(1)).auditEntry(jsonEnvelope, COMPONENT); }
@Test public void shouldNotAuditBlacklistedAction() { initialisePattern(".*\\.action"); auditService.audit(jsonEnvelope, COMPONENT); verify(logger, times(1)).info("Skipping auditing of action test.action due to configured blacklist pattern .*\\.action."); verify(auditClient, never()).auditEntry(jsonEnvelope, COMPONENT); }