From 0f98c7d411496684723390c3faefe752fe683902 Mon Sep 17 00:00:00 2001 From: Benedetta-fabbri Date: Wed, 8 Jan 2025 17:24:56 +0100 Subject: [PATCH] [P4ADEV-1726] fix --- .../mapper/InstallmentPIIMapper.java | 8 ++++++++ .../mapper/InstallmentPIIMapperTest.java | 20 ++++++++++++++++++- .../util/faker/InstallmentFaker.java | 1 + 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/main/java/it/gov/pagopa/pu/debtpositions/mapper/InstallmentPIIMapper.java b/src/main/java/it/gov/pagopa/pu/debtpositions/mapper/InstallmentPIIMapper.java index 045769e..81c9707 100644 --- a/src/main/java/it/gov/pagopa/pu/debtpositions/mapper/InstallmentPIIMapper.java +++ b/src/main/java/it/gov/pagopa/pu/debtpositions/mapper/InstallmentPIIMapper.java @@ -1,5 +1,6 @@ package it.gov.pagopa.pu.debtpositions.mapper; +import it.gov.pagopa.pu.debtpositions.citizen.service.DataCipherService; import it.gov.pagopa.pu.debtpositions.dto.InstallmentPIIDTO; import it.gov.pagopa.pu.debtpositions.dto.generated.InstallmentDTO; import it.gov.pagopa.pu.debtpositions.model.InstallmentNoPII; @@ -10,6 +11,12 @@ @Service public class InstallmentPIIMapper { + private final DataCipherService dataCipherService; + + public InstallmentPIIMapper(DataCipherService dataCipherService) { + this.dataCipherService = dataCipherService; + } + public Pair map(InstallmentDTO installment) { InstallmentNoPII installmentNoPII = new InstallmentNoPII(); @@ -30,6 +37,7 @@ public Pair map(InstallmentDTO installment) installmentNoPII.setBalance(installment.getBalance()); installmentNoPII.setLegacyPaymentMetadata(installment.getLegacyPaymentMetadata()); installmentNoPII.setDebtorEntityType(installment.getDebtor().getUniqueIdentifierType().charAt(0)); + installmentNoPII.setDebtorFiscalCodeHash(dataCipherService.hash(installment.getDebtor().getUniqueIdentifierCode())); installmentNoPII.setCreationDate(installment.getCreationDate()); installmentNoPII.setUpdateDate(installment.getUpdateDate()); installmentNoPII.setUpdateOperatorExternalId(1L); // TODO to check diff --git a/src/test/java/it/gov/pagopa/pu/debtpositions/mapper/InstallmentPIIMapperTest.java b/src/test/java/it/gov/pagopa/pu/debtpositions/mapper/InstallmentPIIMapperTest.java index 5d5a554..5f3cbc5 100644 --- a/src/test/java/it/gov/pagopa/pu/debtpositions/mapper/InstallmentPIIMapperTest.java +++ b/src/test/java/it/gov/pagopa/pu/debtpositions/mapper/InstallmentPIIMapperTest.java @@ -1,23 +1,38 @@ package it.gov.pagopa.pu.debtpositions.mapper; +import it.gov.pagopa.pu.debtpositions.citizen.service.DataCipherService; import it.gov.pagopa.pu.debtpositions.dto.InstallmentPIIDTO; import it.gov.pagopa.pu.debtpositions.dto.generated.InstallmentDTO; import it.gov.pagopa.pu.debtpositions.model.InstallmentNoPII; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.data.util.Pair; import static it.gov.pagopa.pu.debtpositions.util.TestUtils.checkNotNullFields; import static it.gov.pagopa.pu.debtpositions.util.faker.InstallmentFaker.*; import static org.junit.jupiter.api.Assertions.assertEquals; +@ExtendWith(MockitoExtension.class) class InstallmentPIIMapperTest { private InstallmentPIIMapper mapper; + @Mock + private DataCipherService dataCipherServiceMock; + @BeforeEach void init(){ - mapper = new InstallmentPIIMapper(); + mapper = new InstallmentPIIMapper(dataCipherServiceMock); + } + + @AfterEach + void verifyNotMoreInvocation() { + Mockito.verifyNoMoreInteractions(dataCipherServiceMock); } @Test @@ -26,6 +41,9 @@ void testMap(){ InstallmentPIIDTO installmentPIIDTOExpected = buildInstallmentPIIDTO(); InstallmentDTO installmentDTO = buildInstallmentDTO(); + byte[] expectedHashedCF = {}; + Mockito.when(dataCipherServiceMock.hash(installmentDTO.getDebtor().getUniqueIdentifierCode())).thenReturn(expectedHashedCF); + Pair result = mapper.map(installmentDTO); assertEquals(installmentNoPIIExpected, result.getFirst()); diff --git a/src/test/java/it/gov/pagopa/pu/debtpositions/util/faker/InstallmentFaker.java b/src/test/java/it/gov/pagopa/pu/debtpositions/util/faker/InstallmentFaker.java index e18d99c..9289abe 100644 --- a/src/test/java/it/gov/pagopa/pu/debtpositions/util/faker/InstallmentFaker.java +++ b/src/test/java/it/gov/pagopa/pu/debtpositions/util/faker/InstallmentFaker.java @@ -60,6 +60,7 @@ public static InstallmentNoPII buildInstallmentNoPII(){ .legacyPaymentMetadata("legacyPaymentMetadata") .humanFriendlyRemittanceInformation("humanFriendlyRemittanceInformation") .debtorEntityType('F') + .debtorFiscalCodeHash(new byte[] {}) .balance("balance") .build(); }