Search in sources :

Example 6 with RequestType

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

Example 7 with RequestType

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

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

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

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

the class RequestPoliciesApiTest method createDefaultRequestPolicy.

private RequestPolicy createDefaultRequestPolicy() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    List<RequestType> requestTypes = Arrays.asList(RequestType.HOLD, RequestType.PAGE);
    UUID id1 = UUID.randomUUID();
    REQ_POLICY_NAME_INCR++;
    return createDefaultRequestPolicy(id1, DEFAULT_REQUEST_POLICY_NAME + REQ_POLICY_NAME_INCR, "test policy", requestTypes);
}
Also used : UUID(java.util.UUID) RequestType(org.folio.rest.jaxrs.model.RequestType)

Aggregations

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