Search in sources :

Example 11 with Response

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"));
}
Also used : Response(org.folio.rest.support.Response) HttpClientResponse(io.vertx.core.http.HttpClientResponse) UUID(java.util.UUID) Test(org.junit.Test)

Example 12 with Response

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

Example 13 with Response

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));
}
Also used : Response(org.folio.rest.support.Response) HttpClientResponse(io.vertx.core.http.HttpClientResponse) UUID(java.util.UUID) Test(org.junit.Test)

Example 14 with Response

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"));
}
Also used : Response(org.folio.rest.support.Response) HttpClientResponse(io.vertx.core.http.HttpClientResponse) Test(org.junit.Test)

Example 15 with Response

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