use of org.folio.rest.support.builders.RequestRequestBuilder in project mod-circulation-storage by folio-org.
the class RequestsApiTest method canCreateARequestWithValidStatus.
@Test
@Parameters({ OPEN_NOT_YET_FILLED, OPEN_AWAITING_PICKUP, OPEN_AWAITING_DELIVERY, OPEN_IN_TRANSIT, CLOSED_FILLED, CLOSED_UNFILLED, CLOSED_PICKUP_EXPIRED })
public void canCreateARequestWithValidStatus(String status) throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
JsonObject representation = createEntity(new RequestRequestBuilder().recall().toHoldShelf().withStatus(status).create(), requestStorageUrl()).getJson();
assertThat(representation.getString("status"), is(status));
assertCreateEventForRequest(representation);
}
use of org.folio.rest.support.builders.RequestRequestBuilder in project mod-circulation-storage by folio-org.
the class RequestsApiTest method cannotCreateItemLevelRequestIfItemIdAndHoldingsRecordIdAreNull.
@Test
public void cannotCreateItemLevelRequestIfItemIdAndHoldingsRecordIdAreNull() throws MalformedURLException, ExecutionException, InterruptedException, TimeoutException {
CompletableFuture<JsonResponse> createCompleted = new CompletableFuture<>();
JsonObject request = new RequestRequestBuilder().recall().toHoldShelf().create();
request.remove("holdingsRecordId");
request.remove("itemId");
client.post(requestStorageUrl(), request, TENANT_ID, ResponseHandler.json(createCompleted));
JsonObject response = createCompleted.get(5, TimeUnit.SECONDS).getJson();
assertThat(response, hasErrorWith(hasMessageContaining("Item ID in item level request should not be absent")));
assertThat(response, hasErrorWith(hasMessageContaining("Holdings record ID in item level request should not be absent")));
}
use of org.folio.rest.support.builders.RequestRequestBuilder in project mod-circulation-storage by folio-org.
the class RequestsApiTest method canCreateARequestWithOnlyRequiredProperties.
@Test
public void canCreateARequestWithOnlyRequiredProperties() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
UUID id = UUID.randomUUID();
UUID itemId = UUID.randomUUID();
UUID requesterId = UUID.randomUUID();
DateTime requestDate = new DateTime(2017, 7, 22, 10, 22, 54, DateTimeZone.UTC);
JsonObject representation = createEntity(new RequestRequestBuilder().recall().withId(id).withRequestDate(requestDate).withItemId(itemId).withRequesterId(requesterId).toHoldShelf().create(), requestStorageUrl()).getJson();
assertThat(representation.getString("id"), is(id.toString()));
assertThat(representation.getString("requestType"), is("Recall"));
assertThat(representation.getString("requestDate"), is(equivalentTo(requestDate)));
assertThat(representation.getString("itemId"), is(itemId.toString()));
assertThat(representation.getString("requesterId"), is(requesterId.toString()));
assertThat(representation.getString("fulfilmentPreference"), is("Hold Shelf"));
assertThat(representation.containsKey("requestExpirationDate"), is(false));
assertThat(representation.containsKey("holdShelfExpirationDate"), is(false));
assertThat(representation.containsKey("item"), is(false));
assertThat(representation.containsKey("requester"), is(false));
assertCreateEventForRequest(representation);
}
use of org.folio.rest.support.builders.RequestRequestBuilder in project mod-circulation-storage by folio-org.
the class RequestsApiTest method canFilterByRequestStatus.
@Test
public void canFilterByRequestStatus() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException, UnsupportedEncodingException {
UUID itemId = UUID.randomUUID();
UUID otherItemId = UUID.randomUUID();
createEntity(new RequestRequestBuilder().withItemId(itemId).withPosition(1).withStatus(OPEN_NOT_YET_FILLED).create(), requestStorageUrl());
createEntity(new RequestRequestBuilder().withItemId(itemId).withPosition(2).withStatus(OPEN_AWAITING_PICKUP).create(), requestStorageUrl());
createEntity(new RequestRequestBuilder().withItemId(itemId).withPosition(3).withStatus(OPEN_AWAITING_DELIVERY).create(), requestStorageUrl());
createEntity(new RequestRequestBuilder().withItemId(itemId).withNoPosition().withStatus(CLOSED_FILLED).create(), requestStorageUrl());
createEntity(new RequestRequestBuilder().withItemId(otherItemId).withPosition(1).withStatus(OPEN_NOT_YET_FILLED).create(), requestStorageUrl());
createEntity(new RequestRequestBuilder().withItemId(otherItemId).withPosition(2).withStatus(OPEN_AWAITING_PICKUP).create(), requestStorageUrl());
createEntity(new RequestRequestBuilder().withItemId(itemId).withPosition(4).withStatus(OPEN_IN_TRANSIT).create(), requestStorageUrl());
createEntity(new RequestRequestBuilder().withItemId(otherItemId).withNoPosition().withStatus(CLOSED_FILLED).create(), requestStorageUrl());
CompletableFuture<JsonResponse> getRequestsCompleted = new CompletableFuture<>();
String query = URLEncoder.encode(String.format("status=\"%s\"", OPEN_NOT_YET_FILLED), 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();
assertThat(wrappedRequests.getJsonArray("requests").size(), is(2));
assertThat(wrappedRequests.getInteger("totalRecords"), is(2));
}
use of org.folio.rest.support.builders.RequestRequestBuilder in project mod-circulation-storage by folio-org.
the class RequestExpirationApiTest method canExpireASingleOpenAwaitingPickupRequest.
@Test
public void canExpireASingleOpenAwaitingPickupRequest() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
UUID id = UUID.randomUUID();
UUID itemId = UUID.randomUUID();
createEntity(new RequestRequestBuilder().hold().withId(id).withHoldShelfExpirationDate(new DateTime(2017, 7, 30, 10, 22, 54, DateTimeZone.UTC)).withItemId(itemId).withPosition(1).withStatus(OPEN_AWAITING_PICKUP).create(), requestStorageUrl());
expireRequests();
List<JsonObject> events = Awaitility.await().atMost(10, TimeUnit.SECONDS).until(MockServer::getPublishedEvents, hasSize(1));
assertPublishedEvents(events);
JsonObject response = getById(requestStorageUrl(String.format("/%s", id)));
assertThat(response.getString("status"), is(CLOSED_PICKUP_EXPIRED));
assertThat(response.containsKey("position"), is(false));
}
Aggregations