Skip to content

Commit

Permalink
DT-786 second set of changes for Complex validations and Scenario checks
Browse files Browse the repository at this point in the history
  • Loading branch information
preetamnpr committed Feb 28, 2024
1 parent 15e12ae commit 0e52833
Show file tree
Hide file tree
Showing 4 changed files with 379 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.dcsa.conformance.core.toolkit.JsonToolkit;
import org.dcsa.conformance.core.traffic.ConformanceExchange;
import org.dcsa.conformance.core.traffic.HttpMessageType;
import org.dcsa.conformance.standards.booking.checks.BookingChecks;
import org.dcsa.conformance.standards.booking.checks.CarrierGetBookingPayloadResponseConformanceCheck;
import org.dcsa.conformance.standards.booking.party.BookingRole;
import org.dcsa.conformance.standards.booking.party.BookingState;
Expand Down Expand Up @@ -87,41 +88,7 @@ protected Stream<? extends ConformanceCheck> createSubChecks() {
expectedBookingStatus,
expectedAmendedBookingStatus,
requestAmendedContent),
new ActionCheck(
"GET returns the expected Booking data",
BookingRole::isCarrier,
getMatchedExchangeUuid(),
HttpMessageType.RESPONSE) {
@Override
protected Set<String> checkConformance(
Function<UUID, ConformanceExchange> getExchangeByUuid) {
ConformanceExchange getExchange = getExchangeByUuid.apply(getMatchedExchangeUuid());
if (getExchange == null) return Set.of();
Set<String> conformanceErrors = new HashSet<>();
if (previousAction
instanceof UC1_Shipper_SubmitBookingRequestAction submitBookingRequestAction) {
ConformanceExchange submitBookingRequestExchange =
getExchangeByUuid.apply(submitBookingRequestAction.getMatchedExchangeUuid());
if (submitBookingRequestExchange == null) return Set.of();
// this is just an example
String uc1CarrierServiceName =
JsonToolkit.getTextAttributeOrNull(
submitBookingRequestExchange.getRequest().message().body().getJsonBody(),
"carrierServiceName");
String getCarrierServiceName =
JsonToolkit.getTextAttributeOrNull(
getExchange.getResponse().message().body().getJsonBody(),
"carrierServiceName");
if (!Objects.equals(uc1CarrierServiceName, getCarrierServiceName)) {
conformanceErrors.add(
"Expected carrierServiceName '%s' but found '%s'"
.formatted(uc1CarrierServiceName, getCarrierServiceName));
}
}
return conformanceErrors;
}
})
// .filter(Objects::nonNull)
BookingChecks.responseContentChecks(getMatchedExchangeUuid(), getCspSupplier(), getDspSupplier(), expectedBookingStatus, expectedAmendedBookingStatus))
;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
import lombok.extern.slf4j.Slf4j;
import org.dcsa.conformance.core.check.*;
import org.dcsa.conformance.core.traffic.HttpMessageType;
import org.dcsa.conformance.standards.booking.checks.BookingChecks;
import org.dcsa.conformance.standards.booking.checks.CarrierBookingRefStatusPayloadResponseConformanceCheck;
import org.dcsa.conformance.standards.booking.checks.ScenarioType;
import org.dcsa.conformance.standards.booking.checks.ShipperBookingContentConformanceCheck;
import org.dcsa.conformance.standards.booking.party.BookingRole;
import org.dcsa.conformance.standards.booking.party.BookingState;

Expand Down Expand Up @@ -56,7 +55,6 @@ public ConformanceCheck createCheck(String expectedApiVersion) {
return new ConformanceCheck(getActionTitle()) {
@Override
protected Stream<? extends ConformanceCheck> createSubChecks() {
var scenarioType = getDspSupplier().get().scenarioType();
Stream<ActionCheck> primaryExchangeChecks =
Stream.of(
new HttpMethodCheck(BookingRole::isShipper, getMatchedExchangeUuid(), "POST"),
Expand All @@ -77,7 +75,7 @@ protected Stream<? extends ConformanceCheck> createSubChecks() {
getMatchedExchangeUuid(),
BookingState.RECEIVED
),
new ShipperBookingContentConformanceCheck(getMatchedExchangeUuid(),scenarioType),
BookingChecks.requestContentChecks(getMatchedExchangeUuid(), getCspSupplier(), getDspSupplier()),
new JsonSchemaCheck(
BookingRole::isShipper,
getMatchedExchangeUuid(),
Expand Down
Loading

0 comments on commit 0e52833

Please sign in to comment.