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