Search in sources :

Example 6 with RequestRequestBuilder

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

Example 7 with RequestRequestBuilder

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

Example 8 with RequestRequestBuilder

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);
}
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 9 with RequestRequestBuilder

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));
}
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 10 with RequestRequestBuilder

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