Skip to content

Commit

Permalink
DT-836 [1/?]: Add additional scenarios
Browse files Browse the repository at this point in the history
Signed-off-by: Niels Thykier <[email protected]>
  • Loading branch information
nt-gt committed Jan 15, 2024
1 parent a18b7e1 commit b5d6d0a
Show file tree
Hide file tree
Showing 13 changed files with 243 additions and 140 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ public Carrier_SupplyScenarioParametersAction(String carrierPartyName, @NonNull
carrierPartyName,
null,
null,
switch (scenarioType) {
case REGULAR -> "SupplyCSP";
case REEFER -> "SupplyCSP-AR";
case DG -> "SupplyCSP-DG";
},
"SupplyCSP [%s]".formatted(scenarioType.name()),
-1);
this.scenarioType = scenarioType;
this.getDspConsumer().accept(getDspSupplier().get().withScenarioType(scenarioType));
Expand Down Expand Up @@ -67,7 +63,7 @@ public String getHumanReadablePrompt() {
@Override
public JsonNode getJsonForHumanReadablePrompt() {
var csp = switch (scenarioType) {
case REGULAR -> new CarrierScenarioParameters(
case REGULAR_SWB, REGULAR_BOL -> new CarrierScenarioParameters(
"Booking Reference",
"Commodity subreference for regular (non-DG, non-reefer) cargo",
// Any valid regular equipment reference will do as an example.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public EblAction(
this.dspReference =
previousAction == null
? new OverwritingReference<>(
null, new DynamicScenarioParameters(ScenarioType.REGULAR, null, null, null, null, null))
null, new DynamicScenarioParameters(ScenarioType.REGULAR_SWB, null, null, null, null, null))
: new OverwritingReference<>(previousAction.dspReference, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class Shipper_GetShippingInstructionsAction extends EblAction {
private final JsonSchemaValidator responseSchemaValidator;
private final boolean requestAmendedStatus;
private final boolean recordTDR;
private final boolean useTDRef;

public Shipper_GetShippingInstructionsAction(
String carrierPartyName,
Expand All @@ -25,25 +26,41 @@ public Shipper_GetShippingInstructionsAction(
ShippingInstructionsStatus expectedAmendedSiStatus,
JsonSchemaValidator responseSchemaValidator,
boolean requestAmendedStatus,
boolean recordTDR) {
boolean recordTDR,
boolean useTDRef) {
super(shipperPartyName, carrierPartyName, previousAction, requestAmendedStatus ? "GET aSI" : "GET SI", 200);
this.expectedSiStatus = expectedSiStatus;
this.expectedAmendedSiStatus = expectedAmendedSiStatus;
this.useTDRef = useTDRef;
this.responseSchemaValidator = responseSchemaValidator;
this.requestAmendedStatus = requestAmendedStatus;
this.recordTDR = recordTDR;

if (useTDRef && recordTDR) {
throw new IllegalArgumentException("Cannot use recordTDR with useTDRef");
}
}

@Override
public ObjectNode asJsonNode() {
var dsp = getDspSupplier().get();
var documentReference = this.useTDRef ? dsp.transportDocumentReference() : dsp.shippingInstructionsReference();
if (documentReference == null) {
throw new IllegalStateException("Missing document reference for use-case 3");
}
return super.asJsonNode()
.put("sir", getDspSupplier().get().shippingInstructionsReference());
.put("documentReference", documentReference);
}

@Override
public String getHumanReadablePrompt() {
var dsp = getDspSupplier().get();
var documentReference = this.useTDRef ? dsp.transportDocumentReference() : dsp.shippingInstructionsReference();
if (documentReference == null) {
throw new IllegalStateException("Missing document reference for get SI");
}
return "GET the SI with reference '%s'"
.formatted(getDspSupplier().get().shippingInstructionsReference());
.formatted(documentReference);
}

protected void doHandleExchange(ConformanceExchange exchange) {
Expand All @@ -62,11 +79,13 @@ public ConformanceCheck createCheck(String expectedApiVersion) {
return new ConformanceCheck(getActionTitle()) {
@Override
protected Stream<? extends ConformanceCheck> createSubChecks() {
var dsp = getDspSupplier().get();
var documentReference = useTDRef ? dsp.transportDocumentReference() : dsp.shippingInstructionsReference();
return Stream.of(
new UrlPathCheck(
EblRole::isShipper,
getMatchedExchangeUuid(),
"/v3/shipping-instructions/" + getDspSupplier().get().shippingInstructionsReference()),
"/v3/shipping-instructions/" + documentReference),
new ResponseStatusCheck(
EblRole::isCarrier, getMatchedExchangeUuid(), expectedStatus),
new ApiHeaderCheck(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected Stream<? extends ConformanceCheck> createSubChecks() {
getMatchedExchangeUuid(),
HttpMessageType.RESPONSE,
responseSchemaValidator),
EBLChecks.tdContentChecks(getMatchedExchangeUuid(), expectedTdStatus, getDspSupplier()));
EBLChecks.tdContentChecks(getMatchedExchangeUuid(), expectedTdStatus, getCspSupplier(), getDspSupplier()));
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public String getHumanReadablePrompt() {
public ObjectNode asJsonNode() {
ObjectNode jsonNode = super.asJsonNode();
jsonNode.set("csp", getCspSupplier().get().toJson());
return jsonNode;
return jsonNode.put("scenarioType", getDspSupplier().get().scenarioType().name());
}

@Override
Expand Down Expand Up @@ -78,7 +78,7 @@ protected Stream<? extends ConformanceCheck> createSubChecks() {
getMatchedExchangeUuid(),
HttpMessageType.RESPONSE,
responseSchemaValidator),
EBLChecks.siRequestContentChecks(getMatchedExchangeUuid(), getCspSupplier()));
EBLChecks.siRequestContentChecks(getMatchedExchangeUuid(), getCspSupplier(), getDspSupplier()));
return Stream.concat(
primaryExchangeChecks,
Stream.concat(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@ public class UC3_Shipper_SubmitUpdatedShippingInstructionsAction extends StateCh
private final JsonSchemaValidator requestSchemaValidator;
private final JsonSchemaValidator responseSchemaValidator;
private final JsonSchemaValidator notificationSchemaValidator;
private final boolean useTDRef;

public UC3_Shipper_SubmitUpdatedShippingInstructionsAction(
String carrierPartyName,
String shipperPartyName,
EblAction previousAction,
boolean useTDRef,
JsonSchemaValidator requestSchemaValidator,
JsonSchemaValidator responseSchemaValidator,
JsonSchemaValidator notificationSchemaValidator) {
super(shipperPartyName, carrierPartyName, previousAction, "UC3", 200);
super(shipperPartyName, carrierPartyName, previousAction, "UC3" + (useTDRef ? " [TDR]" : ""), 200);
this.useTDRef = useTDRef;
this.requestSchemaValidator = requestSchemaValidator;
this.responseSchemaValidator = responseSchemaValidator;
this.notificationSchemaValidator = notificationSchemaValidator;
Expand All @@ -38,8 +41,14 @@ public String getHumanReadablePrompt() {

@Override
public ObjectNode asJsonNode() {
var dsp = getDspSupplier().get();
var documentReference = this.useTDRef ? dsp.transportDocumentReference() : dsp.shippingInstructionsReference();
if (documentReference == null) {
throw new IllegalStateException("Missing document reference for use-case 3");
}
return super.asJsonNode()
.put("sir", getDspSupplier().get().shippingInstructionsReference());
.put("sir", dsp.shippingInstructionsReference())
.put("documentReference", documentReference);
}

@Override
Expand All @@ -60,7 +69,7 @@ protected Stream<? extends ConformanceCheck> createSubChecks() {
Stream<ActionCheck> primaryExchangeChecks =
Stream.of(
new HttpMethodCheck(EblRole::isShipper, getMatchedExchangeUuid(), "PUT"),
new UrlPathCheck(EblRole::isShipper, getMatchedExchangeUuid(), "/v3/shipping-instructions/%s".formatted(dsp.shippingInstructionsReference())),
new UrlPathCheck(EblRole::isShipper, getMatchedExchangeUuid(), "/v3/shipping-instructions/%s".formatted(useTDRef ? dsp.transportDocumentReference() : dsp.shippingInstructionsReference())),
new ResponseStatusCheck(
EblRole::isCarrier, getMatchedExchangeUuid(), expectedStatus),
new ApiHeaderCheck(
Expand All @@ -83,7 +92,7 @@ protected Stream<? extends ConformanceCheck> createSubChecks() {
getMatchedExchangeUuid(),
HttpMessageType.RESPONSE,
responseSchemaValidator),
EBLChecks.siRequestContentChecks(getMatchedExchangeUuid(), getCspSupplier())
EBLChecks.siRequestContentChecks(getMatchedExchangeUuid(), getCspSupplier(), getDspSupplier())
);
return Stream.concat(
primaryExchangeChecks,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ public static JsonContentCheck tdrInNotificationMustMatchDSP(Supplier<DynamicSce
return JsonAttribute.mustEqual(TD_NOTIFICATION_TDR_PTR, () -> dspSupplier.get().transportDocumentReference());
}

private static <T> Supplier<T> cspValue(Supplier<CarrierScenarioParameters> cspSupplier, Function<CarrierScenarioParameters, T> field) {
private static <T, O> Supplier<T> delayedValue(Supplier<O> cspSupplier, Function<O, T> field) {
return () -> {
var csp = cspSupplier.get();
if (csp == null) {
Expand All @@ -678,19 +678,24 @@ private static <T> Supplier<T> cspValue(Supplier<CarrierScenarioParameters> cspS
};
}

private static void generateCSPRelatedChecks(List<JsonContentCheck> checks, Supplier<CarrierScenarioParameters> cspSupplier, boolean isTD) {
private static void generateScenarioRelatedChecks(List<JsonContentCheck> checks, Supplier<CarrierScenarioParameters> cspSupplier, Supplier<DynamicScenarioParameters> dspSupplier, boolean isTD) {
checks.add(JsonAttribute.mustEqual(
"[Scenario] Verify that the correct 'transportDocumentTypeCode' is used",
"transportDocumentTypeCode",
delayedValue(dspSupplier, dsp -> dsp.scenarioType().transportDocumentTypeCode())
));
checks.add(JsonAttribute.allIndividualMatchesMustBeValid(
"[Scenario] Verify that the correct 'carrierBookingReference' is used",
mav -> mav.submitAllMatching("consignmentItems.*.carrierBookingReference"),
JsonAttribute.matchedMustEqual(cspValue(cspSupplier, CarrierScenarioParameters::carrierBookingReference))
JsonAttribute.matchedMustEqual(delayedValue(cspSupplier, CarrierScenarioParameters::carrierBookingReference))
));
if (!isTD) {
checks.add(
JsonAttribute.allIndividualMatchesMustBeValid(
"[Scenario] Verify that the correct 'commoditySubreference' is used",
mav -> mav.submitAllMatching("consignmentItems.*.commoditySubreference"),
JsonAttribute.matchedMustEqual(
cspValue(cspSupplier, CarrierScenarioParameters::commoditySubreference))));
delayedValue(cspSupplier, CarrierScenarioParameters::commoditySubreference))));
}
checks.add(JsonAttribute.allIndividualMatchesMustBeValid(
"[Scenario] Verify that the correct 'equipmentReference' is used",
Expand All @@ -700,41 +705,41 @@ private static void generateCSPRelatedChecks(List<JsonContentCheck> checks, Supp
mav.submitAllMatching("utilizedTransportEquipments.*.equipmentReference");
mav.submitAllMatching("utilizedTransportEquipments.*.equipment.equipmentReference");
},
JsonAttribute.matchedMustEqualIfPresent(cspValue(cspSupplier, CarrierScenarioParameters::equipmentReference))
JsonAttribute.matchedMustEqualIfPresent(delayedValue(cspSupplier, CarrierScenarioParameters::equipmentReference))
));
checks.add(JsonAttribute.allIndividualMatchesMustBeValid(
"[Scenario] Verify that the correct 'HSCodes' are used",
mav -> mav.submitAllMatching("consignmentItems.*.HSCodes.*"),
JsonAttribute.matchedMustEqual(cspValue(cspSupplier, CarrierScenarioParameters::consignmentItemHSCode))
JsonAttribute.matchedMustEqual(delayedValue(cspSupplier, CarrierScenarioParameters::consignmentItemHSCode))
));
checks.add(JsonAttribute.allIndividualMatchesMustBeValid(
"[Scenario] Verify that the correct 'descriptionOfGoods' is used",
mav -> mav.submitAllMatching("consignmentItems.*.descriptionOfGoods"),
JsonAttribute.matchedMustEqual(cspValue(cspSupplier, CarrierScenarioParameters::descriptionOfGoods))
JsonAttribute.matchedMustEqual(delayedValue(cspSupplier, CarrierScenarioParameters::descriptionOfGoods))
));

checks.add(JsonAttribute.mustEqual(
"[Scenario] Verify that the correct 'serviceContractReference' is used",
"serviceContractReference",
cspValue(cspSupplier, CarrierScenarioParameters::serviceContractReference)
delayedValue(cspSupplier, CarrierScenarioParameters::serviceContractReference)
));
checks.add(JsonAttribute.mustEqual(
"[Scenario] Verify that the correct 'contractQuotationReference' is used",
"contractQuotationReference",
cspValue(cspSupplier, CarrierScenarioParameters::contractQuotationReference)
delayedValue(cspSupplier, CarrierScenarioParameters::contractQuotationReference)
));

checks.add(JsonAttribute.mustEqual(
"[Scenario] Verify that the correct 'invoicePayableAt' location is used",
SI_REQUEST_INVOICE_PAYABLE_AT_UN_LOCATION_CODE,
cspValue(cspSupplier, CarrierScenarioParameters::invoicePayableAtUNLocationCode)
delayedValue(cspSupplier, CarrierScenarioParameters::invoicePayableAtUNLocationCode)
));
}


public static ActionCheck siRequestContentChecks(UUID matched, Supplier<CarrierScenarioParameters> cspSupplier) {
public static ActionCheck siRequestContentChecks(UUID matched, Supplier<CarrierScenarioParameters> cspSupplier, Supplier<DynamicScenarioParameters> dspSupplier) {
var checks = new ArrayList<>(STATIC_SI_CHECKS);
generateCSPRelatedChecks(checks, cspSupplier, false);
generateScenarioRelatedChecks(checks, cspSupplier, dspSupplier, false);
return JsonAttribute.contentChecks(
EblRole::isShipper,
matched,
Expand Down Expand Up @@ -762,7 +767,7 @@ public static ActionCheck siResponseContentChecks(UUID matched, Supplier<Carrier
checks.add(updatedStatusCheck);
}
checks.addAll(STATIC_SI_CHECKS);
generateCSPRelatedChecks(checks, cspSupplier, true);
generateScenarioRelatedChecks(checks, cspSupplier, dspSupplier, false);
return JsonAttribute.contentChecks(
EblRole::isCarrier,
matched,
Expand Down Expand Up @@ -851,7 +856,7 @@ public static ActionCheck tdNotificationContentChecks(UUID matched, TransportDoc
);
}

public static ActionCheck tdContentChecks(UUID matched, TransportDocumentStatus transportDocumentStatus, Supplier<DynamicScenarioParameters> dspSupplier) {
public static ActionCheck tdContentChecks(UUID matched, TransportDocumentStatus transportDocumentStatus, Supplier<CarrierScenarioParameters> cspSupplier, Supplier<DynamicScenarioParameters> dspSupplier) {
List<JsonContentCheck> jsonContentChecks = new ArrayList<>();
jsonContentChecks.add(JsonAttribute.mustEqual(
TD_TDR,
Expand Down Expand Up @@ -899,6 +904,7 @@ public static ActionCheck tdContentChecks(UUID matched, TransportDocumentStatus
return Set.of();
}
));
generateScenarioRelatedChecks(jsonContentChecks, cspSupplier, dspSupplier, true);
return JsonAttribute.contentChecks(
EblRole::isCarrier,
matched,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
package org.dcsa.conformance.standards.ebl.checks;

public enum ScenarioType {
REGULAR,
REGULAR_SWB,
REGULAR_BOL,
REEFER,
DG,
;

public String transportDocumentTypeCode() {
return this == REGULAR_BOL ? "BOL" : "SWB";
}

public boolean isToOrder() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ private void fixupConsignmentItems(ObjectNode transportDocument, ScenarioType sc
// The alternative is having a look-up table of all known packageCode's and their relevant
// description.
switch (scenarioType) {
case REGULAR ->
case REGULAR_SWB, REGULAR_BOL ->
outerPackaging.put("packageCode", "4G")
.put("description", "Fibreboard boxes");
case REEFER ->
Expand All @@ -527,7 +527,7 @@ private void fixupUtilizedTransportEquipments(ObjectNode transportDocument, Scen
// These code must be aligned with the equipment references.
var containerISOEquipmentCode = switch (scenarioType) {
case REEFER -> "45R1";
case REGULAR -> "22G1";
case REGULAR_SWB, REGULAR_BOL -> "22G1";
case DG -> "22GP";
};
var consignmentItemsNode = transportDocument.path("consignmentItems");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private void supplyScenarioParameters(JsonNode actionPrompt) {
var scenarioType = ScenarioType.valueOf(actionPrompt.required("scenarioType").asText());
CarrierScenarioParameters carrierScenarioParameters =
switch (scenarioType) {
case REGULAR -> new CarrierScenarioParameters(
case REGULAR_SWB, REGULAR_BOL -> new CarrierScenarioParameters(
"CBR_123_REGULAR",
"Some Commodity Subreference 123",
// A "22G1" container - keep aligned with the fixupUtilizedTransportEquipments()
Expand Down
Loading

0 comments on commit b5d6d0a

Please sign in to comment.