Search in sources :

Example 26 with Response

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

the class LocationsTest method canListLocations.

@Test
public void canListLocations() throws InterruptedException, ExecutionException, TimeoutException, MalformedURLException {
    createLocation(null, "Main Library", instID, campID, libID, "PI/CC/ML");
    createLocation(null, "Annex Library", instID, campID, libID, "PI/CC/AL");
    CompletableFuture<Response> getCompleted = new CompletableFuture<>();
    send(locationsStorageUrl("/"), HttpMethod.GET, null, SUPPORTED_CONTENT_TYPE_JSON_DEF, ResponseHandler.json(getCompleted));
    Response getResponse = getCompleted.get(5, TimeUnit.SECONDS);
    assertThat(getResponse.getStatusCode(), is(HttpURLConnection.HTTP_OK));
    JsonObject item = getResponse.getJson();
    assertThat(item.getInteger("totalRecords"), is(2));
}
Also used : Response(org.folio.rest.support.Response) HttpClientResponse(io.vertx.core.http.HttpClientResponse) CompletableFuture(java.util.concurrent.CompletableFuture) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 27 with Response

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

the class LocationsTest method canUpdateALocation.

@Test
public void canUpdateALocation() throws InterruptedException, ExecutionException, TimeoutException, MalformedURLException {
    UUID id = UUID.randomUUID();
    createLocation(id, "Main Library", instID, campID, libID, "PI/CC/ML/X");
    JsonObject updateRequest = new JsonObject().put("id", id.toString()).put("name", "Annex Library").put("institutionId", instID.toString()).put("campusId", campID.toString()).put("libraryId", libID.toString()).put("isActive", true).put("code", "AA/BB");
    CompletableFuture<Response> updated = new CompletableFuture<>();
    send(locationsStorageUrl("/" + 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));
    Response getResponse = getById(id);
    assertThat(getResponse.getStatusCode(), is(HttpURLConnection.HTTP_OK));
    JsonObject item = getResponse.getJson();
    assertThat(item.getString("id"), is(id.toString()));
    assertThat(item.getString("name"), is("Annex Library"));
}
Also used : Response(org.folio.rest.support.Response) HttpClientResponse(io.vertx.core.http.HttpClientResponse) CompletableFuture(java.util.concurrent.CompletableFuture) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) Test(org.junit.Test)

Example 28 with Response

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

the class LocationUnitTest method canDeleteACamp.

@Test
public void canDeleteACamp() throws InterruptedException, ExecutionException, TimeoutException, MalformedURLException {
    UUID instId = UUID.randomUUID();
    createInst(instId, "Institute of MetaPhysics", "MPI");
    UUID id = UUID.randomUUID();
    createCamp(id, "Riverside Campus", "RS", instId);
    CompletableFuture<Response> deleteCompleted = new CompletableFuture<>();
    send(locCampusStorageUrl("/" + 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 29 with Response

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

the class LocationUnitTest method canListInsts.

@Test
public void canListInsts() throws InterruptedException, ExecutionException, TimeoutException, MalformedURLException {
    createInst("Institute of MetaPhysics", "MPI");
    createInst("The Other Institute", "OI");
    CompletableFuture<Response> getCompleted = new CompletableFuture<>();
    send(locInstitutionStorageUrl("/"), HttpMethod.GET, null, SUPPORTED_CONTENT_TYPE_JSON_DEF, ResponseHandler.json(getCompleted));
    Response getResponse = getCompleted.get(5, TimeUnit.SECONDS);
    assertThat(getResponse.getStatusCode(), is(HttpURLConnection.HTTP_OK));
    JsonObject item = getResponse.getJson();
    assertThat(item.getInteger("totalRecords"), is(2));
}
Also used : Response(org.folio.rest.support.Response) HttpClientResponse(io.vertx.core.http.HttpClientResponse) CompletableFuture(java.util.concurrent.CompletableFuture) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 30 with Response

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

the class LocationUnitTest method canUpdateALib.

@Test
public void canUpdateALib() 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);
    UUID id = UUID.randomUUID();
    createLib(id, "Main Library", "MPI", campId);
    JsonObject updateRequest = new JsonObject().put("id", id.toString()).put("name", "The Other Library").put("campusId", campId.toString());
    CompletableFuture<Response> updated = new CompletableFuture<>();
    send(locLibraryStorageUrl("/" + 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 = getLibById(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 Library"));
}
Also used : Response(org.folio.rest.support.Response) HttpClientResponse(io.vertx.core.http.HttpClientResponse) CompletableFuture(java.util.concurrent.CompletableFuture) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) 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