Skip to content

Commit

Permalink
[PRDP-269] Updated unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
svariant committed Dec 5, 2023
1 parent 67d5170 commit b938d53
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void getReceiptForMissingOrganizationFiscalCode() {

// test assertion
assertNotNull(response);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatus());
assertEquals(HttpStatus.BAD_REQUEST, response.getStatus());

ProblemJson problemJson = (ProblemJson) response.getBody();
assertNotNull(problemJson);
Expand All @@ -119,7 +119,7 @@ void getReceiptForMissingIUV() {

// test assertion
assertNotNull(response);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatus());
assertEquals(HttpStatus.BAD_REQUEST, response.getStatus());

ProblemJson problemJson = (ProblemJson) response.getBody();
assertNotNull(problemJson);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ void shouldReturnErrorOnMissingRequestData() {

// test assertion
assertNotNull(response);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatus());
assertEquals(HttpStatus.BAD_REQUEST, response.getStatus());
assertEquals(ProblemJson.class, response.getBody().getClass());

ProblemJson responseData = (ProblemJson) response.getBody();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void getReceiptForMissingEventId() {

// test assertion
assertNotNull(response);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatus());
assertEquals(HttpStatus.BAD_REQUEST, response.getStatus());

ProblemJson problemJson = (ProblemJson) response.getBody();
assertNotNull(problemJson);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void recoverFailedReceiptMassiveFailMissingStatusParam() {

// test assertion
assertNotNull(response);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatus());
assertEquals(HttpStatus.BAD_REQUEST, response.getStatus());

ProblemJson problemJson = (ProblemJson) response.getBody();
assertNotNull(problemJson);
Expand All @@ -175,7 +175,7 @@ void recoverFailedReceiptMassiveFailInvalidStatusParam() {

// test assertion
assertNotNull(response);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatus());
assertEquals(HttpStatus.BAD_REQUEST, response.getStatus());

ProblemJson problemJson = (ProblemJson) response.getBody();
assertNotNull(problemJson);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ void recoverFailedReceiptFailMissingEventId() {
HttpResponseMessage response = assertDoesNotThrow(() -> sut.run(requestMock, null, documentdb, contextMock));

assertNotNull(response);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatus());
assertEquals(HttpStatus.BAD_REQUEST, response.getStatus());

ProblemJson problemJson = (ProblemJson) response.getBody();
assertNotNull(problemJson);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ void recoverReceiptFailMissingQueryParam() {

// test assertion
assertNotNull(response);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatus());
assertEquals(HttpStatus.BAD_REQUEST, response.getStatus());

ProblemJson problemJson = (ProblemJson) response.getBody();
assertNotNull(problemJson);
Expand All @@ -222,7 +222,7 @@ void recoverReceiptFailInvalidStatusType() {

// test assertion
assertNotNull(response);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatus());
assertEquals(HttpStatus.BAD_REQUEST, response.getStatus());

ProblemJson problemJson = (ProblemJson) response.getBody();
assertNotNull(problemJson);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void recoverReceiptFailForMissingEventId() {

// test assertion
assertNotNull(response);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatus());
assertEquals(HttpStatus.BAD_REQUEST, response.getStatus());

ProblemJson problemJson = (ProblemJson) response.getBody();
assertNotNull(problemJson);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import it.gov.pagopa.receipt.pdf.helpdesk.util.HttpResponseMessageMock;
import it.gov.pagopa.receipt.pdf.helpdesk.utils.ObjectMapperUtils;
import lombok.SneakyThrows;
import org.apache.http.HttpStatus;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -102,7 +103,7 @@ void regeneratePDFInsuccessMissingRequestData() {
}).when(request).createResponseBuilder(any(com.microsoft.azure.functions.HttpStatus.class));

// test execution
assertEquals(500,assertDoesNotThrow(() -> sut.run(request, null, executionContextMock)).getStatusCode());
assertEquals(HttpStatus.SC_BAD_REQUEST,assertDoesNotThrow(() -> sut.run(request, null, executionContextMock)).getStatusCode());

verifyNoInteractions(receiptCosmosClientMock);
verifyNoInteractions(generateReceiptPdfServiceMock);
Expand All @@ -129,7 +130,7 @@ void regeneratePDFErrorMissingEventData() {
}).when(request).createResponseBuilder(any(com.microsoft.azure.functions.HttpStatus.class));

// test execution
assertEquals(500,assertDoesNotThrow(() -> sut.run(request, "1", executionContextMock)).getStatusCode());
assertEquals(HttpStatus.SC_BAD_REQUEST,assertDoesNotThrow(() -> sut.run(request, "1", executionContextMock)).getStatusCode());

verify(receiptCosmosClientMock).getReceiptDocument(anyString());
}
Expand All @@ -150,7 +151,7 @@ void regeneratePDFErrorReceiptNotFound() {
}).when(request).createResponseBuilder(any(com.microsoft.azure.functions.HttpStatus.class));

// test execution
assertEquals(500,assertDoesNotThrow(() -> sut.run(request, "1", executionContextMock)).getStatusCode());
assertEquals(HttpStatus.SC_BAD_REQUEST,assertDoesNotThrow(() -> sut.run(request, "1", executionContextMock)).getStatusCode());

verify(receiptCosmosClientMock).getReceiptDocument(anyString());

Expand All @@ -177,7 +178,7 @@ void regeneratePDFErrorReceiptGenerationException() {
}).when(request).createResponseBuilder(any(com.microsoft.azure.functions.HttpStatus.class));

// test execution
assertEquals(500,assertDoesNotThrow(() -> sut.run(request, "1", executionContextMock)).getStatusCode());
assertEquals(HttpStatus.SC_BAD_REQUEST,assertDoesNotThrow(() -> sut.run(request, "1", executionContextMock)).getStatusCode());

verify(receiptCosmosClientMock).getReceiptDocument(anyString());
verify(generateReceiptPdfServiceMock).generateReceipts(any(), any(), any());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void testSingletonConnectionError() throws Exception {
@SuppressWarnings("secrets:S6338")
String mockKey = "mockKeymockKeymockKeymockKeymockKeymockKeymockKeymockKeymockKeymockKeymockKeymockKeyMK==";
withEnvironmentVariables(
"RECEIPT_QUEUE_CONN_STRING", "DefaultEndpointsProtocol=https;AccountName=samplequeue;AccountKey="+mockKey+";EndpointSuffix=core.windows.net",
"RECEIPTS_STORAGE_CONN_STRING", "DefaultEndpointsProtocol=https;AccountName=samplequeue;AccountKey="+mockKey+";EndpointSuffix=core.windows.net",
"RECEIPT_QUEUE_TOPIC", "validTopic"
).execute(() -> Assertions.assertDoesNotThrow(ReceiptQueueClientImpl::getInstance)
);
Expand Down

0 comments on commit b938d53

Please sign in to comment.