Search in sources :

Example 11 with RequestPolicy

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

the class RequestPoliciesApiTest method canDeleteRequestPoliciesById.

@Test
public void canDeleteRequestPoliciesById() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    CompletableFuture<JsonResponse> getCompleted = new CompletableFuture<>();
    CompletableFuture<JsonResponse> delCompleted = new CompletableFuture<>();
    CompletableFuture<JsonResponse> getCompletedVerify = new CompletableFuture<>();
    // create a couple of request policies to delete.
    RequestPolicy rp = createDefaultRequestPolicy();
    // Get the newly created request policies
    client.get(requestPolicyStorageUrl("/" + rp.getId()), StorageTestSuite.TENANT_ID, ResponseHandler.json(getCompleted));
    JsonResponse responseGet = getCompleted.get(CONNECTION_TIMEOUT, TimeUnit.SECONDS);
    JsonObject getResultsJson = responseGet.getJson();
    assertThat(getResultsJson, is(notNullValue()));
    assertThat(getResultsJson.getString("id"), is(rp.getId()));
    // Delete existing policy
    client.delete(requestPolicyStorageUrl("/" + rp.getId()), StorageTestSuite.TENANT_ID, ResponseHandler.json(delCompleted));
    JsonResponse responseDel = delCompleted.get(CONNECTION_TIMEOUT, TimeUnit.SECONDS);
    assertThat("Failed to delete all request policies", responseDel.getStatusCode(), is(HttpURLConnection.HTTP_NO_CONTENT));
    // Get all policies again to verify that none comes back
    client.get(requestPolicyStorageUrl("/" + rp.getId()), StorageTestSuite.TENANT_ID, ResponseHandler.json(getCompletedVerify));
    JsonResponse responseGetVerify = getCompletedVerify.get(CONNECTION_TIMEOUT, TimeUnit.SECONDS);
    assertThat(responseGetVerify, isNotFound());
    assertThat(responseGetVerify.getBody().toLowerCase(), containsString("not found"));
}
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) Test(org.junit.Test)

Example 12 with RequestPolicy

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

the class RequestPoliciesApiTest method cannotUpdateRequestPolicyWithoutName.

@Test
public void cannotUpdateRequestPolicyWithoutName() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    CompletableFuture<JsonResponse> failedCompleted = new CompletableFuture<>();
    List<RequestType> requestTypes = Collections.singletonList(RequestType.HOLD);
    RequestPolicy requestPolicy = createDefaultRequestPolicy();
    // update requestPolicy
    requestPolicy.setDescription("new description!!!");
    requestPolicy.setName(null);
    requestPolicy.setRequestTypes(requestTypes);
    client.put(requestPolicyStorageUrl("/" + requestPolicy.getId()), 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) 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 13 with RequestPolicy

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

the class RequestPoliciesApiTest method canUpdateRequestPolicyWithNewId.

@Test
public void canUpdateRequestPolicyWithNewId() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    CompletableFuture<JsonResponse> updateCompleted = new CompletableFuture<>();
    List<RequestType> requestTypes = Arrays.asList(RequestType.HOLD, RequestType.PAGE);
    RequestPolicy requestPolicy = createDefaultRequestPolicy(UUID.randomUUID(), "old name", "plain description", requestTypes);
    // update requestPolicy
    String newUid = UUID.randomUUID().toString();
    requestPolicy.setDescription("new description");
    requestPolicy.setName("new name");
    requestPolicy.setId(newUid);
    client.put(requestPolicyStorageUrl("/" + newUid), 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));
}
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 14 with RequestPolicy

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

the class RequestPoliciesApiTest method cannotGetRequestPolicyByNonExistentName.

@Test
public void cannotGetRequestPolicyByNonExistentName() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    CompletableFuture<JsonResponse> getCompleted = new CompletableFuture<>();
    RequestPolicy requestPolicy = createDefaultRequestPolicy();
    // Get the newly created request policies
    client.get(requestPolicyStorageUrl("?query=name=" + requestPolicy.getName() + "blabblabla"), StorageTestSuite.TENANT_ID, ResponseHandler.json(getCompleted));
    JsonResponse responseGet = getCompleted.get(CONNECTION_TIMEOUT, TimeUnit.SECONDS);
    assertThat("Failed to not get request-policy", responseGet.getStatusCode(), is(HttpURLConnection.HTTP_OK));
    JsonObject getResultsJson = responseGet.getJson();
    assertThat(getResultsJson.getInteger("totalRecords"), is(0));
}
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) Test(org.junit.Test)

Example 15 with RequestPolicy

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

the class RequestPoliciesApiTest method cannotGetRequestPoliciesByUsingNegativeOffset.

@Test
public void cannotGetRequestPoliciesByUsingNegativeOffset() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    CompletableFuture<JsonResponse> getCompleted = new CompletableFuture<>();
    RequestPolicy requestPolicy = createDefaultRequestPolicy();
    // Get the newly created request policies
    client.get(requestPolicyStorageUrl("", "query", "(name=" + requestPolicy.getId() + ")", "offset", "-230"), StorageTestSuite.TENANT_ID, ResponseHandler.json(getCompleted));
    JsonResponse responseGet = getCompleted.get(CONNECTION_TIMEOUT, TimeUnit.SECONDS);
    assertThat(responseGet, isBadRequest());
    assertThat("expected error message not found", responseGet.getBody().toLowerCase(), containsString("offset"));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) 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