Search in sources :

Example 51 with JsonResponse

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

the class RequestPoliciesApiTest method createDefaultRequestPolicy.

private RequestPolicy createDefaultRequestPolicy(UUID id, String name, String descr, List<RequestType> requestTypes) throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    CompletableFuture<JsonResponse> createCompleted = new CompletableFuture<>();
    RequestPolicy requestPolicy = new RequestPolicy();
    requestPolicy.withDescription(descr);
    requestPolicy.withName(name);
    requestPolicy.withRequestTypes(requestTypes);
    if (id != null) {
        requestPolicy.withId(id.toString());
    }
    // Create requestPolicy
    client.post(requestPolicyStorageUrl(""), requestPolicy, StorageTestSuite.TENANT_ID, ResponseHandler.json(createCompleted));
    JsonResponse response = createCompleted.get(CONNECTION_TIMEOUT, TimeUnit.SECONDS);
    assertThat("Failed to create new request-policy", response, isCreated());
    JsonObject representation = response.getJson();
    assertThat(representation.getString("id"), is(notNullValue()));
    assertThat(representation.getString("name"), is(name));
    assertThat(representation.getString("description"), is(descr));
    if (id != null) {
        assertThat(representation.getString("id"), is(id.toString()));
    }
    return requestPolicy;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) JsonObject(io.vertx.core.json.JsonObject) JsonResponse(org.folio.rest.support.JsonResponse) RequestPolicy(org.folio.rest.jaxrs.model.RequestPolicy)

Example 52 with JsonResponse

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

the class RequestPoliciesApiTest method cannotCreateRequestPolicyWithExistingName.

@Test
public void cannotCreateRequestPolicyWithExistingName() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    CompletableFuture<JsonResponse> failedCompleted = new CompletableFuture<>();
    String reqPolicyName = "request_policy_name";
    List<RequestType> requestTypes = Collections.singletonList(RequestType.HOLD);
    // create a requestPolicy with reqPolicyName as name
    createDefaultRequestPolicy(UUID.randomUUID(), reqPolicyName, "test policy", requestTypes);
    // create another requestPolicy with the same name
    UUID id2 = UUID.randomUUID();
    RequestPolicy requestPolicy2 = new RequestPolicy();
    requestPolicy2.withDescription("test policy 2");
    requestPolicy2.withName(reqPolicyName);
    requestPolicy2.withRequestTypes(requestTypes);
    requestPolicy2.withId(id2.toString());
    client.post(requestPolicyStorageUrl(""), requestPolicy2, StorageTestSuite.TENANT_ID, ResponseHandler.json(failedCompleted));
    JsonResponse response2 = failedCompleted.get(CONNECTION_TIMEOUT, TimeUnit.SECONDS);
    assertThat(String.format("Failed to create request policy: %s", response2.getBody()), response2.getStatusCode(), is(HttpURLConnection.HTTP_INTERNAL_ERROR));
    assertThat("unexpected error message", response2.getBody().contains("duplicate key value"));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) StringContains.containsString(org.hamcrest.core.StringContains.containsString) 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 53 with JsonResponse

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

the class RequestPoliciesApiTest method canGetRequestPoliciesByIdUsingQuery.

@Test
public void canGetRequestPoliciesByIdUsingQuery() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    CompletableFuture<JsonResponse> getCompleted = new CompletableFuture<>();
    RequestPolicy requestPolicy1 = createDefaultRequestPolicy();
    // Get the newly created request policies
    client.get(requestPolicyStorageUrl("?query=id=" + requestPolicy1.getId()), StorageTestSuite.TENANT_ID, ResponseHandler.json(getCompleted));
    JsonResponse responseGet = getCompleted.get(CONNECTION_TIMEOUT, TimeUnit.SECONDS);
    JsonObject responseJson = responseGet.getJson();
    JsonArray requestPolicies = responseJson.getJsonArray("requestPolicies");
    assertThat(responseJson.getInteger("totalRecords"), is(1));
    JsonObject aPolicy = requestPolicies.getJsonObject(0);
    validateRequestPolicy(requestPolicy1, aPolicy);
}
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) RequestPolicy(org.folio.rest.jaxrs.model.RequestPolicy) Test(org.junit.Test)

Example 54 with JsonResponse

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

the class RequestPoliciesApiTest method canUpdateRequestPolicy.

@Test
public void canUpdateRequestPolicy() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    CompletableFuture<JsonResponse> updateCompleted = new CompletableFuture<>();
    List<RequestType> requestTypes = Arrays.asList(RequestType.HOLD, RequestType.PAGE);
    RequestPolicy requestPolicy = createDefaultRequestPolicy(UUID.randomUUID(), "sample requet policy", "plain description", requestTypes);
    // update requestPolicy to new values
    requestPolicy.setDescription("new description");
    requestPolicy.setName("sample request policies");
    requestPolicy.setRequestTypes(Arrays.asList(RequestType.RECALL, RequestType.HOLD));
    client.put(requestPolicyStorageUrl("/" + requestPolicy.getId()), requestPolicy, StorageTestSuite.TENANT_ID, ResponseHandler.json(updateCompleted));
    JsonResponse response = updateCompleted.get(CONNECTION_TIMEOUT, TimeUnit.SECONDS);
    assertThat("Failed to update request-policy", response.getStatusCode(), is(HttpURLConnection.HTTP_NO_CONTENT));
    // Get it and examine the updated content
    CompletableFuture<JsonResponse> getCompleted = new CompletableFuture<>();
    client.get(requestPolicyStorageUrl("/" + requestPolicy.getId()), StorageTestSuite.TENANT_ID, ResponseHandler.json(getCompleted));
    JsonResponse getResponse = getCompleted.get(CONNECTION_TIMEOUT, TimeUnit.SECONDS);
    assertThat("Failed to update request-policy", getResponse.getStatusCode(), is(HttpURLConnection.HTTP_OK));
    JsonObject aPolicy = getResponse.getJson();
    validateRequestPolicy(requestPolicy, aPolicy);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) JsonObject(io.vertx.core.json.JsonObject) 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 55 with JsonResponse

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

the class RequestPoliciesApiTest method canGetRequestPolicies.

@Test
public void canGetRequestPolicies() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    CleanupRequestPolicyRecords();
    CompletableFuture<JsonResponse> createCompletedGet = new CompletableFuture<>();
    RequestPolicy requestPolicy1 = createDefaultRequestPolicy();
    RequestPolicy requestPolicy2 = createDefaultRequestPolicy();
    // Get the newly created request policies
    client.get(requestPolicyStorageUrl(""), StorageTestSuite.TENANT_ID, ResponseHandler.json(createCompletedGet));
    JsonResponse responseGet = createCompletedGet.get(CONNECTION_TIMEOUT, TimeUnit.SECONDS);
    JsonObject getResultsJson = responseGet.getJson();
    JsonArray requestPolicies = getResultsJson.getJsonArray("requestPolicies");
    assertThat(getResultsJson.getInteger("totalRecords"), is(2));
    validateRequestPolicy(requestPolicy1, requestPolicies.getJsonObject(0));
    validateRequestPolicy(requestPolicy2, requestPolicies.getJsonObject(1));
}
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) 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