Search in sources :

Example 16 with RequestPolicy

use of org.folio.rest.jaxrs.model.RequestPolicy in project mod-circulation-storage by folio-org.

the class RequestPoliciesApiTest method cannotUpdateRequestPolicyWithWrongId.

@Test
public void cannotUpdateRequestPolicyWithWrongId() 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 request policy", "plain description", requestTypes);
    // update
    String newUid = UUID.randomUUID().toString();
    requestPolicy.setDescription("new description");
    client.put(requestPolicyStorageUrl("/" + newUid), requestPolicy, StorageTestSuite.TENANT_ID, ResponseHandler.json(updateCompleted));
    // Because of the unique name constraint, instead of getting an error message about a nonexistent object, the message
    // is about duplicate name. This happens because PUT can also be used to add a new record to the database.
    JsonResponse response = updateCompleted.get(CONNECTION_TIMEOUT, TimeUnit.SECONDS);
    assertThat(response, isBadRequest());
    assertThat(response.getBody(), containsString("already exists"));
}
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 17 with RequestPolicy

use of org.folio.rest.jaxrs.model.RequestPolicy in project mod-circulation-storage by folio-org.

the class RequestPoliciesApiTest method canGetRequestPolicyByName.

@Test
public void canGetRequestPolicyByName() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    CompletableFuture<JsonResponse> getCompleted = new CompletableFuture<>();
    // create a couple of RequestPolicies
    createDefaultRequestPolicy();
    RequestPolicy requestPolicy2 = createDefaultRequestPolicy();
    // Get the latter created request policy by name
    client.get(requestPolicyStorageUrl("?query=name=" + requestPolicy2.getName()), StorageTestSuite.TENANT_ID, ResponseHandler.json(getCompleted));
    JsonResponse responseGet = getCompleted.get(CONNECTION_TIMEOUT, TimeUnit.SECONDS);
    JsonObject getResultsJson = responseGet.getJson();
    JsonArray requestPolicies = getResultsJson.getJsonArray("requestPolicies");
    assertThat(getResultsJson.getInteger("totalRecords"), is(1));
    JsonObject aPolicy = requestPolicies.getJsonObject(0);
    validateRequestPolicy(requestPolicy2, 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 18 with RequestPolicy

use of org.folio.rest.jaxrs.model.RequestPolicy in project mod-circulation-storage by folio-org.

the class RequestPoliciesApiTest method cannotUpdateRequestPolicyToExistingPolicyName.

@Test
public void cannotUpdateRequestPolicyToExistingPolicyName() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    CompletableFuture<JsonResponse> updateCompleted = new CompletableFuture<>();
    String policy1Name = "Policy 1";
    String policy2Name = "Policy 2";
    List<RequestType> requestTypes = Arrays.asList(RequestType.HOLD, RequestType.PAGE);
    createDefaultRequestPolicy(UUID.randomUUID(), policy1Name, "plain description", requestTypes);
    RequestPolicy requestPolicy2 = createDefaultRequestPolicy(UUID.randomUUID(), policy2Name, "plain description", requestTypes);
    // update: set the name of requestPolicy2 to be of policy1's.
    requestPolicy2.setDescription("new description for policy 2");
    requestPolicy2.setName(policy1Name);
    requestPolicy2.setRequestTypes(Arrays.asList(RequestType.RECALL, RequestType.HOLD));
    client.put(requestPolicyStorageUrl("/" + requestPolicy2.getId()), requestPolicy2, StorageTestSuite.TENANT_ID, ResponseHandler.json(updateCompleted));
    JsonResponse response = updateCompleted.get(CONNECTION_TIMEOUT, TimeUnit.SECONDS);
    assertThat("Failed to update request-policy", response, isBadRequest());
    assertThat("Error message does not contain keyword 'already existed'", response.getBody(), containsString("already exists"));
}
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

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