Search in sources :

Example 46 with JsonResponse

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

the class LoansAnonymizationApiTest method shouldRejectInvalidUUID.

@Test
public void shouldRejectInvalidUUID() throws MalformedURLException, ExecutionException, InterruptedException, TimeoutException {
    final CompletableFuture<JsonResponse> postCompleted = new CompletableFuture<>();
    client.post(loanStorageUrl("/anonymize/" + "foo"), StorageTestSuite.TENANT_ID, ResponseHandler.json(postCompleted));
    final JsonResponse postResponse = postCompleted.get(5, TimeUnit.SECONDS);
    assertThat(postResponse, isValidationResponseWhich(allOf(hasMessage("Invalid user ID, should be a UUID"), hasParameter("userId", "foo"))));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 47 with JsonResponse

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

the class StaffSlipsHoldTransitMigrationScriptTest method canMigrateStaffSlips.

@Test
public void canMigrateStaffSlips() throws Exception {
    executeMultipleSqlStatements(MIGRATION_SCRIPT);
    CompletableFuture<JsonResponse> getCompleted = new CompletableFuture<>();
    client.get(staffSlipsStorageUrl(""), StorageTestSuite.TENANT_ID, ResponseHandler.json(getCompleted));
    JsonResponse getResponse = getCompleted.get(5, TimeUnit.SECONDS);
    assertThat(getResponse.getStatusCode(), Is.is(HttpURLConnection.HTTP_OK));
    JsonArray slipsJsonArray = getResponse.getJson().getJsonArray("staffSlips");
    JsonObject hold = getRecordById(slipsJsonArray, HOLD_ID);
    JsonObject transit = getRecordById(slipsJsonArray, TRANSIT_ID);
    assertStaffSlip(hold, HOLD_ID, "Hold");
    assertStaffSlip(transit, TRANSIT_ID, "Transit");
}
Also used : JsonArray(io.vertx.core.json.JsonArray) CompletableFuture(java.util.concurrent.CompletableFuture) JsonObject(io.vertx.core.json.JsonObject) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 48 with JsonResponse

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

the class StaffSlipsPickRequestMigrationScriptTest method canMigrateStaffSlips.

@Test
public void canMigrateStaffSlips() throws Exception {
    executeMultipleSqlStatements(MIGRATION_SCRIPT);
    CompletableFuture<JsonResponse> getCompleted = new CompletableFuture<>();
    client.get(staffSlipsStorageUrl(""), StorageTestSuite.TENANT_ID, ResponseHandler.json(getCompleted));
    JsonResponse getResponse = getCompleted.get(5, TimeUnit.SECONDS);
    assertThat(getResponse.getStatusCode(), Is.is(HttpURLConnection.HTTP_OK));
    JsonArray slipsJsonArray = getResponse.getJson().getJsonArray("staffSlips");
    JsonObject pickSlips = getRecordById(slipsJsonArray, PICK_SLIPS_ID);
    JsonObject requestDelivery = getRecordById(slipsJsonArray, REQUEST_DELIVERY_ID);
    assertStaffSlip(pickSlips, PICK_SLIPS_ID, "Pick slip");
    assertStaffSlip(requestDelivery, REQUEST_DELIVERY_ID, "Request delivery");
}
Also used : JsonArray(io.vertx.core.json.JsonArray) CompletableFuture(java.util.concurrent.CompletableFuture) JsonObject(io.vertx.core.json.JsonObject) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 49 with JsonResponse

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

the class RequestPoliciesApiTest method cannotCreateRequestPolicyWithoutName.

@Test
public void cannotCreateRequestPolicyWithoutName() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    CompletableFuture<JsonResponse> failedCompleted = new CompletableFuture<>();
    List<RequestType> requestTypes = Collections.singletonList(RequestType.HOLD);
    // create requestPolicy without name
    UUID id = UUID.randomUUID();
    RequestPolicy requestPolicy = new RequestPolicy();
    requestPolicy.withDescription("test policy 2");
    requestPolicy.withRequestTypes(requestTypes);
    requestPolicy.withId(id.toString());
    client.post(requestPolicyStorageUrl(""), requestPolicy, StorageTestSuite.TENANT_ID, ResponseHandler.json(failedCompleted));
    JsonResponse response2 = failedCompleted.get(CONNECTION_TIMEOUT, TimeUnit.SECONDS);
    assertThat(response2, isUnprocessableEntity());
    JsonObject error = extractErrorObject(response2);
    assertThat("unexpected error message", error, // any server language
    anyOf(hasMessage("must not be null"), hasMessage("darf nicht null sein")));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) JsonResponse(org.folio.rest.support.JsonResponse) RequestType(org.folio.rest.jaxrs.model.RequestType) RequestPolicy(org.folio.rest.jaxrs.model.RequestPolicy) Test(org.junit.Test)

Example 50 with JsonResponse

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

the class RequestPoliciesApiTest method cannotCreateRequestPolicyWithBadUID.

@Test
public void cannotCreateRequestPolicyWithBadUID() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    CompletableFuture<JsonResponse> createCompleted = new CompletableFuture<>();
    List<RequestType> requestTypes = Collections.singletonList(RequestType.HOLD);
    String badId = "bad_uuid";
    RequestPolicy requestPolicy = new RequestPolicy();
    requestPolicy.withDescription("test policy");
    requestPolicy.withName("successful_get");
    requestPolicy.withRequestTypes(requestTypes);
    requestPolicy.withId(badId);
    client.post(requestPolicyStorageUrl(""), requestPolicy, StorageTestSuite.TENANT_ID, ResponseHandler.json(createCompleted));
    JsonResponse response = createCompleted.get(CONNECTION_TIMEOUT, TimeUnit.SECONDS);
    assertThat(String.format("Failed to create request policy: %s", response.getBody()), response.getStatusCode(), is(HttpURLConnection.HTTP_INTERNAL_ERROR));
    assertThat(response.getBody(), containsString("Invalid UUID string"));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) StringContains.containsString(org.hamcrest.core.StringContains.containsString) JsonResponse(org.folio.rest.support.JsonResponse) RequestType(org.folio.rest.jaxrs.model.RequestType) RequestPolicy(org.folio.rest.jaxrs.model.RequestPolicy) Test(org.junit.Test)

Aggregations

JsonResponse (org.folio.rest.support.JsonResponse)156 Test (org.junit.Test)133 JsonObject (io.vertx.core.json.JsonObject)91 CompletableFuture (java.util.concurrent.CompletableFuture)91 UUID (java.util.UUID)52 RequestRequestBuilder (org.folio.rest.support.builders.RequestRequestBuilder)20 JsonArray (io.vertx.core.json.JsonArray)19 RequestPolicy (org.folio.rest.jaxrs.model.RequestPolicy)18 IndividualResource (org.folio.rest.support.IndividualResource)15 LoanRequestBuilder (org.folio.rest.support.builders.LoanRequestBuilder)12 URL (java.net.URL)11 RequestType (org.folio.rest.jaxrs.model.RequestType)10 RequestPreference (org.folio.rest.jaxrs.model.RequestPreference)9 StaffSlipRequestBuilder (org.folio.rest.support.builders.StaffSlipRequestBuilder)9 Response (org.folio.rest.support.Response)8 ResponseHandler (org.folio.rest.support.ResponseHandler)8 DateTime (org.joda.time.DateTime)7 MalformedURLException (java.net.MalformedURLException)6 ExecutionException (java.util.concurrent.ExecutionException)6 TimeoutException (java.util.concurrent.TimeoutException)6