Search in sources :

Example 1 with RequestType

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

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

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

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

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

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