diff --git a/helm/values-dev.yaml b/helm/values-dev.yaml index 1baed30a..d4e49c3a 100644 --- a/helm/values-dev.yaml +++ b/helm/values-dev.yaml @@ -1,6 +1,6 @@ microservice-chart: image: - repository: arcditncorecommonacr.azurecr.io/pagopaarcbe + repository: arcditncorecommonacr.azurecr.io/arcbe tag: latest pullPolicy: Always diff --git a/helm/values-prod.yaml b/helm/values-prod.yaml index f55da744..bc99f56c 100644 --- a/helm/values-prod.yaml +++ b/helm/values-prod.yaml @@ -1,6 +1,6 @@ microservice-chart: image: - repository: arcpitncorecommonacr.azurecr.io/pagopaarcbe + repository: arcpitncorecommonacr.azurecr.io/arcbe tag: latest pullPolicy: Always diff --git a/helm/values-uat.yaml b/helm/values-uat.yaml index 1ec234f8..16cc0d89 100644 --- a/helm/values-uat.yaml +++ b/helm/values-uat.yaml @@ -1,6 +1,6 @@ microservice-chart: image: - repository: arcuitncorecommonacr.azurecr.io/pagopaarcbe + repository: arcuitncorecommonacr.azurecr.io/arcbe tag: latest pullPolicy: Always diff --git a/openapi/pagopa-arc-be.openapi.yaml b/openapi/pagopa-arc-be.openapi.yaml index 456728ac..3cd2d81f 100644 --- a/openapi/pagopa-arc-be.openapi.yaml +++ b/openapi/pagopa-arc-be.openapi.yaml @@ -308,6 +308,8 @@ components: - generic_error - transaction_not_found_error - receipt_not_found_error + - invalid_amount + - invalid_date - invalid_request error_description: type: string diff --git a/src/main/java/it/gov/pagopa/arc/exception/ArcExceptionHandler.java b/src/main/java/it/gov/pagopa/arc/exception/ArcExceptionHandler.java index b9f98da1..f4fe0bbe 100644 --- a/src/main/java/it/gov/pagopa/arc/exception/ArcExceptionHandler.java +++ b/src/main/java/it/gov/pagopa/arc/exception/ArcExceptionHandler.java @@ -33,6 +33,16 @@ public ResponseEntity handleBizEventsReceiptNotFoundException(RuntimeE return handleArcErrorException(ex, request, HttpStatus.NOT_FOUND, ErrorDTO.ErrorEnum.RECEIPT_NOT_FOUND_ERROR); } + @ExceptionHandler(BizEventsInvalidAmountException.class) + public ResponseEntity handleBizEventsInvalidAmountException(RuntimeException ex, HttpServletRequest request){ + return handleArcErrorException(ex, request, HttpStatus.BAD_REQUEST, ErrorDTO.ErrorEnum.INVALID_AMOUNT); + } + + @ExceptionHandler(BizEventsInvalidDateException.class) + public ResponseEntity handleBizEventsInvalidDateException(RuntimeException ex, HttpServletRequest request){ + return handleArcErrorException(ex, request, HttpStatus.BAD_REQUEST, ErrorDTO.ErrorEnum.INVALID_DATE); + } + private static ResponseEntity handleArcErrorException(RuntimeException ex, HttpServletRequest request, HttpStatus httpStatus, ErrorDTO.ErrorEnum errorEnum) { String message = ex.getMessage(); log.info("A {} occurred handling request {}: HttpStatus {} - {}", diff --git a/src/main/java/it/gov/pagopa/arc/exception/custom/BizEventsInvalidAmountException.java b/src/main/java/it/gov/pagopa/arc/exception/custom/BizEventsInvalidAmountException.java new file mode 100644 index 00000000..ba355856 --- /dev/null +++ b/src/main/java/it/gov/pagopa/arc/exception/custom/BizEventsInvalidAmountException.java @@ -0,0 +1,8 @@ +package it.gov.pagopa.arc.exception.custom; + +import lombok.Getter; + +@Getter +public class BizEventsInvalidAmountException extends RuntimeException{ + public BizEventsInvalidAmountException(String message){super(message);} +} diff --git a/src/main/java/it/gov/pagopa/arc/exception/custom/BizEventsInvalidDateException.java b/src/main/java/it/gov/pagopa/arc/exception/custom/BizEventsInvalidDateException.java new file mode 100644 index 00000000..5fd4421d --- /dev/null +++ b/src/main/java/it/gov/pagopa/arc/exception/custom/BizEventsInvalidDateException.java @@ -0,0 +1,8 @@ +package it.gov.pagopa.arc.exception.custom; + +import lombok.Getter; + +@Getter +public class BizEventsInvalidDateException extends RuntimeException{ + public BizEventsInvalidDateException(String message){super(message);} +} diff --git a/src/main/java/it/gov/pagopa/arc/utils/Utilities.java b/src/main/java/it/gov/pagopa/arc/utils/Utilities.java index 33a77cdc..be5b8d1b 100644 --- a/src/main/java/it/gov/pagopa/arc/utils/Utilities.java +++ b/src/main/java/it/gov/pagopa/arc/utils/Utilities.java @@ -1,7 +1,8 @@ package it.gov.pagopa.arc.utils; -import it.gov.pagopa.arc.exception.custom.BizEventsInvocationException; +import it.gov.pagopa.arc.exception.custom.BizEventsInvalidAmountException; +import it.gov.pagopa.arc.exception.custom.BizEventsInvalidDateException; import java.text.NumberFormat; import java.text.ParseException; @@ -26,7 +27,7 @@ private static Double euroStringToDouble(String euroString){ Number parse = nf.parse(euroString); return parse.doubleValue(); }catch (ParseException e){ - throw new BizEventsInvocationException("Invalid amount format"); + throw new BizEventsInvalidAmountException("Invalid amount format"); } } @@ -36,7 +37,7 @@ public static ZonedDateTime dateStringToZonedDateTime(String dateString){ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssX"); return ZonedDateTime.parse(dateString, formatter); }catch (DateTimeParseException e){ - throw new BizEventsInvocationException("Invalid date format"); + throw new BizEventsInvalidDateException("Invalid date format"); } } } diff --git a/src/test/java/it/gov/pagopa/arc/controller/TransactionsControllerTest.java b/src/test/java/it/gov/pagopa/arc/controller/TransactionsControllerTest.java index 7f5a0bdc..0b590f8f 100644 --- a/src/test/java/it/gov/pagopa/arc/controller/TransactionsControllerTest.java +++ b/src/test/java/it/gov/pagopa/arc/controller/TransactionsControllerTest.java @@ -51,7 +51,7 @@ void givenFiscalCodeWhenCallGetTransactionsListThenReturnTransactionList() throw //When MvcResult result = mockMvc.perform( - get("/arc/transactions") + get("/transactions") .param("page", String.valueOf(PAGE)) .param("size", String.valueOf(SIZE)) .param("filter", FILTER) @@ -77,7 +77,7 @@ void givenTransactionIdWhenCallGetTransactionDetailsThenReturnTransactionDetails //When MvcResult result = mockMvc.perform( - get("/arc/transactions/{transactionId}", TRANSACTION_ID) + get("/transactions/{transactionId}", TRANSACTION_ID) ).andExpect(status().is2xxSuccessful()) .andReturn(); @@ -100,7 +100,7 @@ void givenTransactionIdWhenCallGetTransactionReceiptThenReturnTransactionReceipt //When MvcResult result = mockMvc.perform( - get("/arc/transactions/{transactionId}/receipt", TRANSACTION_ID) + get("/transactions/{transactionId}/receipt", TRANSACTION_ID) ).andExpect(status().is2xxSuccessful()) .andReturn(); diff --git a/src/test/java/it/gov/pagopa/arc/exception/ArcExceptionHandlerTest.java b/src/test/java/it/gov/pagopa/arc/exception/ArcExceptionHandlerTest.java index 2b8c0bf2..eeee29cb 100644 --- a/src/test/java/it/gov/pagopa/arc/exception/ArcExceptionHandlerTest.java +++ b/src/test/java/it/gov/pagopa/arc/exception/ArcExceptionHandlerTest.java @@ -7,6 +7,7 @@ import it.gov.pagopa.arc.exception.custom.BizEventsReceiptNotFoundException; import it.gov.pagopa.arc.exception.custom.BizEventsTransactionNotFoundException; import it.gov.pagopa.arc.utils.MemoryAppender; +import it.gov.pagopa.arc.exception.custom.*; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -87,6 +88,38 @@ void givenRequestWhenBizEventsServiceReturnErrorThenHandleBizEventsInvocationExc Assertions.assertTrue(memoryAppender.getLoggedEvents().get(0).getFormattedMessage().contains("A class it.gov.pagopa.arc.exception.custom.BizEventsInvocationException occurred handling request GET /test: HttpStatus 500 - Error")); } + @Test + void givenRequestWhenBizEventsServiceReturnInvalidAmountThenHandleBizEventsInvalidAmountException() throws Exception { + doThrow(new BizEventsInvalidAmountException("Error")).when(testControllerSpy).testEndpoint(); + + mockMvc.perform(MockMvcRequestBuilders.get("/test") + .param(DATA, DATA) + .header(HEADER,HEADER) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(MockMvcResultMatchers.status().isBadRequest()) + .andExpect(MockMvcResultMatchers.jsonPath("$.error").value("invalid_amount")) + .andExpect(MockMvcResultMatchers.jsonPath("$.error_description").value("Error")); + + Assertions.assertTrue(memoryAppender.getLoggedEvents().get(0).getFormattedMessage().contains("A class it.gov.pagopa.arc.exception.custom.BizEventsInvalidAmountException occurred handling request GET /test: HttpStatus 400 - Error")); + } + + @Test + void givenRequestWhenBizEventsServiceReturnInvalidDateThenHandleBizEventsInvalidDateException() throws Exception { + doThrow(new BizEventsInvalidDateException("Error")).when(testControllerSpy).testEndpoint(); + + mockMvc.perform(MockMvcRequestBuilders.get("/test") + .param(DATA, DATA) + .header(HEADER,HEADER) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(MockMvcResultMatchers.status().isBadRequest()) + .andExpect(MockMvcResultMatchers.jsonPath("$.error").value("invalid_date")) + .andExpect(MockMvcResultMatchers.jsonPath("$.error_description").value("Error")); + + Assertions.assertTrue(memoryAppender.getLoggedEvents().get(0).getFormattedMessage().contains("A class it.gov.pagopa.arc.exception.custom.BizEventsInvalidDateException occurred handling request GET /test: HttpStatus 400 - Error")); + } + @Test void givenRequestWhenBizEventsServiceReturnNotFoundErrorThenHandleBizEventsNotFoundExceptionTransactionError() throws Exception { doThrow(new BizEventsTransactionNotFoundException("Error")).when(testControllerSpy).testEndpointTransactionDetails(); diff --git a/src/test/java/it/gov/pagopa/arc/utils/UtilitiesTest.java b/src/test/java/it/gov/pagopa/arc/utils/UtilitiesTest.java index 0fcbc4ac..ebadae29 100644 --- a/src/test/java/it/gov/pagopa/arc/utils/UtilitiesTest.java +++ b/src/test/java/it/gov/pagopa/arc/utils/UtilitiesTest.java @@ -1,6 +1,7 @@ package it.gov.pagopa.arc.utils; -import it.gov.pagopa.arc.exception.custom.BizEventsInvocationException; +import it.gov.pagopa.arc.exception.custom.BizEventsInvalidAmountException; +import it.gov.pagopa.arc.exception.custom.BizEventsInvalidDateException; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -40,7 +41,7 @@ void givenWrongEuroStringWhenCallEuroToCentsThenReturnException() { String euroString = ""; //when //then - BizEventsInvocationException exception = assertThrows(BizEventsInvocationException.class, + BizEventsInvalidAmountException exception = assertThrows(BizEventsInvalidAmountException.class, () -> Utilities.euroToCents(euroString)); Assertions.assertEquals("Invalid amount format",exception.getMessage()); @@ -64,7 +65,7 @@ void givenWrongDateStringWhenCallDateStringToZonedDateTimeThenReturnException(){ String wrongDateString = ""; //when //then - BizEventsInvocationException exception = assertThrows(BizEventsInvocationException.class, + BizEventsInvalidDateException exception = assertThrows(BizEventsInvalidDateException.class, () -> Utilities.dateStringToZonedDateTime(wrongDateString)); Assertions.assertEquals("Invalid date format",exception.getMessage()); }