Search in sources :

Example 6 with RequestPolicy

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

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

Example 8 with RequestPolicy

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

the class RequestPoliciesApiTest method createdRequestHasCreationMetadata.

@Test
public void createdRequestHasCreationMetadata() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    final String METADATA_PROPERTY = "metadata";
    CompletableFuture<JsonResponse> createCompleted = new CompletableFuture<>();
    List<RequestType> requestTypes = Arrays.asList(RequestType.HOLD, RequestType.PAGE);
    RequestPolicy requestPolicy = new RequestPolicy();
    requestPolicy.withDescription("Sample request policy");
    requestPolicy.withName("Request Policy 1");
    requestPolicy.withRequestTypes(requestTypes);
    requestPolicy.withId(UUID.randomUUID().toString());
    String creatorId = UUID.randomUUID().toString();
    DateTime requestMade = DateTime.now();
    // Create requestPolicy
    client.post(requestPolicyStorageUrl(""), requestPolicy, StorageTestSuite.TENANT_ID, creatorId, ResponseHandler.json(createCompleted));
    JsonResponse response = createCompleted.get(CONNECTION_TIMEOUT, TimeUnit.SECONDS);
    assertThat("Failed to create new request-policy", response.getStatusCode(), is(HttpURLConnection.HTTP_CREATED));
    JsonObject createdResponse = response.getJson();
    assertThat("Request should have metadata property", createdResponse.containsKey(METADATA_PROPERTY), is(true));
    JsonObject metadata = createdResponse.getJsonObject(METADATA_PROPERTY);
    assertThat("Request should have created user", metadata.getString("createdByUserId"), is(creatorId));
    // RAML-Module-Builder also populates updated information at creation time
    assertThat("Request should have updated user", metadata.getString("updatedByUserId"), is(creatorId));
    assertThat("Request should have update date close to when request was made", metadata.getString("updatedDate"), is(withinSecondsAfter(Seconds.seconds(2), requestMade)));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) JsonObject(io.vertx.core.json.JsonObject) StringContains.containsString(org.hamcrest.core.StringContains.containsString) JsonResponse(org.folio.rest.support.JsonResponse) DateTime(org.joda.time.DateTime) RequestType(org.folio.rest.jaxrs.model.RequestType) RequestPolicy(org.folio.rest.jaxrs.model.RequestPolicy) Test(org.junit.Test)

Example 9 with RequestPolicy

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

the class RequestPoliciesApiTest method cannotGetRequestPoliciesByUsingNegativeLimit.

@Test
public void cannotGetRequestPoliciesByUsingNegativeLimit() 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() + ")", "limit", "-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("limit"));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) JsonResponse(org.folio.rest.support.JsonResponse) RequestPolicy(org.folio.rest.jaxrs.model.RequestPolicy) Test(org.junit.Test)

Example 10 with RequestPolicy

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

the class RequestPoliciesApiTest method canGetRequestPolicyById.

@Test
public void canGetRequestPolicyById() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    CompletableFuture<JsonResponse> getCompleted = new CompletableFuture<>();
    List<RequestType> requestTypes = Arrays.asList(RequestType.HOLD, RequestType.RECALL);
    createDefaultRequestPolicy();
    RequestPolicy req2 = createDefaultRequestPolicy(UUID.randomUUID(), "request2 name", "request policy 2 descr", requestTypes);
    // Get the newly created request policies
    client.get(requestPolicyStorageUrl("/" + req2.getId()), StorageTestSuite.TENANT_ID, ResponseHandler.json(getCompleted));
    JsonResponse responseGet = getCompleted.get(CONNECTION_TIMEOUT, TimeUnit.SECONDS);
    JsonObject aPolicy = responseGet.getJson();
    validateRequestPolicy(req2, 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)

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