Skip to content

Commit

Permalink
SD-1823 Revisit the OVS checks with unit test cases (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
preetamnpr authored Dec 15, 2024
1 parent acc052c commit 9410509
Show file tree
Hide file tree
Showing 13 changed files with 1,195 additions and 255 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.dcsa.conformance.core.traffic.ConformanceExchange;
import org.dcsa.conformance.core.traffic.HttpMessageType;


class JsonAttributeBasedCheck extends ActionCheck {

private final String standardsVersion;
Expand Down
6 changes: 6 additions & 0 deletions ovs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,11 @@
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!-- Test scoped dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -35,38 +35,38 @@ public static LinkedHashMap<String, OvsScenarioListBuilder> createModuleScenario
.thenEither(
scenarioWithParameters(Map.of(CARRIER_SERVICE_NAME, "Great Lion Service")),
scenarioWithParameters(
Map.of(CARRIER_SERVICE_NAME, "Blue Whale Service", LIMIT, "1")),
Map.of(CARRIER_SERVICE_NAME, "Blue Whale Service", LIMIT, "5")),
scenarioWithParameters(
Map.of(
CARRIER_SERVICE_NAME,
"Red Falcon Service",
START_DATE,
"2026-01-01")),
"2024-01-01")),
scenarioWithParameters(
Map.of(
CARRIER_SERVICE_NAME,
"Great Lion Service",
END_DATE,
"2021-01-01")),
"2025-01-01")),
scenarioWithParameters(Map.of(CARRIER_SERVICE_CODE, "BW1")),
scenarioWithParameters(Map.of(CARRIER_SERVICE_CODE, "BW1", LIMIT, "1")),
scenarioWithParameters(Map.of(CARRIER_SERVICE_CODE, "BW1", LIMIT, "5")),
scenarioWithParameters(Map.of(UNIVERSAL_SERVICE_REFERENCE, "SR12345A")),
scenarioWithParameters(
Map.of(UNIVERSAL_SERVICE_REFERENCE, "SR67890B", LIMIT, "1")))),
Map.of(UNIVERSAL_SERVICE_REFERENCE, "SR67890B", LIMIT, "5")))),
Map.entry(
"Vessel schedules",
noAction()
.thenEither(
scenarioWithParameters(Map.of(VESSEL_IMO_NUMBER, "9456789")),
scenarioWithParameters(Map.of(VESSEL_IMO_NUMBER, "9876543", LIMIT, "1")))),
scenarioWithParameters(Map.of(VESSEL_IMO_NUMBER, "9876543", LIMIT, "5")))),
Map.entry(
"Location schedules",
noAction()
.thenEither(
scenarioWithParameters(Map.of(UN_LOCATION_CODE, "NLAMS")),
scenarioWithParameters(Map.of(UN_LOCATION_CODE, "USNYC", LIMIT, "1")),
scenarioWithParameters(Map.of(UN_LOCATION_CODE, "USNYC", LIMIT, "5")),
scenarioWithParameters(Map.of(FACILITY_SMDG_CODE, "APM")),
scenarioWithParameters(Map.of(FACILITY_SMDG_CODE, "APM", LIMIT, "1")))),
scenarioWithParameters(Map.of(FACILITY_SMDG_CODE, "APM", LIMIT, "5")))),
Map.entry(
"Voyage schedules",
noAction()
Expand All @@ -79,7 +79,7 @@ public static LinkedHashMap<String, OvsScenarioListBuilder> createModuleScenario
Map.of(
CARRIER_VOYAGE_NUMBER, "2104S",
CARRIER_SERVICE_CODE, "BW1",
LIMIT, "1")),
LIMIT, "5")),
scenarioWithParameters(
Map.of(
CARRIER_VOYAGE_NUMBER, "2103N",
Expand All @@ -88,7 +88,7 @@ public static LinkedHashMap<String, OvsScenarioListBuilder> createModuleScenario
Map.of(
CARRIER_VOYAGE_NUMBER, "2103S",
UNIVERSAL_SERVICE_REFERENCE, "SR12345A",
LIMIT, "1")),
LIMIT, "5")),
scenarioWithParameters(
Map.of(
UNIVERSAL_VOYAGE_REFERENCE, "2103N",
Expand All @@ -97,7 +97,7 @@ public static LinkedHashMap<String, OvsScenarioListBuilder> createModuleScenario
Map.of(
UNIVERSAL_VOYAGE_REFERENCE, "2103S",
CARRIER_SERVICE_CODE, "FE1",
LIMIT, "1")),
LIMIT, "5")),
scenarioWithParameters(
Map.of(
UNIVERSAL_VOYAGE_REFERENCE, "2105N",
Expand All @@ -106,7 +106,7 @@ public static LinkedHashMap<String, OvsScenarioListBuilder> createModuleScenario
Map.of(
UNIVERSAL_VOYAGE_REFERENCE, "2105S",
UNIVERSAL_SERVICE_REFERENCE, "SR54321C",
LIMIT, "1")))))
LIMIT, "5")))))
.collect(
Collectors.toMap(
Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.Arrays;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

import lombok.Getter;
import org.dcsa.conformance.core.UserFacingException;
import org.dcsa.conformance.standards.ovs.party.OvsFilterParameter;
import org.dcsa.conformance.standards.ovs.party.SuppliedScenarioParameters;

Expand Down Expand Up @@ -90,6 +97,48 @@ public boolean isInputRequired() {
@Override
public void handlePartyInput(JsonNode partyInput) {
super.handlePartyInput(partyInput);
suppliedScenarioParameters = SuppliedScenarioParameters.fromJson(partyInput.get("input"));
JsonNode inputNode = partyInput.get("input");
Set<String> inputKeys =
StreamSupport.stream(
((Iterable<String>) inputNode::fieldNames)
.spliterator(),
false)
.collect(Collectors.toSet());

Set<String> missingKeys =
StreamSupport.stream(
((Iterable<String>) () -> getJsonForHumanReadablePrompt().fieldNames())
.spliterator(),
false)
.collect(Collectors.toSet());
missingKeys.removeAll(inputKeys);
if (!missingKeys.isEmpty()) {
throw new UserFacingException(
"The input must contain: %s".formatted(String.join(", ", missingKeys)));
}

Arrays.stream(OvsFilterParameter.values())
.map(OvsFilterParameter::getQueryParamName)
.filter(
queryParamName ->
queryParamName.startsWith(
OvsFilterParameter.START_DATE.getQueryParamName())
|| queryParamName.startsWith(OvsFilterParameter.END_DATE.getQueryParamName()))
.filter(inputNode::hasNonNull)
.forEach(
queryParamName -> {
String dateValue = inputNode.path(queryParamName).asText();
try {
LocalDate.parse(dateValue, DateTimeFormatter.ISO_DATE);
} catch (DateTimeParseException e) {
throw new UserFacingException(
"Invalid date-time format '%s' for input parameter '%s'"
.formatted(dateValue, queryParamName),
e);
}
});

suppliedScenarioParameters = SuppliedScenarioParameters.fromJson(inputNode);

}
}
Loading

0 comments on commit 9410509

Please sign in to comment.