Search in sources :

Example 1 with Response

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

the class LoanTypesClient method create.

public String create(String name) throws InterruptedException, ExecutionException, TimeoutException {
    CompletableFuture<Response> completed = new CompletableFuture<>();
    JsonObject loanTypeRequest = new JsonObject().put("name", name);
    client.post(loanTypesUrl, loanTypeRequest, StorageTestSuite.TENANT_ID, ResponseHandler.json(completed));
    Response response = completed.get(5, TimeUnit.SECONDS);
    return response.getJson().getString("id");
}
Also used : Response(org.folio.rest.support.Response) CompletableFuture(java.util.concurrent.CompletableFuture) JsonObject(io.vertx.core.json.JsonObject)

Example 2 with Response

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

the class LoanTypeTest method send.

private JsonObject send(URL url, HttpMethod method, String content, int expectedStatusCode) {
    CompletableFuture<Response> future = new CompletableFuture<>();
    Handler<HttpClientResponse> handler = ResponseHandler.any(future);
    send(url, method, content, handler);
    Response response;
    try {
        response = future.get(5, TimeUnit.SECONDS);
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        throw new IllegalStateException(e);
    }
    assertThat(url + " - " + method + " - " + content + ":" + response.getBody(), response.getStatusCode(), is(expectedStatusCode));
    try {
        return response.getJson();
    } catch (DecodeException e) {
        // No body at all or not in JSON format.
        return null;
    }
}
Also used : Response(org.folio.rest.support.Response) HttpClientResponse(io.vertx.core.http.HttpClientResponse) CompletableFuture(java.util.concurrent.CompletableFuture) HttpClientResponse(io.vertx.core.http.HttpClientResponse) ExecutionException(java.util.concurrent.ExecutionException) DecodeException(io.vertx.core.json.DecodeException) TimeoutException(java.util.concurrent.TimeoutException)

Example 3 with Response

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

the class LocationsTest method cannotCreateLocationWithoutCode.

@Test
public void cannotCreateLocationWithoutCode() throws InterruptedException, ExecutionException, TimeoutException, MalformedURLException {
    Response response = createLocation(null, "Main Library", instID, campID, libID, null);
    assertThat(response.getStatusCode(), is(AdditionalHttpStatusCodes.UNPROCESSABLE_ENTITY));
}
Also used : Response(org.folio.rest.support.Response) HttpClientResponse(io.vertx.core.http.HttpClientResponse) Test(org.junit.Test)

Example 4 with Response

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

the class LocationsTest method canDeleteALocation.

@Test
public void canDeleteALocation() throws InterruptedException, ExecutionException, TimeoutException, MalformedURLException {
    UUID id = UUID.randomUUID();
    createLocation(id, "Main Library", instID, campID, libID, "PI/CC/ML/X");
    CompletableFuture<Response> deleteCompleted = new CompletableFuture<>();
    send(locationsStorageUrl("/" + id.toString()), HttpMethod.DELETE, null, SUPPORTED_CONTENT_TYPE_JSON_DEF, ResponseHandler.any(deleteCompleted));
    Response deleteResponse = deleteCompleted.get(5, TimeUnit.SECONDS);
    assertThat(deleteResponse.getStatusCode(), is(HttpURLConnection.HTTP_NO_CONTENT));
}
Also used : Response(org.folio.rest.support.Response) HttpClientResponse(io.vertx.core.http.HttpClientResponse) CompletableFuture(java.util.concurrent.CompletableFuture) UUID(java.util.UUID) Test(org.junit.Test)

Example 5 with Response

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

the class LocationsTest method cannotCreateLocationWithSameName.

@Test
public void cannotCreateLocationWithSameName() throws InterruptedException, ExecutionException, TimeoutException, MalformedURLException {
    createLocation(null, "Main Library", instID, campID, libID, "PI/CC/ML/X");
    Response response = createLocation(null, "Main Library", instID, campID, libID, "AA/BB");
    assertThat(response.getStatusCode(), is(AdditionalHttpStatusCodes.UNPROCESSABLE_ENTITY));
}
Also used : Response(org.folio.rest.support.Response) HttpClientResponse(io.vertx.core.http.HttpClientResponse) Test(org.junit.Test)

Aggregations

Response (org.folio.rest.support.Response)46 HttpClientResponse (io.vertx.core.http.HttpClientResponse)40 Test (org.junit.Test)34 CompletableFuture (java.util.concurrent.CompletableFuture)25 UUID (java.util.UUID)24 JsonObject (io.vertx.core.json.JsonObject)22 HttpClient (org.folio.rest.support.HttpClient)3 ExecutionException (java.util.concurrent.ExecutionException)2 TimeoutException (java.util.concurrent.TimeoutException)2 DecodeException (io.vertx.core.json.DecodeException)1 MalformedURLException (java.net.MalformedURLException)1