@Test public void testAvailableFieldFunctions() { Slf4jAuditLoggerConfig configMock = mock(Slf4jAuditLoggerConfig.class); Map<String, Function<AuditEntry, Object>> availableFieldFunctions = Slf4jAuditLogger.getAvailableFieldFunctionMap(configMock); assertThat(availableFieldFunctions).containsOnlyKeys("CLIENT_IP", "CLIENT_PORT", "COORDINATOR_IP", "USER", "BATCH_ID", "STATUS", "OPERATION", "OPERATION_NAKED", "TIMESTAMP", "SUBJECT"); Function<AuditEntry, Object> clientFunction = availableFieldFunctions.get("CLIENT_IP"); assertThat(clientFunction.apply(logEntryWithAll)).isEqualTo(EXPECTED_CLIENT_ADDRESS); Function<AuditEntry, Object> clientIpFunction = availableFieldFunctions.get("CLIENT_PORT"); assertThat(clientIpFunction.apply(logEntryWithAll)).isEqualTo(EXPECTED_CLIENT_PORT); assertThat(clientIpFunction.apply(logEntryWithoutClientPort)).isEqualTo(null); Function<AuditEntry, Object> coordinatorFunction = availableFieldFunctions.get("COORDINATOR_IP"); assertThat(coordinatorFunction.apply(logEntryWithAll)).isEqualTo(EXPECTED_COORDINATOR_ADDRESS); Function<AuditEntry, Object> userFunction = availableFieldFunctions.get("USER"); assertThat(userFunction.apply(logEntryWithAll)).isEqualTo(EXPECTED_USER); Function<AuditEntry, Object> batchIdFunction = availableFieldFunctions.get("BATCH_ID"); assertThat(batchIdFunction.apply(logEntryWithAll)).isEqualTo(EXPECTED_BATCH_ID); assertThat(batchIdFunction.apply(logEntryWithoutBatch)).isEqualTo(null); Function<AuditEntry, Object> statusFunction = availableFieldFunctions.get("STATUS"); assertThat(statusFunction.apply(logEntryWithAll)).isEqualTo(EXPECTED_STATUS); Function<AuditEntry, Object> operationFunction = availableFieldFunctions.get("OPERATION"); assertThat(operationFunction.apply(logEntryWithAll)).isEqualTo(EXPECTED_STATEMENT); Function<AuditEntry, Object> operationNakedFunction = availableFieldFunctions.get("OPERATION_NAKED"); assertThat(operationNakedFunction.apply(logEntryWithAll)).isEqualTo(EXPECTED_STATEMENT_NAKED); Function<AuditEntry, Object> timestampFunction = availableFieldFunctions.get("TIMESTAMP"); assertThat(timestampFunction.apply(logEntryWithAll)).isEqualTo(EXPECTED_TIMESTAMP); Function<AuditEntry, Object> subjectFunction = availableFieldFunctions.get("SUBJECT"); assertThat(subjectFunction.apply(logEntryWithAll)).isEqualTo(EXPECTED_SUBJECT); assertThat(subjectFunction.apply(logEntryWithoutSubject)).isEqualTo(null); }
static Map<String, Function<AuditEntry, Object>> getAvailableFieldFunctionMap(Slf4jAuditLoggerConfig auditConfig) { return ImmutableMap.<String, Function<AuditEntry, Object>>builder() .put("CLIENT_IP", entry -> getIpOrNull(entry.getClientAddress())) .put("CLIENT_PORT", entry -> getPortOrNull(entry.getClientAddress())) .put("COORDINATOR_IP", entry -> entry.getCoordinatorAddress().getHostAddress()) .put("USER", AuditEntry::getUser) .put("BATCH_ID", entry -> entry.getBatchId().orElse(null)) .put("STATUS", AuditEntry::getStatus) .put("OPERATION", entry -> entry.getOperation().getOperationString()) .put("OPERATION_NAKED", entry -> entry.getOperation().getNakedOperationString()) .put("TIMESTAMP", getTimeFunction(auditConfig)) .put("SUBJECT", entry -> entry.getSubject().orElse(null)) .build(); }
Slf4jAuditLogger implements AuditLogger { static Map<String, Function<AuditEntry, Object>> getAvailableFieldFunctionMap(Slf4jAuditLoggerConfig auditConfig) { return ImmutableMap.<String, Function<AuditEntry, Object>>builder() .put("CLIENT_IP", entry -> getIpOrNull(entry.getClientAddress())) .put("CLIENT_PORT", entry -> getPortOrNull(entry.getClientAddress())) .put("COORDINATOR_IP", entry -> entry.getCoordinatorAddress().getHostAddress()) .put("USER", AuditEntry::getUser) .put("BATCH_ID", entry -> entry.getBatchId().orElse(null)) .put("STATUS", AuditEntry::getStatus) .put("OPERATION", entry -> entry.getOperation().getOperationString()) .put("OPERATION_NAKED", entry -> entry.getOperation().getNakedOperationString()) .put("TIMESTAMP", getTimeFunction(auditConfig)) .put("SUBJECT", entry -> entry.getSubject().orElse(null)) .build(); } }
Slf4jAuditLogger implements AuditLogger { static Map<String, Function<AuditEntry, Object>> getAvailableFieldFunctionMap(Slf4jAuditLoggerConfig auditConfig) { return ImmutableMap.<String, Function<AuditEntry, Object>>builder() .put("CLIENT_IP", entry -> getIpOrNull(entry.getClientAddress())) .put("CLIENT_PORT", entry -> getPortOrNull(entry.getClientAddress())) .put("COORDINATOR_IP", entry -> entry.getCoordinatorAddress().getHostAddress()) .put("USER", AuditEntry::getUser) .put("BATCH_ID", entry -> entry.getBatchId().orElse(null)) .put("STATUS", AuditEntry::getStatus) .put("OPERATION", entry -> entry.getOperation().getOperationString()) .put("OPERATION_NAKED", entry -> entry.getOperation().getNakedOperationString()) .put("TIMESTAMP", getTimeFunction(auditConfig)) .put("SUBJECT", entry -> entry.getSubject().orElse(null)) .build(); } Slf4jAuditLogger(Map<String, String> parameters); @VisibleForTesting  Slf4jAuditLogger(Map<String, String> parameters, String loggerName); @VisibleForTesting  Slf4jAuditLogger(Slf4jAuditLoggerConfig auditConfig, Logger logger); }
Slf4jAuditLogger implements AuditLogger { static Map<String, Function<AuditEntry, Object>> getAvailableFieldFunctionMap(Slf4jAuditLoggerConfig auditConfig) { return ImmutableMap.<String, Function<AuditEntry, Object>>builder() .put("CLIENT_IP", entry -> getIpOrNull(entry.getClientAddress())) .put("CLIENT_PORT", entry -> getPortOrNull(entry.getClientAddress())) .put("COORDINATOR_IP", entry -> entry.getCoordinatorAddress().getHostAddress()) .put("USER", AuditEntry::getUser) .put("BATCH_ID", entry -> entry.getBatchId().orElse(null)) .put("STATUS", AuditEntry::getStatus) .put("OPERATION", entry -> entry.getOperation().getOperationString()) .put("OPERATION_NAKED", entry -> entry.getOperation().getNakedOperationString()) .put("TIMESTAMP", getTimeFunction(auditConfig)) .put("SUBJECT", entry -> entry.getSubject().orElse(null)) .build(); } Slf4jAuditLogger(Map<String, String> parameters); @VisibleForTesting  Slf4jAuditLogger(Map<String, String> parameters, String loggerName); @VisibleForTesting  Slf4jAuditLogger(Slf4jAuditLoggerConfig auditConfig, Logger logger); @Override void log(AuditEntry logEntry); }
Slf4jAuditLogger implements AuditLogger { static Map<String, Function<AuditEntry, Object>> getAvailableFieldFunctionMap(Slf4jAuditLoggerConfig auditConfig) { return ImmutableMap.<String, Function<AuditEntry, Object>>builder() .put("CLIENT_IP", entry -> getIpOrNull(entry.getClientAddress())) .put("CLIENT_PORT", entry -> getPortOrNull(entry.getClientAddress())) .put("COORDINATOR_IP", entry -> entry.getCoordinatorAddress().getHostAddress()) .put("USER", AuditEntry::getUser) .put("BATCH_ID", entry -> entry.getBatchId().orElse(null)) .put("STATUS", AuditEntry::getStatus) .put("OPERATION", entry -> entry.getOperation().getOperationString()) .put("OPERATION_NAKED", entry -> entry.getOperation().getNakedOperationString()) .put("TIMESTAMP", getTimeFunction(auditConfig)) .put("SUBJECT", entry -> entry.getSubject().orElse(null)) .build(); } Slf4jAuditLogger(Map<String, String> parameters); @VisibleForTesting  Slf4jAuditLogger(Map<String, String> parameters, String loggerName); @VisibleForTesting  Slf4jAuditLogger(Slf4jAuditLoggerConfig auditConfig, Logger logger); @Override void log(AuditEntry logEntry); static final String AUDIT_LOGGER_NAME; }