From 6fd68143a7ad3576eaab39d0026456d2a480865c Mon Sep 17 00:00:00 2001 From: SreejaMangarapu Date: Thu, 4 Jul 2024 14:25:44 +0530 Subject: [PATCH] CIRC-2099 Modified TestClass --- .../api/printEvents/PrintEventsTests.java | 52 ++++++++++++++----- 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/src/test/java/api/printEvents/PrintEventsTests.java b/src/test/java/api/printEvents/PrintEventsTests.java index 744f36db5c..95e70421df 100644 --- a/src/test/java/api/printEvents/PrintEventsTests.java +++ b/src/test/java/api/printEvents/PrintEventsTests.java @@ -3,32 +3,60 @@ import api.support.APITests; import io.vertx.core.json.JsonObject; import org.folio.circulation.support.http.client.Response; -import org.hamcrest.core.Is; import org.junit.jupiter.api.Test; -import java.net.HttpURLConnection; import java.util.List; +import static api.support.matchers.ResponseStatusCodeMatcher.hasStatus; +import static org.folio.HttpStatus.HTTP_CREATED; +import static org.folio.HttpStatus.HTTP_UNPROCESSABLE_ENTITY; import static org.hamcrest.MatcherAssert.assertThat; - class PrintEventsTests extends APITests { +class PrintEventsTests extends APITests { public static final String REQUEST_IDS_FIELD = "requestIds"; public static final String REQUESTER_ID_FIELD = "requesterId"; public static final String REQUESTER_NAME_FIELD = "requesterName"; public static final String PRINT_DATE_FIELD = "printEventDate"; + public static final String INVALID_FIELD = "invalidField"; @Test void postPrintEventsTest() { JsonObject printRequest = getPrintEvent(); Response response = printEventsClient.attemptCreate(printRequest); - assertThat(response.getStatusCode(), Is.is(HttpURLConnection.HTTP_CREATED)); + assertThat(response, hasStatus(HTTP_CREATED)); + } + + @Test + void postPrintEventsWithInvalidField() { + JsonObject printRequest = getPrintEvent(); + printRequest.put(INVALID_FIELD, "invalid"); + Response response = printEventsClient.attemptCreate(printRequest); + assertThat(response, hasStatus(HTTP_UNPROCESSABLE_ENTITY)); + } + + @Test + void postPrintEventsWithInvalidField_EmptyRequestIdsList() { + JsonObject printRequest = getPrintEvent(); + List requestIds = List.of(); + printRequest.put(REQUEST_IDS_FIELD, requestIds); + Response response = printEventsClient.attemptCreate(printRequest); + assertThat(response, hasStatus(HTTP_UNPROCESSABLE_ENTITY)); + } + + @Test + void postPrintEventsWithInvalidField_NullFeild() { + JsonObject printRequest = getPrintEvent(); + printRequest.put(REQUESTER_ID_FIELD, null); + Response response = printEventsClient.attemptCreate(printRequest); + assertThat(response, hasStatus(HTTP_UNPROCESSABLE_ENTITY)); + } + + private JsonObject getPrintEvent() { + List requestIds = List.of("request1", "request2"); + return new JsonObject() + .put(REQUEST_IDS_FIELD, requestIds) + .put(REQUESTER_ID_FIELD, "sreeja") + .put(REQUESTER_NAME_FIELD, "Sample Requester") + .put(PRINT_DATE_FIELD, "2024-06-25T14:30:00Z"); } - private JsonObject getPrintEvent() { - List requestIds = List.of("request1", "request2"); - return new JsonObject() - .put(REQUEST_IDS_FIELD, requestIds) - .put(REQUESTER_ID_FIELD, "sample") - .put(REQUESTER_NAME_FIELD, "Sample Requester") - .put(PRINT_DATE_FIELD, "2024-06-25T14:30:00Z"); - } }