Search in sources :

Example 21 with RequestRequestBuilder

use of org.folio.rest.support.builders.RequestRequestBuilder in project mod-circulation-storage by folio-org.

the class RequestsApiTest method canCreateMultipleRequestsForDifferentItemsWithSamePosition.

@Test
public void canCreateMultipleRequestsForDifferentItemsWithSamePosition() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    UUID firstItemId = UUID.randomUUID();
    UUID secondItemId = UUID.randomUUID();
    JsonObject representation = createEntity(new RequestRequestBuilder().withItemId(firstItemId).withPosition(1).create(), requestStorageUrl()).getJson();
    assertThat(representation.getString("id"), is(notNullValue()));
    JsonObject representation2 = createEntity(new RequestRequestBuilder().withItemId(firstItemId).withPosition(2).create(), requestStorageUrl()).getJson();
    assertThat(representation2.getString("id"), is(notNullValue()));
    JsonObject representation3 = createEntity(new RequestRequestBuilder().withItemId(secondItemId).withPosition(1).create(), requestStorageUrl()).getJson();
    assertThat(representation3.getString("id"), is(notNullValue()));
    JsonObject representation4 = createEntity(new RequestRequestBuilder().withItemId(secondItemId).withPosition(2).create(), requestStorageUrl()).getJson();
    assertThat(representation4.getString("id"), is(notNullValue()));
}
Also used : RequestRequestBuilder(org.folio.rest.support.builders.RequestRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) Test(org.junit.Test)

Example 22 with RequestRequestBuilder

use of org.folio.rest.support.builders.RequestRequestBuilder in project mod-circulation-storage by folio-org.

the class RequestsApiTest method canCreateARequestWithPatronComments.

@Test
public void canCreateARequestWithPatronComments() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    JsonObject representation = createEntity(new RequestRequestBuilder().withPatronComments(PATRON_COMMENTS).create(), requestStorageUrl()).getJson();
    assertThat(representation.getString("patronComments"), is(PATRON_COMMENTS));
}
Also used : RequestRequestBuilder(org.folio.rest.support.builders.RequestRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 23 with RequestRequestBuilder

use of org.folio.rest.support.builders.RequestRequestBuilder in project mod-circulation-storage by folio-org.

the class RequestsApiTest method cannotCreateARequestWithInvalidStatus.

@Test
@Parameters({ "Non-existent status", "" })
public void cannotCreateARequestWithInvalidStatus(String status) throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    CompletableFuture<JsonResponse> createCompleted = new CompletableFuture<>();
    JsonObject requestRequest = new RequestRequestBuilder().withStatus(status).create();
    client.post(requestStorageUrl(), requestRequest, TENANT_ID, ResponseHandler.json(createCompleted));
    JsonResponse response = createCompleted.get(5, TimeUnit.SECONDS);
    assertThat(String.format("Should not create request: %s", response.getBody()), response.getStatusCode(), is(HttpURLConnection.HTTP_BAD_REQUEST));
}
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) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 24 with RequestRequestBuilder

use of org.folio.rest.support.builders.RequestRequestBuilder in project mod-circulation-storage by folio-org.

the class RequestsApiTest method awaitingPickupRequestClosedDateIsNotPresentAfterStatusUpdateFromOpenNotYetFilledToClosedCancelled.

@Test
public void awaitingPickupRequestClosedDateIsNotPresentAfterStatusUpdateFromOpenNotYetFilledToClosedCancelled() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    JsonObject request = new RequestRequestBuilder().withStatus(OPEN_NOT_YET_FILLED).create();
    String requestId = createEntity(request, requestStorageUrl()).getJson().getString("id");
    request.put("status", CLOSED_CANCELLED);
    CompletableFuture<Response> putCompleted = new CompletableFuture<>();
    client.put(requestStorageUrl("/" + requestId), request, TENANT_ID, ResponseHandler.empty(putCompleted));
    putCompleted.get(5, TimeUnit.SECONDS);
    JsonObject updatedRequest = getById(requestStorageUrl("/" + requestId));
    assertThat(updatedRequest.getString("awaitingPickupRequestClosedDate"), is(nullValue()));
}
Also used : JsonResponse(org.folio.rest.support.JsonResponse) Response(org.folio.rest.support.Response) TextResponse(org.folio.rest.support.TextResponse) RequestRequestBuilder(org.folio.rest.support.builders.RequestRequestBuilder) CompletableFuture(java.util.concurrent.CompletableFuture) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 25 with RequestRequestBuilder

use of org.folio.rest.support.builders.RequestRequestBuilder in project mod-circulation-storage by folio-org.

the class RequestsApiTest method canCreateARequestAtASpecificLocation.

@Test
public void canCreateARequestAtASpecificLocation() 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("Smith", "Jessica", "721076398251").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.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("Smith"));
    assertThat(representation.getJsonObject("requester").getString("firstName"), is("Jessica"));
    assertThat(representation.getJsonObject("requester").containsKey("middleName"), is(false));
    assertThat(representation.getJsonObject("requester").getString("barcode"), is("721076398251"));
}
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)

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