Search in sources :

Example 36 with JsonResponse

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

the class AssertingRecordClient method getAll.

public MultipleRecords<JsonObject> getAll() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    final CompletableFuture<JsonResponse> fetchManyCompleted = new CompletableFuture<>();
    this.client.get(urlMaker.combine(""), StorageTestSuite.TENANT_ID, ResponseHandler.json(fetchManyCompleted));
    final JsonResponse fetchedLoansResponse = fetchManyCompleted.get(5, TimeUnit.SECONDS);
    assertThat(fetchedLoansResponse, isOk());
    return MultipleRecords.fromJson(fetchedLoansResponse.getJson(), collectionPropertyName);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) JsonResponse(org.folio.rest.support.JsonResponse)

Example 37 with JsonResponse

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

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

the class RequestPreferencesApiTest method cannotDeleteRequestPreferenceByNotExistingId.

@Test
public void cannotDeleteRequestPreferenceByNotExistingId() {
    JsonResponse response = deletePreference(UUID.randomUUID().toString());
    assertThat(response, isNotFound());
}
Also used : JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 39 with JsonResponse

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

the class RequestPreferencesApiTest method cannotUpdateRequestPreferenceWithDuplicateUserId.

@Test
public void cannotUpdateRequestPreferenceWithDuplicateUserId() {
    createRequestPreference(USER_ID);
    RequestPreference secondPreference = createRequestPreference(USER_ID2).getJson().mapTo(RequestPreference.class);
    JsonResponse response = updatePreference(constructDefaultPreference(USER_ID).withId(secondPreference.getId()));
    assertThat(response, isUnprocessableEntity());
    assertThat(response.getJson().toString(), containsString("Request preference for specified user already exists"));
}
Also used : RequestPreference(org.folio.rest.jaxrs.model.RequestPreference) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 40 with JsonResponse

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

the class RequestPreferencesApiTest method cannotUpdateRequestPreferenceWithNotExistingId.

@Test
public void cannotUpdateRequestPreferenceWithNotExistingId() {
    RequestPreference preference = constructDefaultPreference(USER_ID).withId(UUID.randomUUID().toString());
    JsonResponse response = updatePreference(preference);
    assertThat(response, isNotFound());
}
Also used : RequestPreference(org.folio.rest.jaxrs.model.RequestPreference) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Aggregations

JsonResponse (org.folio.rest.support.JsonResponse)156 Test (org.junit.Test)133 JsonObject (io.vertx.core.json.JsonObject)91 CompletableFuture (java.util.concurrent.CompletableFuture)91 UUID (java.util.UUID)52 RequestRequestBuilder (org.folio.rest.support.builders.RequestRequestBuilder)20 JsonArray (io.vertx.core.json.JsonArray)19 RequestPolicy (org.folio.rest.jaxrs.model.RequestPolicy)18 IndividualResource (org.folio.rest.support.IndividualResource)15 LoanRequestBuilder (org.folio.rest.support.builders.LoanRequestBuilder)12 URL (java.net.URL)11 RequestType (org.folio.rest.jaxrs.model.RequestType)10 RequestPreference (org.folio.rest.jaxrs.model.RequestPreference)9 StaffSlipRequestBuilder (org.folio.rest.support.builders.StaffSlipRequestBuilder)9 Response (org.folio.rest.support.Response)8 ResponseHandler (org.folio.rest.support.ResponseHandler)8 DateTime (org.joda.time.DateTime)7 MalformedURLException (java.net.MalformedURLException)6 ExecutionException (java.util.concurrent.ExecutionException)6 TimeoutException (java.util.concurrent.TimeoutException)6