Search in sources :

Example 1 with RequestPolicy

use of org.folio.rest.jaxrs.model.RequestPolicy 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 2 with RequestPolicy

use of org.folio.rest.jaxrs.model.RequestPolicy 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)

Example 3 with RequestPolicy

use of org.folio.rest.jaxrs.model.RequestPolicy 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 4 with RequestPolicy

use of org.folio.rest.jaxrs.model.RequestPolicy 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 5 with RequestPolicy

use of org.folio.rest.jaxrs.model.RequestPolicy 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)

Aggregations

CompletableFuture (java.util.concurrent.CompletableFuture)18 RequestPolicy (org.folio.rest.jaxrs.model.RequestPolicy)18 JsonResponse (org.folio.rest.support.JsonResponse)18 Test (org.junit.Test)17 JsonObject (io.vertx.core.json.JsonObject)11 RequestType (org.folio.rest.jaxrs.model.RequestType)10 StringContains.containsString (org.hamcrest.core.StringContains.containsString)6 JsonArray (io.vertx.core.json.JsonArray)3 UUID (java.util.UUID)2 DateTime (org.joda.time.DateTime)1