Search in sources :

Example 1 with StaffSlipRequestBuilder

use of org.folio.rest.support.builders.StaffSlipRequestBuilder in project mod-circulation-storage by folio-org.

the class StaffSlipsApiTest method canDeleteSlipById.

@Test
public void canDeleteSlipById() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    UUID slipId = UUID.randomUUID();
    makeStaffSlip(new StaffSlipRequestBuilder().withId(slipId).withName(TEST_STAFF_SLIP_1_NAME).withDescription(TEST_STAFF_SLIP_1_DESCRIPTION).withTemplate(TEST_STAFF_SLIP_1_Template).create());
    CompletableFuture<Response> deleteCompleted = new CompletableFuture<>();
    client.delete(staffSlipsStorageUrl("/" + slipId), StorageTestSuite.TENANT_ID, ResponseHandler.empty(deleteCompleted));
    Response deleteReponse = deleteCompleted.get(5, TimeUnit.SECONDS);
    CompletableFuture<JsonResponse> getCompleted = new CompletableFuture<>();
    client.get(staffSlipsStorageUrl("/" + slipId), StorageTestSuite.TENANT_ID, ResponseHandler.json(getCompleted));
    JsonResponse getResponse = getCompleted.get(5, TimeUnit.SECONDS);
    assertThat(deleteReponse.getStatusCode(), is(HttpURLConnection.HTTP_NO_CONTENT));
    assertThat(getResponse.getStatusCode(), is(HttpURLConnection.HTTP_NOT_FOUND));
}
Also used : JsonResponse(org.folio.rest.support.JsonResponse) Response(org.folio.rest.support.Response) CompletableFuture(java.util.concurrent.CompletableFuture) UUID(java.util.UUID) StaffSlipRequestBuilder(org.folio.rest.support.builders.StaffSlipRequestBuilder) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 2 with StaffSlipRequestBuilder

use of org.folio.rest.support.builders.StaffSlipRequestBuilder in project mod-circulation-storage by folio-org.

the class StaffSlipsApiTest method canQueryStaffSlip.

@Test
public void canQueryStaffSlip() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    JsonResponse creationResponse = makeStaffSlip(new StaffSlipRequestBuilder().create());
    CompletableFuture<JsonResponse> getCompleted = new CompletableFuture<>();
    String slipId = creationResponse.getJson().getString(ID_KEY);
    URL path = staffSlipsStorageUrl("?query=" + URLEncoder.encode(String.format("%s==\"%s\"", ID_KEY, slipId), UTF_8));
    client.get(path, StorageTestSuite.TENANT_ID, ResponseHandler.json(getCompleted));
    JsonResponse getResponse = getCompleted.get(10, TimeUnit.SECONDS);
    assertThat(getResponse.getStatusCode(), is(HttpURLConnection.HTTP_OK));
    JsonArray slipsJsonArray = getResponse.getJson().getJsonArray("staffSlips");
    assertThat(slipsJsonArray.getJsonObject(0).getString(ID_KEY), is(slipId));
}
Also used : JsonArray(io.vertx.core.json.JsonArray) CompletableFuture(java.util.concurrent.CompletableFuture) StaffSlipRequestBuilder(org.folio.rest.support.builders.StaffSlipRequestBuilder) JsonResponse(org.folio.rest.support.JsonResponse) URL(java.net.URL) Test(org.junit.Test)

Example 3 with StaffSlipRequestBuilder

use of org.folio.rest.support.builders.StaffSlipRequestBuilder in project mod-circulation-storage by folio-org.

the class StaffSlipsApiTest method canCreateAnInactiveStaffSlip.

@Test
public void canCreateAnInactiveStaffSlip() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    JsonResponse creationResponse = makeStaffSlip(new StaffSlipRequestBuilder().withActive(false).create());
    assertThat(creationResponse.getJson().getBoolean(ACTIVE_KEY), is(false));
}
Also used : StaffSlipRequestBuilder(org.folio.rest.support.builders.StaffSlipRequestBuilder) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 4 with StaffSlipRequestBuilder

use of org.folio.rest.support.builders.StaffSlipRequestBuilder in project mod-circulation-storage by folio-org.

the class StaffSlipsApiTest method cannotCreateStaffSlipWithDuplicateName.

@Test
public void cannotCreateStaffSlipWithDuplicateName() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    makeStaffSlip(new StaffSlipRequestBuilder().withName(TEST_STAFF_SLIP_1_NAME).create());
    JsonResponse creationAttemptResponse = makeStaffSlip(new StaffSlipRequestBuilder().withName(TEST_STAFF_SLIP_1_NAME).create());
    assertThat(creationAttemptResponse, isBadRequest());
}
Also used : StaffSlipRequestBuilder(org.folio.rest.support.builders.StaffSlipRequestBuilder) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 5 with StaffSlipRequestBuilder

use of org.folio.rest.support.builders.StaffSlipRequestBuilder in project mod-circulation-storage by folio-org.

the class StaffSlipsApiTest method cannotCreateAStaffSlipWithoutAName.

@Test
public void cannotCreateAStaffSlipWithoutAName() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    JsonResponse creationResponse = makeStaffSlip(new StaffSlipRequestBuilder().withName(null).create());
    assertThat(String.format("Creating the loan should fail: %s", creationResponse.getBody()), creationResponse, isUnprocessableEntity());
}
Also used : StaffSlipRequestBuilder(org.folio.rest.support.builders.StaffSlipRequestBuilder) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Aggregations

JsonResponse (org.folio.rest.support.JsonResponse)8 StaffSlipRequestBuilder (org.folio.rest.support.builders.StaffSlipRequestBuilder)8 Test (org.junit.Test)8 CompletableFuture (java.util.concurrent.CompletableFuture)4 UUID (java.util.UUID)2 Response (org.folio.rest.support.Response)2 JsonArray (io.vertx.core.json.JsonArray)1 JsonObject (io.vertx.core.json.JsonObject)1 URL (java.net.URL)1