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