From 2cc303e0f2bb6e19edf2fa04f4ec435e3a66b8cf Mon Sep 17 00:00:00 2001 From: "J. Koster" Date: Tue, 26 Nov 2024 11:34:22 +0100 Subject: [PATCH] Generic improvements * Add useful Javadoc * Remove redundant code * Remove double logging of partyInput * Fix comparison of incompatible types * Fix Python method naming in TnT * Apply @ParameterizedTest pattern on TnT --- .../adoption/party/FilterParameter.java | 9 - .../core/check/JsonSchemaCheck.java | 3 - .../EndpointUriOverrideConfiguration.java | 10 +- .../core/party/ScenarioParameters.java | 16 +- .../core/scenario/ConformanceAction.java | 5 + .../core/scenario/ConformanceScenario.java | 2 +- .../conformance/core/toolkit/JsonToolkit.java | 2 +- .../sandbox/ConformanceOrchestrator.java | 13 +- .../standards/tnt/action/TntAction.java | 9 +- .../standards/tnt/checks/TntChecks.java | 21 +- .../standards/tnt/party/SortDirection.java | 2 +- .../standards/tnt/checks/TntChecksTest.java | 248 +++++++++--------- 12 files changed, 169 insertions(+), 171 deletions(-) diff --git a/adoption/src/main/java/org/dcsa/conformance/standards/adoption/party/FilterParameter.java b/adoption/src/main/java/org/dcsa/conformance/standards/adoption/party/FilterParameter.java index c1ae9c93..83d8e492 100644 --- a/adoption/src/main/java/org/dcsa/conformance/standards/adoption/party/FilterParameter.java +++ b/adoption/src/main/java/org/dcsa/conformance/standards/adoption/party/FilterParameter.java @@ -1,9 +1,5 @@ package org.dcsa.conformance.standards.adoption.party; -import java.util.Arrays; -import java.util.Map; -import java.util.function.Function; -import java.util.stream.Collectors; import lombok.Getter; @Getter @@ -17,9 +13,4 @@ public enum FilterParameter { this.queryParamName = queryParamName; } - public static final Map byQueryParamName = - Arrays.stream(values()) - .collect( - Collectors.toUnmodifiableMap( - FilterParameter::getQueryParamName, Function.identity())); } diff --git a/core/src/main/java/org/dcsa/conformance/core/check/JsonSchemaCheck.java b/core/src/main/java/org/dcsa/conformance/core/check/JsonSchemaCheck.java index 4e29a62d..ab3068cd 100644 --- a/core/src/main/java/org/dcsa/conformance/core/check/JsonSchemaCheck.java +++ b/core/src/main/java/org/dcsa/conformance/core/check/JsonSchemaCheck.java @@ -5,12 +5,10 @@ import java.util.UUID; import java.util.function.Function; import java.util.function.Predicate; - import org.dcsa.conformance.core.traffic.ConformanceExchange; import org.dcsa.conformance.core.traffic.HttpMessageType; public class JsonSchemaCheck extends ActionCheck { - private final HttpMessageType httpMessageType; private final JsonSchemaValidator jsonSchemaValidator; public JsonSchemaCheck( @@ -34,7 +32,6 @@ public JsonSchemaCheck( isRelevantForRoleName, matchedExchangeUuid, httpMessageType); - this.httpMessageType = httpMessageType; this.jsonSchemaValidator = jsonSchemaValidator; } diff --git a/core/src/main/java/org/dcsa/conformance/core/party/EndpointUriOverrideConfiguration.java b/core/src/main/java/org/dcsa/conformance/core/party/EndpointUriOverrideConfiguration.java index 5bf99d48..a7dcb0ea 100644 --- a/core/src/main/java/org/dcsa/conformance/core/party/EndpointUriOverrideConfiguration.java +++ b/core/src/main/java/org/dcsa/conformance/core/party/EndpointUriOverrideConfiguration.java @@ -1,16 +1,10 @@ package org.dcsa.conformance.core.party; import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.ToString; +import lombok.Data; -@Getter -@Setter -@ToString +@Data @AllArgsConstructor -@NoArgsConstructor public class EndpointUriOverrideConfiguration { private String method; private String endpointBaseUri; diff --git a/core/src/main/java/org/dcsa/conformance/core/party/ScenarioParameters.java b/core/src/main/java/org/dcsa/conformance/core/party/ScenarioParameters.java index 1378b481..fdd4acc5 100644 --- a/core/src/main/java/org/dcsa/conformance/core/party/ScenarioParameters.java +++ b/core/src/main/java/org/dcsa/conformance/core/party/ScenarioParameters.java @@ -4,10 +4,24 @@ import com.fasterxml.jackson.databind.node.ObjectNode; +/** + * Interface to support Supplied and Dynamic Scenario Parameters. + * + *

SuppliedScenarioParameters (SSP): mechanism that allows an adopter to "parameterize" a + * scenario by providing certain config values without which the synthetic party in the sandbox + * could not send requests that the actual implementation would be able to accept. Usually provided + * by one party, sometimes with separate implementations for both parties. + * + *

DynamicScenarioParameters (DSP): parameters that get captured by the orchestrator while the + * scenario unfolds, by analyzing the traffic data. How to use them: when the Orchestrator calls the + * handleExchange() of the Action class, that action probably needs to save these ids in the DSP so + * that they can be picked up and embedded in the JSON description of subsequent actions. + * + *

SSP and DSP are both captured by actions and saved as part of the orchestrator's state. + */ public interface ScenarioParameters { default ObjectNode toJson() { return OBJECT_MAPPER.valueToTree(this); } - } diff --git a/core/src/main/java/org/dcsa/conformance/core/scenario/ConformanceAction.java b/core/src/main/java/org/dcsa/conformance/core/scenario/ConformanceAction.java index 1f3e9368..03bc4ce6 100644 --- a/core/src/main/java/org/dcsa/conformance/core/scenario/ConformanceAction.java +++ b/core/src/main/java/org/dcsa/conformance/core/scenario/ConformanceAction.java @@ -101,6 +101,11 @@ public boolean isConfirmationRequired() { return false; } + /** + * Whether the action requires input from the user. Overwrite this method to return true if required. + * + * @return true if the action requires input. + */ public boolean isInputRequired() { return false; } diff --git a/core/src/main/java/org/dcsa/conformance/core/scenario/ConformanceScenario.java b/core/src/main/java/org/dcsa/conformance/core/scenario/ConformanceScenario.java index cb9d856b..390b8b7a 100644 --- a/core/src/main/java/org/dcsa/conformance/core/scenario/ConformanceScenario.java +++ b/core/src/main/java/org/dcsa/conformance/core/scenario/ConformanceScenario.java @@ -84,7 +84,7 @@ public ConformanceAction peekNextAction() { public ConformanceAction popNextAction() { ConformanceAction poppedAction = nextActions.pop(); log.info( - "Popped from scenario '%s' action: %s".formatted(toString(), poppedAction.getActionTitle())); + "Popped from scenario '%s', current action: %s".formatted(toString(), poppedAction.getActionTitle())); return poppedAction; } diff --git a/core/src/main/java/org/dcsa/conformance/core/toolkit/JsonToolkit.java b/core/src/main/java/org/dcsa/conformance/core/toolkit/JsonToolkit.java index c0b2cb05..5cc51b35 100644 --- a/core/src/main/java/org/dcsa/conformance/core/toolkit/JsonToolkit.java +++ b/core/src/main/java/org/dcsa/conformance/core/toolkit/JsonToolkit.java @@ -42,7 +42,7 @@ public static JsonNode templateFileToJsonNode( } if (replacements != null) replacements.forEach( - (key, value) -> jsonString.set(jsonString.get().replaceAll(key, value))); + (key, value) -> jsonString.set(jsonString.get().replace(key, value))); return OBJECT_MAPPER.readTree(jsonString.get()); } diff --git a/sandbox/src/main/java/org/dcsa/conformance/sandbox/ConformanceOrchestrator.java b/sandbox/src/main/java/org/dcsa/conformance/sandbox/ConformanceOrchestrator.java index d2a59163..f2f4d32e 100644 --- a/sandbox/src/main/java/org/dcsa/conformance/sandbox/ConformanceOrchestrator.java +++ b/sandbox/src/main/java/org/dcsa/conformance/sandbox/ConformanceOrchestrator.java @@ -231,27 +231,22 @@ public JsonNode handleGetPartyPrompt(String partyName) { public void handlePartyInput(JsonNode partyInput) { log.info("ConformanceOrchestrator.handlePartyInput(%s)".formatted(partyInput.toPrettyString())); if (currentScenarioId == null) { - log.info( - "Ignoring party input %s: no scenario is currently active" - .formatted(partyInput.toPrettyString())); + log.info("Ignoring party input: no scenario is currently active"); return; } ConformanceScenario currentScenario = _getCurrentScenario(); ConformanceAction nextAction = currentScenario.peekNextAction(); if (nextAction == null) { - log.info( - "Ignoring party input %s: the active scenario has no next action" - .formatted(partyInput.toPrettyString())); + log.info("Ignoring party input: the active scenario has no next action"); return; } String actionId = partyInput.get("actionId").asText(); if (!Objects.equals(actionId, nextAction.getId().toString())) { log.info( - "Ignoring party input %s: the expected next action id is %s in current scenario %s" - .formatted( - partyInput.toPrettyString(), nextAction.getId(), currentScenario.toString())); + "Ignoring party input: the expected next action id is %s in current scenario %s" + .formatted(nextAction.getId(), currentScenario.toString())); return; } diff --git a/tnt/src/main/java/org/dcsa/conformance/standards/tnt/action/TntAction.java b/tnt/src/main/java/org/dcsa/conformance/standards/tnt/action/TntAction.java index 14546256..b266cef6 100644 --- a/tnt/src/main/java/org/dcsa/conformance/standards/tnt/action/TntAction.java +++ b/tnt/src/main/java/org/dcsa/conformance/standards/tnt/action/TntAction.java @@ -1,5 +1,7 @@ package org.dcsa.conformance.standards.tnt.action; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ObjectNode; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Collection; @@ -8,9 +10,6 @@ import java.util.Optional; import java.util.function.Function; import java.util.function.Supplier; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ObjectNode; import lombok.extern.slf4j.Slf4j; import org.dcsa.conformance.core.scenario.ConformanceAction; import org.dcsa.conformance.core.scenario.OverwritingReference; @@ -24,7 +23,7 @@ public abstract class TntAction extends ConformanceAction { protected final int expectedStatus; private final OverwritingReference dsp; - public TntAction( + protected TntAction( String sourcePartyName, String targetPartyName, TntAction previousAction, @@ -81,7 +80,7 @@ private void updateCursorFromResponsePayload(ConformanceExchange exchange) { } } - if (!dsp.equals(updatedDsp)) dsp.set(updatedDsp); + if (!dsp.get().equals(updatedDsp)) dsp.set(updatedDsp); } private DynamicScenarioParameters updateIfNotNull( diff --git a/tnt/src/main/java/org/dcsa/conformance/standards/tnt/checks/TntChecks.java b/tnt/src/main/java/org/dcsa/conformance/standards/tnt/checks/TntChecks.java index 92ff75ae..d082fe35 100644 --- a/tnt/src/main/java/org/dcsa/conformance/standards/tnt/checks/TntChecks.java +++ b/tnt/src/main/java/org/dcsa/conformance/standards/tnt/checks/TntChecks.java @@ -70,7 +70,7 @@ public static ActionCheck responseContentChecks( .forEach( eventNode -> { eventIndex.incrementAndGet(); - _checkThatEventValuesMatchParamValues(eventNode, filterParametersMap) + checkThatEventValuesMatchParamValues(eventNode, filterParametersMap) .forEach( validationError -> validationErrors.add( @@ -103,7 +103,7 @@ public static ActionCheck responseContentChecks( TntSchemaConformanceCheck.findEventNodes(body).stream() .map( eventNode -> - _stringToOffsetDateTime(eventNode.path("eventCreatedDateTime").asText())) + stringToOffsetDateTime(eventNode.path("eventCreatedDateTime").asText())) .filter(Objects::nonNull) .forEach( eventCreatedDateTime -> { @@ -111,10 +111,10 @@ public static ActionCheck responseContentChecks( eventCreatedDateTimeParams.forEach( entry -> { OffsetDateTime filterParamDateTime = - _stringToOffsetDateTime(entry.getValue()); + stringToOffsetDateTime(entry.getValue()); if (filterParamDateTime != null) { String validationError = - _validateEventCreatedDateTime( + validateEventCreatedDateTime( eventCreatedDateTime, entry.getKey(), filterParamDateTime); if (validationError != null) { validationErrors.add( @@ -147,7 +147,7 @@ public static ActionCheck responseContentChecks( TntRole::isPublisher, matched, HttpMessageType.RESPONSE, standardVersion, checks); } - private static OffsetDateTime _stringToOffsetDateTime(String dateTimeString) { + private static OffsetDateTime stringToOffsetDateTime(String dateTimeString) { try { return OffsetDateTime.parse(dateTimeString); } catch (DateTimeParseException e) { @@ -155,7 +155,7 @@ private static OffsetDateTime _stringToOffsetDateTime(String dateTimeString) { } } - static TntEventType _getEventType(JsonNode eventNode) { + static TntEventType getEventType(JsonNode eventNode) { return Arrays.stream(TntEventType.values()) .filter( eventType -> eventType.name().equalsIgnoreCase(eventNode.path("eventType").asText())) @@ -163,9 +163,9 @@ static TntEventType _getEventType(JsonNode eventNode) { .orElse(null); } - static Set _checkThatEventValuesMatchParamValues( + static Set checkThatEventValuesMatchParamValues( JsonNode eventNode, Map filterParametersMap) { - TntEventType eventType = _getEventType(eventNode); + TntEventType eventType = getEventType(eventNode); if (eventType == null) return Set.of(); Set validationErrors = new LinkedHashSet<>(); Arrays.stream(TntFilterParameter.values()) @@ -246,10 +246,9 @@ static Set _checkThatEventValuesMatchParamValues( return validationErrors; } - static String _validateEventCreatedDateTime(OffsetDateTime eventCreatedDateTime, TntFilterParameter parameterKey, OffsetDateTime parameterValue) { + static String validateEventCreatedDateTime(OffsetDateTime eventCreatedDateTime, TntFilterParameter parameterKey, OffsetDateTime parameterValue) { switch (parameterKey) { - case EVENT_CREATED_DATE_TIME: - case EVENT_CREATED_DATE_TIME_EQ: + case EVENT_CREATED_DATE_TIME, EVENT_CREATED_DATE_TIME_EQ: if (!eventCreatedDateTime.isEqual(parameterValue)) return "eventCreatedDateTime '%s' does not equal filter parameter date time '%s'" .formatted(eventCreatedDateTime, parameterValue); diff --git a/tnt/src/main/java/org/dcsa/conformance/standards/tnt/party/SortDirection.java b/tnt/src/main/java/org/dcsa/conformance/standards/tnt/party/SortDirection.java index b5cc7b6a..4b60ed83 100644 --- a/tnt/src/main/java/org/dcsa/conformance/standards/tnt/party/SortDirection.java +++ b/tnt/src/main/java/org/dcsa/conformance/standards/tnt/party/SortDirection.java @@ -2,5 +2,5 @@ public enum SortDirection { ASC, - DESC; + DESC } diff --git a/tnt/src/test/java/org/dcsa/conformance/standards/tnt/checks/TntChecksTest.java b/tnt/src/test/java/org/dcsa/conformance/standards/tnt/checks/TntChecksTest.java index cccae1b9..687e52c3 100644 --- a/tnt/src/test/java/org/dcsa/conformance/standards/tnt/checks/TntChecksTest.java +++ b/tnt/src/test/java/org/dcsa/conformance/standards/tnt/checks/TntChecksTest.java @@ -1,57 +1,61 @@ package org.dcsa.conformance.standards.tnt.checks; -import static org.junit.jupiter.api.Assertions.*; import static org.dcsa.conformance.standards.tnt.action.TntEventType.*; import static org.dcsa.conformance.standards.tnt.party.TntFilterParameter.*; +import static org.junit.jupiter.api.Assertions.*; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; -import org.dcsa.conformance.core.toolkit.JsonToolkit; -import org.dcsa.conformance.standards.tnt.action.TntEventType; -import org.dcsa.conformance.standards.tnt.party.TntFilterParameter; -import org.junit.jupiter.api.Test; - import java.time.OffsetDateTime; import java.util.Arrays; import java.util.Map; import java.util.stream.Collectors; import java.util.stream.Stream; +import org.dcsa.conformance.core.toolkit.JsonToolkit; +import org.dcsa.conformance.standards.tnt.action.TntEventType; +import org.dcsa.conformance.standards.tnt.party.TntFilterParameter; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; class TntChecksTest { private static final OffsetDateTime TODAY = OffsetDateTime.now(); private static final OffsetDateTime TOMORROW = TODAY.plusDays(1); - @Test - void testValidateEventCreatedDateTime() { - _check(TODAY, EVENT_CREATED_DATE_TIME_LT, TODAY, false); - _check(TODAY, EVENT_CREATED_DATE_TIME_LTE, TODAY, true); - _check(TODAY, EVENT_CREATED_DATE_TIME, TODAY, true); - _check(TODAY, EVENT_CREATED_DATE_TIME_EQ, TODAY, true); - _check(TODAY, EVENT_CREATED_DATE_TIME_GTE, TODAY, true); - _check(TODAY, EVENT_CREATED_DATE_TIME_GT, TODAY, false); + private static Stream testValidateEventCreatedDateTime() { + return Stream.of( + Arguments.of(TODAY, EVENT_CREATED_DATE_TIME_LT, TODAY, false), + Arguments.of(TODAY, EVENT_CREATED_DATE_TIME_LTE, TODAY, true), + Arguments.of(TODAY, EVENT_CREATED_DATE_TIME, TODAY, true), + Arguments.of(TODAY, EVENT_CREATED_DATE_TIME_EQ, TODAY, true), + Arguments.of(TODAY, EVENT_CREATED_DATE_TIME_GTE, TODAY, true), + Arguments.of(TODAY, EVENT_CREATED_DATE_TIME_GT, TODAY, false), - _check(TODAY, EVENT_CREATED_DATE_TIME_LT, TOMORROW, true); - _check(TODAY, EVENT_CREATED_DATE_TIME_LTE, TOMORROW, true); - _check(TODAY, EVENT_CREATED_DATE_TIME, TOMORROW, false); - _check(TODAY, EVENT_CREATED_DATE_TIME_EQ, TOMORROW, false); - _check(TODAY, EVENT_CREATED_DATE_TIME_GTE, TOMORROW, false); - _check(TODAY, EVENT_CREATED_DATE_TIME_GT, TOMORROW, false); + Arguments.of(TODAY, EVENT_CREATED_DATE_TIME_LT, TOMORROW, true), + Arguments.of(TODAY, EVENT_CREATED_DATE_TIME_LTE, TOMORROW, true), + Arguments.of(TODAY, EVENT_CREATED_DATE_TIME, TOMORROW, false), + Arguments.of(TODAY, EVENT_CREATED_DATE_TIME_EQ, TOMORROW, false), + Arguments.of(TODAY, EVENT_CREATED_DATE_TIME_GTE, TOMORROW, false), + Arguments.of(TODAY, EVENT_CREATED_DATE_TIME_GT, TOMORROW, false), - _check(TOMORROW, EVENT_CREATED_DATE_TIME_LT, TODAY, false); - _check(TOMORROW, EVENT_CREATED_DATE_TIME_LTE, TODAY, false); - _check(TOMORROW, EVENT_CREATED_DATE_TIME, TODAY, false); - _check(TOMORROW, EVENT_CREATED_DATE_TIME_EQ, TODAY, false); - _check(TOMORROW, EVENT_CREATED_DATE_TIME_GTE, TODAY, true); - _check(TOMORROW, EVENT_CREATED_DATE_TIME_GT, TODAY, true); + Arguments.of(TOMORROW, EVENT_CREATED_DATE_TIME_LT, TODAY, false), + Arguments.of(TOMORROW, EVENT_CREATED_DATE_TIME_LTE, TODAY, false), + Arguments.of(TOMORROW, EVENT_CREATED_DATE_TIME, TODAY, false), + Arguments.of(TOMORROW, EVENT_CREATED_DATE_TIME_EQ, TODAY, false), + Arguments.of(TOMORROW, EVENT_CREATED_DATE_TIME_GTE, TODAY, true), + Arguments.of(TOMORROW, EVENT_CREATED_DATE_TIME_GT, TODAY, true)); } - private void _check( + @ParameterizedTest() + @MethodSource("testValidateEventCreatedDateTime") + void testValidateEventCreatedDateTime( OffsetDateTime left, TntFilterParameter operator, OffsetDateTime right, boolean expectedResult) { - String validationError = TntChecks._validateEventCreatedDateTime(left, operator, right); + String validationError = TntChecks.validateEventCreatedDateTime(left, operator, right); if (expectedResult) { assertNull( validationError, @@ -68,148 +72,148 @@ private void _check( @Test void testMatchingCbrAndTrd() { ArrayNode documentReferencesArray = - _arrayOfNodes( - _documentReferenceNode("BKG", "bkg123"), - _documentReferenceNode("BKG", "bkg234"), - _documentReferenceNode("TRD", "trd123"), - _documentReferenceNode("TRD", "trd234")); + arrayOfNodes( + documentReferenceNode("BKG", "bkg123"), + documentReferenceNode("BKG", "bkg234"), + documentReferenceNode("TRD", "trd123"), + documentReferenceNode("TRD", "trd234")); Stream.of(TRANSPORT, EQUIPMENT) .forEach( eventType -> { ObjectNode eventWithCBR = - _withChildNode( - _eventJsonObject(eventType), "documentReferences", documentReferencesArray); + withChildNode( + eventJsonObject(eventType), "documentReferences", documentReferencesArray); assertTrue( - TntChecks._checkThatEventValuesMatchParamValues( + TntChecks.checkThatEventValuesMatchParamValues( eventWithCBR, - _filterParameters( + filterParameters( eventType, Map.entry(CARRIER_BOOKING_REFERENCE, "bkg234"))) .isEmpty()); assertFalse( - TntChecks._checkThatEventValuesMatchParamValues( + TntChecks.checkThatEventValuesMatchParamValues( eventWithCBR, - _filterParameters( + filterParameters( eventType, Map.entry(CARRIER_BOOKING_REFERENCE, "wrong"))) .isEmpty()); assertFalse( - TntChecks._checkThatEventValuesMatchParamValues( + TntChecks.checkThatEventValuesMatchParamValues( eventWithCBR, - _filterParameters( + filterParameters( eventType, Map.entry(CARRIER_BOOKING_REFERENCE, "trd123"))) .isEmpty()); assertTrue( - TntChecks._checkThatEventValuesMatchParamValues( + TntChecks.checkThatEventValuesMatchParamValues( eventWithCBR, - _filterParameters( + filterParameters( eventType, Map.entry(TRANSPORT_DOCUMENT_REFERENCE, "trd123"))) .isEmpty()); assertFalse( - TntChecks._checkThatEventValuesMatchParamValues( + TntChecks.checkThatEventValuesMatchParamValues( eventWithCBR, - _filterParameters( + filterParameters( eventType, Map.entry(TRANSPORT_DOCUMENT_REFERENCE, "wrong"))) .isEmpty()); assertFalse( - TntChecks._checkThatEventValuesMatchParamValues( + TntChecks.checkThatEventValuesMatchParamValues( eventWithCBR, - _filterParameters( + filterParameters( eventType, Map.entry(TRANSPORT_DOCUMENT_REFERENCE, "bkg123"))) .isEmpty()); }); assertTrue( - TntChecks._checkThatEventValuesMatchParamValues( - _eventJsonObject(SHIPMENT) + TntChecks.checkThatEventValuesMatchParamValues( + eventJsonObject(SHIPMENT) .put("documentID", "bkg123") .put("documentTypeCode", "BKG"), - _filterParameters(SHIPMENT, Map.entry(CARRIER_BOOKING_REFERENCE, "bkg123"))) + filterParameters(SHIPMENT, Map.entry(CARRIER_BOOKING_REFERENCE, "bkg123"))) .isEmpty()); assertFalse( - TntChecks._checkThatEventValuesMatchParamValues( - _eventJsonObject(SHIPMENT) + TntChecks.checkThatEventValuesMatchParamValues( + eventJsonObject(SHIPMENT) .put("documentID", "bkg234") .put("documentTypeCode", "BKG"), - _filterParameters(SHIPMENT, Map.entry(CARRIER_BOOKING_REFERENCE, "bkg123"))) + filterParameters(SHIPMENT, Map.entry(CARRIER_BOOKING_REFERENCE, "bkg123"))) .isEmpty()); assertTrue( - TntChecks._checkThatEventValuesMatchParamValues( - _eventJsonObject(SHIPMENT) + TntChecks.checkThatEventValuesMatchParamValues( + eventJsonObject(SHIPMENT) .put("documentID", "bkg234") .put( "documentTypeCode", "CBR"), // which means something else in this context :| - _filterParameters(SHIPMENT, Map.entry(CARRIER_BOOKING_REFERENCE, "bkg123"))) + filterParameters(SHIPMENT, Map.entry(CARRIER_BOOKING_REFERENCE, "bkg123"))) .isEmpty()); assertTrue( - TntChecks._checkThatEventValuesMatchParamValues( - _eventJsonObject(SHIPMENT) + TntChecks.checkThatEventValuesMatchParamValues( + eventJsonObject(SHIPMENT) .put("documentID", "trd123") .put("documentTypeCode", "TRD"), - _filterParameters(SHIPMENT, Map.entry(TRANSPORT_DOCUMENT_REFERENCE, "trd123"))) + filterParameters(SHIPMENT, Map.entry(TRANSPORT_DOCUMENT_REFERENCE, "trd123"))) .isEmpty()); assertFalse( - TntChecks._checkThatEventValuesMatchParamValues( - _eventJsonObject(SHIPMENT) + TntChecks.checkThatEventValuesMatchParamValues( + eventJsonObject(SHIPMENT) .put("documentID", "trd123") .put("documentTypeCode", "TRD"), - _filterParameters(SHIPMENT, Map.entry(TRANSPORT_DOCUMENT_REFERENCE, "wrong"))) + filterParameters(SHIPMENT, Map.entry(TRANSPORT_DOCUMENT_REFERENCE, "wrong"))) .isEmpty()); } @Test void testMatchingDocumentTypeCode() { assertTrue( - TntChecks._checkThatEventValuesMatchParamValues( - _eventJsonObject(SHIPMENT).put("documentTypeCode", "CBR"), - _filterParameters(SHIPMENT, Map.entry(DOCUMENT_TYPE_CODE, "CBR"))) + TntChecks.checkThatEventValuesMatchParamValues( + eventJsonObject(SHIPMENT).put("documentTypeCode", "CBR"), + filterParameters(SHIPMENT, Map.entry(DOCUMENT_TYPE_CODE, "CBR"))) .isEmpty()); assertFalse( - TntChecks._checkThatEventValuesMatchParamValues( - _eventJsonObject(SHIPMENT).put("documentTypeCode", "CBR"), - _filterParameters(SHIPMENT, Map.entry(DOCUMENT_TYPE_CODE, "BKG"))) + TntChecks.checkThatEventValuesMatchParamValues( + eventJsonObject(SHIPMENT).put("documentTypeCode", "CBR"), + filterParameters(SHIPMENT, Map.entry(DOCUMENT_TYPE_CODE, "BKG"))) .isEmpty()); assertTrue( - TntChecks._checkThatEventValuesMatchParamValues( - _eventJsonObject(SHIPMENT).put("documentTypeCode", "CBR"), - _filterParameters(SHIPMENT, Map.entry(DOCUMENT_TYPE_CODE, "CBR,BKG"))) + TntChecks.checkThatEventValuesMatchParamValues( + eventJsonObject(SHIPMENT).put("documentTypeCode", "CBR"), + filterParameters(SHIPMENT, Map.entry(DOCUMENT_TYPE_CODE, "CBR,BKG"))) .isEmpty()); } @Test void testMatchingEventTypeCodes() { assertTrue( - TntChecks._checkThatEventValuesMatchParamValues( - _eventJsonObject(TRANSPORT).put("transportEventTypeCode", "ARRI"), - _filterParameters(TRANSPORT, Map.entry(TRANSPORT_EVENT_TYPE_CODE, "ARRI"))) + TntChecks.checkThatEventValuesMatchParamValues( + eventJsonObject(TRANSPORT).put("transportEventTypeCode", "ARRI"), + filterParameters(TRANSPORT, Map.entry(TRANSPORT_EVENT_TYPE_CODE, "ARRI"))) .isEmpty()); assertFalse( - TntChecks._checkThatEventValuesMatchParamValues( - _eventJsonObject(TRANSPORT).put("transportEventTypeCode", "ARRI"), - _filterParameters(TRANSPORT, Map.entry(TRANSPORT_EVENT_TYPE_CODE, "DEPA"))) + TntChecks.checkThatEventValuesMatchParamValues( + eventJsonObject(TRANSPORT).put("transportEventTypeCode", "ARRI"), + filterParameters(TRANSPORT, Map.entry(TRANSPORT_EVENT_TYPE_CODE, "DEPA"))) .isEmpty()); assertTrue( - TntChecks._checkThatEventValuesMatchParamValues( - _eventJsonObject(SHIPMENT).put("shipmentEventTypeCode", "RECE"), - _filterParameters(SHIPMENT, Map.entry(SHIPMENT_EVENT_TYPE_CODE, "RECE"))) + TntChecks.checkThatEventValuesMatchParamValues( + eventJsonObject(SHIPMENT).put("shipmentEventTypeCode", "RECE"), + filterParameters(SHIPMENT, Map.entry(SHIPMENT_EVENT_TYPE_CODE, "RECE"))) .isEmpty()); assertFalse( - TntChecks._checkThatEventValuesMatchParamValues( - _eventJsonObject(SHIPMENT).put("shipmentEventTypeCode", "RECE"), - _filterParameters(SHIPMENT, Map.entry(SHIPMENT_EVENT_TYPE_CODE, "DRFT"))) + TntChecks.checkThatEventValuesMatchParamValues( + eventJsonObject(SHIPMENT).put("shipmentEventTypeCode", "RECE"), + filterParameters(SHIPMENT, Map.entry(SHIPMENT_EVENT_TYPE_CODE, "DRFT"))) .isEmpty()); assertTrue( - TntChecks._checkThatEventValuesMatchParamValues( - _eventJsonObject(EQUIPMENT).put("equipmentEventTypeCode", "LOAD"), - _filterParameters(EQUIPMENT, Map.entry(EQUIPMENT_EVENT_TYPE_CODE, "LOAD"))) + TntChecks.checkThatEventValuesMatchParamValues( + eventJsonObject(EQUIPMENT).put("equipmentEventTypeCode", "LOAD"), + filterParameters(EQUIPMENT, Map.entry(EQUIPMENT_EVENT_TYPE_CODE, "LOAD"))) .isEmpty()); assertFalse( - TntChecks._checkThatEventValuesMatchParamValues( - _eventJsonObject(EQUIPMENT).put("equipmentEventTypeCode", "LOAD"), - _filterParameters(EQUIPMENT, Map.entry(EQUIPMENT_EVENT_TYPE_CODE, "DISC"))) + TntChecks.checkThatEventValuesMatchParamValues( + eventJsonObject(EQUIPMENT).put("equipmentEventTypeCode", "LOAD"), + filterParameters(EQUIPMENT, Map.entry(EQUIPMENT_EVENT_TYPE_CODE, "DISC"))) .isEmpty()); } @@ -219,10 +223,10 @@ void testMatchingVesselImoNumber() { .forEach( eventType -> { ObjectNode eventWithVesselImo = - _withChildNode( - _eventJsonObject(eventType), + withChildNode( + eventJsonObject(eventType), "transportCall", - _withChildNode( + withChildNode( JsonToolkit.OBJECT_MAPPER.createObjectNode(), "vessel", JsonToolkit.OBJECT_MAPPER @@ -230,14 +234,14 @@ void testMatchingVesselImoNumber() { .put("vesselIMONumber", "1234567"))); assertTrue( - TntChecks._checkThatEventValuesMatchParamValues( + TntChecks.checkThatEventValuesMatchParamValues( eventWithVesselImo, - _filterParameters(eventType, Map.entry(VESSEL_IMO_NUMBER, "1234567"))) + filterParameters(eventType, Map.entry(VESSEL_IMO_NUMBER, "1234567"))) .isEmpty()); assertFalse( - TntChecks._checkThatEventValuesMatchParamValues( + TntChecks.checkThatEventValuesMatchParamValues( eventWithVesselImo, - _filterParameters(eventType, Map.entry(VESSEL_IMO_NUMBER, "2345678"))) + filterParameters(eventType, Map.entry(VESSEL_IMO_NUMBER, "2345678"))) .isEmpty()); }); } @@ -245,87 +249,87 @@ void testMatchingVesselImoNumber() { @Test void testMatchingEquipmentReferences() { ObjectNode equipmentEvent = - _withChildNode( - _eventJsonObject(EQUIPMENT).put("equipmentReference", "ASDF1234567"), + withChildNode( + eventJsonObject(EQUIPMENT).put("equipmentReference", "ASDF1234567"), "references", - _arrayOfNodes(_referenceNode("EQ", "ASDF2345678"), _referenceNode("FF", "ff123"))); + arrayOfNodes(referenceNode("EQ", "ASDF2345678"), referenceNode("FF", "ff123"))); assertTrue( - TntChecks._checkThatEventValuesMatchParamValues( + TntChecks.checkThatEventValuesMatchParamValues( equipmentEvent, - _filterParameters(EQUIPMENT, Map.entry(EQUIPMENT_REFERENCE, "ASDF1234567"))) + filterParameters(EQUIPMENT, Map.entry(EQUIPMENT_REFERENCE, "ASDF1234567"))) .isEmpty()); assertTrue( - TntChecks._checkThatEventValuesMatchParamValues( + TntChecks.checkThatEventValuesMatchParamValues( equipmentEvent, - _filterParameters(EQUIPMENT, Map.entry(EQUIPMENT_REFERENCE, "ASDF2345678"))) + filterParameters(EQUIPMENT, Map.entry(EQUIPMENT_REFERENCE, "ASDF2345678"))) .isEmpty()); assertFalse( - TntChecks._checkThatEventValuesMatchParamValues( + TntChecks.checkThatEventValuesMatchParamValues( equipmentEvent, - _filterParameters(EQUIPMENT, Map.entry(EQUIPMENT_REFERENCE, "ff123"))) + filterParameters(EQUIPMENT, Map.entry(EQUIPMENT_REFERENCE, "ff123"))) .isEmpty()); assertFalse( - TntChecks._checkThatEventValuesMatchParamValues( + TntChecks.checkThatEventValuesMatchParamValues( equipmentEvent, - _filterParameters(EQUIPMENT, Map.entry(EQUIPMENT_REFERENCE, "wrong"))) + filterParameters(EQUIPMENT, Map.entry(EQUIPMENT_REFERENCE, "wrong"))) .isEmpty()); } @Test void testMatchingUnLocationCode() { ObjectNode eventWithVesselImo = - _withChildNode( - _withChildNode( - _eventJsonObject(EQUIPMENT), + withChildNode( + withChildNode( + eventJsonObject(EQUIPMENT), "eventLocation", JsonToolkit.OBJECT_MAPPER.createObjectNode().put("UNLocationCode", "FRPAR")), "transportCall", JsonToolkit.OBJECT_MAPPER.createObjectNode().put("UNLocationCode", "DEHAM")); assertTrue( - TntChecks._checkThatEventValuesMatchParamValues( + TntChecks.checkThatEventValuesMatchParamValues( eventWithVesselImo, - _filterParameters(EQUIPMENT, Map.entry(UN_LOCATION_CODE, "FRPAR"))) + filterParameters(EQUIPMENT, Map.entry(UN_LOCATION_CODE, "FRPAR"))) .isEmpty()); assertTrue( - TntChecks._checkThatEventValuesMatchParamValues( + TntChecks.checkThatEventValuesMatchParamValues( eventWithVesselImo, - _filterParameters(EQUIPMENT, Map.entry(UN_LOCATION_CODE, "DEHAM"))) + filterParameters(EQUIPMENT, Map.entry(UN_LOCATION_CODE, "DEHAM"))) .isEmpty()); assertFalse( - TntChecks._checkThatEventValuesMatchParamValues( + TntChecks.checkThatEventValuesMatchParamValues( eventWithVesselImo, - _filterParameters(EQUIPMENT, Map.entry(UN_LOCATION_CODE, "NLRTM"))) + filterParameters(EQUIPMENT, Map.entry(UN_LOCATION_CODE, "NLRTM"))) .isEmpty()); } - private static ObjectNode _withChildNode( + private static ObjectNode withChildNode( ObjectNode parentNode, String childName, JsonNode childNode) { parentNode.set(childName, childNode); return parentNode; } - private static ArrayNode _arrayOfNodes(JsonNode... elementNodes) { + private static ArrayNode arrayOfNodes(JsonNode... elementNodes) { ArrayNode arrayNode = JsonToolkit.OBJECT_MAPPER.createArrayNode(); Arrays.stream(elementNodes).forEach(arrayNode::add); return arrayNode; } - private static ObjectNode _documentReferenceNode(String type, String value) { + private static ObjectNode documentReferenceNode(String type, String value) { return JsonToolkit.OBJECT_MAPPER .createObjectNode() .put("documentReferenceType", type) .put("documentReferenceValue", value); } - private static ObjectNode _referenceNode(String type, String value) { + private static ObjectNode referenceNode(String type, String value) { return JsonToolkit.OBJECT_MAPPER .createObjectNode() .put("referenceType", type) .put("referenceValue", value); } - private static ObjectNode _eventJsonObject(TntEventType eventType) { + private static ObjectNode eventJsonObject(TntEventType eventType) { return JsonToolkit.OBJECT_MAPPER .createObjectNode() .put(EVENT_TYPE.getQueryParamName(), eventType.name()); @@ -333,7 +337,7 @@ private static ObjectNode _eventJsonObject(TntEventType eventType) { @SafeVarargs @SuppressWarnings("varargs") - private static Map _filterParameters( + private static Map filterParameters( TntEventType eventType, Map.Entry... mapEntryStream) { return Stream.concat( Stream.of(Map.entry(EVENT_TYPE, eventType.name())), Arrays.stream(mapEntryStream))