Skip to content

Commit

Permalink
DT-1504 202 changes added.
Browse files Browse the repository at this point in the history
  • Loading branch information
preetamnpr committed Sep 27, 2024
1 parent fc20614 commit faa49cf
Show file tree
Hide file tree
Showing 14 changed files with 183 additions and 202 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ public Set<String> getReportRoleNames(
public JsonSchemaValidator getMessageSchemaValidator(String apiName, String jsonSchema) {
String schemaFilePath = "/standards/booking/schemas/booking-%s-v%s0.json"
.formatted(apiName, standardVersion.charAt(0));

return JsonSchemaValidator.getInstance(schemaFilePath, jsonSchema);
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected BookingAction(
this.expectedStatus = expectedStatus;
this.dspReference =
previousAction == null
? new OverwritingReference<>(null, new DynamicScenarioParameters(ScenarioType.REGULAR, null, null, null, null, null, null, null))
? new OverwritingReference<>(null, new DynamicScenarioParameters(ScenarioType.REGULAR, null, null, null, null))
: new OverwritingReference<>(previousAction.dspReference, null);
}

Expand Down Expand Up @@ -127,16 +127,10 @@ protected void updateDSPFromResponsePayload(ConformanceExchange exchange) {
getCbrFromNotificationPayload(requestJsonNode) :
responseJsonNode.path("carrierBookingReference").asText(null);
var newCbrr = responseJsonNode.path("carrierBookingRequestReference").asText(null);
var newBookingStatus = parseBookingState(responseJsonNode.path("bookingStatus").asText(null));
var newAmendedBookingStatus = parseBookingState(responseJsonNode.path("amendedBookingStatus").asText(null));
var newBookingCancellationStatus = parseBookingCancellationState(responseJsonNode.path("bookingCancellationStatus").asText(null));

var updatedDsp = dsp;
updatedDsp = updateIfNotNull(updatedDsp, newCbrr, updatedDsp::withCarrierBookingRequestReference);
updatedDsp = updateIfNotNull(updatedDsp, newCbr, updatedDsp::withCarrierBookingReference);
updatedDsp = updateIfNotNull(updatedDsp, newBookingStatus, updatedDsp::withBookingStatus);
updatedDsp = updateIfNotNull(updatedDsp, newAmendedBookingStatus, updatedDsp::withAmendedBookingStatus);
updatedDsp = updateIfNotNull(updatedDsp, newBookingCancellationStatus, updatedDsp::withBookingCancellationStatus);

updatedDsp = updateDSPFromBookingAction(exchange, updatedDsp);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@
@Getter
public class UC10_Carrier_DeclineBookingAction extends StateChangingBookingAction {
private final JsonSchemaValidator requestSchemaValidator;
private final BookingState expectedAmendedBookingStatus;

public UC10_Carrier_DeclineBookingAction(
String carrierPartyName,
String shipperPartyName,
BookingAction previousAction,
BookingState expectedAmendedBookingStatus,
JsonSchemaValidator requestSchemaValidator) {
super(carrierPartyName, shipperPartyName, previousAction, "UC10", 204);
this.requestSchemaValidator = requestSchemaValidator;
this.expectedAmendedBookingStatus = expectedAmendedBookingStatus;
}

@Override
Expand Down Expand Up @@ -53,7 +56,7 @@ protected Stream<? extends ConformanceCheck> createSubChecks() {
new CarrierBookingNotificationDataPayloadRequestConformanceCheck(
getMatchedExchangeUuid(),
BookingState.DECLINED,
dsp.amendedBookingStatus() != null ? BookingState.AMENDMENT_DECLINED : null),
expectedAmendedBookingStatus),
ApiHeaderCheck.createNotificationCheck(
BookingRole::isCarrier,
getMatchedExchangeUuid(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,21 @@ public class UC11_Shipper_CancelBookingRequestAction extends StateChangingBookin
private final JsonSchemaValidator requestSchemaValidator;
private final JsonSchemaValidator responseSchemaValidator;
private final JsonSchemaValidator notificationSchemaValidator;
private final BookingState expectedBookingStatus;

public UC11_Shipper_CancelBookingRequestAction(
String carrierPartyName,
String shipperPartyName,
BookingAction previousAction,
BookingState expectedBookingStatus,
JsonSchemaValidator requestSchemaValidator,
JsonSchemaValidator responseSchemaValidator,
JsonSchemaValidator notificationSchemaValidator) {
super(shipperPartyName, carrierPartyName, previousAction, "UC11", 200);
super(shipperPartyName, carrierPartyName, previousAction, "UC11", 202);
this.requestSchemaValidator = requestSchemaValidator;
this.responseSchemaValidator = responseSchemaValidator;
this.notificationSchemaValidator = notificationSchemaValidator;
this.expectedBookingStatus = expectedBookingStatus;
}

@Override
Expand Down Expand Up @@ -63,15 +66,7 @@ protected Stream<? extends ConformanceCheck> createSubChecks() {
String cbrr = dsp.carrierBookingRequestReference();
return Stream.concat(
Stream.concat(createPrimarySubChecks("PATCH", expectedApiVersion, "/v2/bookings/%s".formatted(cbrr)),
Stream.of(new CarrierBookingRefStatusPayloadResponseConformanceCheck(
getMatchedExchangeUuid(),
BookingState.CANCELLED
),
new JsonSchemaCheck(
BookingRole::isCarrier,
getMatchedExchangeUuid(),
HttpMessageType.RESPONSE,
responseSchemaValidator),
Stream.of(
new JsonSchemaCheck(
BookingRole::isShipper,
getMatchedExchangeUuid(),
Expand All @@ -80,7 +75,7 @@ protected Stream<? extends ConformanceCheck> createSubChecks() {
getNotificationChecks(
expectedApiVersion,
notificationSchemaValidator,
BookingState.CANCELLED,
expectedBookingStatus,
null));
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import org.dcsa.conformance.core.traffic.ConformanceExchange;
import org.dcsa.conformance.core.traffic.HttpMessageType;
import org.dcsa.conformance.standards.booking.checks.CarrierBookingRefStatusPayloadResponseConformanceCheck;
import org.dcsa.conformance.standards.booking.party.BookingCancellationState;
import org.dcsa.conformance.standards.booking.party.BookingRole;
import org.dcsa.conformance.standards.booking.party.BookingState;
import org.dcsa.conformance.standards.booking.party.DynamicScenarioParameters;

import java.util.Objects;
Expand All @@ -20,18 +22,27 @@ public class UC13ShipperCancelConfirmedBookingAction extends StateChangingBookin
private final JsonSchemaValidator requestSchemaValidator;
private final JsonSchemaValidator responseSchemaValidator;
private final JsonSchemaValidator notificationSchemaValidator;
private final BookingState expectedBookingStatus;
private final BookingState expectedAmendedBookingStatus;
private final BookingCancellationState expectedBookingCancellationStatus;

public UC13ShipperCancelConfirmedBookingAction(
String carrierPartyName,
String shipperPartyName,
BookingAction previousAction,
BookingState expectedBookingStatus,
BookingState expectedAmendedBookingStatus,
BookingCancellationState expectedBookingCancellationStatus,
JsonSchemaValidator requestSchemaValidator,
JsonSchemaValidator responseSchemaValidator,
JsonSchemaValidator notificationSchemaValidator) {
super(shipperPartyName, carrierPartyName, previousAction, "UC13", 200);
super(shipperPartyName, carrierPartyName, previousAction, "UC13", 202);
this.requestSchemaValidator = requestSchemaValidator;
this.responseSchemaValidator = responseSchemaValidator;
this.notificationSchemaValidator = notificationSchemaValidator;
this.expectedBookingStatus = expectedBookingStatus;
this.expectedAmendedBookingStatus = expectedAmendedBookingStatus;
this.expectedBookingCancellationStatus = expectedBookingCancellationStatus;
}

@Override
Expand Down Expand Up @@ -69,28 +80,14 @@ public ConformanceCheck createCheck(String expectedApiVersion) {
protected Stream<? extends ConformanceCheck> createSubChecks() {
var dsp = getDspSupplier().get();
String cbr = dsp.carrierBookingReference();
var expectedBookingStatus = getDspSupplier().get().bookingStatus();
var expectedAmendedBookingStatus = getDspSupplier().get().amendedBookingStatus();
var expectedBookingCancellationStatus = getDspSupplier().get().bookingCancellationStatus();
return Stream.concat(
Stream.concat(createPrimarySubChecks("PATCH",expectedApiVersion,"/v2/bookings/%s".formatted(cbr)),
Stream.of(
expectedBookingStatus == null ? null: new CarrierBookingRefStatusPayloadResponseConformanceCheck(
getMatchedExchangeUuid(),
expectedBookingStatus,
expectedAmendedBookingStatus,
expectedBookingCancellationStatus
),
new JsonSchemaCheck(
BookingRole::isShipper,
getMatchedExchangeUuid(),
HttpMessageType.REQUEST,
requestSchemaValidator),
new JsonSchemaCheck(
BookingRole::isCarrier,
getMatchedExchangeUuid(),
HttpMessageType.RESPONSE,
responseSchemaValidator)).filter(Objects::nonNull)),
requestSchemaValidator))),
expectedBookingStatus != null ? getNotificationChecks(
expectedApiVersion,
notificationSchemaValidator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.dcsa.conformance.standards.booking.checks.CarrierBookingNotificationDataPayloadRequestConformanceCheck;
import org.dcsa.conformance.standards.booking.party.BookingCancellationState;
import org.dcsa.conformance.standards.booking.party.BookingRole;
import org.dcsa.conformance.standards.booking.party.BookingState;

import java.util.Objects;
import java.util.stream.Stream;
Expand All @@ -15,16 +16,22 @@
public class UC14CarrierProcessBookingCancellationAction extends StateChangingBookingAction {
private final JsonSchemaValidator requestSchemaValidator;
private final boolean isCancellationConfirmed;
private final BookingState expectedBookingStatus;
private final BookingState expectedAmendedBookingStatus;

public UC14CarrierProcessBookingCancellationAction(
String carrierPartyName,
String shipperPartyName,
BookingAction previousAction,
BookingState expectedBookingStatus,
BookingState expectedAmendedBookingStatus,
JsonSchemaValidator requestSchemaValidator,
boolean isCancellationConfirmed) {
super(carrierPartyName, shipperPartyName, previousAction, "UC14", 204);
this.requestSchemaValidator = requestSchemaValidator;
this.isCancellationConfirmed = isCancellationConfirmed;
this.expectedBookingStatus = expectedBookingStatus;
this.expectedAmendedBookingStatus = expectedAmendedBookingStatus;
}

@Override
Expand All @@ -48,21 +55,18 @@ public ConformanceCheck createCheck(String expectedApiVersion) {
return new ConformanceCheck(getActionTitle()) {
@Override
protected Stream<? extends ConformanceCheck> createSubChecks() {
var dsp = getDspSupplier().get();
var bookingStatus = dsp.bookingStatus();
var amendedBookingStatus = dsp.amendedBookingStatus();
var isCancelled = isCancellationConfirmed ?
var cancelledStatus = isCancellationConfirmed ?
BookingCancellationState.CANCELLATION_CONFIRMED : BookingCancellationState.CANCELLATION_DECLINED;
return Stream.of(
new UrlPathCheck(
BookingRole::isCarrier, getMatchedExchangeUuid(), "/v2/booking-notifications"),
new ResponseStatusCheck(
BookingRole::isShipper, getMatchedExchangeUuid(), expectedStatus),
bookingStatus == null ? null: new CarrierBookingNotificationDataPayloadRequestConformanceCheck(
new CarrierBookingNotificationDataPayloadRequestConformanceCheck(
getMatchedExchangeUuid(),
bookingStatus,
amendedBookingStatus,
isCancelled),
expectedBookingStatus,
expectedAmendedBookingStatus,
cancelledStatus),
ApiHeaderCheck.createNotificationCheck(
BookingRole::isCarrier,
getMatchedExchangeUuid(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public UC1_Shipper_SubmitBookingRequestAction(
JsonSchemaValidator requestSchemaValidator,
JsonSchemaValidator responseSchemaValidator,
JsonSchemaValidator notificationSchemaValidator) {
super(shipperPartyName, carrierPartyName, previousAction, "UC1", 201);
super(shipperPartyName, carrierPartyName, previousAction, "UC1", 202);
this.requestSchemaValidator = requestSchemaValidator;
this.responseSchemaValidator = responseSchemaValidator;
this.notificationSchemaValidator = notificationSchemaValidator;
Expand Down Expand Up @@ -63,24 +63,14 @@ public ConformanceCheck createCheck(String expectedApiVersion) {
return new ConformanceCheck(getActionTitle()) {
@Override
protected Stream<? extends ConformanceCheck> createSubChecks() {

return Stream.concat(
Stream.of(
new CarrierBookingRefStatusPayloadResponseConformanceCheck(
getMatchedExchangeUuid(),
BookingState.RECEIVED
),
BookingChecks.requestContentChecks(getMatchedExchangeUuid(), expectedApiVersion, getCspSupplier(), getDspSupplier()),
new JsonSchemaCheck(
BookingRole::isShipper,
getMatchedExchangeUuid(),
HttpMessageType.REQUEST,
requestSchemaValidator),
new JsonSchemaCheck(
BookingRole::isCarrier,
getMatchedExchangeUuid(),
HttpMessageType.RESPONSE,
responseSchemaValidator)),
requestSchemaValidator)),
Stream.concat(createPrimarySubChecks("POST", expectedApiVersion, "/v2/bookings"),
getNotificationChecks(
expectedApiVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,21 @@ public class UC3_Shipper_SubmitUpdatedBookingRequestAction extends StateChanging
private final JsonSchemaValidator requestSchemaValidator;
private final JsonSchemaValidator responseSchemaValidator;
private final JsonSchemaValidator notificationSchemaValidator;
private final BookingState expectedBookingState;

public UC3_Shipper_SubmitUpdatedBookingRequestAction(
String carrierPartyName,
String shipperPartyName,
BookingAction previousAction,
BookingState expectedBookingState,
JsonSchemaValidator requestSchemaValidator,
JsonSchemaValidator responseSchemaValidator,
JsonSchemaValidator notificationSchemaValidator) {
super(shipperPartyName, carrierPartyName, previousAction, "UC3", 200);
super(shipperPartyName, carrierPartyName, previousAction, "UC3", 202);
this.requestSchemaValidator = requestSchemaValidator;
this.responseSchemaValidator = responseSchemaValidator;
this.notificationSchemaValidator = notificationSchemaValidator;
this.expectedBookingState = expectedBookingState;
}

@Override
Expand Down Expand Up @@ -68,18 +71,13 @@ protected Stream<? extends ConformanceCheck> createSubChecks() {
getMatchedExchangeUuid(),
HttpMessageType.REQUEST,
requestSchemaValidator),
new JsonSchemaCheck(
BookingRole::isCarrier,
getMatchedExchangeUuid(),
HttpMessageType.RESPONSE,
responseSchemaValidator),
BookingChecks.requestContentChecks(getMatchedExchangeUuid(),expectedApiVersion, getCspSupplier(), getDspSupplier())),
Stream.concat(
createPrimarySubChecks("PUT", expectedApiVersion, "/v2/bookings/%s".formatted(cbrr)),
getNotificationChecks(
expectedApiVersion,
notificationSchemaValidator,
BookingState.UPDATE_RECEIVED,
expectedBookingState,
null)));
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,24 @@ public class UC7_Shipper_SubmitBookingAmendment extends StateChangingBookingActi
private final JsonSchemaValidator requestSchemaValidator;
private final JsonSchemaValidator responseSchemaValidator;
private final JsonSchemaValidator notificationSchemaValidator;
private final BookingState expectedBookingStatus;
private final BookingState expectedAmendedBookingStatus;

public UC7_Shipper_SubmitBookingAmendment(
String carrierPartyName,
String shipperPartyName,
BookingAction previousAction,
BookingState expectedBookingStatus,
BookingState expectedAmendedBookingStatus,
JsonSchemaValidator requestSchemaValidator,
JsonSchemaValidator responseSchemaValidator,
JsonSchemaValidator notificationSchemaValidator) {
super(shipperPartyName, carrierPartyName, previousAction, "UC7", 200);
super(shipperPartyName, carrierPartyName, previousAction, "UC7", 202);
this.requestSchemaValidator = requestSchemaValidator;
this.responseSchemaValidator = responseSchemaValidator;
this.notificationSchemaValidator = notificationSchemaValidator;
this.expectedBookingStatus = expectedBookingStatus;
this.expectedAmendedBookingStatus = expectedAmendedBookingStatus;
}

@Override
Expand Down Expand Up @@ -65,29 +71,19 @@ public ConformanceCheck createCheck(String expectedApiVersion) {
protected Stream<? extends ConformanceCheck> createSubChecks() {
var dsp = getDspSupplier().get();
String reference = dsp.carrierBookingReference() != null ? dsp.carrierBookingReference() : dsp.carrierBookingRequestReference();
var expectedBookingStatus = dsp.bookingStatus();
return Stream.concat(
Stream.concat( createPrimarySubChecks("PUT", expectedApiVersion, "/v2/bookings/%s".formatted(reference)),
Stream.of(new CarrierBookingRefStatusPayloadResponseConformanceCheck(
getMatchedExchangeUuid(),
expectedBookingStatus,
BookingState.AMENDMENT_RECEIVED
),
Stream.of(
new JsonSchemaCheck(
BookingRole::isShipper,
getMatchedExchangeUuid(),
HttpMessageType.REQUEST,
requestSchemaValidator),
new JsonSchemaCheck(
BookingRole::isCarrier,
getMatchedExchangeUuid(),
HttpMessageType.RESPONSE,
responseSchemaValidator))),
requestSchemaValidator))),
getNotificationChecks(
expectedApiVersion,
notificationSchemaValidator,
expectedBookingStatus,
BookingState.AMENDMENT_RECEIVED));
expectedAmendedBookingStatus));
}
};
}
Expand Down
Loading

0 comments on commit faa49cf

Please sign in to comment.