use of org.folio.rest.support.builders.RequestRequestBuilder in project mod-circulation-storage by folio-org.
the class RequestExpirationApiTest method canExpireAnFirstOpenUnfilledRequest.
@Test
public void canExpireAnFirstOpenUnfilledRequest() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
UUID id1_1 = UUID.randomUUID();
UUID id1_2 = UUID.randomUUID();
UUID id1_3 = UUID.randomUUID();
UUID id1_4 = UUID.randomUUID();
UUID id1_5 = UUID.randomUUID();
UUID id1_6 = UUID.randomUUID();
UUID itemId1 = UUID.randomUUID();
/* Status "Open - not yet filled" and request expiration date in the past - should be expired */
createEntity(new RequestRequestBuilder().hold().withId(id1_1).withRequestExpirationDate(new DateTime(2017, 7, 30, 10, 22, 54, DateTimeZone.UTC)).withItemId(itemId1).withPosition(1).withStatus(OPEN_NOT_YET_FILLED).create(), requestStorageUrl());
/* Status "Open - In transit" and request expiration date in the past - should NOT be expired */
createEntity(new RequestRequestBuilder().hold().withId(id1_2).withItemId(itemId1).withPosition(2).withStatus(OPEN_IN_TRANSIT).create(), requestStorageUrl());
/* Status "Open - not yet filled" and hold shelf expiration date in the past - should NOT be expired */
createEntity(new RequestRequestBuilder().hold().withId(id1_3).withHoldShelfExpirationDate(new DateTime(2017, 7, 30, 10, 22, 54, DateTimeZone.UTC)).withItemId(itemId1).withPosition(3).withStatus(OPEN_NOT_YET_FILLED).create(), requestStorageUrl());
createEntity(new RequestRequestBuilder().hold().withId(id1_4).withHoldShelfExpirationDate(new DateTime(2017, 7, 30, 10, 22, 54, DateTimeZone.UTC)).withItemId(itemId1).withPosition(4).withStatus(OPEN_NOT_YET_FILLED).create(), requestStorageUrl());
createEntity(new RequestRequestBuilder().hold().withId(id1_5).withHoldShelfExpirationDate(new DateTime(2017, 7, 30, 10, 22, 54, DateTimeZone.UTC)).withItemId(itemId1).withPosition(5).withStatus(OPEN_NOT_YET_FILLED).create(), requestStorageUrl());
createEntity(new RequestRequestBuilder().hold().withId(id1_6).withHoldShelfExpirationDate(new DateTime(2017, 7, 30, 10, 22, 54, DateTimeZone.UTC)).withItemId(itemId1).withPosition(6).withStatus(OPEN_NOT_YET_FILLED).create(), requestStorageUrl());
expireRequests();
JsonObject response1_1 = getById(requestStorageUrl(String.format("/%s", id1_1)));
JsonObject response1_2 = getById(requestStorageUrl(String.format("/%s", id1_2)));
JsonObject response1_3 = getById(requestStorageUrl(String.format("/%s", id1_3)));
JsonObject response1_4 = getById(requestStorageUrl(String.format("/%s", id1_4)));
JsonObject response1_5 = getById(requestStorageUrl(String.format("/%s", id1_5)));
JsonObject response1_6 = getById(requestStorageUrl(String.format("/%s", id1_6)));
assertThat(response1_1.getString("status"), is(CLOSED_UNFILLED));
assertThat(response1_1.containsKey("position"), is(false));
assertThat(response1_2.getString("status"), is(OPEN_IN_TRANSIT));
assertThat(response1_2.getInteger("position"), is(1));
assertThat(response1_3.getString("status"), is(OPEN_NOT_YET_FILLED));
assertThat(response1_3.getInteger("position"), is(2));
assertThat(response1_4.getString("status"), is(OPEN_NOT_YET_FILLED));
assertThat(response1_4.getInteger("position"), is(3));
assertThat(response1_5.getString("status"), is(OPEN_NOT_YET_FILLED));
assertThat(response1_5.getInteger("position"), is(4));
assertThat(response1_6.getString("status"), is(OPEN_NOT_YET_FILLED));
assertThat(response1_6.getInteger("position"), is(5));
}
use of org.folio.rest.support.builders.RequestRequestBuilder in project mod-circulation-storage by folio-org.
the class RequestsApiTest method cannotCreateRequestAtSpecificLocationForSameItemAndPosition.
@Test
public void cannotCreateRequestAtSpecificLocationForSameItemAndPosition() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
UUID itemId = UUID.randomUUID();
UUID secondRequestId = UUID.randomUUID();
createEntity(new RequestRequestBuilder().withItemId(itemId).withPosition(1).create(), requestStorageUrl());
JsonObject secondRequest = new RequestRequestBuilder().withId(secondRequestId).withItemId(itemId).withPosition(1).create();
CompletableFuture<JsonResponse> createCompleted = new CompletableFuture<>();
client.put(requestStorageUrl(String.format("/%s", secondRequestId)), secondRequest, TENANT_ID, ResponseHandler.json(createCompleted));
JsonResponse response = createCompleted.get(5, TimeUnit.SECONDS);
assertThat(response, isValidationResponseWhich(hasMessage("Cannot have more than one request with the same position in the queue")));
assertNoRequestEvent(secondRequest.getString("id"));
}
use of org.folio.rest.support.builders.RequestRequestBuilder in project mod-circulation-storage by folio-org.
the class RequestsApiTest method cannotCreateRequestForSameItemAndPosition.
@Test
public void cannotCreateRequestForSameItemAndPosition() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
UUID itemId = UUID.randomUUID();
createEntity(new RequestRequestBuilder().withItemId(itemId).withPosition(1).create(), requestStorageUrl());
CompletableFuture<JsonResponse> createCompleted = new CompletableFuture<>();
final JsonObject secondRequest = new RequestRequestBuilder().withItemId(itemId).withPosition(1).create();
client.post(requestStorageUrl(), secondRequest, TENANT_ID, ResponseHandler.json(createCompleted));
JsonResponse response = createCompleted.get(5, TimeUnit.SECONDS);
assertThat(response, isValidationResponseWhich(hasMessage("Cannot have more than one request with the same position in the queue")));
assertNoRequestEvent(secondRequest.getString("id"));
}
use of org.folio.rest.support.builders.RequestRequestBuilder in project mod-circulation-storage by folio-org.
the class RequestsApiTest method canGetARequestById.
@Test
public void canGetARequestById() 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);
DateTime requestExpirationDate = new DateTime(2017, 7, 30, 0, 0, DateTimeZone.UTC);
DateTime holdShelfExpirationDate = new DateTime(2017, 8, 31, 0, 0, DateTimeZone.UTC);
createEntity(new RequestRequestBuilder().recall().withId(id).withRequestDate(requestDate).withItemId(itemId).withRequesterId(requesterId).toHoldShelf().withRequestExpirationDate(requestExpirationDate).withHoldShelfExpirationDate(holdShelfExpirationDate).withItem("Nod", "565578437802").withRequester("Jones", "Stuart", "Anthony", "6837502674015").withPosition(3).create(), requestStorageUrl());
JsonObject representation = getById(requestStorageUrl(String.format("/%s", id)));
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.getString("requestExpirationDate"), is(equivalentTo(requestExpirationDate)));
assertThat(representation.getString("holdShelfExpirationDate"), is(equivalentTo(holdShelfExpirationDate)));
assertThat(representation.getInteger("position"), is(3));
assertThat(representation.containsKey("item"), is(true));
assertThat(representation.getJsonObject("item").getString("barcode"), is("565578437802"));
assertThat(representation.containsKey("instance"), is(true));
assertThat(representation.getJsonObject("instance").getString("title"), is("Nod"));
assertThat(representation.containsKey("requester"), is(true));
assertThat(representation.getJsonObject("requester").getString("lastName"), is("Jones"));
assertThat(representation.getJsonObject("requester").getString("firstName"), is("Stuart"));
assertThat(representation.getJsonObject("requester").getString("middleName"), is("Anthony"));
assertThat(representation.getJsonObject("requester").getString("barcode"), is("6837502674015"));
}
use of org.folio.rest.support.builders.RequestRequestBuilder in project mod-circulation-storage by folio-org.
the class RequestsApiTest method canFindRequestsWithIsbnIdentifier.
@Test
public void canFindRequestsWithIsbnIdentifier() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
final UUID nodRequestId = UUID.randomUUID();
final UUID smallAngryPlanetRequestId = UUID.randomUUID();
final UUID issnIdentifierId = UUID.randomUUID();
final UUID isbnIdentifierId = UUID.randomUUID();
final UUID bnbIdentifierId = UUID.randomUUID();
final String isbn = "978-92-8011-566-10";
final RequestItemSummary nod = new RequestItemSummary("Nod", "565578437802").addIdentifier(issnIdentifierId, "978-92-8011-566-9").addIdentifier(bnbIdentifierId, "2193988").addIdentifier(isbnIdentifierId, isbn);
final RequestItemSummary smallAngryPlanet = new RequestItemSummary("SAP", "565578437803").addIdentifier(isbnIdentifierId, isbn).addIdentifier(bnbIdentifierId, "2193989");
final RequestItemSummary temeraire = new RequestItemSummary("Temeraire", "565578437804");
createEntity(new RequestRequestBuilder().withId(nodRequestId).recall().toHoldShelf().withItem(nod).create(), requestStorageUrl());
createEntity(new RequestRequestBuilder().withId(smallAngryPlanetRequestId).recall().toHoldShelf().withItem(smallAngryPlanet).create(), requestStorageUrl());
createEntity(new RequestRequestBuilder().withId(UUID.randomUUID()).recall().toHoldShelf().withItem(temeraire).create(), requestStorageUrl());
List<JsonObject> isbnRequests = findRequestsByQuery("instance.identifiers = %s and instance.identifiers = %s", isbnIdentifierId, isbn);
assertThat(isbnRequests.size(), is(2));
assertThat(isbnRequests.get(0).getString("id"), is(nodRequestId.toString()));
assertThat(isbnRequests.get(1).getString("id"), is(smallAngryPlanetRequestId.toString()));
}
Aggregations