use of org.folio.rest.support.JsonResponse in project mod-circulation-storage by folio-org.
the class RequestsApiTest method canPageRequests.
@Test
public void canPageRequests() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
createEntity(new RequestRequestBuilder().create(), requestStorageUrl());
createEntity(new RequestRequestBuilder().create(), requestStorageUrl());
createEntity(new RequestRequestBuilder().create(), requestStorageUrl());
createEntity(new RequestRequestBuilder().create(), requestStorageUrl());
createEntity(new RequestRequestBuilder().create(), requestStorageUrl());
createEntity(new RequestRequestBuilder().create(), requestStorageUrl());
createEntity(new RequestRequestBuilder().create(), requestStorageUrl());
CompletableFuture<JsonResponse> firstPageCompleted = new CompletableFuture<>();
CompletableFuture<JsonResponse> secondPageCompleted = new CompletableFuture<>();
client.get(requestStorageUrl() + "?limit=4", TENANT_ID, ResponseHandler.json(firstPageCompleted));
client.get(requestStorageUrl() + "?limit=4&offset=4", TENANT_ID, ResponseHandler.json(secondPageCompleted));
JsonResponse firstPageResponse = firstPageCompleted.get(5, TimeUnit.SECONDS);
JsonResponse secondPageResponse = secondPageCompleted.get(5, TimeUnit.SECONDS);
MatcherAssert.assertThat(String.format("Failed to get first page of requests: %s", firstPageResponse.getBody()), firstPageResponse.getStatusCode(), is(200));
assertThat(String.format("Failed to get second page of requests: %s", secondPageResponse.getBody()), secondPageResponse.getStatusCode(), is(200));
JsonObject firstPage = firstPageResponse.getJson();
JsonObject secondPage = secondPageResponse.getJson();
JsonArray firstPageRequests = firstPage.getJsonArray("requests");
JsonArray secondPageRequests = secondPage.getJsonArray("requests");
assertThat(firstPageRequests.size(), is(4));
assertThat(firstPage.getInteger("totalRecords"), is(7));
assertThat(secondPageRequests.size(), is(3));
assertThat(secondPage.getInteger("totalRecords"), is(7));
}
use of org.folio.rest.support.JsonResponse in project mod-circulation-storage by folio-org.
the class RequestsApiTest method canSearchRequestsByUserProxyId.
@Test
public void canSearchRequestsByUserProxyId() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
UUID firstRequester = UUID.randomUUID();
JsonObject j1 = new RequestRequestBuilder().withRequesterId(firstRequester).create();
JsonObject j2 = new RequestRequestBuilder().withRequesterId(firstRequester).create();
JsonObject j3 = new RequestRequestBuilder().withRequesterId(firstRequester).create();
String userProxy1 = UUID.randomUUID().toString();
String userProxy2 = UUID.randomUUID().toString();
String userProxy3 = UUID.randomUUID().toString();
j1.put("proxyUserId", userProxy1);
j2.put("proxyUserId", userProxy2);
j3.put("proxyUserId", userProxy3);
createEntity(j1, requestStorageUrl());
createEntity(j2, requestStorageUrl());
createEntity(j3, requestStorageUrl());
CompletableFuture<JsonResponse> getRequestsCompleted = new CompletableFuture<>();
client.get(requestStorageUrl() + String.format("?query=proxyUserId=%s", userProxy1), TENANT_ID, ResponseHandler.json(getRequestsCompleted));
JsonResponse getRequestsResponse = getRequestsCompleted.get(5, TimeUnit.SECONDS);
assertThat(String.format("Failed to get requests: %s", getRequestsResponse.getBody()), getRequestsResponse.getStatusCode(), is(HttpURLConnection.HTTP_OK));
JsonObject wrappedRequests = getRequestsResponse.getJson();
assertThat(wrappedRequests.getJsonArray("requests").size(), is(1));
assertThat(wrappedRequests.getInteger("totalRecords"), is(1));
CompletableFuture<JsonResponse> getRequestsCompleted2 = new CompletableFuture<>();
String query = String.format("proxyUserId<>%s", UUID.randomUUID());
client.get(requestStorageUrl() + "?query=" + URLEncoder.encode(query, UTF_8), TENANT_ID, ResponseHandler.json(getRequestsCompleted2));
JsonResponse getRequestsResponse2 = getRequestsCompleted2.get(5, TimeUnit.SECONDS);
assertThat(String.format("Failed to get requests: %s", getRequestsResponse2.getBody()), getRequestsResponse2.getStatusCode(), is(HttpURLConnection.HTTP_OK));
JsonObject wrappedRequests2 = getRequestsResponse2.getJson();
assertThat(wrappedRequests2.getJsonArray("requests").size(), is(3));
assertThat(wrappedRequests2.getInteger("totalRecords"), is(3));
}
use of org.folio.rest.support.JsonResponse in project mod-circulation-storage by folio-org.
the class RequestsApiTest method updateFailRequestsByUserProxyId.
@Test
public void updateFailRequestsByUserProxyId() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
UUID requestId = UUID.randomUUID();
JsonObject j1 = new RequestRequestBuilder().withId(requestId).create();
String userProxy1 = UUID.randomUUID().toString();
j1.put("proxyUserId", userProxy1);
createEntity(j1, requestStorageUrl());
// /////////// try to update with a bad proxId ////////////////////
j1.put("proxyUserId", "12345");
CompletableFuture<JsonResponse> createCompleted = new CompletableFuture<>();
client.put(requestStorageUrl("/" + requestId), j1, TENANT_ID, ResponseHandler.json(createCompleted));
JsonResponse putResponse = createCompleted.get(5, TimeUnit.SECONDS);
assertThat(String.format("Failed to create request: %s", putResponse.getBody()), putResponse.getStatusCode(), is(422));
}
use of org.folio.rest.support.JsonResponse in project mod-circulation-storage by folio-org.
the class RequestsApiTest method canSortRequestsByAscendingRequestDate.
@Test
public void canSortRequestsByAscendingRequestDate() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException, UnsupportedEncodingException {
UUID itemId = UUID.randomUUID();
createEntity(new RequestRequestBuilder().withItemId(itemId).withRequestDate(new DateTime(2018, 2, 14, 15, 10, 54, DateTimeZone.UTC)).withPosition(1).create(), requestStorageUrl()).getId();
createEntity(new RequestRequestBuilder().withItemId(itemId).withRequestDate(new DateTime(2017, 11, 24, 12, 31, 27, DateTimeZone.UTC)).withPosition(2).create(), requestStorageUrl()).getId();
createEntity(new RequestRequestBuilder().withItemId(itemId).withRequestDate(new DateTime(2018, 2, 4, 15, 10, 54, DateTimeZone.UTC)).withPosition(3).create(), requestStorageUrl()).getId();
createEntity(new RequestRequestBuilder().withItemId(itemId).withRequestDate(new DateTime(2018, 1, 12, 12, 31, 27, DateTimeZone.UTC)).withPosition(4).create(), requestStorageUrl()).getId();
CompletableFuture<JsonResponse> getRequestsCompleted = new CompletableFuture<>();
String query = URLEncoder.encode(String.format("itemId==%s sortBy requestDate/sort.ascending", itemId), UTF_8);
client.get(requestStorageUrl() + String.format("?query=%s", query), TENANT_ID, ResponseHandler.json(getRequestsCompleted));
JsonResponse getRequestsResponse = getRequestsCompleted.get(5, TimeUnit.SECONDS);
assertThat(String.format("Failed to get requests: %s", getRequestsResponse.getBody()), getRequestsResponse.getStatusCode(), is(HttpURLConnection.HTTP_OK));
JsonObject wrappedRequests = getRequestsResponse.getJson();
List<JsonObject> requests = JsonArrayHelper.toList(wrappedRequests.getJsonArray("requests"));
assertThat(requests.size(), is(4));
assertThat(wrappedRequests.getInteger("totalRecords"), is(4));
List<String> sortedRequestDates = requests.stream().map(request -> request.getString("requestDate")).collect(Collectors.toList());
assertThat(sortedRequestDates, contains("2017-11-24T12:31:27.000+00:00", "2018-01-12T12:31:27.000+00:00", "2018-02-04T15:10:54.000+00:00", "2018-02-14T15:10:54.000+00:00"));
}
use of org.folio.rest.support.JsonResponse in project mod-circulation-storage by folio-org.
the class RequestsApiTest method cannotCreateTitleLevelRequestIfOneOfItemIdAndHoldingsRecordIdIsNotPresent.
@Test
@Parameters({ "holdingsRecordId", "itemId" })
public void cannotCreateTitleLevelRequestIfOneOfItemIdAndHoldingsRecordIdIsNotPresent(String propertyToRemove) throws MalformedURLException, ExecutionException, InterruptedException, TimeoutException {
String requestLevel = "Title";
CompletableFuture<JsonResponse> createCompleted = new CompletableFuture<>();
JsonObject request = new RequestRequestBuilder().recall().toHoldShelf().withRequestLevel(requestLevel).create();
request.remove(propertyToRemove);
client.post(requestStorageUrl(), request, TENANT_ID, ResponseHandler.json(createCompleted));
JsonObject response = createCompleted.get(5, TimeUnit.SECONDS).getJson();
assertThat(response, hasErrorWith(hasMessageContaining("Title level request must have both itemId and holdingsRecordId or neither")));
}
Aggregations