From dbe8562a74b46b63f6e9c61917f14c032e239552 Mon Sep 17 00:00:00 2001 From: Lorenzo Catalano Date: Thu, 11 Apr 2024 08:36:08 +0200 Subject: [PATCH] fix tests --- openapi/openapi.json | 326 +++++++++++------- .../config/ScheduledJobsConfig.java | 5 +- .../pagopa/wispconverter/CarrelloTest.java | 6 + .../it/gov/pagopa/wispconverter/HomeTest.java | 6 + .../wispconverter/OpenApiGenerationTest.java | 8 + .../gov/pagopa/wispconverter/ReceiptTest.java | 26 +- .../it/gov/pagopa/wispconverter/RptTest.java | 19 +- .../pagopa/wispconverter/utils/TestUtils.java | 6 + .../resources/application-test.properties | 4 + src/test/resources/requests/paSendRTV2.xml | 2 +- 10 files changed, 264 insertions(+), 144 deletions(-) diff --git a/openapi/openapi.json b/openapi/openapi.json index ed5c21cd..5f684c19 100644 --- a/openapi/openapi.json +++ b/openapi/openapi.json @@ -1,170 +1,242 @@ { - "openapi": "3.0.1", - "info": { - "description": "A service that permits to handle nodoInviaRPT and nodoInviaCarrelloRPT request from WISP, converting them in NMU payments.\n\n**STANDARD ERRORS:**\nNAME | CODE | DESCRIPTION\n- | - | -\n**WIC-500** | *ERROR* | *...error description...*\n**WIC-1000** | *GENERIC_ERROR* | Error while executing conversion flow. *...error description...*\n**WIC-1001** | *PARSING_GENERIC_ERROR* | Error while parsing payload. *...error description...*\n**WIC-1002** | *PARSING_INVALID_HEADER* | Error while parsing payload. The SOAP header in payload is invalid: *...error description...*\n**WIC-1003** | *PARSING_INVALID_BODY* | Error while parsing payload. The SOAP body in payload is invalid: *...error description...*\n**WIC-1004** | *PARSING_INVALID_XML_NODES* | Error while parsing payload. The list of nodes extracted from document must be greater than zero, but currently it is zero.\n**WIC-1005** | *PARSING_INVALID_ZIPPED_PAYLOAD* | Error while parsing payload. Cannot unzip payload correctly.\n**WIC-1006** | *PARSING_PRIMITIVE_NOT_VALID* | Error while checking primitive. Primitive [*...content...*] not valid.\n**WIC-1100** | *VALIDATION_INVALID_MULTIBENEFICIARY_CART* | Error while generating debt position for GPD service. The cart is defined as multi-beneficiary but there are a number of RPTs lower than 2.\n**WIC-1101** | *VALIDATION_INVALID_IBANS* | Error while generating debt position for GPD service. The IBAN field must be set if digital stamp is not defined for the transfer.\n**WIC-1102** | *VALIDATION_INVALID_DEBTOR* | Error while generating debt position for GPD service. The debtor subject information is different between the various RPT of the cart.\n**WIC-1103** | *VALIDATION_INVALID_CREDITOR_INSTITUTION* | Error while generating debt position for GPD service. The creditor institution information is different between the various RPT of the cart.\n**WIC-1200** | *CONFIGURATION_INVALID_STATION* | Error while generating cart for Checkout service. No valid station found with code [*...content...*].\n**WIC-1201** | *CONFIGURATION_INVALID_STATION_REDIRECT_URL* | Error while generating cart for Checkout service. The station with code [*...content...*] contains wrong redirect URL and it is not possible to generate valid URI.\n**WIC-2000** | *PERSISTENCE_RPT_NOT_FOUND* | Error while retrieving RPT. RPT with sessionId [*...content...*] not found.\n**WIC-2001** | *PERSISTENCE_REQUESTID_CACHING_ERROR* | Error while caching RequestID. *...error description...*\n**WIC-3000** | *CLIENT_APICONFIGCACHE* | Error while communicating with APIConfig cache service. *...error description...*\n**WIC-3001** | *CLIENT_GPD* | Error while communicating with GPD service. *...error description...*\n**WIC-3002** | *CLIENT_IUVGENERATOR* | Error while communicating with IUV Generator service. *...error description...*\n**WIC-3003** | *CLIENT_DECOUPLER_CACHING* | Error while communicating with decoupler caching API. *...error description...*\n**WIC-3004** | *CLIENT_CHECKOUT* | Error while communicating with Checkout service. *...error description...*\n**WIC-3005** | *CLIENT_CHECKOUT_NO_REDIRECT_LOCATION* | Error while communicating with Checkout service. No valid 'Location' header was found,\n**WIC-3006** | *CLIENT_CHECKOUT_INVALID_REDIRECT_LOCATION* | Error while communicating with Checkout service. An empty 'Location' header was found.\n", - "termsOfService": "https://www.pagopa.gov.it/", - "title": "WISP Converter", - "version": "0.0.9" + "openapi" : "3.0.1", + "info" : { + "description" : "A service that permits to handle nodoInviaRPT and nodoInviaCarrelloRPT request from WISP, converting them in NMU payments.\n\n**STANDARD ERRORS:**\nNAME | CODE | DESCRIPTION\n- | - | -\n**WIC-500** | *ERROR* | *...error description...*\n**WIC-1000** | *GENERIC_ERROR* | Error while executing conversion flow. *...error description...*\n**WIC-1001** | *PARSING_GENERIC_ERROR* | Error while parsing payload. *...error description...*\n**WIC-1002** | *PARSING_INVALID_HEADER* | Error while parsing payload. The SOAP header in payload is invalid: *...error description...*\n**WIC-1003** | *PARSING_INVALID_BODY* | Error while parsing payload. The SOAP body in payload is invalid: *...error description...*\n**WIC-1004** | *PARSING_INVALID_XML_NODES* | Error while parsing payload. The list of nodes extracted from document must be greater than zero, but currently it is zero.\n**WIC-1005** | *PARSING_INVALID_ZIPPED_PAYLOAD* | Error while parsing payload. Cannot unzip payload correctly.\n**WIC-1006** | *PARSING_PRIMITIVE_NOT_VALID* | Error while checking primitive. Primitive [*...content...*] not valid.\n**WIC-1100** | *VALIDATION_INVALID_MULTIBENEFICIARY_CART* | Error while generating debt position for GPD service. The cart is defined as multi-beneficiary but there are a number of RPTs lower than 2.\n**WIC-1101** | *VALIDATION_INVALID_IBANS* | Error while generating debt position for GPD service. The IBAN field must be set if digital stamp is not defined for the transfer.\n**WIC-1102** | *VALIDATION_INVALID_DEBTOR* | Error while generating debt position for GPD service. The debtor subject information is different between the various RPT of the cart.\n**WIC-1103** | *VALIDATION_INVALID_CREDITOR_INSTITUTION* | Error while generating debt position for GPD service. The creditor institution information is different between the various RPT of the cart.\n**WIC-1200** | *CONFIGURATION_INVALID_STATION* | Error while generating cart for Checkout service. No valid station found with code [*...content...*].\n**WIC-1201** | *CONFIGURATION_INVALID_STATION_REDIRECT_URL* | Error while generating cart for Checkout service. The station with code [*...content...*] contains wrong redirect URL and it is not possible to generate valid URI.\n**WIC-2000** | *PERSISTENCE_RPT_NOT_FOUND* | Error while retrieving RPT. RPT with sessionId [*...content...*] not found.\n**WIC-2001** | *PERSISTENCE_REQUESTID_CACHING_ERROR* | Error while caching RequestID. *...error description...*\n**WIC-3000** | *CLIENT_APICONFIGCACHE* | Error while communicating with APIConfig cache service. *...error description...*\n**WIC-3001** | *CLIENT_GPD* | Error while communicating with GPD service. *...error description...*\n**WIC-3002** | *CLIENT_IUVGENERATOR* | Error while communicating with IUV Generator service. *...error description...*\n**WIC-3003** | *CLIENT_DECOUPLER_CACHING* | Error while communicating with decoupler caching API. *...error description...*\n**WIC-3004** | *CLIENT_CHECKOUT* | Error while communicating with Checkout service. *...error description...*\n**WIC-3005** | *CLIENT_CHECKOUT_NO_REDIRECT_LOCATION* | Error while communicating with Checkout service. No valid 'Location' header was found,\n**WIC-3006** | *CLIENT_CHECKOUT_INVALID_REDIRECT_LOCATION* | Error while communicating with Checkout service. An empty 'Location' header was found.\n", + "termsOfService" : "https://www.pagopa.gov.it/", + "title" : "WISP Converter", + "version" : "0.0.9" }, - "servers": [ - { - "url": "http://localhost", - "description": "Generated server url" - } - ], - "tags": [ - { - "description": "Application info APIs", - "name": "Home" - }, - { - "description": "Conversion and redirection APIs", - "name": "Redirect" - } - ], - "paths": { - "/info": { - "get": { - "operationId": "healthCheck", - "responses": { - "200": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/AppInfoResponse" + "servers" : [ { + "url" : "http://localhost", + "description" : "Generated server url" + } ], + "tags" : [ { + "description" : "Application info APIs", + "name" : "Home" + }, { + "description" : "Convert sendPaymentResultV2, closePaymentV2 or paSendRTV2 into paaInviaRT to EC", + "name" : "Receipt" + }, { + "description" : "Conversion and redirection APIs", + "name" : "Redirect" + } ], + "paths" : { + "/info" : { + "get" : { + "operationId" : "healthCheck", + "responses" : { + "200" : { + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/AppInfoResponse" } } }, - "description": "OK.", - "headers": { - "X-Request-Id": { - "description": "This header identifies the call", - "schema": { - "type": "string" + "description" : "OK.", + "headers" : { + "X-Request-Id" : { + "description" : "This header identifies the call", + "schema" : { + "type" : "string" } } } } }, - "security": [ - { - "ApiKey": [] - } - ], - "summary": "Return OK if application is started", - "tags": [ - "Home" - ] + "security" : [ { + "ApiKey" : [ ] + } ], + "summary" : "Return OK if application is started", + "tags" : [ "Home" ] }, - "parameters": [ - { - "description": "This header identifies the call, if not passed it is self-generated. This ID is returned in the response.", - "in": "header", - "name": "X-Request-Id", - "schema": { - "type": "string" - } + "parameters" : [ { + "description" : "This header identifies the call, if not passed it is self-generated. This ID is returned in the response.", + "in" : "header", + "name" : "X-Request-Id", + "schema" : { + "type" : "string" } - ] + } ] }, - "/redirect": { - "get": { - "operationId": "redirect_1", - "parameters": [ - { - "example": "identificativoIntermediarioPA_sessionId", - "in": "query", - "name": "sessionId", - "required": true, - "schema": { - "type": "string" + "/receipt/ko" : { + "parameters" : [ { + "description" : "This header identifies the call, if not passed it is self-generated. This ID is returned in the response.", + "in" : "header", + "name" : "X-Request-Id", + "schema" : { + "type" : "string" + } + } ], + "post" : { + "operationId" : "receiptKo", + "requestBody" : { + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/ReceiptRequest" + } + } + }, + "required" : true + }, + "responses" : { + "200" : { + "description" : "Successfully forwarded paaInviaRT- to EC", + "headers" : { + "X-Request-Id" : { + "description" : "This header identifies the call", + "schema" : { + "type" : "string" + } + } } } - ], - "responses": { - "200": { - "content": { - "*/*": { - "schema": { - "$ref": "#/components/schemas/RedirectResponse" + }, + "security" : [ { + "ApiKey" : [ ] + } ], + "tags" : [ "Receipt" ] + } + }, + "/receipt/ok" : { + "parameters" : [ { + "description" : "This header identifies the call, if not passed it is self-generated. This ID is returned in the response.", + "in" : "header", + "name" : "X-Request-Id", + "schema" : { + "type" : "string" + } + } ], + "post" : { + "operationId" : "receiptOk", + "requestBody" : { + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/ReceiptRequest" + } + } + }, + "required" : true + }, + "responses" : { + "200" : { + "description" : "Successfully forwarded paaInviaRT+ to EC", + "headers" : { + "X-Request-Id" : { + "description" : "This header identifies the call", + "schema" : { + "type" : "string" + } + } + } + } + }, + "security" : [ { + "ApiKey" : [ ] + } ], + "tags" : [ "Receipt" ] + } + }, + "/redirect" : { + "get" : { + "operationId" : "redirect_1", + "parameters" : [ { + "example" : "identificativoIntermediarioPA_sessionId", + "in" : "query", + "name" : "sessionId", + "required" : true, + "schema" : { + "type" : "string" + } + } ], + "responses" : { + "200" : { + "content" : { + "*/*" : { + "schema" : { + "$ref" : "#/components/schemas/RedirectResponse" } } }, - "description": "Redirect info to Checkout service.", - "headers": { - "X-Request-Id": { - "description": "This header identifies the call", - "schema": { - "type": "string" + "description" : "Redirect info to Checkout service.", + "headers" : { + "X-Request-Id" : { + "description" : "This header identifies the call", + "schema" : { + "type" : "string" } } } }, - "302": { - "description": "Redirect to Checkout service.", - "headers": { - "X-Request-Id": { - "description": "This header identifies the call", - "schema": { - "type": "string" + "302" : { + "description" : "Redirect to Checkout service.", + "headers" : { + "X-Request-Id" : { + "description" : "This header identifies the call", + "schema" : { + "type" : "string" } } } } }, - "security": [ - { - "ApiKey": [] - } - ], - "tags": [ - "Redirect" - ] + "security" : [ { + "ApiKey" : [ ] + } ], + "tags" : [ "Redirect" ] }, - "parameters": [ - { - "description": "This header identifies the call, if not passed it is self-generated. This ID is returned in the response.", - "in": "header", - "name": "X-Request-Id", - "schema": { - "type": "string" - } + "parameters" : [ { + "description" : "This header identifies the call, if not passed it is self-generated. This ID is returned in the response.", + "in" : "header", + "name" : "X-Request-Id", + "schema" : { + "type" : "string" } - ] + } ] } }, - "components": { - "schemas": { - "AppInfoResponse": { - "type": "object", - "properties": { - "environment": { - "type": "string" + "components" : { + "schemas" : { + "AppInfoResponse" : { + "type" : "object", + "properties" : { + "environment" : { + "type" : "string" }, - "name": { - "type": "string" + "name" : { + "type" : "string" }, - "version": { - "type": "string" + "version" : { + "type" : "string" + } + } + }, + "ReceiptRequest" : { + "type" : "object", + "properties" : { + "content" : { + "type" : "string" } } }, - "RedirectResponse": { - "type": "object", - "properties": { - "redirect-url": { - "type": "string" + "RedirectResponse" : { + "type" : "object", + "properties" : { + "redirect-url" : { + "type" : "string" } } } }, - "securitySchemes": { - "ApiKey": { - "description": "The API key to access this function app.", - "in": "header", - "name": "Ocp-Apim-Subscription-Key", - "type": "apiKey" + "securitySchemes" : { + "ApiKey" : { + "description" : "The API key to access this function app.", + "in" : "header", + "name" : "Ocp-Apim-Subscription-Key", + "type" : "apiKey" } } } -} +} \ No newline at end of file diff --git a/src/main/java/it/gov/pagopa/wispconverter/config/ScheduledJobsConfig.java b/src/main/java/it/gov/pagopa/wispconverter/config/ScheduledJobsConfig.java index fdc50179..6813a88f 100644 --- a/src/main/java/it/gov/pagopa/wispconverter/config/ScheduledJobsConfig.java +++ b/src/main/java/it/gov/pagopa/wispconverter/config/ScheduledJobsConfig.java @@ -1,18 +1,19 @@ package it.gov.pagopa.wispconverter.config; import it.gov.pagopa.wispconverter.service.ConfigCacheService; +import java.time.ZonedDateTime; import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.context.annotation.Configuration; import org.springframework.context.event.EventListener; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; -import java.time.ZonedDateTime; - @Configuration @Slf4j @EnableScheduling +@ConditionalOnExpression("'${info.properties.environment}'!='test'") public class ScheduledJobsConfig { private final ConfigCacheService configCacheService; diff --git a/src/test/java/it/gov/pagopa/wispconverter/CarrelloTest.java b/src/test/java/it/gov/pagopa/wispconverter/CarrelloTest.java index e52bf4f1..115eec5e 100644 --- a/src/test/java/it/gov/pagopa/wispconverter/CarrelloTest.java +++ b/src/test/java/it/gov/pagopa/wispconverter/CarrelloTest.java @@ -9,6 +9,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import it.gov.pagopa.gen.wispconverter.client.iuvgenerator.model.IuvGenerationModelResponseDto; import it.gov.pagopa.wispconverter.repository.RPTRequestRepository; +import it.gov.pagopa.wispconverter.repository.RTRequestRepository; +import it.gov.pagopa.wispconverter.repository.ReEventRepository; import it.gov.pagopa.wispconverter.repository.model.RPTRequestEntity; import it.gov.pagopa.wispconverter.service.ConfigCacheService; import it.gov.pagopa.wispconverter.utils.TestUtils; @@ -44,6 +46,8 @@ class CarrelloTest { @MockBean private RPTRequestRepository rptRequestRepository; + @MockBean + private RTRequestRepository rtRequestRepository; @MockBean private it.gov.pagopa.gen.wispconverter.client.iuvgenerator.invoker.ApiClient iuveneratorClient; @MockBean private it.gov.pagopa.gen.wispconverter.client.gpd.invoker.ApiClient gpdClient; @MockBean private it.gov.pagopa.gen.wispconverter.client.checkout.invoker.ApiClient checkoutClient; @@ -51,6 +55,8 @@ class CarrelloTest { @MockBean private it.gov.pagopa.gen.wispconverter.client.decouplercaching.invoker.ApiClient decouplerCachingClient; @Qualifier("redisSimpleTemplate") @MockBean private RedisTemplate redisSimpleTemplate; + @MockBean + private ReEventRepository reEventRepository; @Test void success() throws Exception { diff --git a/src/test/java/it/gov/pagopa/wispconverter/HomeTest.java b/src/test/java/it/gov/pagopa/wispconverter/HomeTest.java index c5c19827..cf262488 100644 --- a/src/test/java/it/gov/pagopa/wispconverter/HomeTest.java +++ b/src/test/java/it/gov/pagopa/wispconverter/HomeTest.java @@ -6,6 +6,8 @@ import it.gov.pagopa.wispconverter.controller.model.AppInfoResponse; import it.gov.pagopa.wispconverter.repository.CacheRepository; import it.gov.pagopa.wispconverter.repository.RPTRequestRepository; +import it.gov.pagopa.wispconverter.repository.RTRequestRepository; +import it.gov.pagopa.wispconverter.repository.ReEventRepository; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -39,7 +41,11 @@ class HomeTest { @MockBean private RPTRequestRepository rptRequestRepository; @MockBean + private RTRequestRepository rtRequestRepository; + @MockBean private CacheRepository cacheRepository; + @MockBean + private ReEventRepository reEventRepository; @Test void slash() throws Exception { diff --git a/src/test/java/it/gov/pagopa/wispconverter/OpenApiGenerationTest.java b/src/test/java/it/gov/pagopa/wispconverter/OpenApiGenerationTest.java index aed06bb5..9a579d85 100644 --- a/src/test/java/it/gov/pagopa/wispconverter/OpenApiGenerationTest.java +++ b/src/test/java/it/gov/pagopa/wispconverter/OpenApiGenerationTest.java @@ -4,6 +4,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import it.gov.pagopa.wispconverter.controller.RedirectController; import it.gov.pagopa.wispconverter.repository.RPTRequestRepository; +import it.gov.pagopa.wispconverter.repository.RTRequestRepository; +import it.gov.pagopa.wispconverter.repository.ReEventRepository; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; @@ -39,9 +41,15 @@ class OpenApiGenerationTest { @MockBean private RPTRequestRepository rptRequestRepository; + @MockBean + private RTRequestRepository rtRequestRepository; + @MockBean private CosmosAsyncClient cosmosAsyncClient; + @MockBean + private ReEventRepository reEventRepository; + @Test void swaggerSpringPlugin() throws Exception { mvc.perform(MockMvcRequestBuilders.get("/v3/api-docs").accept(MediaType.APPLICATION_JSON)) diff --git a/src/test/java/it/gov/pagopa/wispconverter/ReceiptTest.java b/src/test/java/it/gov/pagopa/wispconverter/ReceiptTest.java index e5dd3cea..6cff2685 100644 --- a/src/test/java/it/gov/pagopa/wispconverter/ReceiptTest.java +++ b/src/test/java/it/gov/pagopa/wispconverter/ReceiptTest.java @@ -8,6 +8,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import it.gov.pagopa.wispconverter.controller.model.ReceiptRequest; import it.gov.pagopa.wispconverter.repository.RPTRequestRepository; +import it.gov.pagopa.wispconverter.repository.RTRequestRepository; +import it.gov.pagopa.wispconverter.repository.ReEventRepository; import it.gov.pagopa.wispconverter.repository.model.RPTRequestEntity; import it.gov.pagopa.wispconverter.service.ConfigCacheService; import it.gov.pagopa.wispconverter.service.ReService; @@ -48,9 +50,10 @@ class ReceiptTest { @MockBean private ApplicationStartup applicationStartup; - @MockBean private RPTRequestRepository rptRequestRepository; + @MockBean + private RTRequestRepository rtRequestRepository; @MockBean private it.gov.pagopa.gen.wispconverter.client.iuvgenerator.invoker.ApiClient iuveneratorClient; @MockBean private it.gov.pagopa.gen.wispconverter.client.gpd.invoker.ApiClient gpdClient; @MockBean private it.gov.pagopa.gen.wispconverter.client.checkout.invoker.ApiClient checkoutClient; @@ -59,8 +62,8 @@ class ReceiptTest { @MockBean private CosmosClientBuilder cosmosClientBuilder; @Qualifier("redisSimpleTemplate") @MockBean private RedisTemplate redisSimpleTemplate; - @SpyBean - private ReService reService; + @MockBean + private ReEventRepository reEventRepository; private String getPaSendRTPayload(){ String pasendrtv2 = TestUtils.loadFileContent("/requests/paSendRTV2.xml"); @@ -79,8 +82,17 @@ private byte[] zip(byte[] uncompressed) throws IOException { @Test void success_positive() throws Exception { String station = "mystation"; - TestUtils.setMock(cacheClient,ResponseEntity.ok().body(TestUtils.configData(station))); - org.springframework.test.util.ReflectionTestUtils.setField(configCacheService, "configCacheClient",cacheClient); + org.springframework.test.util.ReflectionTestUtils.setField(configCacheService, "configData",TestUtils.configData(station)); + + when(rptRequestRepository.findById(any())).thenReturn( + Optional.of( + RPTRequestEntity.builder().primitive("nodoInviaRPT") + .payload( + TestUtils.zipAndEncode(TestUtils.getRptPayload(false,station,"100.00","datispec")) + ).build() + ) + ); + mvc.perform(MockMvcRequestBuilders.post("/receipt/ok") .accept(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON) @@ -93,7 +105,7 @@ void success_positive() throws Exception { }); - verify(reService,times(1)).addRe(any()); + verify(reEventRepository,times(3)).save(any()); } @Test @@ -123,7 +135,7 @@ void success_negative() throws Exception { assertNotNull(result.getResponse()); }); - verify(reService,times(1)).addRe(any()); + verify(reEventRepository,times(3)).save(any()); } } diff --git a/src/test/java/it/gov/pagopa/wispconverter/RptTest.java b/src/test/java/it/gov/pagopa/wispconverter/RptTest.java index 663f6828..205b8490 100644 --- a/src/test/java/it/gov/pagopa/wispconverter/RptTest.java +++ b/src/test/java/it/gov/pagopa/wispconverter/RptTest.java @@ -8,6 +8,7 @@ import it.gov.pagopa.gen.wispconverter.client.iuvgenerator.model.IuvGenerationModelResponseDto; import it.gov.pagopa.wispconverter.repository.RPTRequestRepository; import it.gov.pagopa.wispconverter.repository.RTRequestRepository; +import it.gov.pagopa.wispconverter.repository.ReEventRepository; import it.gov.pagopa.wispconverter.repository.model.RPTRequestEntity; import it.gov.pagopa.wispconverter.service.ConfigCacheService; import it.gov.pagopa.wispconverter.service.ReService; @@ -58,6 +59,8 @@ class RptTest { @MockBean private it.gov.pagopa.gen.wispconverter.client.decouplercaching.invoker.ApiClient decouplerCachingClient; @Qualifier("redisSimpleTemplate") @MockBean private RedisTemplate redisSimpleTemplate; + @MockBean + private ReEventRepository reEventRepository; @SpyBean private ReService reService; @@ -206,7 +209,7 @@ void fail_rpt_not_exists() throws Exception { IuvGenerationModelResponseDto iuvGenerationModelResponseDto = new IuvGenerationModelResponseDto(); iuvGenerationModelResponseDto.setIuv("00000000"); - doThrow(new RestClientException("fail")) + doThrow(new RestClientException("fail", new RuntimeException("this test must fail"))) .when(iuveneratorClient).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); TestUtils.setMock(gpdClient,ResponseEntity.ok().build()); TestUtils.setMock(decouplerCachingClient,ResponseEntity.ok().build()); @@ -240,7 +243,7 @@ void fail_generic() throws Exception { IuvGenerationModelResponseDto iuvGenerationModelResponseDto = new IuvGenerationModelResponseDto(); iuvGenerationModelResponseDto.setIuv("00000000"); - doThrow(new RestClientException("fail")) + doThrow(new RestClientException("fail", new RuntimeException("this test must fail"))) .when(iuveneratorClient).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); TestUtils.setMock(gpdClient,ResponseEntity.ok().build()); TestUtils.setMock(decouplerCachingClient,ResponseEntity.ok().build()); @@ -274,7 +277,7 @@ void fail_getNAVCodeFromIUVGenerator() throws Exception { IuvGenerationModelResponseDto iuvGenerationModelResponseDto = new IuvGenerationModelResponseDto(); iuvGenerationModelResponseDto.setIuv("00000000"); - doThrow(new RestClientException("fail")) + doThrow(new RestClientException("fail", new RuntimeException("this test must fail"))) .when(iuveneratorClient).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); TestUtils.setMock(gpdClient,ResponseEntity.ok().build()); TestUtils.setMock(decouplerCachingClient,ResponseEntity.ok().build()); @@ -310,7 +313,7 @@ void fail_createDebtPositions() throws Exception { IuvGenerationModelResponseDto iuvGenerationModelResponseDto = new IuvGenerationModelResponseDto(); iuvGenerationModelResponseDto.setIuv("00000000"); TestUtils.setMock(iuveneratorClient,ResponseEntity.ok().body(iuvGenerationModelResponseDto)); - doThrow(new RestClientException("fail")) + doThrow(new RestClientException("fail", new RuntimeException("this test must fail"))) .when(gpdClient).parameterToMultiValueMap(any(),any(),any()); TestUtils.setMock(decouplerCachingClient,ResponseEntity.ok().build()); when(rptRequestRepository.findById(any())).thenReturn( @@ -348,8 +351,10 @@ void fail_storeRequestMappingInCache() throws Exception { iuvGenerationModelResponseDto.setIuv("00000000"); TestUtils.setMock(iuveneratorClient,ResponseEntity.ok().body(iuvGenerationModelResponseDto)); TestUtils.setMock(gpdClient,ResponseEntity.ok().build()); - doThrow(new RestClientException("fail")) - .when(decouplerCachingClient).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); + doThrow(new RestClientException("fail", new RuntimeException("this test must fail"))) + .when(decouplerCachingClient) + .invokeAPI( + any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any()); when(rptRequestRepository.findById(any())).thenReturn( Optional.of( RPTRequestEntity.builder().primitive("nodoInviaRPT") @@ -378,7 +383,7 @@ void fail_checkout() throws Exception { org.springframework.test.util.ReflectionTestUtils.setField(configCacheService, "configCacheClient",cacheClient); HttpHeaders headers = new HttpHeaders(); headers.add("location","locationheader"); - doThrow(new RestClientException("fail")) + doThrow(new RestClientException("fail", new RuntimeException("this test must fail"))) .when(checkoutClient).invokeAPI(any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any(),any()); IuvGenerationModelResponseDto iuvGenerationModelResponseDto = new IuvGenerationModelResponseDto(); diff --git a/src/test/java/it/gov/pagopa/wispconverter/utils/TestUtils.java b/src/test/java/it/gov/pagopa/wispconverter/utils/TestUtils.java index baccfbba..d1ac7c62 100644 --- a/src/test/java/it/gov/pagopa/wispconverter/utils/TestUtils.java +++ b/src/test/java/it/gov/pagopa/wispconverter/utils/TestUtils.java @@ -13,6 +13,8 @@ import java.util.Base64; import java.util.HashMap; import java.util.zip.GZIPOutputStream; + +import it.gov.pagopa.gen.wispconverter.client.cache.model.ConnectionDto; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -35,6 +37,10 @@ public static it.gov.pagopa.gen.wispconverter.client.cache.model.ConfigDataV1Dto configDataV1.setStations(new HashMap<>()); it.gov.pagopa.gen.wispconverter.client.cache.model.StationDto station = new it.gov.pagopa.gen.wispconverter.client.cache.model.StationDto(); station.setStationCode(stationCode); + station.setConnection(new ConnectionDto()); + station.getConnection().setIp("127.0.0.1"); + station.getConnection().setPort(8888l); + station.getConnection().setProtocol(ConnectionDto.ProtocolEnum.HTTP); station.setRedirect(new it.gov.pagopa.gen.wispconverter.client.cache.model.RedirectDto()); station.getRedirect().setIp("127.0.0.1"); station.getRedirect().setPath("/redirect"); diff --git a/src/test/resources/application-test.properties b/src/test/resources/application-test.properties index ae2b77ab..598814df 100644 --- a/src/test/resources/application-test.properties +++ b/src/test/resources/application-test.properties @@ -1,5 +1,9 @@ info.properties.environment=test +client.gpd.base-path=${CLIENT_GPD_HOST:http://localhost} +client.checkout.base-path=${CLIENT_CHECKOUT_HOST:http://localhost} +client.decoupler-caching.base-path=${CLIENT_DECOUPLERCACHING_HOST:http://localhost} +client.cache.base-path=${CLIENT_CACHE_HOST:http://localhost} # Logging logging.level.it.gov.pagopa=DEBUG diff --git a/src/test/resources/requests/paSendRTV2.xml b/src/test/resources/requests/paSendRTV2.xml index 39e23ea7..7127e0de 100644 --- a/src/test/resources/requests/paSendRTV2.xml +++ b/src/test/resources/requests/paSendRTV2.xml @@ -3,7 +3,7 @@ 77777777777 77777777777 - 77777777777_01 + mystation c110729d258c4ab1b765fe902aae41d6 311111111112222222