|
| 1 | +package org.folio.rest.api; |
| 2 | + |
| 3 | +import io.vertx.core.json.JsonObject; |
| 4 | +import org.folio.rest.support.ApiTests; |
| 5 | +import org.folio.rest.support.JsonResponse; |
| 6 | +import org.folio.rest.support.ResponseHandler; |
| 7 | +import org.junit.Test; |
| 8 | + |
| 9 | +import java.net.MalformedURLException; |
| 10 | +import java.util.List; |
| 11 | +import java.util.concurrent.CompletableFuture; |
| 12 | +import java.util.concurrent.ExecutionException; |
| 13 | + |
| 14 | +import static org.folio.rest.support.http.InterfaceUrls.printEventsUrl; |
| 15 | +import static org.folio.rest.support.matchers.HttpResponseStatusCodeMatchers.isCreated; |
| 16 | +import static org.folio.rest.support.matchers.HttpResponseStatusCodeMatchers.isUnprocessableEntity; |
| 17 | +import static org.hamcrest.junit.MatcherAssert.assertThat; |
| 18 | + |
| 19 | +public class PrintEventsAPITest extends ApiTests { |
| 20 | + |
| 21 | + @Test |
| 22 | + public void canCreatePrintEventLog() throws MalformedURLException, ExecutionException, InterruptedException { |
| 23 | + JsonObject printEventsJson = getPrintEvent(); |
| 24 | + final CompletableFuture<JsonResponse> postCompleted = new CompletableFuture<>(); |
| 25 | + client.post(printEventsUrl("/print-events-entry"), printEventsJson, StorageTestSuite.TENANT_ID, |
| 26 | + ResponseHandler.json(postCompleted)); |
| 27 | + final JsonResponse postResponse = postCompleted.get(); |
| 28 | + assertThat(postResponse, isCreated()); |
| 29 | + } |
| 30 | + |
| 31 | + @Test |
| 32 | + public void createPrintEventLogWithMissingFields() throws MalformedURLException, ExecutionException, InterruptedException { |
| 33 | + List<String> requestIds = List.of("5f5751b4-e352-4121-adca-204b0c2aec43", "5f5751b4-e352-4121-adca-204b0c2aec44"); |
| 34 | + JsonObject printEventsJson = new JsonObject() |
| 35 | + .put("requestIds", requestIds) |
| 36 | + .put("requesterName", "Sample Requester") |
| 37 | + .put("printEventDate", "2024-06-25T14:30:00Z"); |
| 38 | + final CompletableFuture<JsonResponse> postCompleted = new CompletableFuture<>(); |
| 39 | + client.post(printEventsUrl("/print-events-entry"), printEventsJson, StorageTestSuite.TENANT_ID, |
| 40 | + ResponseHandler.json(postCompleted)); |
| 41 | + final JsonResponse postResponse = postCompleted.get(); |
| 42 | + assertThat(postResponse, isUnprocessableEntity()); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + public void createPrintEventLogWithBlankFields() throws MalformedURLException, ExecutionException, InterruptedException { |
| 47 | + JsonObject printEventsJson = getPrintEvent(); |
| 48 | + printEventsJson.put("requesterId", " "); |
| 49 | + final CompletableFuture<JsonResponse> postCompleted = new CompletableFuture<>(); |
| 50 | + client.post(printEventsUrl("/print-events-entry"), printEventsJson, StorageTestSuite.TENANT_ID, |
| 51 | + ResponseHandler.json(postCompleted)); |
| 52 | + final JsonResponse postResponse = postCompleted.get(); |
| 53 | + assertThat(postResponse, isUnprocessableEntity()); |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + public void createPrintEventLogWhenRequestListIsEmpty() throws MalformedURLException, ExecutionException, InterruptedException { |
| 58 | + List<String> requestIds = List.of(); |
| 59 | + JsonObject printEventsJson = getPrintEvent(); |
| 60 | + printEventsJson.put("requestIds", requestIds); |
| 61 | + final CompletableFuture<JsonResponse> postCompleted = new CompletableFuture<>(); |
| 62 | + client.post(printEventsUrl("/print-events-entry"), printEventsJson, StorageTestSuite.TENANT_ID, |
| 63 | + ResponseHandler.json(postCompleted)); |
| 64 | + final JsonResponse postResponse = postCompleted.get(); |
| 65 | + assertThat(postResponse, isUnprocessableEntity()); |
| 66 | + } |
| 67 | + |
| 68 | + private JsonObject getPrintEvent() { |
| 69 | + List<String> requestIds = List.of("5f5751b4-e352-4121-adca-204b0c2aec43", "5f5751b4-e352-4121-adca-204b0c2aec44"); |
| 70 | + return new JsonObject() |
| 71 | + .put("requestIds", requestIds) |
| 72 | + .put("requesterId", "5f5751b4-e352-4121-adca-204b0c2aec43") |
| 73 | + .put("requesterName", "requester") |
| 74 | + .put("printEventDate", "2024-06-25T14:30:00Z"); |
| 75 | + } |
| 76 | +} |
0 commit comments