Search in sources :

Example 11 with RequestRequestBuilder

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));
}
Also used : RequestRequestBuilder(org.folio.rest.support.builders.RequestRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 12 with RequestRequestBuilder

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"));
}
Also used : RequestRequestBuilder(org.folio.rest.support.builders.RequestRequestBuilder) CompletableFuture(java.util.concurrent.CompletableFuture) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 13 with RequestRequestBuilder

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"));
}
Also used : RequestRequestBuilder(org.folio.rest.support.builders.RequestRequestBuilder) CompletableFuture(java.util.concurrent.CompletableFuture) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 14 with RequestRequestBuilder

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"));
}
Also used : RequestRequestBuilder(org.folio.rest.support.builders.RequestRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 15 with RequestRequestBuilder

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()));
}
Also used : RequestRequestBuilder(org.folio.rest.support.builders.RequestRequestBuilder) RequestItemSummary(org.folio.rest.support.builders.RequestItemSummary) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

RequestRequestBuilder (org.folio.rest.support.builders.RequestRequestBuilder)51 JsonObject (io.vertx.core.json.JsonObject)50 Test (org.junit.Test)49 UUID (java.util.UUID)37 CompletableFuture (java.util.concurrent.CompletableFuture)28 JsonResponse (org.folio.rest.support.JsonResponse)23 DateTime (org.joda.time.DateTime)23 Parameters (junitparams.Parameters)9 TextResponse (org.folio.rest.support.TextResponse)9 IndividualResource (org.folio.rest.support.IndividualResource)5 Response (org.folio.rest.support.Response)5 RequestItemSummary (org.folio.rest.support.builders.RequestItemSummary)5 JsonArray (io.vertx.core.json.JsonArray)4 MockServer (org.folio.support.MockServer)4 Tags (org.folio.rest.jaxrs.model.Tags)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 HttpURLConnection (java.net.HttpURLConnection)2 HTTP_CREATED (java.net.HttpURLConnection.HTTP_CREATED)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2