use of org.folio.rest.support.JsonResponse in project mod-circulation-storage by folio-org.
the class RequestPoliciesApiTest method createDefaultRequestPolicy.
private RequestPolicy createDefaultRequestPolicy(UUID id, String name, String descr, List<RequestType> requestTypes) throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
CompletableFuture<JsonResponse> createCompleted = new CompletableFuture<>();
RequestPolicy requestPolicy = new RequestPolicy();
requestPolicy.withDescription(descr);
requestPolicy.withName(name);
requestPolicy.withRequestTypes(requestTypes);
if (id != null) {
requestPolicy.withId(id.toString());
}
// Create requestPolicy
client.post(requestPolicyStorageUrl(""), requestPolicy, StorageTestSuite.TENANT_ID, ResponseHandler.json(createCompleted));
JsonResponse response = createCompleted.get(CONNECTION_TIMEOUT, TimeUnit.SECONDS);
assertThat("Failed to create new request-policy", response, isCreated());
JsonObject representation = response.getJson();
assertThat(representation.getString("id"), is(notNullValue()));
assertThat(representation.getString("name"), is(name));
assertThat(representation.getString("description"), is(descr));
if (id != null) {
assertThat(representation.getString("id"), is(id.toString()));
}
return requestPolicy;
}
use of org.folio.rest.support.JsonResponse 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"));
}
use of org.folio.rest.support.JsonResponse in project mod-circulation-storage by folio-org.
the class RequestPoliciesApiTest method canGetRequestPoliciesByIdUsingQuery.
@Test
public void canGetRequestPoliciesByIdUsingQuery() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
CompletableFuture<JsonResponse> getCompleted = new CompletableFuture<>();
RequestPolicy requestPolicy1 = createDefaultRequestPolicy();
// Get the newly created request policies
client.get(requestPolicyStorageUrl("?query=id=" + requestPolicy1.getId()), StorageTestSuite.TENANT_ID, ResponseHandler.json(getCompleted));
JsonResponse responseGet = getCompleted.get(CONNECTION_TIMEOUT, TimeUnit.SECONDS);
JsonObject responseJson = responseGet.getJson();
JsonArray requestPolicies = responseJson.getJsonArray("requestPolicies");
assertThat(responseJson.getInteger("totalRecords"), is(1));
JsonObject aPolicy = requestPolicies.getJsonObject(0);
validateRequestPolicy(requestPolicy1, aPolicy);
}
use of org.folio.rest.support.JsonResponse 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);
}
use of org.folio.rest.support.JsonResponse 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));
}
Aggregations