From dac2a0e52093f157c1c59339f637a467b2fdf743 Mon Sep 17 00:00:00 2001 From: Vignesh-Kalyanasundaram Date: Tue, 30 Jul 2024 13:13:01 +0530 Subject: [PATCH] CIRC-2100 Adding and refactoring test cases --- .../domain/RequestRepresentation.java | 3 +- .../storage/PrintEventsRepository.java | 4 +- .../api/printEvents/PrintEventsTests.java | 148 ++------------- .../requests/RequestsAPICreationTests.java | 168 ++++++++++++++++++ .../fakes/FakePrintEventStatusModule.java | 80 ++++----- 5 files changed, 223 insertions(+), 180 deletions(-) diff --git a/src/main/java/org/folio/circulation/domain/RequestRepresentation.java b/src/main/java/org/folio/circulation/domain/RequestRepresentation.java index d03727b397..df5811fa0a 100644 --- a/src/main/java/org/folio/circulation/domain/RequestRepresentation.java +++ b/src/main/java/org/folio/circulation/domain/RequestRepresentation.java @@ -261,7 +261,8 @@ private static void removeSearchIndexFields(JsonObject request) { private static void addPrintEventProperties(JsonObject request, PrintEventDetail printEventDetail) { if (printEventDetail == null) { - log.info("addPrintEventProperties:: printEvent property is null for requestId {}", request.getString("id")); + String msg = "addPrintEventProperties:: printEvent property is null for requestId {}"; + log.info(msg, request.getString("id")); return; } diff --git a/src/main/java/org/folio/circulation/infrastructure/storage/PrintEventsRepository.java b/src/main/java/org/folio/circulation/infrastructure/storage/PrintEventsRepository.java index 10ef85e8c3..d6264ae9d5 100644 --- a/src/main/java/org/folio/circulation/infrastructure/storage/PrintEventsRepository.java +++ b/src/main/java/org/folio/circulation/infrastructure/storage/PrintEventsRepository.java @@ -53,7 +53,8 @@ public CompletableFuture>> findPrintEventDetails log.debug("findPrintEventDetails:: parameters multipleRequests: {}", () -> multipleRecordsAsString(multipleRequests)); return validatePrintEventFeatureFlag() - .thenCompose(isEnabled -> isEnabled ? fetchAndMapPrintEventDetails(multipleRequests) + .thenCompose(isEnabled -> Boolean.TRUE.equals(isEnabled) ? + fetchAndMapPrintEventDetails(multipleRequests) : completedFuture(succeeded(multipleRequests))); } @@ -71,6 +72,7 @@ private CompletableFuture>> fetchAndMapPrintEven } private CompletableFuture validatePrintEventFeatureFlag() { + log.debug("validatePrintEventFeatureFlag:: Fetching and validating enablePrintLog flag from settings"); return circulationSettingsRepository.findBy("query=name=printEventLogFeature") .thenApply(res -> Optional.ofNullable(res.value()) .map(records -> records.getRecords().stream() diff --git a/src/test/java/api/printEvents/PrintEventsTests.java b/src/test/java/api/printEvents/PrintEventsTests.java index bdc301bca3..4459ad504c 100644 --- a/src/test/java/api/printEvents/PrintEventsTests.java +++ b/src/test/java/api/printEvents/PrintEventsTests.java @@ -3,39 +3,23 @@ import api.support.APITests; import api.support.builders.CirculationSettingBuilder; import api.support.builders.RequestBuilder; -import api.support.http.IndividualResource; -import api.support.http.UserResource; import io.vertx.core.json.JsonObject; import org.folio.circulation.support.http.client.Response; -import org.hamcrest.Matchers; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.time.LocalDate; import java.util.ArrayList; import java.util.List; import java.util.UUID; import java.util.stream.IntStream; -import static api.support.http.CqlQuery.exactMatch; import static api.support.http.InterfaceUrls.printEventsUrl; 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; -import static org.hamcrest.core.Is.is; class PrintEventsTests extends APITests { - private IndividualResource servicePointResource; - private UserResource userResource; - - @BeforeEach - void executeBefore() { - userResource = usersFixture.charlotte(); - servicePointResource = servicePointsFixture.cd1(); - circulationSettingsClient.deleteAll(); - } @Test void postPrintEventsTest() { @@ -43,96 +27,11 @@ void postPrintEventsTest() { .withName("printEventLogFeature") .withValue(new JsonObject().put("enablePrintLog", true))); JsonObject printRequest = getPrintEvent(); - printRequest.put("requestIds", createMultipleRequests(100, "test-")); - System.out.println(printRequest.getString("requestIds")); + printRequest.put("requestIds", createOneHundredRequests()); Response response = restAssuredClient.post(printRequest, printEventsUrl("/print-events-entry"), "post-print-event"); assertThat(response, hasStatus(HTTP_CREATED)); } - @Test - void postPrintEventsAndFetchPrintDetailsInRequestApi() { - var itemBarcodePrefix = "itemBarcode-"; - - assertThat("Circulation settings enabled", circulationSettingsClient.getAll().isEmpty()); - - // creating 2 different requests and assert request details without enabling printEvent feature - var uuidList = createMultipleRequests(2, itemBarcodePrefix); - JsonObject requestRepresentation1 = requestsClient.getMany(exactMatch("id", uuidList.get(0))).getFirst(); - JsonObject requestRepresentation2 = requestsClient.getMany(exactMatch("id", uuidList.get(1))).getFirst(); - assertRequestDetails(requestRepresentation1, uuidList.get(0), itemBarcodePrefix+0); - assertRequestDetails(requestRepresentation2, uuidList.get(1), itemBarcodePrefix+1); - assertThat("printDetails should be null for request1 because the print event feature is not enabled", - requestRepresentation1.getJsonObject("printDetails"), Matchers.nullValue()); - assertThat("printDetails should be null for request2 because the print event feature is not enabled", - requestRepresentation2.getJsonObject("printDetails"), Matchers.nullValue()); - - // Enabling printEvent feature and assert request details. - circulationSettingsClient.create(new CirculationSettingBuilder() - .withName("printEventLogFeature") - .withValue(new JsonObject().put("enablePrintLog", true))); - requestRepresentation1 = requestsClient.getMany(exactMatch("id", uuidList.get(0))).getFirst(); - requestRepresentation2 = requestsClient.getMany(exactMatch("id", uuidList.get(1))).getFirst(); - assertRequestDetails(requestRepresentation1, uuidList.get(0), itemBarcodePrefix+0); - assertRequestDetails(requestRepresentation2, uuidList.get(1), itemBarcodePrefix+1); - assertThat("printDetails should be null for request1 because the request is not printed", - requestRepresentation1.getJsonObject("printDetails"), Matchers.nullValue()); - assertThat("printDetails should be null for request2 because the request is not printed", - requestRepresentation2.getJsonObject("printDetails"), Matchers.nullValue()); - - // Printing both request1 and request2 - JsonObject printRequest = getPrintEvent(); - printRequest.put("requestIds", uuidList); - printRequest.put("requesterId", userResource.getId()); - restAssuredClient.post(printRequest, printEventsUrl("/print-events-entry"), "post-print-event"); - requestRepresentation1 = requestsClient.getMany(exactMatch("id", uuidList.get(0))).getFirst(); - requestRepresentation2 = requestsClient.getMany(exactMatch("id", uuidList.get(1))).getFirst(); - assertRequestDetails(requestRepresentation1, uuidList.get(0), itemBarcodePrefix+0); - assertRequestDetails(requestRepresentation2, uuidList.get(1), itemBarcodePrefix+1); - assertThat("printDetails should not be null for request1 because the request is printed", - requestRepresentation1.getJsonObject("printDetails"), Matchers.notNullValue()); - assertThat("printDetails should not be null for request2 because the request is printed", - requestRepresentation2.getJsonObject("printDetails"), Matchers.notNullValue()); - assertPrintDetails(requestRepresentation1, 1, "2024-06-25T11:54:07.000Z"); - assertPrintDetails(requestRepresentation2, 1, "2024-06-25T11:54:07.000Z"); - - // Print both the request id again with same user. - // In this case, we will get the latest print event date and the count is increased - printRequest.put("printEventDate", "2024-06-25T14:54:07.000Z"); - restAssuredClient.post(printRequest, printEventsUrl("/print-events-entry"), "post-print-event"); - requestRepresentation1 = requestsClient.getMany(exactMatch("id", uuidList.get(0))).getFirst(); - requestRepresentation2 = requestsClient.getMany(exactMatch("id", uuidList.get(1))).getFirst(); - assertRequestDetails(requestRepresentation1, uuidList.get(0), itemBarcodePrefix+0); - assertRequestDetails(requestRepresentation2, uuidList.get(1), itemBarcodePrefix+1); - assertThat("printDetails should not be null for request1 because the request is printed", - requestRepresentation1.getJsonObject("printDetails"), Matchers.notNullValue()); - assertThat("printDetails should not be null for request2 because the request is printed", - requestRepresentation2.getJsonObject("printDetails"), Matchers.notNullValue()); - assertPrintDetails(requestRepresentation1, 2, "2024-06-25T14:54:07.000Z"); - assertPrintDetails(requestRepresentation2, 2, "2024-06-25T14:54:07.000Z"); - - // Print only request1 with unknown user id. - // In this case, request representation won't contain lastPrintRequester detail - printRequest.put("requesterId", UUID.randomUUID()); - printRequest.put("requestIds", List.of(uuidList.get(0))); - printRequest.put("printEventDate", "2024-06-25T14:59:07.000Z"); - restAssuredClient.post(printRequest, printEventsUrl("/print-events-entry"), "post-print-event"); - requestRepresentation1 = requestsClient.getMany(exactMatch("id", uuidList.get(0))).getFirst(); - requestRepresentation2 = requestsClient.getMany(exactMatch("id", uuidList.get(1))).getFirst(); - assertRequestDetails(requestRepresentation1, uuidList.get(0), itemBarcodePrefix+0); - assertRequestDetails(requestRepresentation2, uuidList.get(1), itemBarcodePrefix+1); - assertThat("printDetails should not be null for request1 because the request is printed", - requestRepresentation1.getJsonObject("printDetails"), Matchers.notNullValue()); - assertThat("printDetails should not be null for request2 because the request is printed", - requestRepresentation2.getJsonObject("printDetails"), Matchers.notNullValue()); - assertPrintDetails(requestRepresentation2, 2, "2024-06-25T14:54:07.000Z"); - assertThat(requestRepresentation1.getJsonObject("printDetails").getInteger("count"), is(3)); - assertThat(requestRepresentation1.getJsonObject("printDetails").getString("lastPrintedDate"), - is("2024-06-25T14:59:07.000Z")); - assertThat("lastPrintRequester object should be null because we used random uuid for user id while printing", - requestRepresentation1.getJsonObject("printDetails").getJsonObject("lastPrintRequester"), - Matchers.nullValue()); - } - @Test void postPrintEventsWhenCirculationSettingIsNotPresentTest() { JsonObject printRequest = getPrintEvent(); @@ -174,8 +73,8 @@ void postPrintEventsWithInvalidRequestId() { .withName("printEventLogFeature") .withValue(new JsonObject().put("enablePrintLog", true))); JsonObject printRequest = getPrintEvent(); - List requestIds = new ArrayList<>(createMultipleRequests(10, "invalid-")); - requestIds.add(UUID.randomUUID().toString()); + List requestIds = new ArrayList<>(createOneHundredRequests()); + requestIds.add(UUID.randomUUID()); printRequest.put("requestIds", requestIds); Response response = restAssuredClient.post(printRequest, printEventsUrl("/print-events-entry"), "post-print-event"); assertThat(response, hasStatus(HTTP_UNPROCESSABLE_ENTITY)); @@ -211,46 +110,19 @@ private JsonObject getPrintEvent() { return new JsonObject() .put("requesterId", "5f5751b4-e352-4121-adca-204b0c2aec43") .put("requesterName", "requester") - .put("printEventDate", "2024-06-25T11:54:07.000Z"); + .put("printEventDate", "2024-06-25T14:30:00Z"); } - private List createMultipleRequests(int noOfRequests, String itemBarcode) { + private List createOneHundredRequests() { + final UUID pickupServicePointId = servicePointsFixture.cd1().getId(); - return IntStream.range(0, noOfRequests).mapToObj(i -> requestsFixture.place( + return IntStream.range(0, 100).mapToObj(notUsed -> requestsFixture.place( new RequestBuilder() .open() .page() - .forItem(itemsFixture.basedUponSmallAngryPlanet(itemBarcode + i)) - .by(userResource) + .forItem(itemsFixture.basedUponSmallAngryPlanet()) + .by(usersFixture.charlotte()) .fulfillToHoldShelf() - .withRequestExpiration(LocalDate.of(2024, 7, 30)) - .withHoldShelfExpiration(LocalDate.of(2024, 8, 15)) - .withPickupServicePointId(servicePointResource.getId())).getId().toString()).toList(); - } - - private void assertRequestDetails(JsonObject representation, String id, String barcodeName) { - assertThat(representation.getString("id"), is(id)); - assertThat(representation.getString("requestType"), is("Page")); - assertThat(representation.getString("requestLevel"), is("Item")); - assertThat(representation.getString("requestDate"), is("2017-07-15T09:35:27.000Z")); - assertThat(representation.getJsonObject("item").getString("barcode"), is(barcodeName)); - assertThat(representation.getString("fulfillmentPreference"), is("Hold Shelf")); - assertThat(representation.getString("requestExpirationDate"), is("2024-07-30T23:59:59.000Z")); - assertThat(representation.getString("holdShelfExpirationDate"), is("2024-08-15")); - assertThat(representation.getString("status"), is("Open - Not yet filled")); - assertThat(representation.getString("pickupServicePointId"), is(servicePointResource.getId().toString())); - } - - private void assertPrintDetails(JsonObject representation, int count, String printEventDate) { - var printDetailObject = representation.getJsonObject("printDetails"); - var lastPrintRequesterObject = printDetailObject.getJsonObject("lastPrintRequester"); - assertThat(printDetailObject.getInteger("count"), is(count)); - assertThat(printDetailObject.getString("lastPrintedDate"), is(printEventDate)); - assertThat(lastPrintRequesterObject.getString("middleName"), - is(userResource.getJson().getJsonObject("personal").getString("middleName"))); - assertThat(lastPrintRequesterObject.getString("lastName"), - is(userResource.getJson().getJsonObject("personal").getString("lastName"))); - assertThat(lastPrintRequesterObject.getString("firstName"), - is(userResource.getJson().getJsonObject("personal").getString("firstName"))); + .withPickupServicePointId(pickupServicePointId)).getId()).toList(); } } diff --git a/src/test/java/api/requests/RequestsAPICreationTests.java b/src/test/java/api/requests/RequestsAPICreationTests.java index 0595792bd6..24a3bc3a9d 100644 --- a/src/test/java/api/requests/RequestsAPICreationTests.java +++ b/src/test/java/api/requests/RequestsAPICreationTests.java @@ -16,6 +16,7 @@ import static api.support.fixtures.TemplateContextMatchers.getUserContextMatchers; import static api.support.http.CqlQuery.exactMatch; import static api.support.http.CqlQuery.notEqual; +import static api.support.http.InterfaceUrls.printEventsUrl; import static api.support.http.Limit.limit; import static api.support.http.Offset.noOffset; import static api.support.matchers.EventMatchers.isValidLoanDueDateChangedEvent; @@ -107,6 +108,7 @@ import java.util.stream.IntStream; import java.util.stream.Stream; +import api.support.builders.CirculationSettingBuilder; import org.apache.http.HttpStatus; import org.awaitility.Awaitility; import org.folio.circulation.domain.ItemStatus; @@ -194,6 +196,7 @@ public class RequestsAPICreationTests extends APITests { public void afterEach() { mockClockManagerToReturnDefaultDateTime(); configurationsFixture.deleteTlrFeatureConfig(); + circulationSettingsClient.deleteAll(); } @Test @@ -4859,6 +4862,123 @@ void createHoldRequestForDcbItemAndResponseContainsDcbTitle() { } + @Test + void fetchRequestWithOutPrintEventFeature() { + assertThat("Circulation settings enabled", circulationSettingsClient.getAll().isEmpty()); + var barcode1 = "barcode1"; + var barcode2 = "barcode2"; + // creating 2 different requests and assert request details without enabling printEvent feature + var userResource = usersFixture.charlotte(); + var servicePointId = servicePointsFixture.cd1().getId(); + var requestId1 = createRequest(userResource, barcode1, servicePointId).getId(); + var requestId2 = createRequest(userResource, barcode2, servicePointId).getId(); + + JsonObject requestRepresentation1 = requestsClient.getMany(exactMatch("id", requestId1.toString())).getFirst(); + JsonObject requestRepresentation2 = requestsClient.getMany(exactMatch("id", requestId2.toString())).getFirst(); + assertRequestDetails(requestRepresentation1, requestId1, barcode1, servicePointId); + assertRequestDetails(requestRepresentation2, requestId2, barcode2, servicePointId); + assertThat("printDetails should be null for request1 because the print event feature is not enabled", + requestRepresentation1.getJsonObject("printDetails"), Matchers.nullValue()); + assertThat("printDetails should be null for request2 because the print event feature is not enabled", + requestRepresentation2.getJsonObject("printDetails"), Matchers.nullValue()); + } + + @Test + void printAndFetchDetailWithPrintEventFeatureEnabled() { + assertThat("Circulation settings enabled", circulationSettingsClient.getAll().isEmpty()); + var barcode1 = "barcode1"; + var barcode2 = "barcode2"; + // creating 2 different requests and print those 2 requests + // assert request details with enabling printEvent feature + circulationSettingsClient.create(new CirculationSettingBuilder() + .withName("printEventLogFeature") + .withValue(new JsonObject().put("enablePrintLog", true))); + var userResource1 = usersFixture.charlotte(); + var userResource2 = usersFixture.jessica(); + var servicePointId = servicePointsFixture.cd1().getId(); + var requestId1 = createRequest(userResource1, barcode1, servicePointId).getId(); + var requestId2 = createRequest(userResource2, barcode2, servicePointId).getId(); + // Printing request1 using user1 and assertRequest details + var printRequest = getPrintEvent(); + printRequest.put("requestIds", List.of(requestId1)); + printRequest.put("requesterId", userResource1.getId()); + + restAssuredClient.post(printRequest, printEventsUrl("/print-events-entry"), "post-print-event"); + + // Printing request2 using user2 and assertRequest details + printRequest = getPrintEvent(); + printRequest.put("requestIds", List.of(requestId2)); + printRequest.put("requesterId", userResource2.getId()); + + restAssuredClient.post(printRequest, printEventsUrl("/print-events-entry"), "post-print-event"); + JsonObject requestRepresentation1 = requestsClient.getMany(exactMatch("id", requestId1.toString())).getFirst(); + JsonObject requestRepresentation2 = requestsClient.getMany(exactMatch("id", requestId2.toString())).getFirst(); + assertRequestDetails(requestRepresentation1, requestId1, barcode1, servicePointId); + assertRequestDetails(requestRepresentation2, requestId2, barcode2, servicePointId); + assertThat("printDetails should not be null for request1 as the feature is enabled and the request is printed", + requestRepresentation1.getJsonObject("printDetails"), Matchers.notNullValue()); + assertThat("printDetails should not be null for request2 as the feature is enabled and the request is printed", + requestRepresentation2.getJsonObject("printDetails"), Matchers.notNullValue()); + assertPrintDetails(requestRepresentation1, 1, "2024-06-25T11:54:07.000Z", userResource1); + assertPrintDetails(requestRepresentation2, 1, "2024-06-25T11:54:07.000Z", userResource2); + + // printing both request for second time using user2 and assert requestDetails + printRequest.put("printEventDate", "2024-06-25T12:54:07.000Z"); + printRequest.put("requestIds", List.of(requestId1, requestId2)); + printRequest.put("requesterId", userResource2.getId()); + + restAssuredClient.post(printRequest, printEventsUrl("/print-events-entry"), "post-print-event"); + + requestRepresentation1 = requestsClient.getMany(exactMatch("id", requestId1.toString())).getFirst(); + requestRepresentation2 = requestsClient.getMany(exactMatch("id", requestId2.toString())).getFirst(); + assertRequestDetails(requestRepresentation1, requestId1, barcode1, servicePointId); + assertRequestDetails(requestRepresentation2, requestId2, barcode2, servicePointId); + assertPrintDetails(requestRepresentation1, 2, "2024-06-25T12:54:07.000Z", userResource2); + assertPrintDetails(requestRepresentation2, 2, "2024-06-25T12:54:07.000Z", userResource2); + + // printing request1 for third time using user1 and assert requestDetails + printRequest.put("printEventDate", "2024-06-25T12:58:07.000Z"); + printRequest.put("requestIds", List.of(requestId1)); + printRequest.put("requesterId", userResource1.getId()); + + restAssuredClient.post(printRequest, printEventsUrl("/print-events-entry"), "post-print-event"); + + requestRepresentation1 = requestsClient.getMany(exactMatch("id", requestId1.toString())).getFirst(); + requestRepresentation2 = requestsClient.getMany(exactMatch("id", requestId2.toString())).getFirst(); + assertRequestDetails(requestRepresentation1, requestId1, barcode1, servicePointId); + assertRequestDetails(requestRepresentation2, requestId2, barcode2, servicePointId); + assertPrintDetails(requestRepresentation1, 3, "2024-06-25T12:58:07.000Z", userResource1); + assertPrintDetails(requestRepresentation2, 2, "2024-06-25T12:54:07.000Z", userResource2); + } + + @Test + void printAndFetchRequestWithPrintEventFeatureDisabled() { + assertThat("Circulation settings enabled", circulationSettingsClient.getAll().isEmpty()); + var barcode1 = "barcode1"; + var barcode2 = "barcode2"; + // creating 2 different requests and print it + // assert request details without enabling printEvent feature + circulationSettingsClient.create(new CirculationSettingBuilder() + .withName("printEventLogFeature") + .withValue(new JsonObject().put("enablePrintLog", false))); + var userResource = usersFixture.charlotte(); + var servicePointId = servicePointsFixture.cd1().getId(); + var requestId1 = createRequest(userResource, barcode1, servicePointId).getId(); + var requestId2 = createRequest(userResource, barcode2, servicePointId).getId(); + var printRequest = getPrintEvent(); + printRequest.put("requestIds", List.of(requestId1, requestId2)); + + restAssuredClient.post(printRequest, printEventsUrl("/print-events-entry"), "post-print-event"); + + JsonObject requestRepresentation1 = requestsClient.getMany(exactMatch("id", requestId1.toString())).getFirst(); + JsonObject requestRepresentation2 = requestsClient.getMany(exactMatch("id", requestId2.toString())).getFirst(); + assertRequestDetails(requestRepresentation1, requestId1, barcode1, servicePointId); + assertRequestDetails(requestRepresentation2, requestId2, barcode2, servicePointId); + assertThat("printDetails should be null for request1 because the print event feature is disabled", + requestRepresentation1.getJsonObject("printDetails"), Matchers.nullValue()); + assertThat("printDetails should be null for request2 because the print event feature is disabled", + requestRepresentation2.getJsonObject("printDetails"), Matchers.nullValue()); + } private void setUpNoticesForTitleLevelRequests(boolean isNoticeEnabledInTlrSettings, boolean isNoticeEnabledInNoticePolicy) { @@ -5190,4 +5310,52 @@ private void validateInstanceRepresentation(JsonObject requestInstance) { assertThat(firstPublication.getString("place"), is("New York")); assertThat(firstPublication.getString("dateOfPublication"), is("2016")); } + + private IndividualResource createRequest(UserResource userResource, String itemBarcode, + UUID pickupServicePointId) { + return requestsFixture.place( + new RequestBuilder() + .open() + .page() + .forItem(itemsFixture.basedUponSmallAngryPlanet(itemBarcode)) + .by(userResource) + .fulfillToHoldShelf() + .withRequestExpiration(LocalDate.of(2024, 7, 30)) + .withHoldShelfExpiration(LocalDate.of(2024, 8, 15)) + .withPickupServicePointId(pickupServicePointId)); + } + + private void assertRequestDetails(JsonObject representation, UUID id, String barcodeName, UUID servicePointId) { + assertThat(representation.getString("id"), is(id.toString())); + assertThat(representation.getString("requestType"), is("Page")); + assertThat(representation.getString("requestLevel"), is("Item")); + assertThat(representation.getString("requestDate"), is("2017-07-15T09:35:27.000Z")); + assertThat(representation.getJsonObject("item").getString("barcode"), is(barcodeName)); + assertThat(representation.getString("fulfillmentPreference"), is("Hold Shelf")); + assertThat(representation.getString("requestExpirationDate"), is("2024-07-30T23:59:59.000Z")); + assertThat(representation.getString("holdShelfExpirationDate"), is("2024-08-15")); + assertThat(representation.getString("status"), is("Open - Not yet filled")); + assertThat(representation.getString("pickupServicePointId"), is(servicePointId.toString())); + } + + private JsonObject getPrintEvent() { + return new JsonObject() + .put("requesterId", "5f5751b4-e352-4121-adca-204b0c2aec43") + .put("requesterName", "requester") + .put("printEventDate", "2024-06-25T11:54:07.000Z"); + } + + private void assertPrintDetails(JsonObject representation, int count, String printEventDate, + UserResource userResource) { + var printDetailObject = representation.getJsonObject("printDetails"); + var lastPrintRequesterObject = printDetailObject.getJsonObject("lastPrintRequester"); + assertThat(printDetailObject.getInteger("count"), is(count)); + assertThat(printDetailObject.getString("lastPrintedDate"), is(printEventDate)); + assertThat(lastPrintRequesterObject.getString("middleName"), + is(userResource.getJson().getJsonObject("personal").getString("middleName"))); + assertThat(lastPrintRequesterObject.getString("lastName"), + is(userResource.getJson().getJsonObject("personal").getString("lastName"))); + assertThat(lastPrintRequesterObject.getString("firstName"), + is(userResource.getJson().getJsonObject("personal").getString("firstName"))); + } } diff --git a/src/test/java/api/support/fakes/FakePrintEventStatusModule.java b/src/test/java/api/support/fakes/FakePrintEventStatusModule.java index 628fb2203c..aaeced3434 100644 --- a/src/test/java/api/support/fakes/FakePrintEventStatusModule.java +++ b/src/test/java/api/support/fakes/FakePrintEventStatusModule.java @@ -25,7 +25,6 @@ public class FakePrintEventStatusModule { public void register(Router router) { router.post("/print-events-storage/print-events-status") .handler(this::handlePrintEventStatusRequest); - } private void handlePrintEventStatusRequest(RoutingContext routingContext) { @@ -33,51 +32,52 @@ private void handlePrintEventStatusRequest(RoutingContext routingContext) { var requestIds = request.getJsonArray("requestIds"); if (requestIds.isEmpty()) { Buffer buffer = Buffer.buffer( - "Size must be 1", "UTF-8"); + "size must be between 1 and 2147483647", "UTF-8"); routingContext.response() .setStatusCode(HTTP_UNPROCESSABLE_ENTITY.toInt()) .putHeader("content-type", "text/plain; charset=utf-8") .putHeader("content-length", Integer.toString(buffer.length())) .write(buffer); routingContext.response().end(); + } else { + var jsonObjectList = new ArrayList<>(getStorage() + .getTenantResources("/print-events-storage/print-events-entry", getTenantId()) + .values() + .stream() + .toList()); + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX"); + // Sorting jsonObjectList based on PrintEventDate so that it will always return latest printEventDetail + jsonObjectList.sort((obj1, obj2) -> { + try { + Date date1 = dateFormat.parse(obj1.getString("printEventDate")); + Date date2 = dateFormat.parse(obj2.getString("printEventDate")); + return date2.compareTo(date1); + } catch (ParseException e) { + throw new RuntimeException(e); + } + }); + Map> groupByRequestIdMap = new LinkedHashMap<>(); + requestIds.forEach(requestId -> { + var requestList = jsonObjectList.stream().filter(jsonObject -> + jsonObject.getJsonArray("requestIds").contains(requestId)) + .toList(); + groupByRequestIdMap.put((String) requestId, requestList); + }); + var jsonObjectResponse = new JsonObject(); + var printEventStatusResponses = new ArrayList<>(); + jsonObjectResponse.put("printEventsStatusResponses", printEventStatusResponses); + requestIds.forEach(id -> { + var requestDetail = groupByRequestIdMap.get(id); + if (requestDetail != null && !requestDetail.isEmpty()) { + var object = new JsonObject() + .put("requestId", id) + .put("count", requestDetail.size()) + .put("requesterId", requestDetail.get(0).getString("requesterId")) + .put("printEventDate", requestDetail.get(0).getString("printEventDate")); + printEventStatusResponses.add(object); + } + }); + ok(jsonObjectResponse).writeTo(routingContext.response()); } - var jsonObjectList = new ArrayList<>(getStorage() - .getTenantResources("/print-events-storage/print-events-entry", getTenantId()) - .values() - .stream() - .toList()); - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX"); - // Sorting jsonObjectList based on PrintEventDate so that it will always return latest printEventDetail - jsonObjectList.sort((obj1, obj2) -> { - try { - Date date1 = dateFormat.parse(obj1.getString("printEventDate")); - Date date2 = dateFormat.parse(obj2.getString("printEventDate")); - return date2.compareTo(date1); - } catch (ParseException e) { - throw new RuntimeException(e); - } - }); - Map> groupByRequestIdMap = new LinkedHashMap<>(); - requestIds.forEach(requestId -> { - var requestList = jsonObjectList.stream().filter(jsonObject -> - jsonObject.getJsonArray("requestIds").contains(requestId)) - .toList(); - groupByRequestIdMap.put((String) requestId, requestList); - }); - var jsonObjectResponse = new JsonObject(); - var printEventStatusResponses = new ArrayList<>(); - jsonObjectResponse.put("printEventsStatusResponses", printEventStatusResponses); - requestIds.forEach(id -> { - var requestDetail = groupByRequestIdMap.get(id); - if (requestDetail != null && !requestDetail.isEmpty()) { - var object = new JsonObject() - .put("requestId", id) - .put("count", requestDetail.size()) - .put("requesterId", requestDetail.get(0).getString("requesterId")) - .put("printEventDate", requestDetail.get(0).getString("printEventDate")); - printEventStatusResponses.add(object); - } - }); - ok(jsonObjectResponse).writeTo(routingContext.response()); } }