Search in sources :

Example 16 with RequestRequestBuilder

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

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

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

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

Example 20 with RequestRequestBuilder

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