use of org.folio.rest.jaxrs.model.RequestPolicy 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"));
}
use of org.folio.rest.jaxrs.model.RequestPolicy in project mod-circulation-storage by folio-org.
the class RequestPoliciesApiTest method canGetRequestPolicyByName.
@Test
public void canGetRequestPolicyByName() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
CompletableFuture<JsonResponse> getCompleted = new CompletableFuture<>();
// create a couple of RequestPolicies
createDefaultRequestPolicy();
RequestPolicy requestPolicy2 = createDefaultRequestPolicy();
// Get the latter created request policy by name
client.get(requestPolicyStorageUrl("?query=name=" + requestPolicy2.getName()), StorageTestSuite.TENANT_ID, ResponseHandler.json(getCompleted));
JsonResponse responseGet = getCompleted.get(CONNECTION_TIMEOUT, TimeUnit.SECONDS);
JsonObject getResultsJson = responseGet.getJson();
JsonArray requestPolicies = getResultsJson.getJsonArray("requestPolicies");
assertThat(getResultsJson.getInteger("totalRecords"), is(1));
JsonObject aPolicy = requestPolicies.getJsonObject(0);
validateRequestPolicy(requestPolicy2, aPolicy);
}
use of org.folio.rest.jaxrs.model.RequestPolicy in project mod-circulation-storage by folio-org.
the class RequestPoliciesApiTest method cannotUpdateRequestPolicyToExistingPolicyName.
@Test
public void cannotUpdateRequestPolicyToExistingPolicyName() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
CompletableFuture<JsonResponse> updateCompleted = new CompletableFuture<>();
String policy1Name = "Policy 1";
String policy2Name = "Policy 2";
List<RequestType> requestTypes = Arrays.asList(RequestType.HOLD, RequestType.PAGE);
createDefaultRequestPolicy(UUID.randomUUID(), policy1Name, "plain description", requestTypes);
RequestPolicy requestPolicy2 = createDefaultRequestPolicy(UUID.randomUUID(), policy2Name, "plain description", requestTypes);
// update: set the name of requestPolicy2 to be of policy1's.
requestPolicy2.setDescription("new description for policy 2");
requestPolicy2.setName(policy1Name);
requestPolicy2.setRequestTypes(Arrays.asList(RequestType.RECALL, RequestType.HOLD));
client.put(requestPolicyStorageUrl("/" + requestPolicy2.getId()), requestPolicy2, StorageTestSuite.TENANT_ID, ResponseHandler.json(updateCompleted));
JsonResponse response = updateCompleted.get(CONNECTION_TIMEOUT, TimeUnit.SECONDS);
assertThat("Failed to update request-policy", response, isBadRequest());
assertThat("Error message does not contain keyword 'already existed'", response.getBody(), containsString("already exists"));
}
Aggregations