use of org.folio.rest.support.TextResponse in project mod-circulation-storage by folio-org.
the class ValidationResponseMatchers method isValidationResponseWhich.
public static TypeSafeDiagnosingMatcher<JsonResponse> isValidationResponseWhich(Matcher<JsonObject> errorMatcher) {
return new TypeSafeDiagnosingMatcher<JsonResponse>() {
@Override
public void describeTo(Description description) {
description.appendText("A response with status code 422 and an error which ").appendDescriptionOf(errorMatcher);
}
@Override
protected boolean matchesSafely(JsonResponse response, Description description) {
final Matcher<TextResponse> statusCodeMatcher = isUnprocessableEntity();
if (!statusCodeMatcher.matches(response)) {
statusCodeMatcher.describeMismatch(response, description);
return false;
}
final TypeSafeDiagnosingMatcher<JsonObject> validationErrorsMatcher = hasErrorWith(errorMatcher);
final JsonObject body = response.getJson();
validationErrorsMatcher.describeMismatch(body, description);
return validationErrorsMatcher.matches(body);
}
};
}
use of org.folio.rest.support.TextResponse 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);
}
use of org.folio.rest.support.TextResponse 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.TextResponse 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"));
}
use of org.folio.rest.support.TextResponse in project mod-circulation-storage by folio-org.
the class RequestsApiTest method updatedRequestHasUpdatedMetadata.
@Test
public void updatedRequestHasUpdatedMetadata() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
UUID id = UUID.randomUUID();
JsonObject request = new RequestRequestBuilder().withId(id).create();
IndividualResource createResponse = createEntity(request, requestStorageUrl());
JsonObject createdRequest = createResponse.getJson();
JsonObject createdMetadata = createdRequest.getJsonObject(METADATA_PROPERTY);
CompletableFuture<TextResponse> updateCompleted = new CompletableFuture<>();
String updaterId = UUID.randomUUID().toString();
DateTime requestMade = DateTime.now();
client.put(requestStorageUrl(String.format("/%s", id)), request, TENANT_ID, updaterId, 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 updatedRequest = getById(requestStorageUrl(String.format("/%s", id)));
assertThat("Request should have metadata property", updatedRequest.containsKey(METADATA_PROPERTY), is(true));
JsonObject metadata = updatedRequest.getJsonObject(METADATA_PROPERTY);
assertThat("Request should have same created user", metadata.getString("createdByUserId"), is(createdMetadata.getString("createdByUserId")));
assertThat("Request should have same created date", metadata.getString("createdDate"), is(createdMetadata.getString("createdDate")));
assertThat("Request should have updated user", metadata.getString("updatedByUserId"), is(updaterId));
assertThat("Request should have updated date close to when request was made", metadata.getString("updatedDate"), is(withinSecondsAfter(Seconds.seconds(2), requestMade)));
assertThat("Request should have updated date different to original updated date", metadata.getString("updatedDate"), is(not(createdMetadata.getString("updatedDate"))));
assertUpdateEventForRequest(createdRequest, updatedRequest);
}
Aggregations