From 374d5a6f89cff0755fccfe9183aaebc4f12c1ac5 Mon Sep 17 00:00:00 2001 From: giomella Date: Wed, 3 Jan 2024 12:35:20 +0100 Subject: [PATCH 1/5] [PRDP-307] added API to retrieve carts --- .../pagopa/receipt/pdf/helpdesk/GetCart.java | 89 +++++++++++++++++++ .../helpdesk/client/ReceiptCosmosClient.java | 12 ++- .../client/impl/ReceiptCosmosClientImpl.java | 31 +++++-- .../helpdesk/entity/cart/CartForReceipt.java | 22 +++++ .../helpdesk/entity/cart/CartStatusType.java | 5 ++ .../exception/CartNotFoundException.java | 24 +++++ .../service/ReceiptCosmosService.java | 12 +++ .../impl/ReceiptCosmosServiceImpl.java | 19 ++++ 8 files changed, 207 insertions(+), 7 deletions(-) create mode 100644 src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/GetCart.java create mode 100644 src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/entity/cart/CartForReceipt.java create mode 100644 src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/entity/cart/CartStatusType.java create mode 100644 src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/exception/CartNotFoundException.java diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/GetCart.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/GetCart.java new file mode 100644 index 0000000..93dafea --- /dev/null +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/GetCart.java @@ -0,0 +1,89 @@ +package it.gov.pagopa.receipt.pdf.helpdesk; + +import com.microsoft.azure.functions.ExecutionContext; +import com.microsoft.azure.functions.HttpMethod; +import com.microsoft.azure.functions.HttpRequestMessage; +import com.microsoft.azure.functions.HttpResponseMessage; +import com.microsoft.azure.functions.HttpStatus; +import com.microsoft.azure.functions.annotation.AuthorizationLevel; +import com.microsoft.azure.functions.annotation.BindingName; +import com.microsoft.azure.functions.annotation.FunctionName; +import com.microsoft.azure.functions.annotation.HttpTrigger; +import it.gov.pagopa.receipt.pdf.helpdesk.entity.cart.CartForReceipt; +import it.gov.pagopa.receipt.pdf.helpdesk.exception.CartNotFoundException; +import it.gov.pagopa.receipt.pdf.helpdesk.model.ProblemJson; +import it.gov.pagopa.receipt.pdf.helpdesk.service.ReceiptCosmosService; +import it.gov.pagopa.receipt.pdf.helpdesk.service.impl.ReceiptCosmosServiceImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.time.LocalDateTime; +import java.util.Optional; + +/** + * Azure Functions with HTTP Trigger. + */ +public class GetCart { + + private final Logger logger = LoggerFactory.getLogger(GetCart.class); + + private final ReceiptCosmosService receiptCosmosService; + + public GetCart() { + this.receiptCosmosService = new ReceiptCosmosServiceImpl(); + } + + GetCart(ReceiptCosmosService receiptCosmosService) { + this.receiptCosmosService = receiptCosmosService; + } + + /** + * This function will be invoked when a Http Trigger occurs. + *

+ * It retrieves the receipt with the specified biz event id + *

+ * + * @return response with {@link HttpStatus#OK} and the receipt if found + */ + @FunctionName("GetCart") + public HttpResponseMessage run( + @HttpTrigger(name = "GetCartTrigger", + methods = {HttpMethod.GET}, + route = "cart/{cart-id}", + authLevel = AuthorizationLevel.ANONYMOUS) + HttpRequestMessage> request, + @BindingName("cart-id") String cartId, + final ExecutionContext context) { + logger.info("[{}] function called at {}", context.getFunctionName(), LocalDateTime.now()); + + if (cartId == null || cartId.isBlank()) { + return request + .createResponseBuilder(HttpStatus.BAD_REQUEST) + .body(ProblemJson.builder() + .title(HttpStatus.BAD_REQUEST.name()) + .detail("Please pass a valid cart id") + .status(HttpStatus.BAD_REQUEST.value()) + .build()) + .build(); + } + + try { + CartForReceipt cart = this.receiptCosmosService.getCart(cartId); + return request + .createResponseBuilder(HttpStatus.OK) + .body(cart) + .build(); + } catch (CartNotFoundException e) { + String responseMsg = String.format("Unable to retrieve the cart with id %s", cartId); + logger.error("[{}] {}", context.getFunctionName(), responseMsg, e); + return request + .createResponseBuilder(HttpStatus.NOT_FOUND) + .body(ProblemJson.builder() + .title(HttpStatus.NOT_FOUND.name()) + .detail(responseMsg) + .status(HttpStatus.NOT_FOUND.value()) + .build()) + .build(); + } + } +} diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/ReceiptCosmosClient.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/ReceiptCosmosClient.java index da07eec..948d817 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/ReceiptCosmosClient.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/ReceiptCosmosClient.java @@ -2,17 +2,18 @@ import com.azure.cosmos.models.CosmosItemResponse; import com.azure.cosmos.models.FeedResponse; +import it.gov.pagopa.receipt.pdf.helpdesk.entity.cart.CartForReceipt; import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.IOMessage; import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.Receipt; import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.ReceiptError; import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.enumeration.ReceiptStatusType; +import it.gov.pagopa.receipt.pdf.helpdesk.exception.CartNotFoundException; import it.gov.pagopa.receipt.pdf.helpdesk.exception.IoMessageNotFoundException; import it.gov.pagopa.receipt.pdf.helpdesk.exception.ReceiptNotFoundException; public interface ReceiptCosmosClient { Receipt getReceiptDocument(String eventId) throws ReceiptNotFoundException; - /** * Retrieve the failed receipt documents with {@link ReceiptStatusType#INSERTED} status * @@ -57,4 +58,13 @@ public interface ReceiptCosmosClient { Iterable> getIOErrorToNotifyReceiptDocuments(String continuationToken, Integer pageSize); IOMessage getIoMessage(String messageId) throws IoMessageNotFoundException; + + /** + * Retrieve the cart with the provided id from Cosmos + * + * @param cartId the cart id + * @return the cart + * @throws CartNotFoundException if no cart was found in the container + */ + CartForReceipt getCartDocument(String cartId) throws CartNotFoundException; } diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/ReceiptCosmosClientImpl.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/ReceiptCosmosClientImpl.java index 69a0bf6..ba46ab5 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/ReceiptCosmosClientImpl.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/ReceiptCosmosClientImpl.java @@ -9,11 +9,13 @@ import com.azure.cosmos.models.FeedResponse; import com.azure.cosmos.util.CosmosPagedIterable; import it.gov.pagopa.receipt.pdf.helpdesk.client.ReceiptCosmosClient; +import it.gov.pagopa.receipt.pdf.helpdesk.entity.cart.CartForReceipt; import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.IOMessage; import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.Receipt; import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.ReceiptError; import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.enumeration.ReceiptErrorStatusType; import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.enumeration.ReceiptStatusType; +import it.gov.pagopa.receipt.pdf.helpdesk.exception.CartNotFoundException; import it.gov.pagopa.receipt.pdf.helpdesk.exception.IoMessageNotFoundException; import it.gov.pagopa.receipt.pdf.helpdesk.exception.ReceiptNotFoundException; @@ -29,9 +31,8 @@ public class ReceiptCosmosClientImpl implements ReceiptCosmosClient { private final String databaseId = System.getenv().getOrDefault("COSMOS_RECEIPT_DB_NAME", "db"); private final String containerId = System.getenv().getOrDefault("COSMOS_RECEIPT_CONTAINER_NAME", "receipt"); - + private final String containerCartId = System.getenv().getOrDefault("COSMOS_RECEIPT_CART_CONTAINER_NAME", "cart-for-receipts"); private final String containerMessageId = System.getenv().getOrDefault("COSMOS_RECEIPT_MESSAGE_CONTAINER_NAME", "receipts-io-messages"); - private final String containerReceiptErrorId = System.getenv().getOrDefault("COSMOS_RECEIPT_ERROR_CONTAINER_NAME", "receipts-message-errors"); private final String millisDiff = System.getenv("MAX_DATE_DIFF_MILLIS"); @@ -43,6 +44,7 @@ public class ReceiptCosmosClientImpl implements ReceiptCosmosClient { private final int recordsLimitRecoverNotNotified = Integer.parseInt(System.getenv().getOrDefault("RECOVER_NOT_NOTIFIED_MASSIVE_MAX_RECORDS", "200")); + private static final String DOCUMENT_NOT_FOUND_ERR_MSG = "Document not found in the defined container"; private final CosmosClient cosmosClient; @@ -88,7 +90,7 @@ public Receipt getReceiptDocument(String eventId) throws ReceiptNotFoundExceptio if (queryResponse.iterator().hasNext()) { return queryResponse.iterator().next(); } - throw new ReceiptNotFoundException("Document not found in the defined container"); + throw new ReceiptNotFoundException(DOCUMENT_NOT_FOUND_ERR_MSG); } /** @@ -169,9 +171,8 @@ public ReceiptError getReceiptError(String bizEventId) throws ReceiptNotFoundEx if (queryResponse.iterator().hasNext()) { return queryResponse.iterator().next(); - } else { - throw new ReceiptNotFoundException("Document not found in the defined container"); } + throw new ReceiptNotFoundException(DOCUMENT_NOT_FOUND_ERR_MSG); } /** @@ -260,6 +261,24 @@ public IOMessage getIoMessage(String messageId) throws IoMessageNotFoundExceptio if (queryResponse.iterator().hasNext()) { return queryResponse.iterator().next(); } - throw new IoMessageNotFoundException("Document not found in the defined container"); + throw new IoMessageNotFoundException(DOCUMENT_NOT_FOUND_ERR_MSG); + } + + @Override + public CartForReceipt getCartDocument(String cartId) throws CartNotFoundException { + CosmosDatabase cosmosDatabase = this.cosmosClient.getDatabase(databaseId); + CosmosContainer cosmosContainer = cosmosDatabase.getContainer(containerCartId); + + //Build query + String query = String.format("SELECT * FROM c WHERE c.id = '%s'", cartId); + + //Query the container + CosmosPagedIterable queryResponse = cosmosContainer + .queryItems(query, new CosmosQueryRequestOptions(), CartForReceipt.class); + + if (queryResponse.iterator().hasNext()) { + return queryResponse.iterator().next(); + } + throw new CartNotFoundException(DOCUMENT_NOT_FOUND_ERR_MSG); } } diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/entity/cart/CartForReceipt.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/entity/cart/CartForReceipt.java new file mode 100644 index 0000000..a72ae41 --- /dev/null +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/entity/cart/CartForReceipt.java @@ -0,0 +1,22 @@ +package it.gov.pagopa.receipt.pdf.helpdesk.entity.cart; + +import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.ReasonError; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Set; + +@AllArgsConstructor +@NoArgsConstructor +@Builder +@Data +public class CartForReceipt { + + private Long id; + private Set cartPaymentId; + private Integer totalNotice; + private CartStatusType status; + private ReasonError reasonError; +} \ No newline at end of file diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/entity/cart/CartStatusType.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/entity/cart/CartStatusType.java new file mode 100644 index 0000000..dea4239 --- /dev/null +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/entity/cart/CartStatusType.java @@ -0,0 +1,5 @@ +package it.gov.pagopa.receipt.pdf.helpdesk.entity.cart; + +public enum CartStatusType { + INSERTED, FAILED, SENT +} diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/exception/CartNotFoundException.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/exception/CartNotFoundException.java new file mode 100644 index 0000000..7c9da21 --- /dev/null +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/exception/CartNotFoundException.java @@ -0,0 +1,24 @@ +package it.gov.pagopa.receipt.pdf.helpdesk.exception; + +/** Thrown in case no cart is found in the CosmosDB container */ +public class CartNotFoundException extends Exception{ + + /** + * Constructs new exception with provided message and cause + * + * @param message Detail message + */ + public CartNotFoundException(String message) { + super(message); + } + + /** + * Constructs new exception with provided message and cause + * + * @param message Detail message + * @param cause Exception thrown + */ + public CartNotFoundException(String message, Throwable cause) { + super(message, cause); + } +} \ No newline at end of file diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/service/ReceiptCosmosService.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/service/ReceiptCosmosService.java index 2fd4840..4d42bc8 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/service/ReceiptCosmosService.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/service/ReceiptCosmosService.java @@ -2,9 +2,11 @@ import com.azure.cosmos.models.FeedResponse; import it.gov.pagopa.receipt.pdf.helpdesk.client.ReceiptCosmosClient; +import it.gov.pagopa.receipt.pdf.helpdesk.entity.cart.CartForReceipt; import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.IOMessage; import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.Receipt; import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.enumeration.ReceiptStatusType; +import it.gov.pagopa.receipt.pdf.helpdesk.exception.CartNotFoundException; import it.gov.pagopa.receipt.pdf.helpdesk.exception.IoMessageNotFoundException; import it.gov.pagopa.receipt.pdf.helpdesk.exception.ReceiptNotFoundException; @@ -56,4 +58,14 @@ Iterable> getFailedReceiptByStatus( * @return */ IOMessage getReceiptMessage(String messageId) throws IoMessageNotFoundException; + + + /** + * Retrieve the cart with the provided id + * + * @param cartId the cart id + * @return the cart + * @throws CartNotFoundException if the cart was not found or the retrieved cart is null + */ + CartForReceipt getCart(String cartId) throws CartNotFoundException; } diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/ReceiptCosmosServiceImpl.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/ReceiptCosmosServiceImpl.java index 016b588..6f91bb7 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/ReceiptCosmosServiceImpl.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/ReceiptCosmosServiceImpl.java @@ -3,9 +3,11 @@ import com.azure.cosmos.models.FeedResponse; import it.gov.pagopa.receipt.pdf.helpdesk.client.ReceiptCosmosClient; import it.gov.pagopa.receipt.pdf.helpdesk.client.impl.ReceiptCosmosClientImpl; +import it.gov.pagopa.receipt.pdf.helpdesk.entity.cart.CartForReceipt; import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.IOMessage; import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.Receipt; import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.enumeration.ReceiptStatusType; +import it.gov.pagopa.receipt.pdf.helpdesk.exception.CartNotFoundException; import it.gov.pagopa.receipt.pdf.helpdesk.exception.IoMessageNotFoundException; import it.gov.pagopa.receipt.pdf.helpdesk.exception.ReceiptNotFoundException; import it.gov.pagopa.receipt.pdf.helpdesk.service.ReceiptCosmosService; @@ -102,4 +104,21 @@ public IOMessage getReceiptMessage(String messageId) throws IoMessageNotFoundExc } return message; } + + @Override + public CartForReceipt getCart(String cartId) throws CartNotFoundException { + CartForReceipt cartForReceipt; + try { + cartForReceipt = this.receiptCosmosClient.getCartDocument(cartId); + } catch (CartNotFoundException e) { + String errorMsg = String.format("Receipt not found with the biz-event id %s", cartId); + throw new CartNotFoundException(errorMsg, e); + } + + if (cartForReceipt == null) { + String errorMsg = String.format("Receipt retrieved with the biz-event id %s is null", cartId); + throw new CartNotFoundException(errorMsg); + } + return cartForReceipt; + } } \ No newline at end of file From d5af19f0e8951bac1ad698a34709df9cfe215903 Mon Sep 17 00:00:00 2001 From: giomella Date: Wed, 3 Jan 2024 12:59:18 +0100 Subject: [PATCH 2/5] [PRDP-307] added unit tests --- .../client/impl/ReceiptCosmosClientImpl.java | 2 +- .../receipt/pdf/helpdesk/GetCartTest.java | 115 ++++++++++++++++++ .../impl/ReceiptCosmosClientImplTest.java | 50 ++++++++ .../impl/ReceiptCosmosServiceImplTest.java | 25 ++++ 4 files changed, 191 insertions(+), 1 deletion(-) create mode 100644 src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/GetCartTest.java diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/ReceiptCosmosClientImpl.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/ReceiptCosmosClientImpl.java index ba46ab5..609e00e 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/ReceiptCosmosClientImpl.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/ReceiptCosmosClientImpl.java @@ -270,7 +270,7 @@ public CartForReceipt getCartDocument(String cartId) throws CartNotFoundExceptio CosmosContainer cosmosContainer = cosmosDatabase.getContainer(containerCartId); //Build query - String query = String.format("SELECT * FROM c WHERE c.id = '%s'", cartId); + String query = String.format("SELECT * FROM c WHERE c.id = %s", cartId); //Query the container CosmosPagedIterable queryResponse = cosmosContainer diff --git a/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/GetCartTest.java b/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/GetCartTest.java new file mode 100644 index 0000000..275ce8a --- /dev/null +++ b/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/GetCartTest.java @@ -0,0 +1,115 @@ +package it.gov.pagopa.receipt.pdf.helpdesk; + +import com.microsoft.azure.functions.ExecutionContext; +import com.microsoft.azure.functions.HttpRequestMessage; +import com.microsoft.azure.functions.HttpResponseMessage; +import com.microsoft.azure.functions.HttpStatus; +import it.gov.pagopa.receipt.pdf.helpdesk.entity.cart.CartForReceipt; +import it.gov.pagopa.receipt.pdf.helpdesk.exception.CartNotFoundException; +import it.gov.pagopa.receipt.pdf.helpdesk.model.ProblemJson; +import it.gov.pagopa.receipt.pdf.helpdesk.service.ReceiptCosmosService; +import it.gov.pagopa.receipt.pdf.helpdesk.util.HttpResponseMessageMock; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.stubbing.Answer; + +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +class GetCartTest { + + private static final String CART_ID = "cartId"; + + @Mock + private ExecutionContext executionContextMock; + + @Mock + private ReceiptCosmosService receiptCosmosServiceMock; + + @Mock + private HttpRequestMessage> requestMock; + + private GetCart sut; + + private AutoCloseable closeable; + + @BeforeEach + public void openMocks() { + closeable = MockitoAnnotations.openMocks(this); + sut = spy(new GetCart(receiptCosmosServiceMock)); + } + + @AfterEach + public void releaseMocks() throws Exception { + closeable.close(); + } + + + @Test + void getCartReceiptSuccess() throws CartNotFoundException { + CartForReceipt cart = new CartForReceipt(); + when(receiptCosmosServiceMock.getCart(CART_ID)).thenReturn(cart); + + doAnswer((Answer) invocation -> { + HttpStatus status = (HttpStatus) invocation.getArguments()[0]; + return new HttpResponseMessageMock.HttpResponseMessageBuilderMock().status(status); + }).when(requestMock).createResponseBuilder(any(HttpStatus.class)); + + // test execution + HttpResponseMessage response = sut.run(requestMock, CART_ID, executionContextMock); + + // test assertion + assertNotNull(response); + assertEquals(HttpStatus.OK, response.getStatus()); + assertNotNull(response.getBody()); + assertEquals(cart, response.getBody()); + } + + @Test + void getCartForMissingEventId() { + doAnswer((Answer) invocation -> { + HttpStatus status = (HttpStatus) invocation.getArguments()[0]; + return new HttpResponseMessageMock.HttpResponseMessageBuilderMock().status(status); + }).when(requestMock).createResponseBuilder(any(HttpStatus.class)); + + // test execution + HttpResponseMessage response = sut.run(requestMock, "", executionContextMock); + + // test assertion + assertNotNull(response); + assertEquals(HttpStatus.BAD_REQUEST, response.getStatus()); + + ProblemJson problemJson = (ProblemJson) response.getBody(); + assertNotNull(problemJson); + assertEquals(HttpStatus.BAD_REQUEST.value(), problemJson.getStatus()); + assertEquals(HttpStatus.BAD_REQUEST.name(), problemJson.getTitle()); + assertNotNull(problemJson.getDetail()); + } + + @Test + void getCartReceiptNotFound() throws CartNotFoundException { + when(receiptCosmosServiceMock.getCart(CART_ID)).thenThrow(CartNotFoundException.class); + + doAnswer((Answer) invocation -> { + HttpStatus status = (HttpStatus) invocation.getArguments()[0]; + return new HttpResponseMessageMock.HttpResponseMessageBuilderMock().status(status); + }).when(requestMock).createResponseBuilder(any(HttpStatus.class)); + + // test execution + HttpResponseMessage response = sut.run(requestMock, CART_ID, executionContextMock); + + // test assertion + assertNotNull(response); + assertEquals(HttpStatus.NOT_FOUND, response.getStatus()); + assertNotNull(response.getBody()); + } +} \ No newline at end of file diff --git a/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/ReceiptCosmosClientImplTest.java b/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/ReceiptCosmosClientImplTest.java index 7b637ef..1e83fed 100644 --- a/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/ReceiptCosmosClientImplTest.java +++ b/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/ReceiptCosmosClientImplTest.java @@ -4,8 +4,10 @@ import com.azure.cosmos.CosmosContainer; import com.azure.cosmos.CosmosDatabase; import com.azure.cosmos.util.CosmosPagedIterable; +import it.gov.pagopa.receipt.pdf.helpdesk.entity.cart.CartForReceipt; import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.IOMessage; import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.Receipt; +import it.gov.pagopa.receipt.pdf.helpdesk.exception.CartNotFoundException; import it.gov.pagopa.receipt.pdf.helpdesk.exception.IoMessageNotFoundException; import it.gov.pagopa.receipt.pdf.helpdesk.exception.ReceiptNotFoundException; import org.junit.jupiter.api.BeforeEach; @@ -26,6 +28,7 @@ class ReceiptCosmosClientImplTest { private static final String RECEIPT_ID = "a valid receipt id"; + private static final Long CART_ID = 1L; private CosmosClient mockClient; @@ -243,4 +246,51 @@ void getIoMessageReceiptDocumentFail() { assertThrows(IoMessageNotFoundException.class, () -> client.getIoMessage("an invalid receipt id")); } + + @Test + void getCartDocumentSuccess() { + CosmosDatabase mockDatabase = mock(CosmosDatabase.class); + CosmosContainer mockContainer = mock(CosmosContainer.class); + + CosmosPagedIterable mockIterable = mock(CosmosPagedIterable.class); + + Iterator mockIterator = mock(Iterator.class); + CartForReceipt cart = new CartForReceipt(); + cart.setId(CART_ID); + + when(mockIterator.hasNext()).thenReturn(true); + when(mockIterator.next()).thenReturn(cart); + + when(mockIterable.iterator()).thenReturn(mockIterator); + + when(mockContainer.queryItems(anyString(), any(), eq(CartForReceipt.class))) + .thenReturn(mockIterable); + when(mockDatabase.getContainer(any())).thenReturn(mockContainer); + when(mockClient.getDatabase(any())).thenReturn(mockDatabase); + + CartForReceipt cartForReceipt = assertDoesNotThrow(() -> client.getCartDocument(CART_ID.toString())); + + assertEquals(CART_ID, cartForReceipt.getId()); + } + + @Test + void getCartDocumentFail() { + CosmosDatabase mockDatabase = mock(CosmosDatabase.class); + CosmosContainer mockContainer = mock(CosmosContainer.class); + + CosmosPagedIterable mockIterable = mock(CosmosPagedIterable.class); + + Iterator mockIterator = mock(Iterator.class); + + when(mockIterator.hasNext()).thenReturn(false); + + when(mockIterable.iterator()).thenReturn(mockIterator); + + when(mockContainer.queryItems(anyString(), any(), eq(CartForReceipt.class))) + .thenReturn(mockIterable); + when(mockDatabase.getContainer(any())).thenReturn(mockContainer); + when(mockClient.getDatabase(any())).thenReturn(mockDatabase); + + assertThrows(CartNotFoundException.class, () -> client.getCartDocument("an invalid receipt id")); + } } \ No newline at end of file diff --git a/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/ReceiptCosmosServiceImplTest.java b/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/ReceiptCosmosServiceImplTest.java index 2dcbcec..622278a 100644 --- a/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/ReceiptCosmosServiceImplTest.java +++ b/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/ReceiptCosmosServiceImplTest.java @@ -2,9 +2,11 @@ import com.azure.cosmos.models.FeedResponse; import it.gov.pagopa.receipt.pdf.helpdesk.client.ReceiptCosmosClient; +import it.gov.pagopa.receipt.pdf.helpdesk.entity.cart.CartForReceipt; import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.IOMessage; import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.Receipt; import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.enumeration.ReceiptStatusType; +import it.gov.pagopa.receipt.pdf.helpdesk.exception.CartNotFoundException; import it.gov.pagopa.receipt.pdf.helpdesk.exception.IoMessageNotFoundException; import it.gov.pagopa.receipt.pdf.helpdesk.exception.ReceiptNotFoundException; import it.gov.pagopa.receipt.pdf.helpdesk.service.ReceiptCosmosService; @@ -199,4 +201,27 @@ void getReceiptMessageFailClientReturnNull() throws IoMessageNotFoundException { assertThrows(IoMessageNotFoundException.class, () -> sut.getReceiptMessage(anyString())); } + + @Test + void getCartSuccess() throws CartNotFoundException { + when(receiptCosmosClientMock.getCartDocument(anyString())).thenReturn(new CartForReceipt()); + + CartForReceipt cart = assertDoesNotThrow(() -> sut.getCart(anyString())); + + assertNotNull(cart); + } + + @Test + void getCartFailClientThrowsCartNotFoundException() throws CartNotFoundException { + when(receiptCosmosClientMock.getCartDocument(anyString())).thenThrow(CartNotFoundException.class); + + assertThrows(CartNotFoundException.class, () -> sut.getCart(anyString())); + } + + @Test + void getCartFailClientReturnNull() throws CartNotFoundException { + when(receiptCosmosClientMock.getCartDocument(anyString())).thenReturn(null); + + assertThrows(CartNotFoundException.class, () -> sut.getCart(anyString())); + } } \ No newline at end of file From 55447f12fb696f41a1faa411f8240c6d8e855fd5 Mon Sep 17 00:00:00 2001 From: giomella Date: Wed, 3 Jan 2024 14:36:29 +0100 Subject: [PATCH 3/5] [PRDP-307] updated openapi.json --- openapi/openapi.json | 147 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) diff --git a/openapi/openapi.json b/openapi/openapi.json index 013fce0..86e5757 100644 --- a/openapi/openapi.json +++ b/openapi/openapi.json @@ -639,6 +639,126 @@ } ] }, + "/cart/{cart-id}": { + "get": { + "tags": [ + "API-getCart" + ], + "summary": "Retrieve from CosmosDB the cart with the given cart id", + "operationId": "GetCart", + "parameters": [ + { + "in": "path", + "name": "cart-id", + "description": "Cart id.", + "schema": { + "type": "string" + }, + "required": true + } + ], + "responses": { + "200": { + "description": "Successful Calls.", + "headers": { + "X-Request-Id": { + "description": "This header identifies the call", + "schema": { + "type": "string" + } + } + }, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/CartForReceipt" + } + } + } + }, + "400": { + "description": "Bad request.", + "headers": { + "X-Request-Id": { + "description": "This header identifies the call", + "schema": { + "type": "string" + } + } + }, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemJson" + } + } + } + }, + "404": { + "description": "Receipt error not found.", + "headers": { + "X-Request-Id": { + "description": "This header identifies the call", + "schema": { + "type": "string" + } + } + }, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemJson" + } + } + } + }, + "500": { + "description": "Receipt could not be updated with the new attachments", + "headers": { + "X-Request-Id": { + "description": "This header identifies the call", + "schema": { + "type": "string" + } + } + }, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemJson" + } + } + } + }, + "default": { + "description": "Unexpected error.", + "headers": { + "X-Request-Id": { + "description": "This header identifies the call", + "schema": { + "type": "string" + } + } + } + } + }, + "security": [ + { + "ApiKey": [] + } + ] + }, + "parameters": [ + { + "name": "X-Request-Id", + "in": "header", + "description": "This header identifies the call, if not passed it is self-generated. This ID is returned in the response.", + "schema": { + "type": "string" + } + } + ] + }, "/receipts-error/{event-id}/reviewed": { "post": { "tags": [ @@ -1530,6 +1650,33 @@ } } }, + "CartForReceipt": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "example": "712341" + }, + "cartPaymentId": { + "type": "array", + "items": { + "type": "string", + "example": "76abb1f1-c9f9-4ead-9e66-12fec4d51042" + } + }, + "totalNotice": { + "type": "integer", + "example": "3" + }, + "status": { + "type": "string", + "enum": ["INSERTED", "FAILED", "SENT"] + }, + "reasonError": { + "$ref": "#/components/schemas/ReasonErr" + } + } + }, "ProblemJson": { "type": "object", "properties": { From cf61ac83fb3f0312b1c3edd78ce305ae13fabd84 Mon Sep 17 00:00:00 2001 From: giomella Date: Wed, 3 Jan 2024 14:42:04 +0100 Subject: [PATCH 4/5] [PRDP-307] added env in helm chart and updated README.md --- README.md | 68 ++++++++++++++++++++++++------------------- helm/values-dev.yaml | 1 + helm/values-prod.yaml | 1 + helm/values-uat.yaml | 1 + 4 files changed, 41 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 74cf948..35bf789 100644 --- a/README.md +++ b/README.md @@ -3,13 +3,19 @@ [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=pagopa_pagopa-receipt-pdf-helpdesk&metric=alert_status)](https://sonarcloud.io/dashboard?id=pagopa_pagopa-receipt-pdf-helpdesk) Java Azure Functions that exposed the following recover APIs: +- GetCart - GetReceipt - GetReceiptByOrganizationFiscalCodeAndIUV +- GetReceiptError +- GetReceiptMessage +- GetReceiptPdf - ReceiptToReviewed - RecoverFailedReceipt - RecoverFailedReceiptMassive +- RecoverFailedReceiptScheduled - RecoverNotNotifiedReceipt - RecoverNotNotifiedReceiptMassive +- RecoverNotNotifiedReceiptScheduled - RegenerateReceiptPdf --- @@ -79,42 +85,44 @@ On terminal type: then replace env variables with correct values (if there is NO default value, the variable HAS to be defined) -| VARIABLE | USAGE | DEFAULT VALUE | -|---------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------|:------------------------------------------------------:| -| `RECEIPTS_STORAGE_CONN_STRING` | Connection string to the Receipt Queue | | -| `RECEIPT_QUEUE_TOPIC` | Topic name of the Receipt Queue | | -| `COSMOS_BIZ_EVENT_CONN_STRING` | Connection string to the BizEvent CosmosDB | | -| `COSMOS_BIZ_EVENT_SERVICE_ENDPOINT` | Endpoint to the BizEvent CosmosDB | | -| `COSMOS_BIZ_EVENT_DB_NAME` | Database name of the BizEvent database in CosmosDB | | -| `COSMOS_BIZ_EVENT_CONTAINER_NAME` | Container name of the BizEvent container in CosmosDB | | -| `COSMOS_RECEIPTS_CONN_STRING` | Connection string to the Receipt CosmosDB | | -| `COSMOS_RECEIPT_SERVICE_ENDPOINT` | Endpoint to the Receipt CosmosDB | | -| `COSMOS_RECEIPT_KEY` | Key to the Receipt CosmosDB | | -| `COSMOS_RECEIPT_DB_NAME` | Database name of the Receipt database in CosmosDB | | -| `COSMOS_RECEIPT_CONTAINER_NAME` | Container name of the Receipt container in CosmosDB | | -| `COSMOS_RECEIPT_ERROR_CONTAINER_NAME` | Container name of the Receipt-message-error container in CosmosDB | | -| `BLOB_STORAGE_ACCOUNT_ENDPOINT` | Endpoint to the Receipt Blob Storage | | -| `BLOB_STORAGE_CONTAINER_NAME` | Container name of the Blob Storage containing the pdf attachments | | -| `BLOB_STORAGE_DOWNLOAD_TIMEOUT` | Timeout for the call to retrieve the attachment from the blob storage | 10 | -| `BLOB_STORAGE_DOWNLOAD_MAX_RETRY` | Max number of retry for the call to retrieve the attachment from the blob storage | 5 | -| `PDV_TOKENIZER_BASE_PATH` | PDV Tokenizer API base path | "https://api.uat.tokenizer.pdv.pagopa.it/tokenizer/v1" | -| `PDV_TOKENIZER_SEARCH_TOKEN_ENDPOINT` | PDV Tokenizer API search token endpoint | "/tokens/search" | -| `PDV_TOKENIZER_FIND_PII_ENDPOINT` | PDV Tokenizer API find pii endpoint | "/tokens/%s/pii" | -| `PDV_TOKENIZER_CREATE_TOKEN_ENDPOINT` | PDV Tokenizer API create token endpoint | "/tokens" | -| `PDV_TOKENIZER_SUBSCRIPTION_KEY` | API azure ocp apim subscription key | | -| `PDV_TOKENIZER_INITIAL_INTERVAL` | PDV Tokenizer initial interval for retry a request that fail with 429 status code | 200 | -| `PDV_TOKENIZER_MULTIPLIER` | PDV Tokenizer interval multiplier for subsequent request retry | 2.0 | -| `PDV_TOKENIZER_RANDOMIZATION_FACTOR` | PDV Tokenizer randomization factor for interval retry calculation | 0.6 | -| `PDV_TOKENIZER_MAX_RETRIES` | PDV Tokenizer max request retry | 3 | -| `TOKENIZER_APIM_HEADER_KEY` | Tokenizer APIM header key | x-api-key | +| VARIABLE | USAGE | DEFAULT VALUE | +|-----------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------|:------------------------------------------------------:| +| `RECEIPTS_STORAGE_CONN_STRING` | Connection string to the Receipt Queue | | +| `RECEIPT_QUEUE_TOPIC` | Topic name of the Receipt Queue | | +| `COSMOS_BIZ_EVENT_CONN_STRING` | Connection string to the BizEvent CosmosDB | | +| `COSMOS_BIZ_EVENT_SERVICE_ENDPOINT` | Endpoint to the BizEvent CosmosDB | | +| `COSMOS_BIZ_EVENT_DB_NAME` | Database name of the BizEvent database in CosmosDB | | +| `COSMOS_BIZ_EVENT_CONTAINER_NAME` | Container name of the BizEvent container in CosmosDB | | +| `COSMOS_RECEIPTS_CONN_STRING` | Connection string to the Receipt CosmosDB | | +| `COSMOS_RECEIPT_SERVICE_ENDPOINT` | Endpoint to the Receipt CosmosDB | | +| `COSMOS_RECEIPT_KEY` | Key to the Receipt CosmosDB | | +| `COSMOS_RECEIPT_DB_NAME` | Database name of the Receipt database in CosmosDB | | +| `COSMOS_RECEIPT_CONTAINER_NAME` | Container name of the Receipt container in CosmosDB | | +| `COSMOS_RECEIPT_ERROR_CONTAINER_NAME` | Container name of the receipt-message-error container in CosmosDB | | +| `COSMOS_RECEIPT_MESSAGE_CONTAINER_NAME` | Container name of the receipts-io-messages container in CosmosDB | | +| `COSMOS_RECEIPT_CART_CONTAINER_NAME` | Container name of the cart-for-receipts container in CosmosDB | | +| `BLOB_STORAGE_ACCOUNT_ENDPOINT` | Endpoint to the Receipt Blob Storage | | +| `BLOB_STORAGE_CONTAINER_NAME` | Container name of the Blob Storage containing the pdf attachments | | +| `BLOB_STORAGE_DOWNLOAD_TIMEOUT` | Timeout for the call to retrieve the attachment from the blob storage | 10 | +| `BLOB_STORAGE_DOWNLOAD_MAX_RETRY` | Max number of retry for the call to retrieve the attachment from the blob storage | 5 | +| `PDV_TOKENIZER_BASE_PATH` | PDV Tokenizer API base path | "https://api.uat.tokenizer.pdv.pagopa.it/tokenizer/v1" | +| `PDV_TOKENIZER_SEARCH_TOKEN_ENDPOINT` | PDV Tokenizer API search token endpoint | "/tokens/search" | +| `PDV_TOKENIZER_FIND_PII_ENDPOINT` | PDV Tokenizer API find pii endpoint | "/tokens/%s/pii" | +| `PDV_TOKENIZER_CREATE_TOKEN_ENDPOINT` | PDV Tokenizer API create token endpoint | "/tokens" | +| `PDV_TOKENIZER_SUBSCRIPTION_KEY` | API azure ocp apim subscription key | | +| `PDV_TOKENIZER_INITIAL_INTERVAL` | PDV Tokenizer initial interval for retry a request that fail with 429 status code | 200 | +| `PDV_TOKENIZER_MULTIPLIER` | PDV Tokenizer interval multiplier for subsequent request retry | 2.0 | +| `PDV_TOKENIZER_RANDOMIZATION_FACTOR` | PDV Tokenizer randomization factor for interval retry calculation | 0.6 | +| `PDV_TOKENIZER_MAX_RETRIES` | PDV Tokenizer max request retry | 3 | +| `TOKENIZER_APIM_HEADER_KEY` | Tokenizer APIM header key | x-api-key | | `MAX_DATE_DIFF_MILLIS` | Difference in millis between the current time and the date from witch the
receipts will be fetched in massive recover operation | 360000 | | `MAX_DATE_DIFF_NOTIFY_MILLIS` | Difference in millis between the current time and the date from witch the
receipts will be fetched in massive recover operation on notification | 360000 | | `RECOVER_FAILED_CRON` | CRON expression for timer trigger function that recover failed receipt | | | `TRIGGER_NOTIFY_REC_SCHEDULE` | CRON expression for timer trigger function that recover not notifier receipt | | | `RECOVER_FAILED_MASSIVE_MAX_DAYS` | Number of days in addition to the current one to executed failed recovery | 0 | | `RECOVER_NOT_NOTIFIED_MASSIVE_MAX_DAYS` | Number of days in addition to the current one to executed not notified recovery | 0 | -| `AES_SECRET_KEY` | AES encryption secret key | | -| `AES_SALT` | AES encryption salt | +| `AES_SECRET_KEY` | AES encryption secret key | | +| `AES_SALT` | AES encryption salt | > to doc details about AZ fn config > see [here](https://stackoverflow.com/questions/62669672/azure-functions-what-is-the-purpose-of-having-host-json-and-local-settings-jso) diff --git a/helm/values-dev.yaml b/helm/values-dev.yaml index f419a32..0365912 100644 --- a/helm/values-dev.yaml +++ b/helm/values-dev.yaml @@ -90,6 +90,7 @@ microservice-chart: COSMOS_RECEIPT_CONTAINER_NAME: "receipts" COSMOS_RECEIPT_ERROR_CONTAINER_NAME: "receipts-message-errors" COSMOS_RECEIPT_MESSAGE_CONTAINER_NAME: "receipts-io-messages" + COSMOS_RECEIPT_CART_CONTAINER_NAME: "cart-for-receipts" COSMOS_BIZ_EVENT_CONTAINER_NAME: "biz-events" PDF_ENGINE_ENDPOINT: "https://api.dev.platform.pagopa.it/shared/pdf-engine/v1/generate-pdf" BLOB_STORAGE_ACCOUNT_ENDPOINT: "https://pagopadweureceiptsfnsa.blob.core.windows.net/" diff --git a/helm/values-prod.yaml b/helm/values-prod.yaml index 2facee5..21b5d37 100644 --- a/helm/values-prod.yaml +++ b/helm/values-prod.yaml @@ -90,6 +90,7 @@ microservice-chart: COSMOS_RECEIPT_CONTAINER_NAME: "receipts" COSMOS_RECEIPT_ERROR_CONTAINER_NAME: "receipts-message-errors" COSMOS_RECEIPT_MESSAGE_CONTAINER_NAME: "receipts-io-messages" + COSMOS_RECEIPT_CART_CONTAINER_NAME: "cart-for-receipts" COSMOS_BIZ_EVENT_CONTAINER_NAME: "biz-events" PDF_ENGINE_ENDPOINT: "https://api.platform.pagopa.it/shared/pdf-engine/v1/generate-pdf" BLOB_STORAGE_ACCOUNT_ENDPOINT: "https://pagopapweureceiptsfnsa.blob.core.windows.net" diff --git a/helm/values-uat.yaml b/helm/values-uat.yaml index b21f2c3..974fffc 100644 --- a/helm/values-uat.yaml +++ b/helm/values-uat.yaml @@ -90,6 +90,7 @@ microservice-chart: COSMOS_RECEIPT_CONTAINER_NAME: "receipts" COSMOS_RECEIPT_ERROR_CONTAINER_NAME: "receipts-message-errors" COSMOS_RECEIPT_MESSAGE_CONTAINER_NAME: "receipts-io-messages" + COSMOS_RECEIPT_CART_CONTAINER_NAME: "cart-for-receipts" COSMOS_BIZ_EVENT_CONTAINER_NAME: "biz-events" PDF_ENGINE_ENDPOINT: "https://api.uat.platform.pagopa.it/shared/pdf-engine/v1/generate-pdf" BLOB_STORAGE_ACCOUNT_ENDPOINT: "https://pagopauweureceiptsfnsa.blob.core.windows.net" From 14ad3099c830262ad4b8321b2c4dbb3e5b1dac15 Mon Sep 17 00:00:00 2001 From: giomella Date: Wed, 3 Jan 2024 15:49:49 +0100 Subject: [PATCH 5/5] [PRDP-307] fix cart id type --- .../pdf/helpdesk/client/impl/ReceiptCosmosClientImpl.java | 2 +- .../receipt/pdf/helpdesk/entity/cart/CartForReceipt.java | 2 +- .../pdf/helpdesk/client/impl/ReceiptCosmosClientImplTest.java | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/ReceiptCosmosClientImpl.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/ReceiptCosmosClientImpl.java index 609e00e..ba46ab5 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/ReceiptCosmosClientImpl.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/ReceiptCosmosClientImpl.java @@ -270,7 +270,7 @@ public CartForReceipt getCartDocument(String cartId) throws CartNotFoundExceptio CosmosContainer cosmosContainer = cosmosDatabase.getContainer(containerCartId); //Build query - String query = String.format("SELECT * FROM c WHERE c.id = %s", cartId); + String query = String.format("SELECT * FROM c WHERE c.id = '%s'", cartId); //Query the container CosmosPagedIterable queryResponse = cosmosContainer diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/entity/cart/CartForReceipt.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/entity/cart/CartForReceipt.java index a72ae41..444cfb5 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/entity/cart/CartForReceipt.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/entity/cart/CartForReceipt.java @@ -14,7 +14,7 @@ @Data public class CartForReceipt { - private Long id; + private String id; private Set cartPaymentId; private Integer totalNotice; private CartStatusType status; diff --git a/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/ReceiptCosmosClientImplTest.java b/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/ReceiptCosmosClientImplTest.java index 1e83fed..9a8777b 100644 --- a/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/ReceiptCosmosClientImplTest.java +++ b/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/ReceiptCosmosClientImplTest.java @@ -28,7 +28,7 @@ class ReceiptCosmosClientImplTest { private static final String RECEIPT_ID = "a valid receipt id"; - private static final Long CART_ID = 1L; + private static final String CART_ID = "a valid cart id"; private CosmosClient mockClient; @@ -268,7 +268,7 @@ void getCartDocumentSuccess() { when(mockDatabase.getContainer(any())).thenReturn(mockContainer); when(mockClient.getDatabase(any())).thenReturn(mockDatabase); - CartForReceipt cartForReceipt = assertDoesNotThrow(() -> client.getCartDocument(CART_ID.toString())); + CartForReceipt cartForReceipt = assertDoesNotThrow(() -> client.getCartDocument(CART_ID)); assertEquals(CART_ID, cartForReceipt.getId()); }