From 7f8016208b8cca5b505536b12d819d1c34604304 Mon Sep 17 00:00:00 2001 From: preetamnpr <128618622+preetamnpr@users.noreply.github.com> Date: Fri, 13 Dec 2024 11:41:36 +0100 Subject: [PATCH] SD-642 adjust the isExportDeclarationRequired condition and add relevant unit test cases. --- .../booking/checks/BookingChecks.java | 16 +++---- .../messages/booking-api-2.0.0-dg.json | 2 - .../booking-api-2.0.0-reefer-temp-change.json | 2 - .../messages/booking-api-2.0.0-reefer.json | 2 - .../booking-api-2.0.0-regular-2re1c.json | 2 - .../booking-api-2.0.0-regular-2re2c.json | 2 - .../booking-api-2.0.0-regular-cho-dest.json | 2 - .../booking-api-2.0.0-regular-cho-orig.json | 2 - ...pi-2.0.0-regular-non-operating-reefer.json | 2 - ...oking-api-2.0.0-regular-shipper-owned.json | 2 - .../messages/booking-api-2.0.0-regular.json | 4 -- .../booking/checks/BookingChecksTest.java | 45 +++++++++++++++++++ 12 files changed, 50 insertions(+), 33 deletions(-) diff --git a/booking/src/main/java/org/dcsa/conformance/standards/booking/checks/BookingChecks.java b/booking/src/main/java/org/dcsa/conformance/standards/booking/checks/BookingChecks.java index ef02e31a..a9fefc54 100644 --- a/booking/src/main/java/org/dcsa/conformance/standards/booking/checks/BookingChecks.java +++ b/booking/src/main/java/org/dcsa/conformance/standards/booking/checks/BookingChecks.java @@ -191,18 +191,13 @@ private static Consumer allDg(Consumer consumer.accept(mav.path("requestedEquipments").all().path("commodities").all().path("outerPackaging").path("dangerousGoods").all()); } - private static final JsonContentCheck IS_EXPORT_DECLARATION_REFERENCE_ABSENCE = JsonAttribute.ifThen( - "Check Export declaration reference absence", - JsonAttribute.isFalse("/isExportDeclarationRequired"), + static final JsonContentCheck IS_EXPORT_DECLARATION_REFERENCE_PRESENCE = JsonAttribute.ifThenElse( + "Check Export declaration reference presence", + JsonAttribute.isTrue(JsonPointer.compile("/isExportDeclarationRequired")), + JsonAttribute.mustBePresent(JsonPointer.compile("/exportDeclarationReference")), JsonAttribute.mustBeAbsent(JsonPointer.compile("/exportDeclarationReference")) ); - private static final JsonContentCheck IS_IMPORT_DECLARATION_REFERENCE_ABSENCE = JsonAttribute.ifThen( - "Check Import declaration reference absence", - JsonAttribute.isFalse("/isImportLicenseRequired"), - JsonAttribute.mustBeAbsent(JsonPointer.compile("/importLicenseReference")) - ); - private static final JsonRebaseableContentCheck DOCUMENT_PARTY_FUNCTIONS_MUST_BE_UNIQUE = JsonAttribute.customValidator( "Each document party can be used at most once", JsonAttribute.path( @@ -630,8 +625,7 @@ private static void generateScenarioRelatedChecks(List checks, NOR_PLUS_ISO_CODE_IMPLIES_ACTIVE_REEFER, ISO_EQUIPMENT_CODE_AND_NOR_CHECK, REFERENCE_TYPE_VALIDATION, - IS_EXPORT_DECLARATION_REFERENCE_ABSENCE, - IS_IMPORT_DECLARATION_REFERENCE_ABSENCE, + IS_EXPORT_DECLARATION_REFERENCE_PRESENCE, DOCUMENT_PARTY_FUNCTIONS_MUST_BE_UNIQUE, UNIVERSAL_SERVICE_REFERENCE, VALIDATE_SHIPMENT_CUTOFF_TIME_CODE, diff --git a/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-dg.json b/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-dg.json index 12c96b4a..caafd1d4 100644 --- a/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-dg.json +++ b/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-dg.json @@ -6,8 +6,6 @@ "serviceContractReference": "SERVICE_CONTRACT_REFERENCE_PLACEHOLDER", "carrierExportVoyageNumber": "CARRIER_EXPORT_VOYAGE_NUMBER_PLACEHOLDER", "carrierServiceName": "CARRIER_SERVICE_NAME_PLACEHOLDER", - "isExportDeclarationRequired": true, - "isImportLicenseRequired": true, "isEquipmentSubstitutionAllowed": true, "carrierServiceCode": "TA1", "vessel": { diff --git a/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-reefer-temp-change.json b/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-reefer-temp-change.json index afca6868..820e31c6 100644 --- a/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-reefer-temp-change.json +++ b/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-reefer-temp-change.json @@ -6,8 +6,6 @@ "serviceContractReference": "SERVICE_CONTRACT_REFERENCE_PLACEHOLDER", "carrierExportVoyageNumber": "CARRIER_EXPORT_VOYAGE_NUMBER_PLACEHOLDER", "carrierServiceName": "CARRIER_SERVICE_NAME_PLACEHOLDER", - "isExportDeclarationRequired": false, - "isImportLicenseRequired": false, "isEquipmentSubstitutionAllowed": true, "carrierServiceCode": "TA1", "vessel": { diff --git a/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-reefer.json b/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-reefer.json index 66942f83..06c8701c 100644 --- a/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-reefer.json +++ b/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-reefer.json @@ -6,8 +6,6 @@ "serviceContractReference": "SERVICE_CONTRACT_REFERENCE_PLACEHOLDER", "carrierExportVoyageNumber": "CARRIER_EXPORT_VOYAGE_NUMBER_PLACEHOLDER", "carrierServiceName": "CARRIER_SERVICE_NAME_PLACEHOLDER", - "isExportDeclarationRequired": true, - "isImportLicenseRequired": true, "isEquipmentSubstitutionAllowed": true, "vessel": { "name": "King of the Seas" diff --git a/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-regular-2re1c.json b/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-regular-2re1c.json index 3f677a2d..93cfc3cf 100644 --- a/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-regular-2re1c.json +++ b/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-regular-2re1c.json @@ -6,8 +6,6 @@ "serviceContractReference": "SERVICE_CONTRACT_REFERENCE_PLACEHOLDER", "carrierExportVoyageNumber": "CARRIER_EXPORT_VOYAGE_NUMBER_PLACEHOLDER", "carrierServiceName": "CARRIER_SERVICE_NAME_PLACEHOLDER", - "isExportDeclarationRequired": true, - "isImportLicenseRequired": true, "isEquipmentSubstitutionAllowed": true, "carrierServiceCode": "TA1", "vessel": { diff --git a/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-regular-2re2c.json b/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-regular-2re2c.json index 20c916f5..d7bf3a80 100644 --- a/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-regular-2re2c.json +++ b/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-regular-2re2c.json @@ -6,8 +6,6 @@ "serviceContractReference": "SERVICE_CONTRACT_REFERENCE_PLACEHOLDER", "carrierExportVoyageNumber": "CARRIER_EXPORT_VOYAGE_NUMBER_PLACEHOLDER", "carrierServiceName": "CARRIER_SERVICE_NAME_PLACEHOLDER", - "isExportDeclarationRequired": true, - "isImportLicenseRequired": true, "isEquipmentSubstitutionAllowed": true, "carrierServiceCode": "TA1", "vessel": { diff --git a/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-regular-cho-dest.json b/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-regular-cho-dest.json index cabca26e..6063a8ff 100644 --- a/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-regular-cho-dest.json +++ b/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-regular-cho-dest.json @@ -6,8 +6,6 @@ "serviceContractReference": "SERVICE_CONTRACT_REFERENCE_PLACEHOLDER", "carrierExportVoyageNumber": "CARRIER_EXPORT_VOYAGE_NUMBER_PLACEHOLDER", "carrierServiceName": "CARRIER_SERVICE_NAME_PLACEHOLDER", - "isExportDeclarationRequired": true, - "isImportLicenseRequired": true, "isEquipmentSubstitutionAllowed": true, "carrierServiceCode": "TA1", "vessel": { diff --git a/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-regular-cho-orig.json b/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-regular-cho-orig.json index 4e610b47..e2e0a7cc 100644 --- a/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-regular-cho-orig.json +++ b/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-regular-cho-orig.json @@ -6,8 +6,6 @@ "serviceContractReference": "SERVICE_CONTRACT_REFERENCE_PLACEHOLDER", "carrierExportVoyageNumber": "CARRIER_EXPORT_VOYAGE_NUMBER_PLACEHOLDER", "carrierServiceName": "CARRIER_SERVICE_NAME_PLACEHOLDER", - "isExportDeclarationRequired": false, - "isImportLicenseRequired": false, "isEquipmentSubstitutionAllowed": true, "carrierServiceCode": "TA1", "vessel": { diff --git a/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-regular-non-operating-reefer.json b/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-regular-non-operating-reefer.json index b58c9474..2a4b084e 100644 --- a/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-regular-non-operating-reefer.json +++ b/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-regular-non-operating-reefer.json @@ -6,8 +6,6 @@ "serviceContractReference": "SERVICE_CONTRACT_REFERENCE_PLACEHOLDER", "carrierExportVoyageNumber": "CARRIER_EXPORT_VOYAGE_NUMBER_PLACEHOLDER", "carrierServiceName": "CARRIER_SERVICE_NAME_PLACEHOLDER", - "isExportDeclarationRequired": false, - "isImportLicenseRequired": false, "isEquipmentSubstitutionAllowed": true, "carrierServiceCode": "TA1", "vessel": { diff --git a/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-regular-shipper-owned.json b/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-regular-shipper-owned.json index 6fc1cc20..eb37c01a 100644 --- a/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-regular-shipper-owned.json +++ b/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-regular-shipper-owned.json @@ -6,8 +6,6 @@ "serviceContractReference": "SERVICE_CONTRACT_REFERENCE_PLACEHOLDER", "carrierExportVoyageNumber": "CARRIER_EXPORT_VOYAGE_NUMBER_PLACEHOLDER", "carrierServiceName": "CARRIER_SERVICE_NAME_PLACEHOLDER", - "isExportDeclarationRequired": false, - "isImportLicenseRequired": false, "isEquipmentSubstitutionAllowed": true, "carrierServiceCode": "TA1", "vessel": { diff --git a/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-regular.json b/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-regular.json index b6046a40..d63d9eaf 100644 --- a/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-regular.json +++ b/booking/src/main/resources/standards/booking/messages/booking-api-2.0.0-regular.json @@ -28,10 +28,6 @@ "universalExportVoyageReference": "2103N", "declaredValue": 1231.1, "declaredValueCurrency": "EUR", - "isExportDeclarationRequired": true, - "exportDeclarationReference": "ABC123123", - "isImportLicenseRequired": true, - "importLicenseReference": "XYZ987987", "expectedDepartureDate": "2064-10-17", "expectedArrivalAtPlaceOfDeliveryStartDate": "2064-11-10", "expectedArrivalAtPlaceOfDeliveryEndDate": "2064-11-15", diff --git a/booking/src/test/java/org/dcsa/conformance/standards/booking/checks/BookingChecksTest.java b/booking/src/test/java/org/dcsa/conformance/standards/booking/checks/BookingChecksTest.java index 676850f2..17acabcd 100644 --- a/booking/src/test/java/org/dcsa/conformance/standards/booking/checks/BookingChecksTest.java +++ b/booking/src/test/java/org/dcsa/conformance/standards/booking/checks/BookingChecksTest.java @@ -9,7 +9,9 @@ import java.util.Set; import static org.dcsa.conformance.core.toolkit.JsonToolkit.OBJECT_MAPPER; +import static org.dcsa.conformance.standards.booking.checks.BookingChecks.IS_EXPORT_DECLARATION_REFERENCE_PRESENCE; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; public class BookingChecksTest { @@ -93,4 +95,47 @@ void testCargoGrossWeightMissingInRequestedEquipmentsAndInOneOfTheCommodities_in errors.contains( "The 'requestedEquipments[0]' must have cargo gross weight at commodities position 0")); } + + @Test + void testIsExportDeclarationReferencePresence_requiredAndPresent() { + booking.put("isExportDeclarationRequired", true); + booking.put("exportDeclarationReference", "testReference"); + Set errors = IS_EXPORT_DECLARATION_REFERENCE_PRESENCE.validate(booking); + assertTrue(errors.isEmpty()); + } + + @Test + void testIsExportDeclarationReferencePresence_requiredAndAbsent() { + booking.put("isExportDeclarationRequired", true); + Set errors = IS_EXPORT_DECLARATION_REFERENCE_PRESENCE.validate(booking); + assertEquals(1, errors.size()); + } + + @Test + void testIsExportDeclarationReferencePresence_notRequiredAndAbsent() { + booking.put("isExportDeclarationRequired", false); + Set errors = IS_EXPORT_DECLARATION_REFERENCE_PRESENCE.validate(booking); + assertTrue(errors.isEmpty()); + } + + @Test + void testIsExportDeclarationReferencePresence_notRequiredAndPresent() { + booking.put("isExportDeclarationRequired", false); + booking.put("exportDeclarationReference", "testReferenceValue"); + Set errors = IS_EXPORT_DECLARATION_REFERENCE_PRESENCE.validate(booking); + assertEquals(1, errors.size()); + } + + @Test + void testIsExportDeclarationReferencePresence_missingFlagAndAbsent() { + Set errors = IS_EXPORT_DECLARATION_REFERENCE_PRESENCE.validate(booking); + assertTrue(errors.isEmpty()); + } + + @Test + void testIsExportDeclarationReferencePresence_missingFlagAndPresent() { + booking.put("exportDeclarationReference", "testReference"); + Set errors = IS_EXPORT_DECLARATION_REFERENCE_PRESENCE.validate(booking); + assertEquals(1, errors.size()); + } }