Search in sources :

Example 6 with TextResponse

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);
        }
    };
}
Also used : Description(org.hamcrest.Description) JsonObject(io.vertx.core.json.JsonObject) TextResponse(org.folio.rest.support.TextResponse) JsonResponse(org.folio.rest.support.JsonResponse) TypeSafeDiagnosingMatcher(org.hamcrest.TypeSafeDiagnosingMatcher)

Example 7 with TextResponse

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

Example 8 with TextResponse

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);
}
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 9 with TextResponse

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

Example 10 with TextResponse

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

Aggregations

TextResponse (org.folio.rest.support.TextResponse)13 Test (org.junit.Test)10 CompletableFuture (java.util.concurrent.CompletableFuture)9 JsonObject (io.vertx.core.json.JsonObject)8 UUID (java.util.UUID)6 DateTime (org.joda.time.DateTime)5 RequestRequestBuilder (org.folio.rest.support.builders.RequestRequestBuilder)4 IndividualResource (org.folio.rest.support.IndividualResource)3 JsonResponse (org.folio.rest.support.JsonResponse)3 Parameters (junitparams.Parameters)2 JsonArray (io.vertx.core.json.JsonArray)1 RequestsBatchAPI (org.folio.rest.impl.RequestsBatchAPI)1 Response (org.folio.rest.support.Response)1 ResponseHandler (org.folio.rest.support.ResponseHandler)1 LoanRequestBuilder (org.folio.rest.support.builders.LoanRequestBuilder)1 Description (org.hamcrest.Description)1 TypeSafeDiagnosingMatcher (org.hamcrest.TypeSafeDiagnosingMatcher)1 Ignore (org.junit.Ignore)1