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"));
}
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")));
}
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));
}
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));
}
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"));
}
Aggregations