diff --git a/edocumentation-application/src/main/java/org/dcsa/edocumentation/controller/BookingSummaryController.java b/edocumentation-application/src/main/java/org/dcsa/edocumentation/controller/BookingSummaryController.java deleted file mode 100644 index 711965f8..00000000 --- a/edocumentation-application/src/main/java/org/dcsa/edocumentation/controller/BookingSummaryController.java +++ /dev/null @@ -1,94 +0,0 @@ -package org.dcsa.edocumentation.controller; - -import lombok.RequiredArgsConstructor; -import org.dcsa.edocumentation.infra.enums.BookingStatus; -import org.dcsa.edocumentation.infra.validation.StringEnumValidation; -import org.dcsa.edocumentation.service.BookingSummaryService; -import org.dcsa.edocumentation.transferobjects.BookingSummaryTO; -import org.dcsa.skernel.infrastructure.pagination.Pagination; -import org.dcsa.skernel.infrastructure.sorting.Sorter; -import org.springframework.data.domain.Sort; -import org.springframework.http.HttpStatus; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseStatus; -import org.springframework.web.bind.annotation.RestController; - -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import jakarta.validation.constraints.Min; -import java.util.List; - -@Validated -@RestController -@RequiredArgsConstructor -public class BookingSummaryController { - - private final BookingSummaryService service; - - @GetMapping(path = "${spring.application.bkg-context-path}" + "/booking-summaries") - @ResponseStatus(HttpStatus.OK) - public List getBookingSummaries( - @RequestParam(required = false) - @StringEnumValidation(value = BookingStatus.class) - String bookingStatus, - @RequestParam(value = Pagination.DCSA_PAGE_PARAM_NAME, defaultValue = "0", required = false) - @Min(0) - int page, - @RequestParam( - value = Pagination.DCSA_PAGESIZE_PARAM_NAME, - defaultValue = "100", - required = false) - @Min(1) - int pageSize, - @RequestParam(value = Pagination.DCSA_SORT_PARAM_NAME, required = false) String sort, - @RequestParam(value = "API-Version", required = false) String apiVersion, - HttpServletRequest request, - HttpServletResponse response) { - - return Pagination.with(request, response, page, pageSize) - .sortBy( - sort, - List.of(new Sort.Order(Sort.Direction.ASC, "bookingRequestCreatedDateTime")), - Sorter.SortableFields.of(configureSortableFields())) - .paginate(pageRequest -> service.findBookingSummaries(pageRequest, bookingStatus)); - } - - // ToDo a shared-kernel feature where you can create a sorter based on a TO could be a nice - // optimization - private String[] configureSortableFields() { - return new String[] { - "bookingStatus", - "bookingRequestCreatedDateTime", - "bookingRequestUpdatedDateTime", - "receiptTypeAtOrigin", - "deliveryTypeAtDestination", - "cargoMovementTypeAtOrigin", - "cargoMovementTypeAtDestination", - "serviceContractReference", - "carrierExportVoyageNumber", - "universalExportVoyageReference", - "declaredValue", - "declaredValueCurrency", - "paymentTermCode", - "isPartialLoadAllowed", - "isExportDeclarationRequired", - "exportDeclarationReference", - "isImportLicenseRequired", - "importLicenseReference", - "isAMSACIFilingRequired", - "isDestinationFilingRequired", - "contractQuotationReference", - "expectedDepartureDate", - "expectedArrivalAtPlaceOfDeliveryStartDate", - "expectedArrivalAtPlaceOfDeliveryEndDate", - "transportDocumentTypeCode", - "transportDocumentReference", - "bookingChannelReference", - "incoTerms", - "communicationChannelCode", - "isEquipmentSubstitutionAllowed" - }; - } -} diff --git a/edocumentation-application/src/main/java/org/dcsa/edocumentation/controller/ShippingInstructionSummaryController.java b/edocumentation-application/src/main/java/org/dcsa/edocumentation/controller/ShippingInstructionSummaryController.java deleted file mode 100644 index 296fae8b..00000000 --- a/edocumentation-application/src/main/java/org/dcsa/edocumentation/controller/ShippingInstructionSummaryController.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.dcsa.edocumentation.controller; - -import lombok.RequiredArgsConstructor; -import org.dcsa.edocumentation.infra.enums.BookingStatus; -import org.dcsa.edocumentation.infra.enums.EblDocumentStatus; -import org.dcsa.edocumentation.infra.validation.StringEnumValidation; -import org.dcsa.edocumentation.service.ShippingInstructionSummaryService; -import org.dcsa.edocumentation.transferobjects.ShippingInstructionSummaryTO; -import org.dcsa.skernel.infrastructure.pagination.Pagination; -import org.dcsa.skernel.infrastructure.sorting.Sorter; -import org.springframework.data.domain.Sort; -import org.springframework.http.HttpStatus; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseStatus; -import org.springframework.web.bind.annotation.RestController; - -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import jakarta.validation.constraints.Min; -import java.util.List; - -@Validated -@RestController -@RequiredArgsConstructor -public class ShippingInstructionSummaryController { - - private final ShippingInstructionSummaryService service; - - @GetMapping(path = "${spring.application.ebl-context-path}" + "/shipping-instructions-summaries") - @ResponseStatus(HttpStatus.OK) - List getShippingInstructionSummaries( - @RequestParam(required = false) - @StringEnumValidation(value = EblDocumentStatus.class) - String documentStatus, - @RequestParam(required = false) - String carrierBookingReference, - @RequestParam(value = Pagination.DCSA_PAGE_PARAM_NAME, defaultValue = "0", required = false) - @Min(0) - int page, - @RequestParam( - value = Pagination.DCSA_PAGESIZE_PARAM_NAME, - defaultValue = "100", - required = false) - @Min(1) - int pageSize, - @RequestParam(value = Pagination.DCSA_SORT_PARAM_NAME, required = false) String sort, - @RequestParam(value = "API-Version", required = false) String apiVersion, - HttpServletRequest request, - HttpServletResponse response) { - - return Pagination.with(request, response, page, pageSize) - .sortBy( - sort, - List.of(new Sort.Order(Sort.Direction.ASC, "shippingInstructionCreatedDateTime")), - Sorter.SortableFields.of(configureSortableFields()) - .addMapping("shippingInstructionCreatedDateTime", "createdDateTime") - .addMapping("shippingInstructionUpdatedDateTime", "updatedDateTime")) - .paginate( - pageRequest -> - service.findShippingInstructionSummaries(pageRequest, documentStatus, carrierBookingReference)); - } - private String[] configureSortableFields() { - return new String[] { - "shippingInstructionReference", - "documentStatus", - "shippingInstructionCreatedDateTime", - "shippingInstructionUpdatedDateTime", - "amendToTransportDocument", - "transportDocumentTypeCode", - "numberOfCopies", - "numberOfOriginals", - "displayedNameForPlaceOfReceipt", - "displayedNameForPortOfLoad", - "displayedNameForPortOfDischarge", - "displayedNameForPlaceOfDelivery" - }; - } -} diff --git a/edocumentation-application/src/test/java/org/dcsa/edocumentation/controller/BookingRequestSummaryControllerTest.java b/edocumentation-application/src/test/java/org/dcsa/edocumentation/controller/BookingRequestSummaryControllerTest.java deleted file mode 100644 index b867ceff..00000000 --- a/edocumentation-application/src/test/java/org/dcsa/edocumentation/controller/BookingRequestSummaryControllerTest.java +++ /dev/null @@ -1,126 +0,0 @@ -package org.dcsa.edocumentation.controller; - -import org.dcsa.edocumentation.datafactories.BookingSummaryDataFactory; -import org.dcsa.edocumentation.infra.enums.BookingStatus; -import org.dcsa.edocumentation.service.BookingSummaryService; -import org.dcsa.edocumentation.transferobjects.BookingSummaryTO; -import org.dcsa.skernel.errors.infrastructure.ConcreteRequestErrorMessageExceptionHandler; -import org.dcsa.skernel.errors.infrastructure.FallbackExceptionHandler; -import org.dcsa.skernel.errors.infrastructure.JakartaValidationExceptionHandler; -import org.dcsa.skernel.errors.infrastructure.SpringExceptionHandler; -import org.dcsa.skernel.infrastructure.pagination.PagedResult; -import org.junit.Ignore; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.context.annotation.Import; -import org.springframework.data.domain.PageImpl; -import org.springframework.http.MediaType; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.web.servlet.MockMvc; - -import java.util.List; - -import static org.hamcrest.Matchers.containsString; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.when; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@ActiveProfiles("test") -@WebMvcTest(controllers = {BookingSummaryController.class}) -@Import({ - SpringExceptionHandler.class, - JakartaValidationExceptionHandler.class, - FallbackExceptionHandler.class, - ConcreteRequestErrorMessageExceptionHandler.class, -}) -class BookingRequestSummaryControllerTest { - - @Autowired MockMvc mockMvc; - @MockBean BookingSummaryService bookingSummaryService; - private final String path = "/bkg/v2/booking-summaries"; - - @Test - void testBookingSummaryController_getBookingSummariesSingleResult() throws Exception { - BookingSummaryTO mockBookingSummaryTO = BookingSummaryDataFactory.singleBookingSummaryTO(); - when(bookingSummaryService.findBookingSummaries(any(), any())) - .thenReturn(new PagedResult<>(new PageImpl<>(List.of(mockBookingSummaryTO)))); - - mockMvc - .perform(get(path).accept(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(jsonPath("$").isArray()) - .andExpect( - jsonPath("$.[0].carrierBookingRequestReference") - .value(mockBookingSummaryTO.carrierBookingRequestReference())); - } - - @Test - void testBookingSummaryController_getBookingSummariesMultipleResult() throws Exception { - List mockBookingSummaryTO = - BookingSummaryDataFactory.multipleBookingSummaryTos(); - when(bookingSummaryService.findBookingSummaries(any(), any())) - .thenReturn(new PagedResult<>(new PageImpl<>(mockBookingSummaryTO))); - - mockMvc - .perform(get(path).accept(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(jsonPath("$").isArray()) - .andExpect( - jsonPath("$.[0].carrierBookingRequestReference") - .value(mockBookingSummaryTO.get(0).carrierBookingRequestReference())) - .andExpect( - jsonPath("$.[1].carrierBookingRequestReference") - .value(mockBookingSummaryTO.get(1).carrierBookingRequestReference())); - } - - @Test - void testBookingSummaryController_getBookingSummariesSingleResultWithDocumentStatus() - throws Exception { - BookingSummaryTO mockBookingSummaryTO = BookingSummaryDataFactory.singleBookingSummaryTO(); - when(bookingSummaryService.findBookingSummaries(any(), eq(BookingStatus.RECEIVED))) - .thenReturn(new PagedResult<>(new PageImpl<>(List.of(mockBookingSummaryTO)))); - - mockMvc - .perform( - get(path) - .param("bookingStatus", BookingStatus.RECEIVED) - .accept(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(jsonPath("$").isArray()) - .andExpect( - jsonPath("$.[0].carrierBookingRequestReference") - .value(mockBookingSummaryTO.carrierBookingRequestReference())); - } - - @Test - void testBookingSummaryController_getBookingSummariesWithInvalidDocumentStatus() - throws Exception { - BookingSummaryTO mockBookingSummaryTO = BookingSummaryDataFactory.singleBookingSummaryTO(); - when(bookingSummaryService.findBookingSummaries(any(), any())) - .thenReturn(new PagedResult<>(new PageImpl<>(List.of(mockBookingSummaryTO)))); - - - mockMvc - .perform( - get(path) - .param("bookingStatus", "INVALID") - .accept(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isBadRequest()) - .andExpect(jsonPath("$.httpMethod").value("GET")) - .andExpect(jsonPath("$.requestUri").value(path)) - .andExpect(jsonPath("$.errors[0].reason").value("invalidInput")) - .andExpect( - jsonPath("$.errors[0].message") - .value(containsString("bookingStatus Unexpected value 'INVALID', should have been one of"))); - } -} diff --git a/edocumentation-application/src/test/java/org/dcsa/edocumentation/controller/ShippingInstructionSummaryControllerTest.java b/edocumentation-application/src/test/java/org/dcsa/edocumentation/controller/ShippingInstructionSummaryControllerTest.java deleted file mode 100644 index 11f73bd8..00000000 --- a/edocumentation-application/src/test/java/org/dcsa/edocumentation/controller/ShippingInstructionSummaryControllerTest.java +++ /dev/null @@ -1,193 +0,0 @@ -package org.dcsa.edocumentation.controller; - -import org.dcsa.edocumentation.datafactories.ShippingInstructionSummaryDataFactory; -import org.dcsa.edocumentation.service.ShippingInstructionSummaryService; -import org.dcsa.edocumentation.transferobjects.ShippingInstructionSummaryTO; -import org.dcsa.skernel.errors.infrastructure.ConcreteRequestErrorMessageExceptionHandler; -import org.dcsa.skernel.errors.infrastructure.FallbackExceptionHandler; -import org.dcsa.skernel.errors.infrastructure.JakartaValidationExceptionHandler; -import org.dcsa.skernel.errors.infrastructure.SpringExceptionHandler; -import org.dcsa.skernel.infrastructure.pagination.PagedResult; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.context.annotation.Import; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageImpl; -import org.springframework.http.MediaType; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.web.servlet.MockMvc; - -import java.util.List; - -import static org.hamcrest.Matchers.containsString; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@ActiveProfiles("test") -@WebMvcTest(controllers = {ShippingInstructionSummaryController.class}) -@Import({ - SpringExceptionHandler.class, - JakartaValidationExceptionHandler.class, - FallbackExceptionHandler.class, - ConcreteRequestErrorMessageExceptionHandler.class -}) -class ShippingInstructionSummaryControllerTest { - - private final String path = "/ebl/v3/shipping-instructions-summaries"; - @Autowired MockMvc mockMvc; - @MockBean ShippingInstructionSummaryService shippingInstructionSummaryService; - - @Test - void testShippingInstructionSummary_singleResultNoDocumentStatus() throws Exception { - ShippingInstructionSummaryTO mockShippingInstructionSummaryResponse = - ShippingInstructionSummaryDataFactory.singleShippingInstructionSummaryTO(); - Page pageResult = - new PageImpl<>(List.of(mockShippingInstructionSummaryResponse)); - when(shippingInstructionSummaryService.findShippingInstructionSummaries(any(), any(), any())) - .thenReturn(new PagedResult<>(pageResult)); - - mockMvc - .perform(get(path).accept(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(jsonPath("$").isArray()) - .andExpect( - jsonPath("$.[0].shippingInstructionReference") - .value(mockShippingInstructionSummaryResponse.shippingInstructionReference())); - } - - @Test - void testShippingInstructionSummary_getShipmentSummariesSingleResulWithDocumentStatus() - throws Exception { - ShippingInstructionSummaryTO mockShippingInstructionSummaryResponse = - ShippingInstructionSummaryDataFactory.singleShippingInstructionSummaryTO(); - Page pageResult = - new PageImpl<>(List.of(mockShippingInstructionSummaryResponse)); - when(shippingInstructionSummaryService.findShippingInstructionSummaries(any(), any(), any())) - .thenReturn(new PagedResult<>(pageResult)); - - mockMvc - .perform(get(path).param("documentStatus", "RECEIVED").accept(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(jsonPath("$").isArray()) - .andExpect( - jsonPath("$.[0].shippingInstructionReference") - .value(mockShippingInstructionSummaryResponse.shippingInstructionReference())) - .andExpect( - jsonPath("$.[0].documentStatus") - .value(mockShippingInstructionSummaryResponse.documentStatus())); - } - - @Test - void testShippingInstructionSummary_getShipmentSummariesSingleResulWithCarrierBookingReference() - throws Exception { - ShippingInstructionSummaryTO mockShippingInstructionSummaryResponse = - ShippingInstructionSummaryDataFactory.singleShippingInstructionSummaryTO(); - Page pageResult = - new PageImpl<>(List.of(mockShippingInstructionSummaryResponse)); - when(shippingInstructionSummaryService.findShippingInstructionSummaries(any(), any(), any())) - .thenReturn(new PagedResult<>(pageResult)); - - mockMvc - .perform( - get(path) - .param("carrierBookingReference", "bca68f1d3b804ff88aaa1e43055432f7") - .accept(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(jsonPath("$").isArray()) - .andExpect( - jsonPath("$.[0].shippingInstructionReference") - .value(mockShippingInstructionSummaryResponse.shippingInstructionReference())) - .andExpect( - jsonPath("$.[0].carrierBookingReferences[0]") - .value(mockShippingInstructionSummaryResponse.carrierBookingReferences().get(0))); - } - - @Test - void - testShippingInstructionSummary_getShipmentSummariesSingleResulWithCarrierBookingReferenceAndDocumentStatus() - throws Exception { - ShippingInstructionSummaryTO mockShippingInstructionSummaryResponse = - ShippingInstructionSummaryDataFactory.singleShippingInstructionSummaryTO(); - Page pageResult = - new PageImpl<>(List.of(mockShippingInstructionSummaryResponse)); - when(shippingInstructionSummaryService.findShippingInstructionSummaries(any(), any(), any())) - .thenReturn(new PagedResult<>(pageResult)); - - mockMvc - .perform( - get(path) - .param("carrierBookingReference", "bca68f1d3b804ff88aaa1e43055432f7") - .param("documentStatus", "RECEIVED") - .accept(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(jsonPath("$").isArray()) - .andExpect( - jsonPath("$.[0].shippingInstructionReference") - .value(mockShippingInstructionSummaryResponse.shippingInstructionReference())) - .andExpect( - jsonPath("$.[0].carrierBookingReferences[0]") - .value(mockShippingInstructionSummaryResponse.carrierBookingReferences().get(0))) - .andExpect( - jsonPath("$.[0].documentStatus") - .value(mockShippingInstructionSummaryResponse.documentStatus())); - } - - @Test - void testShippingInstructionSummary_getShipmentSummariesMultipleResult() throws Exception { - List mockShippingInstructionSummaries = ShippingInstructionSummaryDataFactory.multipleShippingInstructionSummaryTO(); - Page pageResult = new PageImpl<>(mockShippingInstructionSummaries); - when(shippingInstructionSummaryService.findShippingInstructionSummaries(any(), any(), any())).thenReturn(new PagedResult<>(pageResult)); - - mockMvc - .perform( - get(path).accept(MediaType.APPLICATION_JSON) - ) - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(jsonPath("$").isArray()) - .andExpect( - jsonPath("$.[0].shippingInstructionReference") - .value(mockShippingInstructionSummaries.get(0).shippingInstructionReference())) - .andExpect( - jsonPath("$.[1].carrierBookingReferences[0]") - .value(mockShippingInstructionSummaries.get(1).carrierBookingReferences().get(0))) - .andExpect( - jsonPath("$.[1].shippingInstructionReference") - .value(mockShippingInstructionSummaries.get(1).shippingInstructionReference())) - .andExpect( - jsonPath("$.[0].carrierBookingReferences[0]") - .value(mockShippingInstructionSummaries.get(0).carrierBookingReferences().get(0))) - .andExpect( - jsonPath("$.[0].documentStatus") - .value(mockShippingInstructionSummaries.get(0).documentStatus())); - } - - @Test - void testShippingInstructionSummary_getShipmentSummariesWithInvalidDocumentStatus() - throws Exception { - List mockShippingInstructionSummaries = ShippingInstructionSummaryDataFactory.multipleShippingInstructionSummaryTO(); - Page pageResult = new PageImpl<>(mockShippingInstructionSummaries); - when(shippingInstructionSummaryService.findShippingInstructionSummaries(any(), any(), any())).thenReturn(new PagedResult<>(pageResult)); - - mockMvc - .perform(get(path).param("documentStatus", "INVALID").accept(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isBadRequest()) - .andExpect(jsonPath("$.httpMethod").value("GET")) - .andExpect(jsonPath("$.requestUri").value(path)) - .andExpect(jsonPath("$.errors[0].reason").value("invalidInput")) - .andExpect( - jsonPath("$.errors[0].message") - .value(containsString("documentStatus Unexpected value 'INVALID', should have been one of"))); - } -} diff --git a/edocumentation-application/src/test/java/org/dcsa/edocumentation/datafactories/BookingSummaryDataFactory.java b/edocumentation-application/src/test/java/org/dcsa/edocumentation/datafactories/BookingSummaryDataFactory.java deleted file mode 100644 index 76afc062..00000000 --- a/edocumentation-application/src/test/java/org/dcsa/edocumentation/datafactories/BookingSummaryDataFactory.java +++ /dev/null @@ -1,104 +0,0 @@ -package org.dcsa.edocumentation.datafactories; - -import lombok.experimental.UtilityClass; -import org.dcsa.edocumentation.infra.enums.BookingStatus; -import org.dcsa.edocumentation.transferobjects.BookingSummaryTO; -import org.dcsa.edocumentation.transferobjects.enums.*; - -import java.time.LocalDate; -import java.time.OffsetDateTime; -import java.util.List; - -@UtilityClass -public class BookingSummaryDataFactory { - - public BookingSummaryTO singleBookingSummaryTO() { - return BookingSummaryTO.builder() - .carrierBookingRequestReference("BOOKING_REQ_REF_01") - .bookingStatus(BookingStatus.RECEIVED) - .receiptTypeAtOrigin(ReceiptDeliveryType.CY) - .deliveryTypeAtDestination(ReceiptDeliveryType.CY) - .cargoMovementTypeAtOrigin(CargoMovementType.FCL) - .cargoMovementTypeAtDestination(CargoMovementType.FCL) - .serviceContractReference("serviceRef") - .paymentTermCode(PaymentTerm.COL) - .isPartialLoadAllowed(false) - .isExportDeclarationRequired(true) - .exportDeclarationReference("exportRef") - .isImportLicenseRequired(true) - .importLicenseReference("importRef") - .submissionDateTime(OffsetDateTime.now()) - .isAMSACIFilingRequired(true) - .isDestinationFilingRequired(true) - .contractQuotationReference("contractRef") - .incoTerms(IncoTerms.FCA.name()) - .expectedDepartureDate(LocalDate.of(2023, 10, 12)) - .expectedArrivalAtPlaceOfDeliveryStartDate(LocalDate.of(2023, 11, 9)) - .expectedArrivalAtPlaceOfDeliveryEndDate(LocalDate.of(2023, 11, 15)) - .transportDocumentTypeCode(TransportDocumentTypeCode.BOL) - .communicationChannelCode(CommunicationChannelCode.AO.name()) - .isEquipmentSubstitutionAllowed(false) - .vesselIMONumber("1234567") - .build(); - } - - public List multipleBookingSummaryTos() { - BookingSummaryTO bookingSummaryTO1 = BookingSummaryTO.builder() - .carrierBookingRequestReference("BOOKING_REQ_REF_01") - .bookingStatus(BookingStatus.RECEIVED) - .receiptTypeAtOrigin(ReceiptDeliveryType.CY) - .deliveryTypeAtDestination(ReceiptDeliveryType.CY) - .cargoMovementTypeAtOrigin(CargoMovementType.FCL) - .cargoMovementTypeAtDestination(CargoMovementType.FCL) - .serviceContractReference("serviceRef") - .paymentTermCode(PaymentTerm.COL) - .isPartialLoadAllowed(false) - .isExportDeclarationRequired(true) - .exportDeclarationReference("exportRef") - .isImportLicenseRequired(true) - .importLicenseReference("importRef") - .submissionDateTime(OffsetDateTime.now()) - .isAMSACIFilingRequired(true) - .isDestinationFilingRequired(true) - .contractQuotationReference("contractRef") - .incoTerms(IncoTerms.FCA.name()) - .expectedDepartureDate(LocalDate.of(2023, 10, 12)) - .expectedArrivalAtPlaceOfDeliveryStartDate(LocalDate.of(2023, 11, 9)) - .expectedArrivalAtPlaceOfDeliveryEndDate(LocalDate.of(2023, 11, 15)) - .transportDocumentTypeCode(TransportDocumentTypeCode.BOL) - .communicationChannelCode(CommunicationChannelCode.AO.name()) - .isEquipmentSubstitutionAllowed(false) - .vesselIMONumber("1234567") - .build(); - - BookingSummaryTO bookingSummaryTO2 = BookingSummaryTO.builder() - .carrierBookingRequestReference("BOOKING_REQ_REF_02") - .bookingStatus(BookingStatus.RECEIVED) - .receiptTypeAtOrigin(ReceiptDeliveryType.CY) - .deliveryTypeAtDestination(ReceiptDeliveryType.CY) - .cargoMovementTypeAtOrigin(CargoMovementType.FCL) - .cargoMovementTypeAtDestination(CargoMovementType.FCL) - .serviceContractReference("serviceRef") - .paymentTermCode(PaymentTerm.COL) - .isPartialLoadAllowed(false) - .isExportDeclarationRequired(true) - .exportDeclarationReference("exportRef") - .isImportLicenseRequired(true) - .importLicenseReference("importRef") - .submissionDateTime(OffsetDateTime.now()) - .isAMSACIFilingRequired(true) - .isDestinationFilingRequired(true) - .contractQuotationReference("contractRef") - .incoTerms(IncoTerms.FCA.name()) - .expectedDepartureDate(LocalDate.of(2023, 10, 12)) - .expectedArrivalAtPlaceOfDeliveryStartDate(LocalDate.of(2023, 11, 9)) - .expectedArrivalAtPlaceOfDeliveryEndDate(LocalDate.of(2023, 11, 15)) - .transportDocumentTypeCode(TransportDocumentTypeCode.BOL) - .communicationChannelCode(CommunicationChannelCode.AO.name()) - .isEquipmentSubstitutionAllowed(false) - .vesselIMONumber("1234567") - .build(); - - return List.of(bookingSummaryTO1, bookingSummaryTO2); - } -} diff --git a/edocumentation-application/src/test/java/org/dcsa/edocumentation/datafactories/ShippingInstructionSummaryDataFactory.java b/edocumentation-application/src/test/java/org/dcsa/edocumentation/datafactories/ShippingInstructionSummaryDataFactory.java deleted file mode 100644 index 7d57b475..00000000 --- a/edocumentation-application/src/test/java/org/dcsa/edocumentation/datafactories/ShippingInstructionSummaryDataFactory.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.dcsa.edocumentation.datafactories; - -import lombok.experimental.UtilityClass; -import org.dcsa.edocumentation.transferobjects.ShippingInstructionSummaryTO; -import org.dcsa.edocumentation.infra.enums.EblDocumentStatus; -import org.dcsa.edocumentation.transferobjects.enums.TransportDocumentTypeCode; - -import java.time.OffsetDateTime; -import java.util.List; -import java.util.UUID; - -@UtilityClass -public class ShippingInstructionSummaryDataFactory { - - public ShippingInstructionSummaryTO singleShippingInstructionSummaryTO() { - return ShippingInstructionSummaryTO.builder() - .shippingInstructionReference(UUID.randomUUID().toString()) - .documentStatus(EblDocumentStatus.RECEIVED) - .carrierBookingReferences( - List.of("bca68f1d3b804ff88aaa1e43055432f7", "832deb4bd4ea4b728430b857c59bd057")) - .shippingInstructionCreatedDateTime(OffsetDateTime.now()) - .shippingInstructionUpdatedDateTime(OffsetDateTime.now()) - .transportDocumentTypeCode(TransportDocumentTypeCode.BOL) - .isShippedOnBoardType(true) - .isElectronic(true) - .isToOrder(true) - .areChargesDisplayedOnOriginals(false) - .areChargesDisplayedOnOriginals(false) - .displayedNameForPlaceOfDelivery(List.of("Amsterdam")) - .displayedNameForPlaceOfReceipt(List.of("Singapore")) - .displayedNameForPortOfLoad(List.of("Port of Singapore")) - .displayedNameForPortOfDischarge(List.of("Port of Rotterdam")) - .build(); - } - - public List multipleShippingInstructionSummaryTO() { - ShippingInstructionSummaryTO shippingInstructionSummaryTO = ShippingInstructionSummaryTO.builder() - .shippingInstructionReference(UUID.randomUUID().toString()) - .documentStatus(EblDocumentStatus.RECEIVED) - .carrierBookingReferences( - List.of("bca68f1d3b804ff88aaa1e43055432f7", "832deb4bd4ea4b728430b857c59bd057")) - .shippingInstructionCreatedDateTime(OffsetDateTime.now()) - .shippingInstructionUpdatedDateTime(OffsetDateTime.now()) - .transportDocumentTypeCode(TransportDocumentTypeCode.BOL) - .isShippedOnBoardType(true) - .isElectronic(true) - .isToOrder(true) - .areChargesDisplayedOnOriginals(false) - .areChargesDisplayedOnOriginals(false) - .displayedNameForPlaceOfDelivery(List.of("Los Angeles")) - .displayedNameForPlaceOfReceipt(List.of("Hong Kong")) - .displayedNameForPortOfLoad(List.of("Port of Hong Kong")) - .displayedNameForPortOfDischarge(List.of("Port of Long Beach")) - .build(); - - return List.of(shippingInstructionSummaryTO, singleShippingInstructionSummaryTO()); - } -} diff --git a/edocumentation-domain/src/main/java/org/dcsa/edocumentation/domain/persistence/repository/BookingRequestRepository.java b/edocumentation-domain/src/main/java/org/dcsa/edocumentation/domain/persistence/repository/BookingRequestRepository.java index 83c63272..3e927dea 100644 --- a/edocumentation-domain/src/main/java/org/dcsa/edocumentation/domain/persistence/repository/BookingRequestRepository.java +++ b/edocumentation-domain/src/main/java/org/dcsa/edocumentation/domain/persistence/repository/BookingRequestRepository.java @@ -14,21 +14,6 @@ @Repository public interface BookingRequestRepository extends JpaRepository { - @EntityGraph("graph.booking-request-summary") - @Query( - value = "FROM BookingRequest WHERE bookingStatus = :bookingStatus AND validUntil IS NULL", - countQuery = "SELECT count(*) FROM BookingRequest WHERE bookingStatus = :bookingStatus AND validUntil IS NULL" - ) - Page findAllByBookingStatus( - @NonNull String bookingStatus, Pageable pageable); - - @EntityGraph("graph.booking-request-summary") - @Query( - value = "FROM BookingRequest WHERE validUntil IS NULL", - countQuery = "SELECT count(*) FROM BookingRequest WHERE validUntil IS NULL" - ) - @Override - Page findAll(Pageable pageable); @EntityGraph("graph.booking-request") @Query("FROM BookingRequest WHERE carrierBookingRequestReference = :carrierBookingRequestReference AND validUntil IS NULL") diff --git a/edocumentation-domain/src/main/java/org/dcsa/edocumentation/domain/persistence/repository/ShippingInstructionRepository.java b/edocumentation-domain/src/main/java/org/dcsa/edocumentation/domain/persistence/repository/ShippingInstructionRepository.java index 1de5485b..0f4d04ce 100644 --- a/edocumentation-domain/src/main/java/org/dcsa/edocumentation/domain/persistence/repository/ShippingInstructionRepository.java +++ b/edocumentation-domain/src/main/java/org/dcsa/edocumentation/domain/persistence/repository/ShippingInstructionRepository.java @@ -1,14 +1,9 @@ package org.dcsa.edocumentation.domain.persistence.repository; import org.dcsa.edocumentation.domain.persistence.entity.ShippingInstruction; -import org.dcsa.edocumentation.domain.persistence.repository.specification.ShippingInstructionSpecification; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.repository.EntityGraph; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.lang.Nullable; import org.springframework.stereotype.Repository; import java.util.List; diff --git a/edocumentation-domain/src/main/java/org/dcsa/edocumentation/domain/persistence/repository/specification/ShippingInstructionSpecification.java b/edocumentation-domain/src/main/java/org/dcsa/edocumentation/domain/persistence/repository/specification/ShippingInstructionSpecification.java deleted file mode 100644 index 85485aef..00000000 --- a/edocumentation-domain/src/main/java/org/dcsa/edocumentation/domain/persistence/repository/specification/ShippingInstructionSpecification.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.dcsa.edocumentation.domain.persistence.repository.specification; - -import lombok.Builder; -import lombok.experimental.UtilityClass; -import lombok.extern.slf4j.Slf4j; -import org.dcsa.edocumentation.domain.persistence.entity.*; -import org.springframework.data.jpa.domain.Specification; - -import jakarta.persistence.criteria.*; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -@Slf4j -@UtilityClass -public class ShippingInstructionSpecification { - - public record ShippingInstructionFilters( - List carrierBookingReference, String documentStatus) { - @Builder - public ShippingInstructionFilters {} - } - - public static Specification withFilters( - final ShippingInstructionFilters filters) { - - return (root, query, builder) -> { - List predicates = new ArrayList<>(); - - if (null != filters.documentStatus) { - Predicate predicate = builder.equal(root.get(ShippingInstruction_.DOCUMENT_STATUS), filters.documentStatus); - predicates.add(predicate); - } - if (null != filters.carrierBookingReference && !filters.carrierBookingReference.isEmpty()) { - var subquery = query.subquery(UUID.class); - var subqueryRoot = subquery.from(ShippingInstruction.class); - var consignmentItemRoot = subqueryRoot.join(ShippingInstruction_.CONSIGNMENT_ITEMS); - var consignmentItemShipmentJoin = consignmentItemRoot.join(ConsignmentItem_.CONFIRMED_BOOKING, JoinType.LEFT); - subquery.select(subqueryRoot.get(ShippingInstruction_.ID)); - subquery.where(builder - .in(consignmentItemShipmentJoin.get(ConfirmedBooking_.CARRIER_BOOKING_REFERENCE)) - .value(filters.carrierBookingReference)); - Predicate predicate = builder.in(root.get(ShippingInstruction_.ID)).value(subquery); - predicates.add(predicate); - } - return builder.and(predicates.toArray(Predicate[]::new)); - }; - } -} diff --git a/edocumentation-domain/src/main/java/org/dcsa/edocumentation/domain/persistence/repository/specification/TransportDocumentSpecification.java b/edocumentation-domain/src/main/java/org/dcsa/edocumentation/domain/persistence/repository/specification/TransportDocumentSpecification.java deleted file mode 100644 index 24ca97d3..00000000 --- a/edocumentation-domain/src/main/java/org/dcsa/edocumentation/domain/persistence/repository/specification/TransportDocumentSpecification.java +++ /dev/null @@ -1,62 +0,0 @@ -package org.dcsa.edocumentation.domain.persistence.repository.specification; - -import lombok.AccessLevel; -import lombok.Builder; -import lombok.NoArgsConstructor; -import org.dcsa.edocumentation.domain.persistence.entity.*; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; - -import jakarta.persistence.criteria.Join; -import jakarta.persistence.criteria.JoinType; -import jakarta.persistence.criteria.Predicate; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class TransportDocumentSpecification { - - @Builder(toBuilder = true) - public static class Filters { - private List carrierBookingReference; - private String documentStatus; - private PageRequest pageRequest; - } - - public static Specification withFilters(final Filters filters) { - - return (root, query, builder) -> { - Join tdSiJoin = - root.join(TransportDocument_.SHIPPING_INSTRUCTION, JoinType.LEFT); - - List predicates = new ArrayList<>(); - - - - if (null != filters.documentStatus) { - Predicate docStatusPredicate = - builder.equal( - tdSiJoin.get(ShippingInstruction_.DOCUMENT_STATUS), filters.documentStatus); - predicates.add(docStatusPredicate); - } - - if (null != filters.carrierBookingReference) { - var subquery = query.subquery(UUID.class); - var subqueryRoot = subquery.from(ShippingInstruction.class); - var consignmentItemRoot = subqueryRoot.join(ShippingInstruction_.CONSIGNMENT_ITEMS); - var consignmentItemShipmentJoin = consignmentItemRoot.join(ConsignmentItem_.CONFIRMED_BOOKING, JoinType.LEFT); - subquery.select(subqueryRoot.get(ShippingInstruction_.ID)); - subquery.where(builder - .in(consignmentItemShipmentJoin.get(ConfirmedBooking_.CARRIER_BOOKING_REFERENCE)) - .value(filters.carrierBookingReference)); - Predicate predicate = builder.in( - root.get(TransportDocument_.SHIPPING_INSTRUCTION).get(ShippingInstruction_.ID) - ).value(subquery); - predicates.add(predicate); - } - - return builder.and(predicates.toArray(Predicate[]::new)); - }; - } -} diff --git a/edocumentation-service/src/main/java/org/dcsa/edocumentation/service/BookingSummaryService.java b/edocumentation-service/src/main/java/org/dcsa/edocumentation/service/BookingSummaryService.java deleted file mode 100644 index 7de5dce3..00000000 --- a/edocumentation-service/src/main/java/org/dcsa/edocumentation/service/BookingSummaryService.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.dcsa.edocumentation.service; - -import lombok.RequiredArgsConstructor; -import org.dcsa.edocumentation.domain.persistence.repository.BookingRequestRepository; -import org.dcsa.edocumentation.service.mapping.BookingSummaryMapper; -import org.dcsa.edocumentation.transferobjects.BookingSummaryTO; -import org.dcsa.skernel.infrastructure.pagination.PagedResult; -import org.springframework.data.domain.PageRequest; -import org.springframework.stereotype.Service; - -import jakarta.transaction.Transactional; -import java.util.Optional; - -@Service -@RequiredArgsConstructor -public class BookingSummaryService { - private final BookingRequestRepository repository; - private final BookingSummaryMapper bookingSummaryMapper; - - @Transactional - public PagedResult findBookingSummaries( - PageRequest pageRequest, String bookingStatus) { - - return new PagedResult<>( - Optional.ofNullable(bookingStatus) - .map( - bookingStatus2 -> - repository.findAllByBookingStatus(bookingStatus2, pageRequest)) - .orElseGet(() -> repository.findAll(pageRequest)) - .map(bookingSummaryMapper::BookingToBookingSummary)); - } -} diff --git a/edocumentation-service/src/main/java/org/dcsa/edocumentation/service/ShippingInstructionSummaryService.java b/edocumentation-service/src/main/java/org/dcsa/edocumentation/service/ShippingInstructionSummaryService.java deleted file mode 100644 index e6d88c47..00000000 --- a/edocumentation-service/src/main/java/org/dcsa/edocumentation/service/ShippingInstructionSummaryService.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.dcsa.edocumentation.service; - -import jakarta.transaction.Transactional; -import lombok.RequiredArgsConstructor; -import org.dcsa.edocumentation.domain.persistence.entity.ShippingInstruction; -import org.dcsa.edocumentation.domain.persistence.repository.ShippingInstructionRepository; -import org.dcsa.edocumentation.domain.persistence.repository.specification.ShippingInstructionSpecification; -import org.dcsa.edocumentation.service.mapping.ShippingInstructionSummaryMapper; -import org.dcsa.edocumentation.transferobjects.ShippingInstructionSummaryTO; -import org.dcsa.skernel.infrastructure.pagination.PagedResult; -import org.springframework.data.domain.PageRequest; -import org.springframework.lang.Nullable; -import org.springframework.stereotype.Service; - -import java.util.Arrays; -import java.util.UUID; - -@Service -@RequiredArgsConstructor -public class ShippingInstructionSummaryService extends AbstractSpecificationService { - private final ShippingInstructionRepository shippingInstructionRepository; - private final ShippingInstructionSummaryMapper shippingInstructionMapper; - - @Override - protected ShippingInstructionRepository getRepository() { - return shippingInstructionRepository; - } - - @Transactional - public PagedResult findShippingInstructionSummaries( - PageRequest pageRequest, - String documentStatus, - @Nullable String carrierBookingReference) { - return this.findViaComplexSpecificationWithLookup( - ShippingInstructionSpecification.withFilters( - ShippingInstructionSpecification.ShippingInstructionFilters.builder() - .carrierBookingReference( - carrierBookingReference == null - ? null - : Arrays.asList(carrierBookingReference.split(","))) - .documentStatus(documentStatus) - .build()), - pageRequest, - ShippingInstruction::getId, - shippingInstructionMapper::shippingInstructionToShippingInstructionSummary - ); - } -} diff --git a/edocumentation-service/src/main/java/org/dcsa/edocumentation/service/mapping/BookingSummaryMapper.java b/edocumentation-service/src/main/java/org/dcsa/edocumentation/service/mapping/BookingSummaryMapper.java deleted file mode 100644 index e0a9c0e1..00000000 --- a/edocumentation-service/src/main/java/org/dcsa/edocumentation/service/mapping/BookingSummaryMapper.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.dcsa.edocumentation.service.mapping; - -import org.dcsa.edocumentation.domain.persistence.entity.BookingRequest; -import org.dcsa.edocumentation.transferobjects.BookingSummaryTO; -import org.mapstruct.Mapper; -import org.mapstruct.Mapping; - -@Mapper(componentModel = "spring", config = EDocumentationMappingConfig.class) -public interface BookingSummaryMapper { - - @Mapping(source = "bookingRequest.vessel.vesselIMONumber", target = "vesselIMONumber") - @Mapping(target = "submissionDateTime", ignore = true) // FIXME: Verify if this should be mapped - @Mapping(target = "vesselName", ignore = true) // FIXME: Verify if this should be mapped - @Mapping(target = "exportVoyageNumber", ignore = true) // FIXME: Verify if this should be mapped - BookingSummaryTO BookingToBookingSummary(BookingRequest bookingRequest); -} diff --git a/edocumentation-service/src/main/java/org/dcsa/edocumentation/service/mapping/ShippingInstructionSummaryMapper.java b/edocumentation-service/src/main/java/org/dcsa/edocumentation/service/mapping/ShippingInstructionSummaryMapper.java deleted file mode 100644 index b2a277fb..00000000 --- a/edocumentation-service/src/main/java/org/dcsa/edocumentation/service/mapping/ShippingInstructionSummaryMapper.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.dcsa.edocumentation.service.mapping; - -import org.dcsa.edocumentation.domain.persistence.entity.ConsignmentItem; -import org.dcsa.edocumentation.domain.persistence.entity.ShippingInstruction; -import org.dcsa.edocumentation.transferobjects.ShippingInstructionSummaryTO; -import org.mapstruct.Mapper; -import org.mapstruct.Mapping; - -@Mapper( - componentModel = "spring", - config = EDocumentationMappingConfig.class, - uses = {DisplayedAddressMapper.class}) -public interface ShippingInstructionSummaryMapper { - @Mapping( - source = "consignmentItems", - target = "carrierBookingReferences") - @Mapping(target = "amendToTransportDocument", ignore = true) // FIXME: amendToTransportDocument is obsolete and should be removed! - @Mapping(target = "areChargesDisplayedOnOriginals", ignore = true) // Not in the swagger entity - ShippingInstructionSummaryTO shippingInstructionToShippingInstructionSummary(ShippingInstruction shippingInstruction); - - default String mapShipmentToCarrierBookingReference(ConsignmentItem consignmentItem) { - return consignmentItem.getCarrierBookingReference(); - } -} diff --git a/edocumentation-service/src/test/java/org/dcsa/edocumentation/service/BookingRequestSummaryServiceTest.java b/edocumentation-service/src/test/java/org/dcsa/edocumentation/service/BookingRequestSummaryServiceTest.java deleted file mode 100644 index 3ff6d59d..00000000 --- a/edocumentation-service/src/test/java/org/dcsa/edocumentation/service/BookingRequestSummaryServiceTest.java +++ /dev/null @@ -1,127 +0,0 @@ -package org.dcsa.edocumentation.service; - -import org.dcsa.edocumentation.datafactories.BookingDataFactory; -import org.dcsa.edocumentation.domain.persistence.entity.BookingRequest; -import org.dcsa.edocumentation.infra.enums.BookingStatus; -import org.dcsa.edocumentation.domain.persistence.repository.BookingRequestRepository; -import org.dcsa.edocumentation.service.mapping.BookingSummaryMapper; -import org.dcsa.edocumentation.transferobjects.BookingSummaryTO; -import org.dcsa.skernel.infrastructure.pagination.PagedResult; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mapstruct.factory.Mappers; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Spy; -import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageImpl; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; - -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; - -@ExtendWith(MockitoExtension.class) -class BookingRequestSummaryServiceTest { - - @Mock private BookingRequestRepository bookingRequestRepository; - - @Spy - private BookingSummaryMapper bookingSummaryMapper = Mappers.getMapper(BookingSummaryMapper.class); - - @InjectMocks private BookingSummaryService bookingSummaryService; - - private final PageRequest mockPageRequest = PageRequest.of(1, 1); - - @Test - void testBookingSummary_singleResultNoDocumentStatus() { - BookingRequest mockBookingRequest = BookingDataFactory.singleShallowBookingWithVesselAndModeOfTransport(); - Page pagedResult = new PageImpl<>(List.of(mockBookingRequest)); - when(bookingRequestRepository.findAll(any(Pageable.class))).thenReturn(pagedResult); - - PagedResult result = - bookingSummaryService.findBookingSummaries(mockPageRequest, null); - assertEquals(1, result.totalPages()); - assertEquals( - mockBookingRequest.getCarrierBookingRequestReference(), - result.content().get(0).carrierBookingRequestReference()); - assertEquals( - mockBookingRequest.getVessel().getVesselIMONumber(), result.content().get(0).vesselIMONumber()); - } - - @Test - void testBookingSummary_singleResultWithDocumentStatus() { - BookingRequest mockBookingRequest = BookingDataFactory.singleShallowBookingWithVesselAndModeOfTransport(); - Page pagedResult = new PageImpl<>(List.of(mockBookingRequest)); - when(bookingRequestRepository.findAllByBookingStatus(any(), any(Pageable.class))) - .thenReturn(pagedResult); - - PagedResult result = - bookingSummaryService.findBookingSummaries( - mockPageRequest, BookingStatus.RECEIVED); - assertEquals(1, result.totalPages()); - assertEquals( - mockBookingRequest.getCarrierBookingRequestReference(), - result.content().get(0).carrierBookingRequestReference()); - } - - @Test - void testBookingSummary_multipleResultsWithoutDocumentStatus() { - List mockBookingRequests = - BookingDataFactory.multipleShallowBookingsWithVesselAndModeOfTransport(); - Page pagedResult = new PageImpl<>(mockBookingRequests); - when(bookingRequestRepository.findAll(any(Pageable.class))).thenReturn(pagedResult); - - PagedResult result = - bookingSummaryService.findBookingSummaries(mockPageRequest, null); - assertEquals(1, result.totalPages()); - assertEquals(2, result.content().size()); - assertEquals( - mockBookingRequests.get(0).getCarrierBookingRequestReference(), - result.content().get(0).carrierBookingRequestReference()); - assertEquals( - mockBookingRequests.get(1).getCarrierBookingRequestReference(), - result.content().get(1).carrierBookingRequestReference()); - } - - @Test - void testBookingSummary_multipleResultsWithDocumentStatus() { - List mockBookingRequests = - BookingDataFactory.multipleShallowBookingsWithVesselAndModeOfTransport(); - Page pagedResult = new PageImpl<>(mockBookingRequests); - when(bookingRequestRepository.findAllByBookingStatus(any(), any(Pageable.class))) - .thenReturn(pagedResult); - - PagedResult result = - bookingSummaryService.findBookingSummaries( - mockPageRequest, BookingStatus.RECEIVED); - assertEquals(1, result.totalPages()); - assertEquals(2, result.content().size()); - assertEquals( - mockBookingRequests.get(0).getCarrierBookingRequestReference(), - result.content().get(0).carrierBookingRequestReference()); - assertEquals( - mockBookingRequests.get(1).getCarrierBookingRequestReference(), - result.content().get(1).carrierBookingRequestReference()); - } - - @Test - void testBookingSummary_singleResultWithoutDocumentStatusWithoutVessel() { - BookingRequest mockBookingRequest = BookingDataFactory.singleShallowBooking(); - Page pagedResult = new PageImpl<>(List.of(mockBookingRequest)); - when(bookingRequestRepository.findAll(any(Pageable.class))).thenReturn(pagedResult); - - PagedResult result = - bookingSummaryService.findBookingSummaries(mockPageRequest, null); - assertEquals(1, result.totalPages()); - assertEquals( - mockBookingRequest.getCarrierBookingRequestReference(), - result.content().get(0).carrierBookingRequestReference()); - assertNull(result.content().get(0).vesselIMONumber()); - } -} diff --git a/edocumentation-service/src/test/java/org/dcsa/edocumentation/service/ShippingInstructionSummaryServiceTest.java b/edocumentation-service/src/test/java/org/dcsa/edocumentation/service/ShippingInstructionSummaryServiceTest.java deleted file mode 100644 index ea2f95b2..00000000 --- a/edocumentation-service/src/test/java/org/dcsa/edocumentation/service/ShippingInstructionSummaryServiceTest.java +++ /dev/null @@ -1,208 +0,0 @@ -package org.dcsa.edocumentation.service; - -import org.dcsa.edocumentation.datafactories.ShippingInstructionDataFactory; -import org.dcsa.edocumentation.domain.persistence.entity.ShippingInstruction; -import org.dcsa.edocumentation.infra.enums.EblDocumentStatus; -import org.dcsa.edocumentation.domain.persistence.repository.ShippingInstructionRepository; -import org.dcsa.edocumentation.service.mapping.DisplayedAddressMapper; -import org.dcsa.edocumentation.service.mapping.ShippingInstructionSummaryMapper; -import org.dcsa.edocumentation.transferobjects.ShippingInstructionSummaryTO; -import org.dcsa.skernel.infrastructure.pagination.PagedResult; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mapstruct.factory.Mappers; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Spy; -import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageImpl; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.test.util.ReflectionTestUtils; - -import java.util.List; -import java.util.UUID; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; - -@ExtendWith(MockitoExtension.class) -class ShippingInstructionSummaryServiceTest { - - @Mock private ShippingInstructionRepository shippingInstructionRepository; - - @Spy - private ShippingInstructionSummaryMapper shippingInstructionSummaryMapper = - Mappers.getMapper(ShippingInstructionSummaryMapper.class); - - @InjectMocks private ShippingInstructionSummaryService service; - - private final PageRequest mockPageRequest = PageRequest.of(1, 1); - - @BeforeEach - void setupMappers() { - DisplayedAddressMapper displayedAddressMapper = new DisplayedAddressMapper(); - ReflectionTestUtils.setField(shippingInstructionSummaryMapper, "displayedAddressMapper", displayedAddressMapper); - } - - @Test - void testShippingInstructionSummary_singleShallowResult() { - ShippingInstruction mockShippingInstruction = - ShippingInstructionDataFactory.singleShallowShippingInstruction(); - Page pagedResult = new PageImpl<>(List.of(mockShippingInstruction)); - when(shippingInstructionRepository.findAll(any(Specification.class), any(Pageable.class))) - .thenReturn(pagedResult); - when(shippingInstructionRepository.findAllById(any(List.class))) - .thenReturn(List.of(mockShippingInstruction)); - - PagedResult result = - service.findShippingInstructionSummaries(mockPageRequest, null, null); - assertEquals(1, result.totalPages()); - assertEquals( - mockShippingInstruction.getShippingInstructionReference(), - result.content().get(0).shippingInstructionReference()); - assertEquals( - mockShippingInstruction.getShippingInstructionCreatedDateTime(), - result.content().get(0).shippingInstructionCreatedDateTime()); - assertNull(mockShippingInstruction.getConsignmentItems()); - } - - @Test - void testShippingInstructionSummary_singleShallowResultWithDocumentStatus() { - ShippingInstruction mockShippingInstruction = - ShippingInstructionDataFactory.singleShallowShippingInstruction(); - Page pagedResult = new PageImpl<>(List.of(mockShippingInstruction)); - when(shippingInstructionRepository.findAll(any(Specification.class), any(Pageable.class))) - .thenReturn(pagedResult); - when(shippingInstructionRepository.findAllById(any(List.class))) - .thenReturn(List.of(mockShippingInstruction)); - - PagedResult result = - service.findShippingInstructionSummaries(mockPageRequest, EblDocumentStatus.RECEIVED, null); - assertEquals(1, result.totalPages()); - assertEquals( - mockShippingInstruction.getShippingInstructionReference(), - result.content().get(0).shippingInstructionReference()); - assertEquals( - mockShippingInstruction.getShippingInstructionCreatedDateTime(), - result.content().get(0).shippingInstructionCreatedDateTime()); - assertNull(mockShippingInstruction.getConsignmentItems()); - } - - @Test - void testShippingInstructionSummary_singleShallowResultWithShipment() { - ShippingInstruction mockShippingInstruction = - ShippingInstructionDataFactory - .singleShallowShippingInstructionWithPlaceOfIssueAndShipments(); - Page pagedResult = new PageImpl<>(List.of(mockShippingInstruction)); - when(shippingInstructionRepository.findAll(any(Specification.class), any(Pageable.class))) - .thenReturn(pagedResult); - when(shippingInstructionRepository.findAllById(any(List.class))) - .thenReturn(List.of(mockShippingInstruction)); - - PagedResult result = - service.findShippingInstructionSummaries(mockPageRequest, null, null); - assertEquals(1, result.totalPages()); - assertEquals( - mockShippingInstruction.getShippingInstructionReference(), - result.content().get(0).shippingInstructionReference()); - assertEquals( - mockShippingInstruction.getShippingInstructionCreatedDateTime(), - result.content().get(0).shippingInstructionCreatedDateTime()); - assertEquals( - mockShippingInstruction.getConsignmentItems().stream() - .toList() - .get(0) - .getCarrierBookingReference(), - result.content().get(0).carrierBookingReferences().get(0)); - } - - @Test - void testShippingInstructionSummary_singleShallowResultWithShipmentWithCarrierBookingReference() { - ShippingInstruction mockShippingInstruction = - ShippingInstructionDataFactory - .singleShallowShippingInstructionWithPlaceOfIssueAndShipments(); - Page pagedResult = new PageImpl<>(List.of(mockShippingInstruction)); - when(shippingInstructionRepository.findAll(any(Specification.class), any(Pageable.class))) - .thenReturn(pagedResult); - when(shippingInstructionRepository.findAllById(any(List.class))) - .thenReturn(List.of(mockShippingInstruction)); - - PagedResult result = - service.findShippingInstructionSummaries(mockPageRequest, null, UUID.randomUUID().toString()); - assertEquals(1, result.totalPages()); - assertEquals( - mockShippingInstruction.getShippingInstructionReference(), - result.content().get(0).shippingInstructionReference()); - assertEquals( - mockShippingInstruction.getShippingInstructionCreatedDateTime(), - result.content().get(0).shippingInstructionCreatedDateTime()); - assertEquals( - mockShippingInstruction.getConsignmentItems().stream() - .toList() - .get(0) - .getCarrierBookingReference(), - result.content().get(0).carrierBookingReferences().get(0)); - } - - @Test - void testShippingInstructionSummary_singleShallowResultWithShipmentWithCarrierBookingReferenceAndDocumentStatus() { - ShippingInstruction mockShippingInstruction = - ShippingInstructionDataFactory - .singleShallowShippingInstructionWithPlaceOfIssueAndShipments(); - Page pagedResult = new PageImpl<>(List.of(mockShippingInstruction)); - when(shippingInstructionRepository.findAll(any(Specification.class), any(Pageable.class))) - .thenReturn(pagedResult); - when(shippingInstructionRepository.findAllById(any(List.class))) - .thenReturn(List.of(mockShippingInstruction)); - - PagedResult result = - service.findShippingInstructionSummaries(mockPageRequest, EblDocumentStatus.RECEIVED, UUID.randomUUID().toString()); - assertEquals(1, result.totalPages()); - assertEquals( - mockShippingInstruction.getShippingInstructionReference(), - result.content().get(0).shippingInstructionReference()); - assertEquals( - mockShippingInstruction.getShippingInstructionCreatedDateTime(), - result.content().get(0).shippingInstructionCreatedDateTime()); - assertEquals( - mockShippingInstruction.getConsignmentItems().stream() - .toList() - .get(0) - .getCarrierBookingReference(), - result.content().get(0).carrierBookingReferences().get(0)); - } - - @Test - void testShippingInstructionSummary_multipleShallowResultsWithShipment() { - List mockShippingInstructions = - ShippingInstructionDataFactory - .multipleShallowShippingInstructionWithPlaceOfIssueAndShipments(); - Page pagedResult = new PageImpl<>(mockShippingInstructions); - when(shippingInstructionRepository.findAll(any(Specification.class), any(Pageable.class))) - .thenReturn(pagedResult); - when(shippingInstructionRepository.findAllById(any(List.class))) - .thenReturn(mockShippingInstructions); - - PagedResult result = - service.findShippingInstructionSummaries(mockPageRequest, null, null); - assertEquals(1, result.totalPages()); - assertEquals( - mockShippingInstructions.get(0).getShippingInstructionReference(), - result.content().get(0).shippingInstructionReference()); - assertEquals( - mockShippingInstructions.get(0).getShippingInstructionCreatedDateTime(), - result.content().get(0).shippingInstructionCreatedDateTime()); - assertEquals( - mockShippingInstructions.get(0).getConsignmentItems().stream() - .toList() - .get(0) - .getCarrierBookingReference(), - result.content().get(0).carrierBookingReferences().get(0)); - } -} diff --git a/edocumentation-transfer-obj/src/main/java/org/dcsa/edocumentation/transferobjects/BookingSummaryTO.java b/edocumentation-transfer-obj/src/main/java/org/dcsa/edocumentation/transferobjects/BookingSummaryTO.java deleted file mode 100644 index d44b26db..00000000 --- a/edocumentation-transfer-obj/src/main/java/org/dcsa/edocumentation/transferobjects/BookingSummaryTO.java +++ /dev/null @@ -1,115 +0,0 @@ -package org.dcsa.edocumentation.transferobjects; - -import com.fasterxml.jackson.annotation.JsonFormat; -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.Builder; -import org.dcsa.edocumentation.transferobjects.enums.*; -import org.dcsa.skernel.infrastructure.validation.PseudoEnum; -import org.dcsa.skernel.infrastructure.validation.ValidVesselIMONumber; - -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.NotNull; -import jakarta.validation.constraints.Size; -import java.time.LocalDate; -import java.time.OffsetDateTime; -import java.util.List; - -public record BookingSummaryTO( - String carrierBookingRequestReference, - - @JsonProperty(access = JsonProperty.Access.READ_ONLY) - //TODO: enable once DT-211 changes are merged to the master - // @PseudoEnum(value = "bookingstatuscodes.csv", column = "booking_status_code") - String bookingStatus, - - @JsonProperty(access = JsonProperty.Access.READ_ONLY) - List requestedChanges, - - @JsonProperty(access = JsonProperty.Access.READ_ONLY) - @JsonFormat(shape = JsonFormat.Shape.STRING) - OffsetDateTime bookingRequestCreatedDateTime, - - @JsonProperty(access = JsonProperty.Access.READ_ONLY) - @JsonFormat(shape = JsonFormat.Shape.STRING) - OffsetDateTime bookingRequestUpdatedDateTime, - - @NotNull(message = "The attribute receiptTypeAtOrigin is required.") - ReceiptDeliveryType receiptTypeAtOrigin, - - @NotNull(message = "The attribute deliveryTypeAtDestination is required.") - ReceiptDeliveryType deliveryTypeAtDestination, - - @NotNull(message = "The attribute cargoMovementTypeAtOrigin is required.") - CargoMovementType cargoMovementTypeAtOrigin, - - @NotNull(message = "The attribute cargoMovementTypeAtDestination is required.") - CargoMovementType cargoMovementTypeAtDestination, - - @NotBlank(message = "The attribute serviceContractReference is required.") - @Size(max = 30, message = "The attribute serviceContractReference has a max size of 30.") - String serviceContractReference, - - PaymentTerm paymentTermCode, - - @NotNull(message = "The attribute isPartialLoadAllowed is required.") - Boolean isPartialLoadAllowed, - - @NotNull(message = "The attribute isExportDeclarationRequired is required.") - Boolean isExportDeclarationRequired, - - String exportDeclarationReference, - - @NotNull(message = "The attribute isImportLicenseRequired is required.") - Boolean isImportLicenseRequired, - - @Size(max = 35, message = "The attribute importLicenseReference has a max size of 35.") - String importLicenseReference, - - @JsonFormat(shape = JsonFormat.Shape.STRING) - @NotNull(message = "The attribute submissionDateTime is required.") - OffsetDateTime submissionDateTime, - - Boolean isAMSACIFilingRequired, - - Boolean isDestinationFilingRequired, - - @Size(max = 35, message = "The attribute contractQuotationReference has a max size of 35.") - String contractQuotationReference, - - @JsonFormat(shape = JsonFormat.Shape.STRING) - LocalDate expectedDepartureDate, - - @JsonFormat(shape = JsonFormat.Shape.STRING) - LocalDate expectedArrivalAtPlaceOfDeliveryStartDate, - - @JsonFormat(shape = JsonFormat.Shape.STRING) - LocalDate expectedArrivalAtPlaceOfDeliveryEndDate, - - TransportDocumentTypeCode transportDocumentTypeCode, - - @Size(max = 20, message = "The attribute transportDocumentReference has a max size of 20.") - String transportDocumentReference, - - @Size(max = 20, message = "The attribute bookingChannelReference has a max size of 20.") - String bookingChannelReference, - - String incoTerms, - - @NotNull(message = "The attribute communicationChannelCode is required.") - String communicationChannelCode, - - @NotNull(message = "The attribute isEquipmentSubstitutionAllowed is required.") - Boolean isEquipmentSubstitutionAllowed, - - @Size(max = 35, message = "The attribute vesselName has a max size of 35.") - String vesselName, - - @ValidVesselIMONumber(allowNull = true, message = "The attribute vesselIMONumber is invalid.") - String vesselIMONumber, - - @Size(max = 50, message = "The attribute exportVoyageNumber has a max size of 50.") - String exportVoyageNumber -) { - @Builder - public BookingSummaryTO { } -} diff --git a/edocumentation-transfer-obj/src/main/java/org/dcsa/edocumentation/transferobjects/ShippingInstructionSummaryTO.java b/edocumentation-transfer-obj/src/main/java/org/dcsa/edocumentation/transferobjects/ShippingInstructionSummaryTO.java deleted file mode 100644 index 754fa0f1..00000000 --- a/edocumentation-transfer-obj/src/main/java/org/dcsa/edocumentation/transferobjects/ShippingInstructionSummaryTO.java +++ /dev/null @@ -1,78 +0,0 @@ -package org.dcsa.edocumentation.transferobjects; - -import com.fasterxml.jackson.annotation.JsonAlias; -import com.fasterxml.jackson.annotation.JsonFormat; -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.Builder; -import org.dcsa.edocumentation.transferobjects.enums.TransportDocumentTypeCode; - -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.NotNull; -import jakarta.validation.constraints.Size; -import java.time.OffsetDateTime; -import java.util.List; - -public record ShippingInstructionSummaryTO( - @NotBlank(message = "The attribute shippingInstructionReference is required.") - @Size(max = 100, message = "The attribute shippingInstructionReference has a max size of 100.") - String shippingInstructionReference, - - @NotNull(message = "The attribute documentStatus is required.") - @JsonProperty(access = JsonProperty.Access.READ_ONLY) - String documentStatus, - - @JsonProperty(access = JsonProperty.Access.READ_ONLY) - List requestedChanges, - - @JsonProperty(access = JsonProperty.Access.READ_ONLY) - @JsonFormat(shape = JsonFormat.Shape.STRING) - @NotNull(message = "The attribute shippingInstructionCreatedDateTime is required.") - OffsetDateTime shippingInstructionCreatedDateTime, - - @JsonProperty(access = JsonProperty.Access.READ_ONLY) - @JsonFormat(shape = JsonFormat.Shape.STRING) - @NotNull(message = "The attribute shippingInstructionUpdatedDateTime is required.") - OffsetDateTime shippingInstructionUpdatedDateTime, - - @Size(max = 20, message = "The attribute amendToTransportDocument has a max size of 20.") - String amendToTransportDocument, - - TransportDocumentTypeCode transportDocumentTypeCode, - - @NotNull(message = "The boolean attribute isShippedOnBoardType is required.") - boolean isShippedOnBoardType, - - Integer numberOfCopiesWithCharges, - - Integer numberOfCopiesWithoutCharges, - - @JsonAlias({"numberOfOriginals", "requestedNumberOfOriginals"}) - Integer numberOfOriginalsWithCharges, - - Integer numberOfOriginalsWithoutCharges, - - @NotNull(message = "The boolean attribute isElectronic is required.") - boolean isElectronic, - - @NotNull(message = "The boolean attribute isToOrder is required.") - boolean isToOrder, - - boolean areChargesDisplayedOnOriginals, - - @Size(max = 5) - List<@Size(max = 35) String> displayedNameForPlaceOfReceipt, - - @Size(max = 5) - List<@Size(max = 35) String> displayedNameForPortOfLoad, - - @Size(max = 5) - List<@Size(max = 35) String>displayedNameForPortOfDischarge, - - @Size(max = 5) - List<@Size(max = 35) String> displayedNameForPlaceOfDelivery, - - List<@Size(max = 100, message = "The attribute carrierBookingReference has a max size of 100.") String> carrierBookingReferences -) { - @Builder - public ShippingInstructionSummaryTO { } -} diff --git a/postman_collection.json b/postman_collection.json index be07191a..0c749799 100755 --- a/postman_collection.json +++ b/postman_collection.json @@ -7,752 +7,6 @@ "_collection_link": "https://grey-desert-2866.postman.co/workspace/New-Team-Workspace~9634308f-0889-42d7-99bd-1d4b0f653244/collection/10391075-f5fa76b3-98bd-4ed9-badf-df48ecb613ff?action=share&source=collection_link&creator=10391075" }, "item": [ - { - "name": "Booking request summaries", - "item": [ - { - "name": "Positive test cases", - "item": [ - { - "name": "Booking request summaries", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test('Body contains 5 or more items', () => {\r", - " pm.expect(pm.response.json().length).to.greaterThan(5);\r", - "});" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [], - "url": { - "raw": "{{BASE_URL}}{{BKG_CONTEXT_PATH}}/booking-summaries", - "host": [ - "{{BASE_URL}}{{BKG_CONTEXT_PATH}}" - ], - "path": [ - "booking-summaries" - ] - } - }, - "response": [] - }, - { - "name": "Booking request summaries COMPLETED", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test('All matches must have correct status', () => {\r", - " const response = pm.response.json()\r", - " for (let i = 0; i < response.length ; i++) {\r", - " pm.expect(response[i].bookingStatus).to.equal(\"COMPLETED\");\r", - " }\r", - "});\r", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [], - "url": { - "raw": "{{BASE_URL}}{{BKG_CONTEXT_PATH}}/booking-summaries?bookingStatus=COMPLETED", - "host": [ - "{{BASE_URL}}{{BKG_CONTEXT_PATH}}" - ], - "path": [ - "booking-summaries" - ], - "query": [ - { - "key": "bookingStatus", - "value": "COMPLETED" - } - ] - } - }, - "response": [] - }, - { - "name": "Booking request status per bookingStatus", - "event": [ - { - "listen": "prerequest", - "script": { - "exec": [ - "let bookingStatusses = pm.collectionVariables.get(\"BOOKING_STATUSSES\");\r", - "\r", - "if(!bookingStatusses || bookingStatusses.length == 0) {\r", - " console.log(\"retrieving all known booking statusses currently available\")\r", - " let baseURL = pm.collectionVariables.get(\"BASE_URL\");\r", - " let contextPath = pm.collectionVariables.get(\"BKG_CONTEXT_PATH\");\r", - " pm.sendRequest(baseURL+contextPath+\"/booking-summaries\", (err, response) => {\r", - " const seen = new Set();\r", - " const bookingStatusses = response.json()\r", - " .map(({bookingStatus}) => bookingStatus)\r", - " .filter(bookingStatus => {\r", - " const alreadySeen = !seen.has(bookingStatus);\r", - " seen.add(bookingStatus);\r", - " return alreadySeen;\r", - " });\r", - " pm.collectionVariables.set(\"BOOKING_STATUSSES\", bookingStatusses);\r", - " });\r", - "} else {\r", - " let currentBookingStatus = bookingStatusses.shift();\r", - " pm.request.url.query.add(\"bookingStatus=\" + currentBookingStatus);\r", - " pm.collectionVariables.set(\"BOOKING_STATUSSES\", bookingStatusses);\r", - "}\r", - "\r", - "\r", - "" - ], - "type": "text/javascript" - } - }, - { - "listen": "test", - "script": { - "exec": [ - "const bookingStatusses = pm.collectionVariables.get(\"BOOKING_STATUSSES\");\r", - "\r", - "if (bookingStatusses && bookingStatusses.length > 0) {\r", - " postman.setNextRequest(\"Booking request status per bookingStatus\");\r", - "} else {\r", - " postman.setNextRequest(\"Booking request summaries sort\");\r", - " pm.collectionVariables.unset(\"BOOKING_STATUSSES\");\r", - "}\r", - "\r", - "bookingStatusUnderTest = pm.request.url.query.get(\"bookingStatus\");\r", - "console.log(\"query param bookingStatus=[\" + bookingStatusUnderTest + \"]\");\r", - "\r", - "if (bookingStatusUnderTest) {\r", - " bookingStatusUnderTest = bookingStatusUnderTest.replace(/%20/g, \" \");\r", - " console.log(\"bookingStatusUnderTest='\" + bookingStatusUnderTest + \"'\");\r", - "\r", - " pm.test(\"bookingStatus should be \" + bookingStatusUnderTest, () => {\r", - " let bookingStatusses = pm.response.json().map(({ bookingStatus }) => bookingStatus);\r", - " pm.expect(bookingStatusses.every(v => v === bookingStatusUnderTest)).to.eql(true);\r", - " });\r", - "}" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [], - "url": { - "raw": "{{BASE_URL}}{{BKG_CONTEXT_PATH}}/booking-summaries", - "host": [ - "{{BASE_URL}}{{BKG_CONTEXT_PATH}}" - ], - "path": [ - "booking-summaries" - ] - } - }, - "response": [] - }, - { - "name": "Booking request summaries sort", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"First datetime is smaller then last date time when sorting on dateTime Ascending\", () => {\r", - " let bookingRequestUpdatedDateTimes = pm.response.json().map(({bookingRequestUpdatedDateTime}) => bookingRequestUpdatedDateTime);\r", - " let firstTime = new Date(bookingRequestUpdatedDateTimes[0]);\r", - " let lastTime = new Date(bookingRequestUpdatedDateTimes[bookingRequestUpdatedDateTimes.length - 1]);\r", - " pm.expect(firstTime.getTime()).to.be.lessThan(lastTime.getTime());\r", - "});" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [], - "url": { - "raw": "{{BASE_URL}}{{BKG_CONTEXT_PATH}}/booking-summaries?sort=bookingRequestUpdatedDateTime:ASC", - "host": [ - "{{BASE_URL}}{{BKG_CONTEXT_PATH}}" - ], - "path": [ - "booking-summaries" - ], - "query": [ - { - "key": "sort", - "value": "bookingRequestUpdatedDateTime:ASC" - } - ] - } - }, - "response": [] - } - ], - "event": [ - { - "listen": "prerequest", - "script": { - "type": "text/javascript", - "exec": [ - "" - ] - } - }, - { - "listen": "test", - "script": { - "type": "text/javascript", - "exec": [ - "const schema = pm.collectionVariables.get(\"BOOKING_SUMMARY_SCHEMA\");", - "const schemaObject = JSON.parse(schema);", - "", - "pm.test('Schema is valid', () => {", - " pm.response.to.have.jsonSchema(schemaObject);", - "});", - "", - "pm.test(\"Status code is 200\", () => {", - " pm.response.to.have.status(200);", - "});" - ] - } - } - ] - }, - { - "name": "Negative test cases", - "item": [ - { - "name": "Booking request summaries Invalid bookingStatus", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 400\", () => {\r", - " pm.response.to.have.status(400);\r", - "});\r", - "\r", - "pm.test(\"Error reason is invalidParameter\", () => {\r", - " var jsonData = pm.response.json();\r", - " pm.expect(jsonData.errors[0].reason).to.eql(\"invalidInput\");\r", - "});\r", - "\r", - "pm.test(\"BookingStatus must contain a valid value\", () => {\r", - " var jsonData = pm.response.json();\r", - " console.log(jsonData.errors[0].message);\r", - " pm.expect(jsonData.errors[0].message).to.contains(\"bookingStatus Unexpected value 'null', should have been one of\");\r", - "});" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [], - "url": { - "raw": "{{BASE_URL}}{{BKG_CONTEXT_PATH}}/booking-summaries?bookingStatus=null", - "host": [ - "{{BASE_URL}}{{BKG_CONTEXT_PATH}}" - ], - "path": [ - "booking-summaries" - ], - "query": [ - { - "key": "bookingStatus", - "value": "null" - } - ] - } - }, - "response": [] - } - ], - "event": [ - { - "listen": "prerequest", - "script": { - "type": "text/javascript", - "exec": [ - "" - ] - } - }, - { - "listen": "test", - "script": { - "type": "text/javascript", - "exec": [ - "const schema = pm.collectionVariables.get(\"ERROR_SCHEMA\");", - "const schemaObject = JSON.parse(schema);", - "", - "pm.test('Schema is valid', () => {", - " pm.response.to.have.jsonSchema(schemaObject);", - "});", - "", - "" - ] - } - } - ] - } - ], - "description": "The tests in this folder is about testing that the shipper (or their delegate) can request a list of their requested bookings.\n\nThe positive tests are about features that should be possible according the API specification.\n\nThe negative tests are about features that should not be possible according to the API specification.", - "event": [ - { - "listen": "prerequest", - "script": { - "type": "text/javascript", - "exec": [ - "" - ] - } - }, - { - "listen": "test", - "script": { - "type": "text/javascript", - "exec": [ - "pm.test(\"API-Version is present\", () => {", - " pm.response.to.have.header(\"API-Version\");", - "});", - "", - "pm.test(\"API-Version header is set correctly\", () => {", - " pm.expect(pm.response.headers.get(\"API-Version\")).to.eql(pm.collectionVariables.get(\"BKG_SPEC_VERSION\"));", - "});" - ] - } - } - ] - }, - { - "name": "Shipping instruction summaries", - "item": [ - { - "name": "Positive test cases", - "item": [ - { - "name": "Shipping instruction summaries", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test('Body contains 5 or more items', () => {\r", - " pm.expect(pm.response.json().length).to.greaterThan(5);\r", - "});" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [], - "url": { - "raw": "{{BASE_URL}}{{EBL_CONTEXT_PATH}}/shipping-instructions-summaries", - "host": [ - "{{BASE_URL}}{{EBL_CONTEXT_PATH}}" - ], - "path": [ - "shipping-instructions-summaries" - ] - } - }, - "response": [] - }, - { - "name": "Shipping instructions summaries CMPL", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test('Body contains 0 or more items', () => {\r", - " pm.expect(pm.response.json().length).to.equal(0);\r", - "});" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [], - "url": { - "raw": "{{BASE_URL}}{{EBL_CONTEXT_PATH}}/shipping-instructions-summaries?documentStatus=VOID", - "host": [ - "{{BASE_URL}}{{EBL_CONTEXT_PATH}}" - ], - "path": [ - "shipping-instructions-summaries" - ], - "query": [ - { - "key": "documentStatus", - "value": "VOID" - } - ] - } - }, - "response": [] - }, - { - "name": "Shipping instruction summaries per documentStatus", - "event": [ - { - "listen": "prerequest", - "script": { - "exec": [ - "let documentStatusses = pm.collectionVariables.get(\"DOCUMENT_STATUSSES\");\r", - "\r", - "if(!documentStatusses || documentStatusses.length == 0) {\r", - " console.log(\"retrieving all known document statusses currently available\")\r", - " let baseURL = pm.collectionVariables.get(\"BASE_URL\");\r", - " let contextPath = pm.collectionVariables.get(\"EBL_CONTEXT_PATH\");\r", - " pm.sendRequest(baseURL+contextPath+\"/shipping-instructions-summaries\",function(err, response){\r", - " let documentStatusses = response.json().map(({documentStatus}) => documentStatus);\r", - " pm.collectionVariables.set(\"DOCUMENT_STATUSSES\", documentStatusses);\r", - " });\r", - "} else {\r", - " let currentDocumentStatus = documentStatusses.shift();\r", - " pm.request.url.query.add(\"documentStatus=\" + currentDocumentStatus);\r", - " pm.collectionVariables.set(\"DOCUMENT_STATUSSES\", documentStatusses);\r", - "}\r", - "" - ], - "type": "text/javascript" - } - }, - { - "listen": "test", - "script": { - "exec": [ - "const documentStatusses = pm.collectionVariables.get(\"DOCUMENT_STATUSSES\");\r", - "\r", - "if (documentStatusses && documentStatusses.length > 0){\r", - " postman.setNextRequest(\"Shipping instruction summaries per documentStatus\");\r", - "} else {\r", - " postman.setNextRequest(\"Shipping instruction for carrierBookingReference\");\r", - " pm.collectionVariables.unset(\"DOCUMENT_STATUSSES\");\r", - "}\r", - "\r", - "let documentStatusUnderTest = pm.request.url.query.get(\"documentStatus\");\r", - "console.log(\"query param documentStatus=[\" + documentStatusUnderTest + \"]\");\r", - "\r", - "if(documentStatusUnderTest) {\r", - " documentStatusUnderTest = documentStatusUnderTest.replace(/%20/g, \" \");\r", - " console.log(\"documentStatusUnderTest='\" + documentStatusUnderTest + \"'\");\r", - "\r", - " pm.test(\"documentStatus should be \" + documentStatusUnderTest, () => {\r", - " let documentStatusses = pm.response.json().map(({documentStatus}) => documentStatus);\r", - " pm.expect(documentStatusses.every(v => v === documentStatusUnderTest)).to.eql(true);\r", - " });\r", - "}\r", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [], - "url": { - "raw": "{{BASE_URL}}{{EBL_CONTEXT_PATH}}/shipping-instructions-summaries", - "host": [ - "{{BASE_URL}}{{EBL_CONTEXT_PATH}}" - ], - "path": [ - "shipping-instructions-summaries" - ] - } - }, - "response": [] - }, - { - "name": "Shipping instruction for carrierBookingReference", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "let jsonResponse = pm.response.json();\r", - "\r", - "pm.test(\"Response contains only 1 summary\", () => {\r", - " pm.expect(jsonResponse.length).to.eql(1);\r", - "});\r", - "\r", - "pm.test(\"Carrier booking reference matches filter request\", () => {\r", - " pm.expect(jsonResponse[0].carrierBookingReferences.includes(\"D659FDB7E33C\")).to.eql(true);\r", - "});" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [], - "url": { - "raw": "{{BASE_URL}}{{EBL_CONTEXT_PATH}}/shipping-instructions-summaries?carrierBookingReference=D659FDB7E33C", - "host": [ - "{{BASE_URL}}{{EBL_CONTEXT_PATH}}" - ], - "path": [ - "shipping-instructions-summaries" - ], - "query": [ - { - "key": "carrierBookingReference", - "value": "D659FDB7E33C" - } - ] - } - }, - "response": [] - }, - { - "name": "Shipping instruction for unknown carrierBookingReference", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "let jsonResponse = pm.response.json();\r", - "\r", - "pm.test(\"Response contains only 0 summaries\", () => {\r", - " pm.expect(jsonResponse.length).to.eql(0);\r", - "});\r", - "\r", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [], - "url": { - "raw": "{{BASE_URL}}{{EBL_CONTEXT_PATH}}/shipping-instructions-summaries?carrierBookingReference=unkown", - "host": [ - "{{BASE_URL}}{{EBL_CONTEXT_PATH}}" - ], - "path": [ - "shipping-instructions-summaries" - ], - "query": [ - { - "key": "carrierBookingReference", - "value": "unkown" - } - ] - } - }, - "response": [] - }, - { - "name": "Shipping instruction for multiple carrierBookingReferences", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "let jsonResponse = pm.response.json();\r", - "\r", - "pm.test(\"Response contains at least 1 summary\", () => {\r", - " pm.expect(jsonResponse.length).to.gte(1);\r", - "});\r", - "\r", - "pm.test(\"Carrier booking reference matches filter request\", () => {\r", - " // FIXME: Swagger is unclear here; RI does OR, so the test match that until the swagger gets clarified\r", - " for (const summary of jsonResponse) {\r", - " const carrierBookingReferences = summary.carrierBookingReferences;\r", - " pm.expect(carrierBookingReferences.includes(\"E379021B7782\") || carrierBookingReferences.includes(\"A379021B7782\")).to.eql(true);\r", - " }\r", - "});\r", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [], - "url": { - "raw": "{{BASE_URL}}{{EBL_CONTEXT_PATH}}/shipping-instructions-summaries?carrierBookingReference=E379021B7782,A379021B7782", - "host": [ - "{{BASE_URL}}{{EBL_CONTEXT_PATH}}" - ], - "path": [ - "shipping-instructions-summaries" - ], - "query": [ - { - "key": "carrierBookingReference", - "value": "E379021B7782,A379021B7782" - } - ] - } - }, - "response": [] - } - ], - "event": [ - { - "listen": "prerequest", - "script": { - "type": "text/javascript", - "exec": [ - "" - ] - } - }, - { - "listen": "test", - "script": { - "type": "text/javascript", - "exec": [ - "const schema = pm.collectionVariables.get(\"SHIPPING_INSTRUCTIONS_SUMMARY_SCHEMA\");", - "const schemaObject = JSON.parse(schema);", - "", - "pm.test('Schema is valid', () => {", - " pm.response.to.have.jsonSchema(schemaObject);", - "});", - "", - "pm.test(\"Status code is 200\", () => {", - " pm.response.to.have.status(200);", - "});" - ] - } - } - ] - }, - { - "name": "Negative test cases", - "item": [ - { - "name": "Shipping instruction summaries invalid document status", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 400\", () => {\r", - " pm.response.to.have.status(400);\r", - "});\r", - "\r", - "pm.test(\"Error reason is invalidInput\", () => {\r", - " var jsonData = pm.response.json();\r", - " pm.expect(jsonData.errors[0].reason).to.eql(\"invalidInput\");\r", - "});\r", - "\r", - "pm.test(\"DocumentStatus must contain a valid value\", () => {\r", - " var jsonData = pm.response.json();\r", - " pm.expect(jsonData.errors[0].message).to.contains(\"getShippingInstructionSummaries.documentStatus Unexpected value 'INVALID', should have been one of: 'RECEIVED', 'PENDING UPDATE', 'DRAFT', 'PENDING APPROVAL', 'APPROVED', 'ISSUED', 'SURRENDERED', 'VOID', 'REJECTED'\");\r", - "});" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [], - "url": { - "raw": "{{BASE_URL}}{{EBL_CONTEXT_PATH}}/shipping-instructions-summaries?documentStatus=INVALID", - "host": [ - "{{BASE_URL}}{{EBL_CONTEXT_PATH}}" - ], - "path": [ - "shipping-instructions-summaries" - ], - "query": [ - { - "key": "documentStatus", - "value": "INVALID" - } - ] - } - }, - "response": [] - } - ], - "event": [ - { - "listen": "prerequest", - "script": { - "type": "text/javascript", - "exec": [ - "" - ] - } - }, - { - "listen": "test", - "script": { - "type": "text/javascript", - "exec": [ - "const schema = pm.collectionVariables.get(\"ERROR_SCHEMA\");", - "const schemaObject = JSON.parse(schema);", - "", - "pm.test('Schema is valid', () => {", - " pm.response.to.have.jsonSchema(schemaObject);", - "});", - "" - ] - } - } - ] - } - ], - "description": "The tests in this folder is about testing that the shipper (or their delegate) can request a list of their shipping instructions or transport document amendment requests.\n\nThe positive tests are about features that should be possible according the API specification.\n\nThe negative tests are about features that should not be possible according to the API specification.", - "event": [ - { - "listen": "prerequest", - "script": { - "type": "text/javascript", - "exec": [ - "" - ] - } - }, - { - "listen": "test", - "script": { - "type": "text/javascript", - "exec": [ - "pm.test(\"API-Version is present\", () => {", - " pm.response.to.have.header(\"API-Version\");", - "});", - "", - "pm.test(\"API-Version header is set correctly\", () => {", - " pm.expect(pm.response.headers.get(\"API-Version\")).to.eql(pm.collectionVariables.get(\"EBL_SPEC_VERSION\"));", - "});" - ] - } - } - ] - }, { "name": "GET Booking request", "item": [