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);
}
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());
}
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());
}
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));
}
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());
}
Aggregations