Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: [P4PU-752] added mappers #175

Merged
merged 3 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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<PaymentOptionDetailsDTO> 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<PaymentOptionDetailsDTO> 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());
}

}
Original file line number Diff line number Diff line change
@@ -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> 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);

}
}
Original file line number Diff line number Diff line change
@@ -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<Arguments> 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)
);
}
}
Original file line number Diff line number Diff line change
@@ -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<PaymentOptionDetailsDTO> paymentOptionDetailsDTOList = PaymentOptionDetailsDTOFaker.mockInstance(bias, isPartialPayment);

return PaymentNoticeDetailsDTO.builder()
.iupd("TEST_IUPD%d".formatted(bias))
.paTaxCode("12345678901")
.paFullName("Test Company")
.status(PaymentNoticeDetailsStatus.VALID)
.paymentOptions(paymentOptionDetailsDTOList);
}
}
Original file line number Diff line number Diff line change
@@ -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<PaymentOptionDetailsDTO> mockInstance(Integer bias, Boolean isPartialPayment) {
List<PaymentOptionDetailsDTO> 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);
}
}
Loading