Skip to content

Commit

Permalink
DT-1156 Booking conformance scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
gj0dcsa committed May 19, 2024
1 parent c236897 commit ef5c3b4
Show file tree
Hide file tree
Showing 23 changed files with 246 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,21 @@ public class BookingComponentFactory extends AbstractComponentFactory {
public static final String STANDARD_NAME = "Booking";
public static final List<String> STANDARD_VERSIONS = List.of("2.0.0");

public static final List<String> SCENARIO_SUITES = List.of("Conformance", "Reference Implementation");

private static final String CARRIER_AUTH_HEADER_VALUE = UUID.randomUUID().toString();
private static final String SHIPPER_AUTH_HEADER_VALUE = UUID.randomUUID().toString();

private final String standardVersion;

public BookingComponentFactory(String standardVersion) {
this.standardVersion = standardVersion;
public BookingComponentFactory(String standardVersion, String scenarioSuite) {
super(standardVersion, scenarioSuite);
if (STANDARD_VERSIONS.stream().noneMatch(version -> version.equals(standardVersion))) {
throw new IllegalArgumentException(
"Unsupported standard version '%s'".formatted(standardVersion));
}
if (SCENARIO_SUITES.stream().noneMatch(version -> version.equals(scenarioSuite))) {
throw new IllegalArgumentException(
"Unsupported scenario suite '%s'".formatted(scenarioSuite));
}
}

public List<ConformanceParty> createParties(
Expand Down Expand Up @@ -135,10 +139,12 @@ public JsonNode getJsonSandboxConfigurationTemplate(
Map.ofEntries(
Map.entry("STANDARD_NAME_PLACEHOLDER", STANDARD_NAME),
Map.entry("STANDARD_VERSION_PLACEHOLDER", standardVersion),
Map.entry("SCENARIO_SUITE_PLACEHOLDER", scenarioSuite),
Map.entry("CARRIER_AUTH_HEADER_VALUE_PLACEHOLDER", CARRIER_AUTH_HEADER_VALUE),
Map.entry("SHIPPER_AUTH_HEADER_VALUE_PLACEHOLDER", SHIPPER_AUTH_HEADER_VALUE),
Map.entry(
"SANDBOX_ID_PREFIX",
AbstractComponentFactory._sandboxIdPrefix(STANDARD_NAME, standardVersion))));
AbstractComponentFactory._sandboxIdPrefix(
STANDARD_NAME, standardVersion, scenarioSuite))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,174 @@ public static LinkedHashMap<String, BookingScenarioListBuilder> createModuleScen
threadLocalComponentFactory.set(componentFactory);
threadLocalCarrierPartyName.set(carrierPartyName);
threadLocalShipperPartyName.set(shipperPartyName);
if ("Conformance".equals(componentFactory.getScenarioSuite())) {
return createConformanceScenarios(carrierPartyName);
}
if ("Reference Implementation".equals(componentFactory.getScenarioSuite())) {
return createReferenceImplementationScenarios(carrierPartyName);
}
throw new IllegalArgumentException("Invalid scenario suite name '%s'".formatted(componentFactory.getScenarioSuite()));
}

private static LinkedHashMap<String, BookingScenarioListBuilder> createConformanceScenarios(
String carrierPartyName) {
return Stream.of(
Map.entry(
"Dry cargo",
carrier_SupplyScenarioParameters(carrierPartyName, ScenarioType.REGULAR)
.then(
uc1_shipper_SubmitBookingRequest()
.then(
shipper_GetBooking(RECEIVED)
.thenEither(
uc2_carrier_requestUpdateToBookingRequest()
.then(
shipper_GetBooking(PENDING_UPDATE)
.then(
uc3_shipper_submitUpdatedBookingRequest()
.then(
shipper_GetBooking(UPDATE_RECEIVED)
.then(
uc5_carrier_confirmBookingRequest()
.then(
shipper_GetBooking(
CONFIRMED)
.then(
uc12_carrier_confirmBookingCompleted()
.then(
shipper_GetBooking(
COMPLETED)))))))),
uc3_shipper_submitUpdatedBookingRequest()
.then(
shipper_GetBooking(UPDATE_RECEIVED)
.then(
uc5_carrier_confirmBookingRequest()
.then(
shipper_GetBooking(CONFIRMED)
.then(
uc12_carrier_confirmBookingCompleted()
.then(
shipper_GetBooking(
COMPLETED)))))),
uc4_carrier_rejectBookingRequest()
.then(shipper_GetBooking(REJECTED)),
uc5_carrier_confirmBookingRequest()
.then(
shipper_GetBooking(CONFIRMED)
.thenEither(
uc5_carrier_confirmBookingRequest()
.then(
shipper_GetBooking(CONFIRMED)
.then(
uc12_carrier_confirmBookingCompleted()
.then(
shipper_GetBooking(
COMPLETED)))),
uc7_shipper_submitBookingAmendment()
.then(
shipper_GetBooking(
CONFIRMED,
AMENDMENT_RECEIVED)
.thenEither(
uc8a_carrier_approveBookingAmendment()
.then(
shipper_GetBooking(
CONFIRMED,
AMENDMENT_CONFIRMED)
.then(
uc12_carrier_confirmBookingCompleted()
.then(
shipper_GetBooking(
COMPLETED)))),
uc8b_carrier_declineBookingAmendment()
.then(
shipper_GetBooking(
CONFIRMED,
AMENDMENT_DECLINED)
.then(
uc12_carrier_confirmBookingCompleted()
.then(
shipper_GetBooking(
COMPLETED)))),
uc9_shipper_cancelBookingAmendment()
.then(
shipper_GetBooking(
CONFIRMED,
AMENDMENT_CANCELLED)
.then(
uc12_carrier_confirmBookingCompleted()
.then(
shipper_GetBooking(
COMPLETED)))))),
uc10_carrier_declineBooking()
.then(shipper_GetBooking(DECLINED)),
uc12_carrier_confirmBookingCompleted()
.then(shipper_GetBooking(COMPLETED)))),
uc11_shipper_cancelBooking()
.then(shipper_GetBooking(CANCELLED)))))),
Map.entry(
"Dangerous goods",
carrier_SupplyScenarioParameters(carrierPartyName, ScenarioType.DG)
.then(
uc1_shipper_SubmitBookingRequest()
.then(
shipper_GetBooking(RECEIVED)
.thenEither(
uc3_shipper_submitUpdatedBookingRequest()
.then(
shipper_GetBooking(UPDATE_RECEIVED)
.then(
uc5_carrier_confirmBookingRequest()
.then(
shipper_GetBooking(CONFIRMED)
.then(
uc12_carrier_confirmBookingCompleted()
.then(
shipper_GetBooking(
COMPLETED)))))),
uc5_carrier_confirmBookingRequest()
.then(
shipper_GetBooking(CONFIRMED)
.then(
uc12_carrier_confirmBookingCompleted()
.then(
shipper_GetBooking(
COMPLETED)))))))),
Map.entry(
"Reefer containers",
carrier_SupplyScenarioParameters(carrierPartyName, ScenarioType.REEFER)
.then(
uc1_shipper_SubmitBookingRequest()
.then(
shipper_GetBooking(RECEIVED)
.thenEither(
uc3_shipper_submitUpdatedBookingRequest()
.then(
shipper_GetBooking(UPDATE_RECEIVED)
.then(
uc5_carrier_confirmBookingRequest()
.then(
shipper_GetBooking(CONFIRMED)
.then(
uc12_carrier_confirmBookingCompleted()
.then(
shipper_GetBooking(
COMPLETED)))))),
uc5_carrier_confirmBookingRequest()
.then(
shipper_GetBooking(CONFIRMED)
.then(
uc12_carrier_confirmBookingCompleted()
.then(
shipper_GetBooking(
COMPLETED)))))))))
.collect(
Collectors.toMap(
Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
}

private static LinkedHashMap<String, BookingScenarioListBuilder>
createReferenceImplementationScenarios(String carrierPartyName) {
return Stream.of(
Map.entry(
"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"name" : "STANDARD_NAME_PLACEHOLDER",
"version" : "STANDARD_VERSION_PLACEHOLDER"
},
"scenarioSuite": "SCENARIO_SUITE_PLACEHOLDER",
"orchestrator" : {
"active": true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"name" : "STANDARD_NAME_PLACEHOLDER",
"version" : "STANDARD_VERSION_PLACEHOLDER"
},
"scenarioSuite": "SCENARIO_SUITE_PLACEHOLDER",
"orchestrator" : {
"active": false
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"name" : "STANDARD_NAME_PLACEHOLDER",
"version" : "STANDARD_VERSION_PLACEHOLDER"
},
"scenarioSuite": "SCENARIO_SUITE_PLACEHOLDER",
"orchestrator" : {
"active": true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"name" : "STANDARD_NAME_PLACEHOLDER",
"version" : "STANDARD_VERSION_PLACEHOLDER"
},
"scenarioSuite": "SCENARIO_SUITE_PLACEHOLDER",
"orchestrator" : {
"active": false
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"name" : "STANDARD_NAME_PLACEHOLDER",
"version" : "STANDARD_VERSION_PLACEHOLDER"
},
"scenarioSuite": "SCENARIO_SUITE_PLACEHOLDER",
"orchestrator" : {
"active": true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"name" : "STANDARD_NAME_PLACEHOLDER",
"version" : "STANDARD_VERSION_PLACEHOLDER"
},
"scenarioSuite": "SCENARIO_SUITE_PLACEHOLDER",
"orchestrator" : {
"active": false
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"name" : "STANDARD_NAME_PLACEHOLDER",
"version" : "STANDARD_VERSION_PLACEHOLDER"
},
"scenarioSuite": "SCENARIO_SUITE_PLACEHOLDER",
"orchestrator" : {
"active": true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"name" : "STANDARD_NAME_PLACEHOLDER",
"version" : "STANDARD_VERSION_PLACEHOLDER"
},
"scenarioSuite": "SCENARIO_SUITE_PLACEHOLDER",
"orchestrator" : {
"active": false
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"name" : "STANDARD_NAME_PLACEHOLDER",
"version" : "STANDARD_VERSION_PLACEHOLDER"
},
"scenarioSuite": "SCENARIO_SUITE_PLACEHOLDER",
"orchestrator" : {
"active": true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,26 @@
import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Stream;

import lombok.Getter;
import org.dcsa.conformance.core.party.ConformanceParty;
import org.dcsa.conformance.core.party.CounterpartConfiguration;
import org.dcsa.conformance.core.party.PartyConfiguration;
import org.dcsa.conformance.core.party.PartyWebClient;
import org.dcsa.conformance.core.scenario.ScenarioListBuilder;
import org.dcsa.conformance.core.state.JsonNodeMap;

@Getter
public abstract class AbstractComponentFactory {

protected final String standardVersion;
protected final String scenarioSuite;

protected AbstractComponentFactory(String standardVersion, String scenarioSuite) {
this.standardVersion = standardVersion;
this.scenarioSuite = scenarioSuite;
}

public abstract List<ConformanceParty> createParties(
PartyConfiguration[] partyConfigurations,
CounterpartConfiguration[] counterpartConfigurations,
Expand All @@ -21,10 +33,10 @@ public abstract List<ConformanceParty> createParties(

/**
* Creates the ScenarioListBuilders of each standard module.
* <p>
* For a standard without modules, return a single-entry map with "" as key:
* <p>
* <code>
*
* <p>For a standard without modules, return a single-entry map with "" as key:
*
* <p><code>
* return Stream.of(Map.entry("", yourRootScenarioListBuilder)).collect(Collectors.toMap(
* Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new))
* </code>
Expand Down Expand Up @@ -62,9 +74,19 @@ protected static String _findPartyOrCounterpartName(

protected static String _sandboxIdPrefix(String standardName, String standardVersion) {
return "%s-%s"
.formatted(
standardName.replaceAll(" ", ""),
standardVersion.replaceAll("\\.", "").replaceAll("-", ""))
.toLowerCase();
}

protected static String _sandboxIdPrefix(
String standardName, String standardVersion, String scenarioSuite) {
return "%s-%s-%s"
.formatted(
standardName.replaceAll(" ", ""),
standardVersion.replaceAll("\\.", "").replaceAll("-", ""))
standardVersion.replaceAll("\\.", "").replaceAll("-", ""),
scenarioSuite.replaceAll(" ", "-"))
.toLowerCase();
}
}
Loading

0 comments on commit ef5c3b4

Please sign in to comment.