use of org.folio.rest.support.builders.RequestRequestBuilder in project mod-circulation-storage by folio-org.
the class RequestsApiTest method canCreateARequestToBeFulfilledByDeliveryToAnAddress.
@Test
public void canCreateARequestToBeFulfilledByDeliveryToAnAddress() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
UUID id = UUID.randomUUID();
UUID deliveryAddressTypeId = UUID.randomUUID();
JsonObject representation = createEntity(new RequestRequestBuilder().recall().deliverToAddress(deliveryAddressTypeId).withId(id).create(), requestStorageUrl()).getJson();
assertThat(representation.getString("id"), is(id.toString()));
assertThat(representation.getString("requestType"), is("Recall"));
assertThat(representation.getString("fulfilmentPreference"), is("Delivery"));
assertThat(representation.getString("deliveryAddressTypeId"), is(deliveryAddressTypeId.toString()));
CompletableFuture<JsonResponse> getCompleted = new CompletableFuture<>();
client.get(requestStorageUrl() + String.format("/%s", representation.getString("id")), TENANT_ID, ResponseHandler.json(getCompleted));
JsonResponse getResponse = getCompleted.get(5, TimeUnit.SECONDS);
assertThat(String.format("Failed to get request: %s", getResponse.getBody()), getResponse.getStatusCode(), is(HttpURLConnection.HTTP_OK));
JsonObject fetchedRepresentation = getResponse.getJson();
assertThat(fetchedRepresentation.getString("id"), is(id.toString()));
assertThat(fetchedRepresentation.getString("requestType"), is("Recall"));
assertThat(fetchedRepresentation.getString("fulfilmentPreference"), is("Delivery"));
assertThat(fetchedRepresentation.getString("deliveryAddressTypeId"), is(deliveryAddressTypeId.toString()));
assertCreateEventForRequest(representation);
}
use of org.folio.rest.support.builders.RequestRequestBuilder in project mod-circulation-storage by folio-org.
the class RequestsApiTest method cannotPutTitleLevelRequestIfOneOfItemIdAndHoldingsRecordIdIsNotPresent.
@Test
@Parameters({ "holdingsRecordId", "itemId" })
public void cannotPutTitleLevelRequestIfOneOfItemIdAndHoldingsRecordIdIsNotPresent(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.put(requestStorageUrl(String.format("/%s", request.getString("id"))), 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")));
}
use of org.folio.rest.support.builders.RequestRequestBuilder in project mod-circulation-storage by folio-org.
the class RequestsApiTest method canSearchForActiveRequestsForAnItem.
@Test
public void canSearchForActiveRequestsForAnItem() 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("itemId==%s and status==(\"%s\" or \"%s\" or \"%s\" or \"%s\")", itemId, OPEN_NOT_YET_FILLED, OPEN_AWAITING_PICKUP, OPEN_IN_TRANSIT, OPEN_AWAITING_DELIVERY), 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(4));
assertThat(wrappedRequests.getInteger("totalRecords"), is(4));
}
use of org.folio.rest.support.builders.RequestRequestBuilder in project mod-circulation-storage by folio-org.
the class RequestsApiTest method canDeleteARequest.
@Test
public void canDeleteARequest() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
CompletableFuture<JsonResponse> createCompleted = new CompletableFuture<>();
UUID id = UUID.randomUUID();
JsonObject request = createEntity(new RequestRequestBuilder().withId(id).create(), requestStorageUrl()).getJson();
client.delete(requestStorageUrl(String.format("/%s", id)), TENANT_ID, ResponseHandler.json(createCompleted));
JsonResponse createResponse = createCompleted.get(5, TimeUnit.SECONDS);
assertThat(String.format("Failed to delete request: %s", createResponse.getBody()), createResponse.getStatusCode(), is(HttpURLConnection.HTTP_NO_CONTENT));
checkNotFound(requestStorageUrl(String.format("/%s", id)));
assertRemoveEventForRequest(request);
}
use of org.folio.rest.support.builders.RequestRequestBuilder in project mod-circulation-storage by folio-org.
the class RequestsApiTest method canUpdateARequestWithValidStatus.
@Test
@Parameters({ "Open - Awaiting pickup", "Closed - Filled" })
public void canUpdateARequestWithValidStatus(String status) 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);
createEntity(new RequestRequestBuilder().recall().withId(id).withRequestDate(requestDate).withItemId(itemId).withRequesterId(requesterId).toHoldShelf().withItem("Nod", "565578437802").withRequester("Jones", "Stuart", "Anthony", "6837502674015").withStatus("Open - Not yet filled").create(), requestStorageUrl());
JsonObject getAfterCreateResponse = getById(requestStorageUrl(String.format("/%s", id)));
CompletableFuture<TextResponse> updateCompleted = new CompletableFuture<>();
JsonObject updateRequestRequest = getAfterCreateResponse.copy().put("status", status);
client.put(requestStorageUrl(String.format("/%s", id)), updateRequestRequest, TENANT_ID, ResponseHandler.text(updateCompleted));
TextResponse response = updateCompleted.get(5, TimeUnit.SECONDS);
assertThat(String.format("Failed to update request: %s", response.getBody()), response.getStatusCode(), is(HttpURLConnection.HTTP_NO_CONTENT));
JsonObject representation = getById(requestStorageUrl(String.format("/%s", id)));
assertThat(representation.getString("status"), is(status));
assertUpdateEventForRequest(getAfterCreateResponse, representation);
}
Aggregations