Search in sources :

Example 26 with RequestRequestBuilder

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

the class RequestsApiTest method awaitingPickupRequestClosedDateIsPresentAfterStatusUpdateFromOpenAwaitingPickupToClosedCancelled.

@Test
public void awaitingPickupRequestClosedDateIsPresentAfterStatusUpdateFromOpenAwaitingPickupToClosedCancelled() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    JsonObject request = new RequestRequestBuilder().withStatus(OPEN_AWAITING_PICKUP).create();
    String requestId = createEntity(request, requestStorageUrl()).getJson().getString("id");
    request.put("status", CLOSED_CANCELLED);
    DateTime requestUpdatedDate = DateTime.now();
    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(notNullValue()));
    assertThat(updatedRequest.getString("awaitingPickupRequestClosedDate"), is(withinSecondsAfter(Seconds.seconds(2), requestUpdatedDate)));
}
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) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 27 with RequestRequestBuilder

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

the class RequestsApiTest method canCreateMultipleRequestsForSameItemWithNoPosition.

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

Example 28 with RequestRequestBuilder

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

the class RequestsApiTest method canCreateARequest.

@Test
@Parameters({ "Title", "Item" })
public void canCreateARequest(String requestLevel) throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    UUID id = UUID.randomUUID();
    UUID itemId = UUID.randomUUID();
    UUID requesterId = UUID.randomUUID();
    UUID proxyId = UUID.randomUUID();
    UUID holdingsRecordId = UUID.randomUUID();
    UUID instanceId = UUID.randomUUID();
    UUID pickupServicePointId = 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);
    UUID isbnIdentifierId = UUID.randomUUID();
    UUID issnIdentifierId = UUID.randomUUID();
    final RequestItemSummary nod = new RequestItemSummary("Nod", "565578437802").addIdentifier(isbnIdentifierId, "978-92-8011-566-9").addIdentifier(issnIdentifierId, "2193988");
    JsonObject representation = createEntity(new RequestRequestBuilder().recall().toHoldShelf().withId(id).withRequestDate(requestDate).withItemId(itemId).withRequesterId(requesterId).withProxyId(proxyId).withRequestExpirationDate(requestExpirationDate).withHoldShelfExpirationDate(holdShelfExpirationDate).withRequestLevel(requestLevel).withItem(nod).withHoldingsRecordId(holdingsRecordId).withInstanceId(instanceId).withRequester("Jones", "Stuart", "Anthony", "6837502674015").withProxy("Stuart", "Rebecca", "6059539205").withStatus(OPEN_NOT_YET_FILLED).withPosition(1).withPickupServicePointId(pickupServicePointId).withTags(new Tags().withTagList(asList("new", "important"))).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("instanceId"), is(instanceId.toString()));
    assertThat(representation.getString("holdingsRecordId"), is(holdingsRecordId.toString()));
    assertThat(representation.getString("requesterId"), is(requesterId.toString()));
    assertThat(representation.getString("proxyUserId"), is(proxyId.toString()));
    assertThat(representation.getString("fulfilmentPreference"), is("Hold Shelf"));
    assertThat(representation.getString("requestExpirationDate"), is(equivalentTo(requestExpirationDate)));
    assertThat(representation.getString("holdShelfExpirationDate"), is(equivalentTo(holdShelfExpirationDate)));
    assertThat(representation.getString("status"), is(OPEN_NOT_YET_FILLED));
    assertThat(representation.getInteger("position"), is(1));
    assertThat(representation.getString("pickupServicePointId"), is(pickupServicePointId.toString()));
    assertThat(representation.containsKey("patronComments"), is(false));
    assertThat(representation.containsKey("item"), is(true));
    JsonObject item = representation.getJsonObject("item");
    assertThat(item.getString("barcode"), is("565578437802"));
    assertThat(representation.containsKey("instance"), is(true));
    JsonObject instance = representation.getJsonObject("instance");
    assertThat(instance.getString("title"), is("Nod"));
    JsonArray identifiers = instance.getJsonArray("identifiers");
    assertThat(identifiers.size(), is(2));
    assertThat(identifiers.getJsonObject(0).getString("identifierTypeId"), is(isbnIdentifierId.toString()));
    assertThat(identifiers.getJsonObject(0).getString("value"), is("978-92-8011-566-9"));
    assertThat(identifiers.getJsonObject(1).getString("identifierTypeId"), is(issnIdentifierId.toString()));
    assertThat(identifiers.getJsonObject(1).getString("value"), is("2193988"));
    assertThat(representation.containsKey("requester"), is(true));
    final JsonObject requesterRepresentation = representation.getJsonObject("requester");
    assertThat(requesterRepresentation.getString("lastName"), is("Jones"));
    assertThat(requesterRepresentation.getString("firstName"), is("Stuart"));
    assertThat(requesterRepresentation.getString("middleName"), is("Anthony"));
    assertThat(requesterRepresentation.getString("barcode"), is("6837502674015"));
    assertThat("has information taken from proxying user", representation.containsKey("proxy"), is(true));
    final JsonObject proxyRepresentation = representation.getJsonObject("proxy");
    assertThat("last name is taken from proxying user", proxyRepresentation.getString("lastName"), is("Stuart"));
    assertThat("first name is taken from proxying user", proxyRepresentation.getString("firstName"), is("Rebecca"));
    assertThat("middle name is not taken from proxying user", proxyRepresentation.containsKey("middleName"), is(false));
    assertThat("barcode is taken from proxying user", proxyRepresentation.getString("barcode"), is("6059539205"));
    assertThat(representation.containsKey("tags"), is(true));
    final JsonObject tagsRepresentation = representation.getJsonObject("tags");
    assertThat(tagsRepresentation.containsKey("tagList"), is(true));
    assertThat(tagsRepresentation.getJsonArray("tagList"), contains("new", "important"));
    assertCreateEventForRequest(representation);
}
Also used : JsonArray(io.vertx.core.json.JsonArray) RequestRequestBuilder(org.folio.rest.support.builders.RequestRequestBuilder) RequestItemSummary(org.folio.rest.support.builders.RequestItemSummary) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) DateTime(org.joda.time.DateTime) Tags(org.folio.rest.jaxrs.model.Tags) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 29 with RequestRequestBuilder

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

the class RequestsApiTest method canUpdateAnExistingRequestAtASpecificLocation.

@Test
public void canUpdateAnExistingRequestAtASpecificLocation() 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);
    IndividualResource creationResponse = createEntity(new RequestRequestBuilder().recall().withId(id).withRequestDate(requestDate).withItemId(itemId).withRequesterId(requesterId).toHoldShelf().withItem("Nod", "565578437802").withRequester("Jones", "Stuart", "Anthony", "6837502674015").withPosition(1).create(), requestStorageUrl());
    JsonObject createdRequest = creationResponse.getJson();
    JsonObject getAfterCreateResponse = getById(requestStorageUrl(String.format("/%s", id)));
    CompletableFuture<TextResponse> updateCompleted = new CompletableFuture<>();
    UUID newRequesterId = UUID.randomUUID();
    UUID proxyId = UUID.randomUUID();
    JsonObject updateRequestRequest = getAfterCreateResponse.copy().put("requesterId", newRequesterId.toString()).put("proxyUserId", proxyId.toString()).put("position", 2).put("requester", new JsonObject().put("lastName", "Smith").put("firstName", "Jessica").put("barcode", "721076398251")).put("proxy", new JsonObject().put("lastName", "Stuart").put("firstName", "Rebecca").put("barcode", "6059539205")).put("requestExpirationDate", requestExpirationDate.toString(ISODateTimeFormat.dateTime())).put("holdShelfExpirationDate", holdShelfExpirationDate.toString(ISODateTimeFormat.dateTime()));
    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("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(newRequesterId.toString()));
    assertThat(representation.getString("proxyUserId"), is(proxyId.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(2));
    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));
    final JsonObject requesterRepresentation = representation.getJsonObject("requester");
    assertThat(requesterRepresentation.getString("lastName"), is("Smith"));
    assertThat(requesterRepresentation.getString("firstName"), is("Jessica"));
    assertThat(requesterRepresentation.containsKey("middleName"), is(false));
    assertThat(requesterRepresentation.getString("barcode"), is("721076398251"));
    assertThat("has information taken from proxying user", representation.containsKey("proxy"), is(true));
    final JsonObject proxyRepresentation = representation.getJsonObject("proxy");
    assertThat("last name is taken from proxying user", proxyRepresentation.getString("lastName"), is("Stuart"));
    assertThat("first name is taken from proxying user", proxyRepresentation.getString("firstName"), is("Rebecca"));
    assertThat("middle name is not taken from proxying user", proxyRepresentation.containsKey("middleName"), is(false));
    assertThat("barcode is taken from proxying user", proxyRepresentation.getString("barcode"), is("6059539205"));
    assertUpdateEventForRequest(createdRequest, 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) IndividualResource(org.folio.rest.support.IndividualResource) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 30 with RequestRequestBuilder

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

the class RequestsApiTest method cannotUpdateARequestWithInvalidStatus.

@Test
@Parameters({ "Non-existent status", "" })
public void cannotUpdateARequestWithInvalidStatus(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("Should fail to update request: %s", response.getBody()), response.getStatusCode(), is(HttpURLConnection.HTTP_BAD_REQUEST));
    JsonObject representation = getById(requestStorageUrl(String.format("/%s", id)));
    assertThat(representation.getString("status"), is("Open - Not yet filled"));
}
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