diff --git a/src/main/java/it/gov/pagopa/arc/dto/mapper/gpd/GPDPaymentNoticeDetailsDTO2PaymentNoticeDetailsDTOMapper.java b/src/main/java/it/gov/pagopa/arc/dto/mapper/gpd/GPDPaymentNoticeDetailsDTO2PaymentNoticeDetailsDTOMapper.java new file mode 100644 index 0000000..701175e --- /dev/null +++ b/src/main/java/it/gov/pagopa/arc/dto/mapper/gpd/GPDPaymentNoticeDetailsDTO2PaymentNoticeDetailsDTOMapper.java @@ -0,0 +1,15 @@ +package it.gov.pagopa.arc.dto.mapper.gpd; + +import it.gov.pagopa.arc.connector.gpd.dto.GPDPaymentNoticeDetailsDTO; +import it.gov.pagopa.arc.dto.mapper.MapperUtilities; +import it.gov.pagopa.arc.model.generated.PaymentNoticeDetailsDTO; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +@Mapper(componentModel = "spring", uses = {MapperUtilities.class, GPDPaymentOptionDetailsDTO2PaymentOptionDetailsDTOMapper.class}) +public interface GPDPaymentNoticeDetailsDTO2PaymentNoticeDetailsDTOMapper { + @Mapping(target = "paTaxCode", source = "organizationFiscalCode") + @Mapping(target = "paFullName", source = "companyName") + @Mapping(target = "paymentOptions", source = "paymentOption") + PaymentNoticeDetailsDTO toPaymentNoticeDetailsDTO(GPDPaymentNoticeDetailsDTO gpdPaymentNoticeDetailsDTO); +} diff --git a/src/main/java/it/gov/pagopa/arc/dto/mapper/gpd/GPDPaymentOptionDetailsDTO2PaymentOptionDetailsDTOMapper.java b/src/main/java/it/gov/pagopa/arc/dto/mapper/gpd/GPDPaymentOptionDetailsDTO2PaymentOptionDetailsDTOMapper.java new file mode 100644 index 0000000..b772669 --- /dev/null +++ b/src/main/java/it/gov/pagopa/arc/dto/mapper/gpd/GPDPaymentOptionDetailsDTO2PaymentOptionDetailsDTOMapper.java @@ -0,0 +1,15 @@ +package it.gov.pagopa.arc.dto.mapper.gpd; + +import it.gov.pagopa.arc.connector.gpd.dto.GPDPaymentOptionDetailsDTO; +import it.gov.pagopa.arc.dto.mapper.MapperUtilities; +import it.gov.pagopa.arc.model.generated.PaymentOptionDetailsDTO; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.NullValueCheckStrategy; + +@Mapper(componentModel = "spring", uses = {MapperUtilities.class, GPDPaymentOptionDetailsStatus2PaymentOptionStatusMapper.class}) +public interface GPDPaymentOptionDetailsDTO2PaymentOptionDetailsDTOMapper { + + @Mapping(source = "dueDate", target = "dueDate", nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, qualifiedByName = "convertToZonedDateTimeAndTruncateSeconds") + PaymentOptionDetailsDTO toPaymentOptionDetailsDTO(GPDPaymentOptionDetailsDTO gpdPaymentOptionDetailsDTO); +} diff --git a/src/main/java/it/gov/pagopa/arc/dto/mapper/gpd/GPDPaymentOptionDetailsStatus2PaymentOptionStatusMapper.java b/src/main/java/it/gov/pagopa/arc/dto/mapper/gpd/GPDPaymentOptionDetailsStatus2PaymentOptionStatusMapper.java new file mode 100644 index 0000000..2e0ffc6 --- /dev/null +++ b/src/main/java/it/gov/pagopa/arc/dto/mapper/gpd/GPDPaymentOptionDetailsStatus2PaymentOptionStatusMapper.java @@ -0,0 +1,16 @@ +package it.gov.pagopa.arc.dto.mapper.gpd; + +import it.gov.pagopa.arc.connector.gpd.enums.GPDPaymentOptionDetailsStatus; +import it.gov.pagopa.arc.model.generated.PaymentOptionStatus; +import org.mapstruct.Mapper; +import org.mapstruct.ValueMapping; + +@Mapper(componentModel = "spring") +public interface GPDPaymentOptionDetailsStatus2PaymentOptionStatusMapper { + + @ValueMapping(target = "UNPAID", source = "PO_UNPAID") + @ValueMapping(target = "PAID", source = "PO_PAID") + @ValueMapping(target = "PARTIALLY_REPORTED", source = "PO_PARTIALLY_REPORTED") + @ValueMapping(target = "REPORTED", source = "PO_REPORTED") + PaymentOptionStatus toPaymentOptionStatus(GPDPaymentOptionDetailsStatus gpdPaymentOptionDetailsStatus); +} diff --git a/src/test/java/it/gov/pagopa/arc/dto/mapper/gpd/GPDPaymentNoticeDetailsDTO2PaymentNoticeDetailsDTOMapperTest.java b/src/test/java/it/gov/pagopa/arc/dto/mapper/gpd/GPDPaymentNoticeDetailsDTO2PaymentNoticeDetailsDTOMapperTest.java new file mode 100644 index 0000000..e57a854 --- /dev/null +++ b/src/test/java/it/gov/pagopa/arc/dto/mapper/gpd/GPDPaymentNoticeDetailsDTO2PaymentNoticeDetailsDTOMapperTest.java @@ -0,0 +1,75 @@ +package it.gov.pagopa.arc.dto.mapper.gpd; + +import it.gov.pagopa.arc.connector.gpd.dto.GPDPaymentNoticeDetailsDTO; +import it.gov.pagopa.arc.fakers.connector.PaymentOptionDetailsDTOFaker; +import it.gov.pagopa.arc.fakers.connector.gpd.GPDPaymentNoticeDetailsDTOFaker; +import it.gov.pagopa.arc.model.generated.PaymentNoticeDetailsDTO; +import it.gov.pagopa.arc.model.generated.PaymentNoticeDetailsStatus; +import it.gov.pagopa.arc.model.generated.PaymentOptionDetailsDTO; +import it.gov.pagopa.arc.utils.TestUtils; +import org.junit.jupiter.api.Assertions; +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.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.List; + +import static org.mockito.ArgumentMatchers.any; + +@ExtendWith(MockitoExtension.class) +class GPDPaymentNoticeDetailsDTO2PaymentNoticeDetailsDTOMapperTest { + @Mock + private GPDPaymentOptionDetailsDTO2PaymentOptionDetailsDTOMapper gpdPaymentOptionDetailsDTO2PaymentOptionDetailsDTOMapperMock; + + @InjectMocks + private final GPDPaymentNoticeDetailsDTO2PaymentNoticeDetailsDTOMapper mapper = Mappers.getMapper(GPDPaymentNoticeDetailsDTO2PaymentNoticeDetailsDTOMapper.class); + + @Test + void givenGPDPaymentNoticeDetailsDTOWhenToPaymentNoticeDetailsDTOThenReturnPaymentNoticeDetailsDTO() { + //given + List paymentOptionDetailsDTOList = PaymentOptionDetailsDTOFaker.mockInstance(1, false); + GPDPaymentNoticeDetailsDTO gpdPaymentNoticeDetailsDTO = GPDPaymentNoticeDetailsDTOFaker.mockInstance(1, false); + + Mockito.when(gpdPaymentOptionDetailsDTO2PaymentOptionDetailsDTOMapperMock.toPaymentOptionDetailsDTO(gpdPaymentNoticeDetailsDTO.getPaymentOption().get(0))).thenReturn(paymentOptionDetailsDTOList.get(0)); + //when + PaymentNoticeDetailsDTO result = mapper.toPaymentNoticeDetailsDTO(gpdPaymentNoticeDetailsDTO); + + //then + Assertions.assertNotNull(result); + Assertions.assertEquals(gpdPaymentNoticeDetailsDTO.getIupd() , result.getIupd()); + Assertions.assertEquals(gpdPaymentNoticeDetailsDTO.getOrganizationFiscalCode() , result.getPaTaxCode()); + Assertions.assertEquals(gpdPaymentNoticeDetailsDTO.getCompanyName() , result.getPaFullName()); + Assertions.assertEquals(PaymentNoticeDetailsStatus.VALID , result.getStatus()); + Assertions.assertEquals(1, result.getPaymentOptions().size()); + Assertions.assertEquals(paymentOptionDetailsDTOList, result.getPaymentOptions()); + TestUtils.assertNotNullFields(result); + } + + @Test + void givenGPDPaymentNoticeDetailsDTOWithInstallmentsWhenToPaymentNoticeDetailsDTOThenReturnPaymentNoticeDetailsDTO() { + //given + List paymentOptionDetailsDTOList = PaymentOptionDetailsDTOFaker.mockInstance(2, true); + GPDPaymentNoticeDetailsDTO gpdPaymentNoticeDetailsDTO = GPDPaymentNoticeDetailsDTOFaker.mockInstance(2, true); + + Mockito.when(gpdPaymentOptionDetailsDTO2PaymentOptionDetailsDTOMapperMock.toPaymentOptionDetailsDTO(gpdPaymentNoticeDetailsDTO.getPaymentOption().get(0))).thenReturn(paymentOptionDetailsDTOList.get(0)); + Mockito.when(gpdPaymentOptionDetailsDTO2PaymentOptionDetailsDTOMapperMock.toPaymentOptionDetailsDTO(gpdPaymentNoticeDetailsDTO.getPaymentOption().get(1))).thenReturn(paymentOptionDetailsDTOList.get(1)); + //when + PaymentNoticeDetailsDTO result = mapper.toPaymentNoticeDetailsDTO(gpdPaymentNoticeDetailsDTO); + + //then + Assertions.assertNotNull(result); + Assertions.assertEquals(gpdPaymentNoticeDetailsDTO.getIupd() , result.getIupd()); + Assertions.assertEquals(gpdPaymentNoticeDetailsDTO.getOrganizationFiscalCode() , result.getPaTaxCode()); + Assertions.assertEquals(gpdPaymentNoticeDetailsDTO.getCompanyName() , result.getPaFullName()); + Assertions.assertEquals(PaymentNoticeDetailsStatus.VALID , result.getStatus()); + Assertions.assertEquals(2, result.getPaymentOptions().size()); + Assertions.assertEquals(paymentOptionDetailsDTOList, result.getPaymentOptions()); + TestUtils.assertNotNullFields(result); + Mockito.verify(gpdPaymentOptionDetailsDTO2PaymentOptionDetailsDTOMapperMock, Mockito.times(2)).toPaymentOptionDetailsDTO(any()); + } + +} \ No newline at end of file diff --git a/src/test/java/it/gov/pagopa/arc/dto/mapper/gpd/GPDPaymentOptionDetailsDTO2PaymentOptionDetailsDTOMapperTest.java b/src/test/java/it/gov/pagopa/arc/dto/mapper/gpd/GPDPaymentOptionDetailsDTO2PaymentOptionDetailsDTOMapperTest.java new file mode 100644 index 0000000..f2a53fe --- /dev/null +++ b/src/test/java/it/gov/pagopa/arc/dto/mapper/gpd/GPDPaymentOptionDetailsDTO2PaymentOptionDetailsDTOMapperTest.java @@ -0,0 +1,50 @@ +package it.gov.pagopa.arc.dto.mapper.gpd; + +import it.gov.pagopa.arc.connector.gpd.dto.GPDPaymentOptionDetailsDTO; +import it.gov.pagopa.arc.connector.gpd.enums.GPDPaymentOptionDetailsStatus; +import it.gov.pagopa.arc.fakers.connector.gpd.GPDPaymentOptionDetailsDTOFaker; +import it.gov.pagopa.arc.model.generated.PaymentOptionDetailsDTO; +import it.gov.pagopa.arc.model.generated.PaymentOptionStatus; +import it.gov.pagopa.arc.utils.TestUtils; +import org.junit.jupiter.api.Assertions; +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.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.time.ZonedDateTime; +import java.util.List; + +@ExtendWith(MockitoExtension.class) +class GPDPaymentOptionDetailsDTO2PaymentOptionDetailsDTOMapperTest { + @Mock + private GPDPaymentOptionDetailsStatus2PaymentOptionStatusMapper gpdPaymentOptionDetailsStatus2PaymentOptionStatusMapperMock; + + @InjectMocks + GPDPaymentOptionDetailsDTO2PaymentOptionDetailsDTOMapper mapper = Mappers.getMapper(GPDPaymentOptionDetailsDTO2PaymentOptionDetailsDTOMapper.class); + @Test + void givenToPaymentOptionDetailsDTOWhenThen() { + //given + List gpdPaymentOptionDetailsDTO = GPDPaymentOptionDetailsDTOFaker.mockInstance(1, false); + Mockito.when(gpdPaymentOptionDetailsStatus2PaymentOptionStatusMapperMock.toPaymentOptionStatus(GPDPaymentOptionDetailsStatus.PO_UNPAID)).thenReturn(PaymentOptionStatus.UNPAID); + + //when + PaymentOptionDetailsDTO result = mapper.toPaymentOptionDetailsDTO(gpdPaymentOptionDetailsDTO.get(0)); + //then + Assertions.assertNotNull(result); + Assertions.assertEquals(gpdPaymentOptionDetailsDTO.get(0).getNav() , result.getNav()); + Assertions.assertEquals(gpdPaymentOptionDetailsDTO.get(0).getIuv() , result.getIuv()); + Assertions.assertEquals(gpdPaymentOptionDetailsDTO.get(0).getAmount(), result.getAmount()); + Assertions.assertEquals(gpdPaymentOptionDetailsDTO.get(0).getDescription(), result.getDescription()); + Assertions.assertEquals(gpdPaymentOptionDetailsDTO.get(0).getIsPartialPayment(), result.getIsPartialPayment()); + Assertions.assertEquals(ZonedDateTime.parse("2024-10-30T23:59:59Z"), result.getDueDate()); + Assertions.assertEquals(gpdPaymentOptionDetailsDTO.get(0).getNotificationFee(), result.getNotificationFee()); + Assertions.assertEquals(PaymentOptionStatus.UNPAID, result.getStatus()); + + TestUtils.assertNotNullFields(result); + + } +} \ No newline at end of file diff --git a/src/test/java/it/gov/pagopa/arc/dto/mapper/gpd/GPDPaymentOptionDetailsStatus2PaymentOptionStatusMapperTest.java b/src/test/java/it/gov/pagopa/arc/dto/mapper/gpd/GPDPaymentOptionDetailsStatus2PaymentOptionStatusMapperTest.java new file mode 100644 index 0000000..c6be670 --- /dev/null +++ b/src/test/java/it/gov/pagopa/arc/dto/mapper/gpd/GPDPaymentOptionDetailsStatus2PaymentOptionStatusMapperTest.java @@ -0,0 +1,34 @@ +package it.gov.pagopa.arc.dto.mapper.gpd; + +import it.gov.pagopa.arc.connector.gpd.enums.GPDPaymentOptionDetailsStatus; +import it.gov.pagopa.arc.model.generated.PaymentOptionStatus; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import org.mapstruct.factory.Mappers; + +import java.util.stream.Stream; + +class GPDPaymentOptionDetailsStatus2PaymentOptionStatusMapperTest { + private final GPDPaymentOptionDetailsStatus2PaymentOptionStatusMapper mapper = Mappers.getMapper(GPDPaymentOptionDetailsStatus2PaymentOptionStatusMapper.class); + + @ParameterizedTest + @MethodSource("provideEnumMappings") + void givenGPDPaymentOptionDetailsStatusWhenToPaymentOptionStatusThenReturnPaymentOptionStatus(GPDPaymentOptionDetailsStatus gpdPaymentOptionDetailsStatus, PaymentOptionStatus paymentOptionStatus) { + //when + PaymentOptionStatus result = mapper.toPaymentOptionStatus(gpdPaymentOptionDetailsStatus); + //then + Assertions.assertNotNull(result); + Assertions.assertEquals(paymentOptionStatus, result); + } + + private static Stream provideEnumMappings() { + return Stream.of( + Arguments.of(GPDPaymentOptionDetailsStatus.PO_UNPAID, PaymentOptionStatus.UNPAID), + Arguments.of(GPDPaymentOptionDetailsStatus.PO_PAID, PaymentOptionStatus.PAID), + Arguments.of(GPDPaymentOptionDetailsStatus.PO_PARTIALLY_REPORTED, PaymentOptionStatus.PARTIALLY_REPORTED), + Arguments.of(GPDPaymentOptionDetailsStatus.PO_REPORTED, PaymentOptionStatus.REPORTED) + ); + } +} \ No newline at end of file diff --git a/src/test/java/it/gov/pagopa/arc/fakers/connector/PaymentNoticeDetailsDTOFaker.java b/src/test/java/it/gov/pagopa/arc/fakers/connector/PaymentNoticeDetailsDTOFaker.java new file mode 100644 index 0000000..603d704 --- /dev/null +++ b/src/test/java/it/gov/pagopa/arc/fakers/connector/PaymentNoticeDetailsDTOFaker.java @@ -0,0 +1,24 @@ +package it.gov.pagopa.arc.fakers.connector; + +import it.gov.pagopa.arc.model.generated.PaymentNoticeDetailsDTO; +import it.gov.pagopa.arc.model.generated.PaymentNoticeDetailsStatus; +import it.gov.pagopa.arc.model.generated.PaymentOptionDetailsDTO; + +import java.util.List; + +public class PaymentNoticeDetailsDTOFaker { + public static PaymentNoticeDetailsDTO mockInstance(Integer bias, Boolean isPartialPayment) { + return mockInstanceBuilder(bias, isPartialPayment).build(); + } + + public static PaymentNoticeDetailsDTO.PaymentNoticeDetailsDTOBuilder mockInstanceBuilder(Integer bias, Boolean isPartialPayment) { + List paymentOptionDetailsDTOList = PaymentOptionDetailsDTOFaker.mockInstance(bias, isPartialPayment); + + return PaymentNoticeDetailsDTO.builder() + .iupd("TEST_IUPD%d".formatted(bias)) + .paTaxCode("12345678901") + .paFullName("Test Company") + .status(PaymentNoticeDetailsStatus.VALID) + .paymentOptions(paymentOptionDetailsDTOList); + } +} diff --git a/src/test/java/it/gov/pagopa/arc/fakers/connector/PaymentOptionDetailsDTOFaker.java b/src/test/java/it/gov/pagopa/arc/fakers/connector/PaymentOptionDetailsDTOFaker.java new file mode 100644 index 0000000..96bea46 --- /dev/null +++ b/src/test/java/it/gov/pagopa/arc/fakers/connector/PaymentOptionDetailsDTOFaker.java @@ -0,0 +1,45 @@ +package it.gov.pagopa.arc.fakers.connector; + +import it.gov.pagopa.arc.model.generated.PaymentOptionDetailsDTO; +import it.gov.pagopa.arc.model.generated.PaymentOptionStatus; + +import java.time.ZonedDateTime; +import java.util.ArrayList; +import java.util.List; + +public class PaymentOptionDetailsDTOFaker { + + public static List mockInstance(Integer bias, Boolean isPartialPayment) { + List paymentOptionDetailsDTOList = new ArrayList<>(); + + paymentOptionDetailsDTOList.add(mockInstanceBuilder(bias, isPartialPayment).build()); + if (isPartialPayment){ + paymentOptionDetailsDTOList.add(mockInstanceBuilder(bias+1, isPartialPayment).build()); + } + return paymentOptionDetailsDTOList; + } + + public static PaymentOptionDetailsDTO.PaymentOptionDetailsDTOBuilder mockInstanceBuilder(Integer bias, Boolean isPartialPayment) { + PaymentOptionDetailsDTO.PaymentOptionDetailsDTOBuilder paymentOptionDetailsDTO = getPaymentOptionDetailsDTOBuilder(bias); + + if (isPartialPayment) { + paymentOptionDetailsDTO + .isPartialPayment(true) + .description("Installments Payment"); + } + + return paymentOptionDetailsDTO; + } + + private static PaymentOptionDetailsDTO.PaymentOptionDetailsDTOBuilder getPaymentOptionDetailsDTOBuilder(Integer bias) { + return PaymentOptionDetailsDTO.builder() + .nav("TEST_NAV%d".formatted(bias)) + .iuv("TEST_IUV%d".formatted(bias)) + .amount(1000L) + .description("Single Payment") + .isPartialPayment(false) + .dueDate(ZonedDateTime.parse("2024-10-30T23:59:59Z")) + .notificationFee(2L) + .status(PaymentOptionStatus.UNPAID); + } +}