From 730d2f2a6cded04a322b4599c7d744ffc026754e Mon Sep 17 00:00:00 2001 From: flaminiaScarciofolo <113031535+flaminiaScarciofolo@users.noreply.github.com> Date: Fri, 14 Jun 2024 17:05:34 +0200 Subject: [PATCH] [SELC-5086] Fix: InstitutionMapper for null billing (#256) --- .../connector/rest/MsCoreConnectorImpl.java | 2 +- .../rest/mapper/InstitutionMapper.java | 11 +++++--- .../rest/MsCoreConnectorImplTest.java | 26 +++++++++++++++++++ 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/connector/rest/src/main/java/it/pagopa/selfcare/external_api/connector/rest/MsCoreConnectorImpl.java b/connector/rest/src/main/java/it/pagopa/selfcare/external_api/connector/rest/MsCoreConnectorImpl.java index 32faa2a8..d33fac6d 100644 --- a/connector/rest/src/main/java/it/pagopa/selfcare/external_api/connector/rest/MsCoreConnectorImpl.java +++ b/connector/rest/src/main/java/it/pagopa/selfcare/external_api/connector/rest/MsCoreConnectorImpl.java @@ -144,7 +144,7 @@ public List getInstitutionDetails(String institutionId @Override public String createPgInstitution(String description, String taxId) { log.trace("createPgInstitution start"); - CreatePgInstitutionRequest createPgInstitutionRequest = new CreatePgInstitutionRequest(description, false, taxId); + CreatePgInstitutionRequest createPgInstitutionRequest = new CreatePgInstitutionRequest(description, true, taxId); InstitutionResponse institutionResponse = Objects.requireNonNull(institutionApiClient. _createPgInstitutionUsingPOST(createPgInstitutionRequest) .getBody()); diff --git a/connector/rest/src/main/java/it/pagopa/selfcare/external_api/connector/rest/mapper/InstitutionMapper.java b/connector/rest/src/main/java/it/pagopa/selfcare/external_api/connector/rest/mapper/InstitutionMapper.java index 62df272b..531975bb 100644 --- a/connector/rest/src/main/java/it/pagopa/selfcare/external_api/connector/rest/mapper/InstitutionMapper.java +++ b/connector/rest/src/main/java/it/pagopa/selfcare/external_api/connector/rest/mapper/InstitutionMapper.java @@ -61,11 +61,14 @@ static AssistanceContacts toAssistanceContacts(InstitutionResponse dto) { @Named("setBillingData") static Billing setBillingData(List onboardings) { if(Objects.nonNull(onboardings) && !onboardings.isEmpty()) { - Billing billing = new Billing(); + Billing billing = null; BillingResponse billingResponse = onboardings.get(0).getBilling(); - billing.setRecipientCode(billingResponse.getRecipientCode()); - billing.setVatNumber(billingResponse.getVatNumber()); - billing.setPublicServices(billingResponse.getPublicServices()); + if(Objects.nonNull(billingResponse)) { + billing = new Billing(); + billing.setRecipientCode(billingResponse.getRecipientCode()); + billing.setVatNumber(billingResponse.getVatNumber()); + billing.setPublicServices(billingResponse.getPublicServices()); + } return billing; } return null; diff --git a/connector/rest/src/test/java/it/pagopa/selfcare/external_api/connector/rest/MsCoreConnectorImplTest.java b/connector/rest/src/test/java/it/pagopa/selfcare/external_api/connector/rest/MsCoreConnectorImplTest.java index 21760048..6010d3e8 100644 --- a/connector/rest/src/test/java/it/pagopa/selfcare/external_api/connector/rest/MsCoreConnectorImplTest.java +++ b/connector/rest/src/test/java/it/pagopa/selfcare/external_api/connector/rest/MsCoreConnectorImplTest.java @@ -313,4 +313,30 @@ void createPgInstitution() { assertEquals(institutionId, institutionPnPgResponse); } + + @Test + void getInstitutionsDetailsBillingNull() throws IOException { + String institutionId = "institutionId"; + + ClassPathResource resource = new ClassPathResource("stubs/institutionResponse.json"); + byte[] resourceStream = Files.readAllBytes(resource.getFile().toPath()); + InstitutionResponse response = objectMapper.readValue(resourceStream, new TypeReference<>() { + }); + response.getOnboarding().forEach(onboardedProductResponse -> onboardedProductResponse.setBilling(null)); + + when(institutionApiClient._retrieveInstitutionByIdUsingGET(anyString())) + .thenReturn(ResponseEntity.of(Optional.of(response))); + + ClassPathResource expectationResource = new ClassPathResource("stubs/OnboardedInstitutionInfo.json"); + byte[] expectationStream = Files.readAllBytes(expectationResource.getFile().toPath()); + List expectation = objectMapper.readValue(expectationStream, new TypeReference<>() { + }); + expectation.forEach(onboardedInstitutionInfo -> onboardedInstitutionInfo.setBilling(null)); + + List onboardedInstitutionInfos = msCoreConnector.getInstitutionDetails(institutionId); + assertEquals(1, onboardedInstitutionInfos.size()); + assertEquals(expectation, onboardedInstitutionInfos); + verify(institutionApiClient, times(1))._retrieveInstitutionByIdUsingGET(institutionId); + + } }