Search in sources :

Example 21 with IndividualResource

use of org.folio.rest.support.IndividualResource 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 22 with IndividualResource

use of org.folio.rest.support.IndividualResource in project mod-inventory-storage by folio-org.

the class InstanceStorageTest method canUpdateInstanceWithDiscoverySuppressProperty.

@Test
public void canUpdateInstanceWithDiscoverySuppressProperty() throws Exception {
    IndividualResource instance = createInstance(smallAngryPlanet(UUID.randomUUID()));
    assertThat(instance.getJson().getBoolean(DISCOVERY_SUPPRESS), is(false));
    final IndividualResource updateInstance = updateInstance(getById(instance.getId()).getJson().copy().put(DISCOVERY_SUPPRESS, true));
    assertSuppressedFromDiscovery(instance.getId().toString());
    assertUpdateEventForInstance(instance.getJson(), updateInstance.getJson());
}
Also used : IndividualResource(org.folio.rest.support.IndividualResource) Test(org.junit.Test)

Example 23 with IndividualResource

use of org.folio.rest.support.IndividualResource in project mod-inventory-storage by folio-org.

the class InstanceStorageTest method canPostDiscoverySuppressedInstance.

@Test
public void canPostDiscoverySuppressedInstance() throws Exception {
    IndividualResource instance = createInstance(smallAngryPlanet(UUID.randomUUID()).put(DISCOVERY_SUPPRESS, true));
    assertThat(instance.getJson().getBoolean(DISCOVERY_SUPPRESS), is(true));
    assertSuppressedFromDiscovery(instance.getId().toString());
}
Also used : IndividualResource(org.folio.rest.support.IndividualResource) Test(org.junit.Test)

Example 24 with IndividualResource

use of org.folio.rest.support.IndividualResource in project mod-inventory-storage by folio-org.

the class InstanceStorageTest method canReplaceAnInstanceAtSpecificLocation.

@Test
public void canReplaceAnInstanceAtSpecificLocation() throws InterruptedException, ExecutionException, TimeoutException {
    UUID id = UUID.randomUUID();
    String adminNote = "An Admin note";
    final IndividualResource createdInstance = createInstance(smallAngryPlanet(id));
    JsonObject replacement = createdInstance.copyJson();
    replacement.put("title", "A Long Way to a Small Angry Planet");
    replacement.put("administrativeNotes", new JsonArray().add(adminNote));
    CompletableFuture<Response> replaceCompleted = new CompletableFuture<>();
    client.put(instancesStorageUrl(String.format("/%s", id)), replacement, TENANT_ID, ResponseHandler.empty(replaceCompleted));
    Response putResponse = replaceCompleted.get(5, SECONDS);
    // PUT currently cannot return a response
    assertThat(putResponse.getStatusCode(), is(HttpURLConnection.HTTP_NO_CONTENT));
    Response updatedInstance = getById(id);
    assertThat(updatedInstance.getStatusCode(), is(HTTP_OK));
    JsonObject itemFromGet = updatedInstance.getJson();
    assertThat(itemFromGet.getString("id"), is(id.toString()));
    assertThat(itemFromGet.getString("title"), is("A Long Way to a Small Angry Planet"));
    assertThat(itemFromGet.getString(STATUS_UPDATED_DATE_PROPERTY), is(replacement.getString(STATUS_UPDATED_DATE_PROPERTY)));
    assertThat(itemFromGet.getBoolean(DISCOVERY_SUPPRESS), is(false));
    assertUpdateEventForInstance(createdInstance.getJson(), updatedInstance.getJson());
    assertThat(itemFromGet.getJsonArray("administrativeNotes").contains(adminNote), is(true));
}
Also used : JsonArray(io.vertx.core.json.JsonArray) JsonErrorResponse(org.folio.rest.support.JsonErrorResponse) InstancesBatchResponse(org.folio.rest.jaxrs.model.InstancesBatchResponse) Response(org.folio.rest.support.Response) CompletableFuture(java.util.concurrent.CompletableFuture) JsonObject(io.vertx.core.json.JsonObject) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) UUID(java.util.UUID) IndividualResource(org.folio.rest.support.IndividualResource) Test(org.junit.Test)

Example 25 with IndividualResource

use of org.folio.rest.support.IndividualResource in project mod-inventory-storage by folio-org.

the class InstanceStorageTest method canUpdateInstanceWithPublicationPeriod.

@Test
public void canUpdateInstanceWithPublicationPeriod() throws Exception {
    var entity = smallAngryPlanet(UUID.randomUUID()).mapTo(Instance.class).withPublication(Collections.singletonList(new Publication().withDateOfPublication("1997")));
    IndividualResource instance = createInstance(JsonObject.mapFrom(entity));
    entity = instance.getJson().mapTo(Instance.class).withPublication(Collections.singletonList(new Publication().withDateOfPublication("2006")));
    final IndividualResource updateInstance = updateInstance(JsonObject.mapFrom(entity));
    assertEquals(Integer.valueOf(2006), updateInstance.getJson().mapTo(Instance.class).getPublicationPeriod().getStart());
}
Also used : DomainEventAssertions.assertRemoveAllEventForInstance(org.folio.rest.support.matchers.DomainEventAssertions.assertRemoveAllEventForInstance) DomainEventAssertions.assertRemoveEventForInstance(org.folio.rest.support.matchers.DomainEventAssertions.assertRemoveEventForInstance) DomainEventAssertions.assertCreateEventForInstance(org.folio.rest.support.matchers.DomainEventAssertions.assertCreateEventForInstance) Instance(org.folio.rest.jaxrs.model.Instance) DomainEventAssertions.assertUpdateEventForInstance(org.folio.rest.support.matchers.DomainEventAssertions.assertUpdateEventForInstance) Publication(org.folio.rest.jaxrs.model.Publication) IndividualResource(org.folio.rest.support.IndividualResource) Test(org.junit.Test)

Aggregations

IndividualResource (org.folio.rest.support.IndividualResource)89 Test (org.junit.Test)73 JsonObject (io.vertx.core.json.JsonObject)44 UUID (java.util.UUID)37 Response (org.folio.rest.support.Response)20 CompletableFuture (java.util.concurrent.CompletableFuture)19 JsonArray (io.vertx.core.json.JsonArray)17 JsonResponse (org.folio.rest.support.JsonResponse)17 LoanRequestBuilder (org.folio.rest.support.builders.LoanRequestBuilder)17 DateTime (org.joda.time.DateTime)12 PrecedingSucceedingTitle (org.folio.rest.api.entities.PrecedingSucceedingTitle)11 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)11 TextResponse (org.folio.rest.support.TextResponse)7 ItemRequestBuilder (org.folio.rest.support.builders.ItemRequestBuilder)7 InstancesBatchResponse (org.folio.rest.jaxrs.model.InstancesBatchResponse)6 JsonErrorResponse (org.folio.rest.support.JsonErrorResponse)6 TRUE (java.lang.Boolean.TRUE)4 HttpURLConnection (java.net.HttpURLConnection)4 MalformedURLException (java.net.MalformedURLException)4 DateFormat (java.text.DateFormat)4