use of org.folio.rest.support.Response in project mod-inventory-storage by folio-org.
the class LocationUnitTest method canCreateACamp.
// //////////// Campus tests
@Test
public void canCreateACamp() throws InterruptedException, ExecutionException, TimeoutException, MalformedURLException {
UUID instId = UUID.randomUUID();
createInst(instId, "Institute of MetaPhysics", "MPI");
Response response = createCamp(null, "Riverside Campus", "RS", instId);
assertThat(response.getStatusCode(), is(HttpURLConnection.HTTP_CREATED));
assertThat(response.getJson().getString("id"), notNullValue());
assertThat(response.getJson().getString("name"), is("Riverside Campus"));
assertThat(response.getJson().getString("code"), is("RS"));
}
use of org.folio.rest.support.Response in project mod-inventory-storage by folio-org.
the class LocationUnitTest method createCamp.
/*
TODO - A test that checks thatn institution can not be deleted if used by
a location.
@Test
public void cannotDeleteAnInstAssociatedWithAnItem()
throws InterruptedException,
ExecutionException,
TimeoutException,
MalformedURLException {
UUID locationId = UUID.randomUUID();
createInst(locationId, "Institute of MetaPhysics", "MPI");
JsonObject item = createItemRequest(locationId.toString());
CompletableFuture<Response> createItemCompleted = new CompletableFuture<>();
send(itemsStorageUrl(""), HttpMethod.POST, item.toString(),
SUPPORTED_CONTENT_TYPE_JSON_DEF, ResponseHandler.json(createItemCompleted));
Response createItemResponse = createItemCompleted.get(5, TimeUnit.SECONDS);
assertThat(createItemResponse.getStatusCode(), is(HttpURLConnection.HTTP_CREATED));
CompletableFuture<Response> deleteCompleted = new CompletableFuture<>();
send(locInstitutionStorageUrl(locationId.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_BAD_REQUEST));
}
*/
// //////////////////////////////////// Campus test helpers
public static Response createCamp(UUID id, String name, String code, UUID instId) throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
CompletableFuture<Response> createLocationUnit = new CompletableFuture<>();
JsonObject request = new JsonObject().put("name", name).put("code", code).put("institutionId", instId.toString());
if (id != null) {
request.put("id", id.toString());
}
send(locCampusStorageUrl(""), HttpMethod.POST, request.toString(), SUPPORTED_CONTENT_TYPE_JSON_DEF, ResponseHandler.json(createLocationUnit));
return createLocationUnit.get(5, TimeUnit.SECONDS);
}
use of org.folio.rest.support.Response in project mod-inventory-storage by folio-org.
the class LocationUnitTest method cannotCreateLibWithSameName.
@Test
public void cannotCreateLibWithSameName() throws InterruptedException, ExecutionException, TimeoutException, MalformedURLException {
UUID instId = UUID.randomUUID();
createInst(instId, "Institute of MetaPhysics", "MPI");
UUID campId = UUID.randomUUID();
createCamp(campId, "Riverside Campus", "RS", instId);
createLib(null, "Main Library", "RS", campId);
Response response = createLib(null, "Main Library", "RS", campId);
assertThat(response.getStatusCode(), is(AdditionalHttpStatusCodes.UNPROCESSABLE_ENTITY));
}
use of org.folio.rest.support.Response in project mod-inventory-storage by folio-org.
the class LocationUnitTest method canCreateAnInst.
// ///////////////////// Inst tests
@Test
public void canCreateAnInst() throws InterruptedException, ExecutionException, TimeoutException, MalformedURLException {
Response response = createInst("Institute of MetaPhysics", "MPI");
assertThat(response.getStatusCode(), is(HttpURLConnection.HTTP_CREATED));
assertThat(response.getJson().getString("id"), notNullValue());
assertThat(response.getJson().getString("name"), is("Institute of MetaPhysics"));
assertThat(response.getJson().getString("code"), is("MPI"));
}
use of org.folio.rest.support.Response in project mod-inventory-storage by folio-org.
the class LocationUnitTest method canUpdateAnInst.
@Test
public void canUpdateAnInst() throws InterruptedException, ExecutionException, TimeoutException, MalformedURLException {
UUID id = UUID.randomUUID();
createInst(id, "Institute of MetaPhysics", "MPI");
JsonObject updateRequest = new JsonObject().put("id", id.toString()).put("name", "The Other Institute");
CompletableFuture<Response> updated = new CompletableFuture<>();
send(locInstitutionStorageUrl("/" + id.toString()), HttpMethod.PUT, updateRequest.toString(), SUPPORTED_CONTENT_TYPE_JSON_DEF, ResponseHandler.any(updated));
Response updateResponse = updated.get(5, TimeUnit.SECONDS);
assertThat(updateResponse, statusCodeIs(HttpURLConnection.HTTP_NO_CONTENT));
assertThat(updateResponse.getStatusCode(), is(HttpURLConnection.HTTP_NO_CONTENT));
Response getResponse = getInstById(id);
assertThat(getResponse.getStatusCode(), is(HttpURLConnection.HTTP_OK));
JsonObject item = getResponse.getJson();
assertThat(item.getString("id"), is(id.toString()));
assertThat(item.getString("name"), is("The Other Institute"));
}
Aggregations