From 088544aa4a89e99462e875e0f297785b138a305e Mon Sep 17 00:00:00 2001 From: Alessio Cialini Date: Fri, 13 Sep 2024 16:06:09 +0200 Subject: [PATCH] [PPANTT-81] feat: Updated rest call and related tests and interfaces --- .../clients/CreditorInstitutionRestClient.java | 13 ++++++------- .../CreditorInstitutionRestClientInterface.java | 6 +++--- .../services/CreditorInstitutionService.java | 8 ++++---- .../payment/options/WireMockExtensions.java | 6 ++---- .../CreditorInstitutionRestClientTest.java | 12 ++++-------- .../CreditorInstitutionServiceTest.java | 17 +++++++++-------- 6 files changed, 28 insertions(+), 34 deletions(-) diff --git a/src/main/java/it/gov/pagopa/payment/options/clients/CreditorInstitutionRestClient.java b/src/main/java/it/gov/pagopa/payment/options/clients/CreditorInstitutionRestClient.java index 26f5d44..24e9d46 100644 --- a/src/main/java/it/gov/pagopa/payment/options/clients/CreditorInstitutionRestClient.java +++ b/src/main/java/it/gov/pagopa/payment/options/clients/CreditorInstitutionRestClient.java @@ -35,9 +35,6 @@ public class CreditorInstitutionRestClient { * @param targetHost verify service host * @param targetPort verify service port * @param targetPath verify service path - * @param idPsp psp id to be used as parameter for the call - * @param idBrokerPsp broker id to be used as parameter for the call - * @param idStazione station id to be used for the call * @param fiscalCode fiscal code to be used as input for the call * @param noticeNumber notice number to be used as input for the call * @return PaymentOptionResponse @@ -47,8 +44,8 @@ public class CreditorInstitutionRestClient { public PaymentOptionsResponse callEcPaymentOptionsVerify( String endpoint, String proxyHost, Long proxyPort, String targetHost, Long targetPort, String targetPath, - String idPsp, String idBrokerPsp, - String idStazione, String fiscalCode, String noticeNumber) +// String idPA, String idBrokerPA, String idStazione, + String fiscalCode, String noticeNumber) throws MalformedURLException { RestClientBuilder builder = @@ -60,8 +57,10 @@ public PaymentOptionsResponse callEcPaymentOptionsVerify( CreditorInstitutionRestClientInterface.class); try (Response response = ecRestClientInterface.verifyPaymentOptions( - fiscalCode, noticeNumber, idPsp, idBrokerPsp, idStazione, - targetHost, targetPort.intValue(), targetPath)) { + fiscalCode, noticeNumber, +// idPA, idBrokerPA, idStazione, + targetHost, targetPort.intValue(), + targetPath)) { if (response.getStatus() != 200) { manageErrorResponse(response); diff --git a/src/main/java/it/gov/pagopa/payment/options/clients/CreditorInstitutionRestClientInterface.java b/src/main/java/it/gov/pagopa/payment/options/clients/CreditorInstitutionRestClientInterface.java index a7ffded..61708e2 100644 --- a/src/main/java/it/gov/pagopa/payment/options/clients/CreditorInstitutionRestClientInterface.java +++ b/src/main/java/it/gov/pagopa/payment/options/clients/CreditorInstitutionRestClientInterface.java @@ -19,9 +19,9 @@ public interface CreditorInstitutionRestClientInterface { Response verifyPaymentOptions( @PathParam("fiscal-code") String fiscalCode, @PathParam("notice-number") String noticeNumber, - @QueryParam("idPA") String idPA, - @QueryParam("idBrokerPA") String idBrokerPA, - @QueryParam("idStation") String idStation, +// @QueryParam("idPA") String idPA, +// @QueryParam("idBrokerPA") String idBrokerPA, +// @QueryParam("idStation") String idStation, @HeaderParam("X-Host-Url") String hostUrl, @HeaderParam("X-Host-Port") Integer hostPort, @HeaderParam("X-Host-Path") String hostPath diff --git a/src/main/java/it/gov/pagopa/payment/options/services/CreditorInstitutionService.java b/src/main/java/it/gov/pagopa/payment/options/services/CreditorInstitutionService.java index 073b434..941f496 100644 --- a/src/main/java/it/gov/pagopa/payment/options/services/CreditorInstitutionService.java +++ b/src/main/java/it/gov/pagopa/payment/options/services/CreditorInstitutionService.java @@ -36,15 +36,15 @@ public class CreditorInstitutionService { * The method contains checks regarding the endpoint to use, and attempts to * extract the REST target params * - * @param idPsp psp identifier - * @param idBrokerPsp broker psp identifier +// * @param idPA pa identifier +// * @param idBrokerPA broker pa identifier * @param noticeNumber input notice number * @param fiscalCode input fiscal code * @param station station containing the connection config to use * @return */ public PaymentOptionsResponse getPaymentOptions( - String idPsp, String idBrokerPsp, + //String idPA, String idBrokerPA, String noticeNumber, String fiscalCode, Station station) { if (station.getConnection().getIp() == null || @@ -85,7 +85,7 @@ public PaymentOptionsResponse getPaymentOptions( station.getProxy() != null ? station.getProxy().getProxyHost() : null, station.getProxy() != null ? station.getProxy().getProxyPort() : null, targetHost, targetPort, targetPath, - idPsp, idBrokerPsp, station.getStationCode(), fiscalCode, noticeNumber + fiscalCode, noticeNumber ); } catch (MalformedURLException e) { logger.error("[Payment Options] Malformed URL: {}", e.getMessage()); diff --git a/src/test/java/it/gov/pagopa/payment/options/WireMockExtensions.java b/src/test/java/it/gov/pagopa/payment/options/WireMockExtensions.java index d143825..91689b0 100644 --- a/src/test/java/it/gov/pagopa/payment/options/WireMockExtensions.java +++ b/src/test/java/it/gov/pagopa/payment/options/WireMockExtensions.java @@ -27,8 +27,7 @@ public Map start() { wireMockServer.stubFor( get(urlEqualTo( - "/payment-options/organizations/77777777777/notices/311111111112222222" - + "?idPA=88888888888&idBrokerPA=88888888888&idStation=88888888888_01")) + "/payment-options/organizations/77777777777/notices/311111111112222222")) .willReturn(aResponse() .withHeader("Content-Type", "application/json") .withResponseBody( @@ -41,8 +40,7 @@ public Map start() { wireMockServer.stubFor( get(urlEqualTo( - "/payment-options/organizations/87777777777/notices/311111111112222222" - + "?idPA=88888888888&idBrokerPA=88888888888&idStation=88888888888_01")) + "/payment-options/organizations/87777777777/notices/311111111112222222")) .willReturn(aResponse() .withHeader("Content-Type", "application/json") .withStatus(412) diff --git a/src/test/java/it/gov/pagopa/payment/options/clients/CreditorInstitutionRestClientTest.java b/src/test/java/it/gov/pagopa/payment/options/clients/CreditorInstitutionRestClientTest.java index 9a20abe..594f9d3 100644 --- a/src/test/java/it/gov/pagopa/payment/options/clients/CreditorInstitutionRestClientTest.java +++ b/src/test/java/it/gov/pagopa/payment/options/clients/CreditorInstitutionRestClientTest.java @@ -35,8 +35,7 @@ void callEcPaymentOptionsVerifyShouldReturnData() { assertDoesNotThrow(() -> creditorInstitutionRestClient.callEcPaymentOptionsVerify( wiremockUrl, null, null, "http://externalService", 443L, "/externalPath", - "88888888888", "88888888888", "88888888888_01", - "77777777777", "311111111112222222")); + "88888888888", "88888888888")); assertNotNull(paymentOptionsResponse); } @@ -47,8 +46,7 @@ void callEcPaymentOptionsVerifyShouldReturnErrorResponse() { () -> creditorInstitutionRestClient.callEcPaymentOptionsVerify( wiremockUrl, null, null, "http://externalService", 443L, "/externalPath", - "88888888888", "88888888888", "88888888888_01", - "87777777777", "311111111112222222")); + "88888888888", "88888888888")); assertNotNull(exception); assertEquals(exception.getErrorResponse().getHttpStatusCode(), 500); } @@ -60,8 +58,7 @@ void callEcPaymentOptionsVerifyShouldReturnUnreachableKOWithoutErrorResponse() { () -> creditorInstitutionRestClient.callEcPaymentOptionsVerify( wiremockUrl, null, null, "http://externalService", 443L, "/externalPath", - "08888888888", "88888888888", "88888888888_01", - "87777777777", "311111111112222222")); + "08888888888", "88888888888")); assertNotNull(exception); assertEquals(exception.getErrorCode(), AppErrorCodeEnum.ODP_STAZIONE_INT_PA_IRRAGGIUNGIBILE); } @@ -73,8 +70,7 @@ void callEcPaymentOptionsVerifyShouldReturnExceptionOnMalformedUrl() { () -> creditorInstitutionRestClient.callEcPaymentOptionsVerify( "AAAAAAA", null, null, "http://externalService", 443L, "/externalPath", - "88888888888", "88888888888", "88888888888_01", - "87777777777", "311111111112222222")); + "88888888888", "88888888888")); } diff --git a/src/test/java/it/gov/pagopa/payment/options/services/CreditorInstitutionServiceTest.java b/src/test/java/it/gov/pagopa/payment/options/services/CreditorInstitutionServiceTest.java index e94f707..210a06a 100644 --- a/src/test/java/it/gov/pagopa/payment/options/services/CreditorInstitutionServiceTest.java +++ b/src/test/java/it/gov/pagopa/payment/options/services/CreditorInstitutionServiceTest.java @@ -39,11 +39,11 @@ public void init() { @Test void getPaymentOptionsShouldReturnData() throws MalformedURLException { when(creditorInstitutionRestClient.callEcPaymentOptionsVerify( - any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any()) + any(), any(), any(), any(), any(), any(), any(), any()) ).thenReturn(PaymentOptionsResponse.builder().build()); PaymentOptionsResponse paymentOptionsResponse = assertDoesNotThrow(() -> creditorInstitutionService.getPaymentOptions( - "000001","000001","12345","322334", + "000001","000001", Station.builder().stationCode("000001_01") .connection( Connection.builder() @@ -58,17 +58,17 @@ void getPaymentOptionsShouldReturnData() throws MalformedURLException { )); assertNotNull(paymentOptionsResponse); verify(creditorInstitutionRestClient).callEcPaymentOptionsVerify( - any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any()); + any(), any(), any(), any(), any(), any(), any(), any()); } @Test void getPaymentOptionsShouldReturnExceptionOnMalformed() throws MalformedURLException { when(creditorInstitutionRestClient.callEcPaymentOptionsVerify( - any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any()) + any(), any(), any(), any(), any(), any(), any(), any()) ).thenThrow(new MalformedURLException()); PaymentOptionsException paymentOptionsException = assertThrows(PaymentOptionsException.class, () -> creditorInstitutionService.getPaymentOptions( - "000001","000001","12345","322334", + "000001","000001", Station.builder().stationCode("000001_01") .connection( Connection.builder() @@ -84,14 +84,15 @@ void getPaymentOptionsShouldReturnExceptionOnMalformed() throws MalformedURLExce assertNotNull(paymentOptionsException); assertEquals(paymentOptionsException.getErrorCode(), AppErrorCodeEnum.ODP_SEMANTICA); verify(creditorInstitutionRestClient).callEcPaymentOptionsVerify( - any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any()); + any(), any(), any(), any(), any(), any(), any(), any() + ); } @Test void getPaymentOptionsShouldReturnExceptionOnMissingEndpoint() throws MalformedURLException { PaymentOptionsException paymentOptionsException = assertThrows(PaymentOptionsException.class, () -> creditorInstitutionService.getPaymentOptions( - "000001","000001","12345","322334", + "000001","000001", Station.builder().stationCode("000001_01") .connection( Connection.builder() @@ -113,7 +114,7 @@ void getPaymentOptionsShouldReturnExceptionOnMissingEndpoint() throws MalformedU void getPaymentOptionsShouldReturnExceptionOnBrokerServiceUrl() throws MalformedURLException { PaymentOptionsException paymentOptionsException = assertThrows(PaymentOptionsException.class, () -> creditorInstitutionService.getPaymentOptions( - "000001","000001","12345","322334", + "000001","000001", Station.builder().stationCode("000001_01") .connection( Connection.builder()