use of org.folio.rest.support.JsonResponse in project mod-circulation-storage by folio-org.
the class LoanPoliciesApiTest method cannotCreateLoanPolicyWithItemLimitAboveMaximum.
@Test
public void cannotCreateLoanPolicyWithItemLimitAboveMaximum() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
CompletableFuture<JsonResponse> createCompleted = new CompletableFuture<>();
UUID id = UUID.randomUUID();
JsonObject loanPolicyRequest = defaultRollingPolicy().withId(id).withName("Example Loan Policy").withDescription("An example loan policy").create();
loanPolicyRequest.getJsonObject("loansPolicy").put("itemLimit", 10_000);
client.post(loanPolicyStorageUrl(), loanPolicyRequest, StorageTestSuite.TENANT_ID, ResponseHandler.json(createCompleted));
JsonResponse response = createCompleted.get(5, TimeUnit.SECONDS);
assertThat(String.format("Should fail to create loan policy: %s", response.getBody()), response, matchesUnprocessableEntity());
JsonObject error = getErrorFromResponse(response);
JsonObject parameters = error.getJsonArray("parameters").getJsonObject(0);
assertThat(error.getString("message"), is("must be less than or equal to 9999"));
assertThat(parameters.getString("key"), is("loansPolicy.itemLimit"));
assertThat(parameters.getString("value"), is("10000"));
}
use of org.folio.rest.support.JsonResponse in project mod-circulation-storage by folio-org.
the class LoanPoliciesApiTest method cannotUseHoldAlternateRenewalLoanPeriodForFixedProfile.
@Test
public void cannotUseHoldAlternateRenewalLoanPeriodForFixedProfile() throws Exception {
DateTime from = DateTime.now().minusMonths(3);
DateTime to = DateTime.now().plusMonths(3);
DateTime dueDate = to.plusDays(15);
IndividualResource fixedDueDateSchedule = createFixedDueDateSchedule("semester_for_fixed_policy", from, to, dueDate);
LoanPolicyRequestBuilder loanPolicy = emptyPolicy().fixed(fixedDueDateSchedule.getId()).withAlternateFixedDueDateScheduleId(fixedDueDateSchedule.getId()).withHoldsRenewalLoanPeriod(new Period().withDuration(1).withIntervalId(Period.IntervalId.DAYS));
CompletableFuture<JsonResponse> createCompleted = new CompletableFuture<>();
client.post(loanPolicyStorageUrl(), loanPolicy.create(), StorageTestSuite.TENANT_ID, ResponseHandler.json(createCompleted));
JsonResponse postResponse = createCompleted.get(5, TimeUnit.SECONDS);
assertThat(postResponse.getStatusCode(), is(422));
assertThat(postResponse.getJson().getJsonArray("errors").getJsonObject(0).getString("message"), is("Alternate Renewal Loan Period for Holds is not allowed for policies with Fixed profile"));
}
use of org.folio.rest.support.JsonResponse in project mod-circulation-storage by folio-org.
the class LoanPoliciesApiTest method postLoanPolicyWith422.
/**
* Assert that a POST of the loanPolicyRequest returns a 422 HTTP status code.
* @return the body with the validation failure message
*/
private JsonObject postLoanPolicyWith422(JsonObject loanPolicyRequest) {
try {
CompletableFuture<JsonResponse> createCompleted = new CompletableFuture<>();
client.post(loanPolicyStorageUrl(), loanPolicyRequest, StorageTestSuite.TENANT_ID, ResponseHandler.json(createCompleted));
JsonResponse postResponse = createCompleted.get(5, TimeUnit.SECONDS);
assertThat(String.format("Expected validation failure when creating loan policy: request=%s, response=%s", loanPolicyRequest.encodePrettily(), postResponse.getBody()), postResponse, matchesUnprocessableEntity());
return postResponse.getJson();
} catch (MalformedURLException | InterruptedException | ExecutionException | TimeoutException e) {
throw new RuntimeException(e.getMessage() + ": " + loanPolicyRequest.encodePrettily(), e);
}
}
use of org.folio.rest.support.JsonResponse in project mod-circulation-storage by folio-org.
the class LoanPoliciesApiTest method canDeleteALoanPolicy.
@Test
public void canDeleteALoanPolicy() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
CompletableFuture<JsonResponse> deleteCompleted = new CompletableFuture<>();
UUID id = UUID.randomUUID();
createLoanPolicy(defaultRollingPolicy().withId(id).create());
client.delete(loanPolicyStorageUrl(String.format("/%s", id.toString())), StorageTestSuite.TENANT_ID, ResponseHandler.json(deleteCompleted));
JsonResponse createResponse = deleteCompleted.get(5, TimeUnit.SECONDS);
assertThat(String.format("Failed to delete loan policy: %s", createResponse.getBody()), createResponse, matchesNoContent());
JsonResponse getResponse = getById(id);
assertThat(String.format("Found a deleted loan policy: %s", getResponse.getBody()), getResponse, matchesNotFound());
}
use of org.folio.rest.support.JsonResponse in project mod-circulation-storage by folio-org.
the class LoanPoliciesApiTest method canGetALoanPolicyById.
@Test
public void canGetALoanPolicyById() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
UUID id = UUID.randomUUID();
createLoanPolicy(defaultRollingPolicy().withId(id).create());
JsonResponse getResponse = getById(id);
assertThat(String.format("Failed to get loan policy: %s", getResponse.getBody()), getResponse, matchesOk());
JsonObject representation = getResponse.getJson();
assertThat(representation.getString("id"), is(notNullValue()));
assertThat(representation.getString("description"), is("An example loan policy"));
assertThat(representation.getString("name"), is("Example Loan Policy"));
assertThat(representation.getBoolean("loanable"), is(true));
assertThat(representation.getBoolean("renewable"), is(true));
assertThat(representation.containsKey("loansPolicy"), is(true));
JsonObject loansPolicy = representation.getJsonObject("loansPolicy");
assertThat(loansPolicy.getString("profileId"), is("Rolling"));
assertThat(loansPolicy.getJsonObject("period"), matchesPeriod(1, "Months"));
assertThat(loansPolicy.getString("closedLibraryDueDateManagementId"), is("CURRENT_DUE_DATE"));
assertThat(loansPolicy.getJsonObject("gracePeriod"), matchesPeriod(7, "Days"));
assertThat(loansPolicy.getJsonObject("openingTimeOffset"), matchesPeriod(3, "Hours"));
checkRequestManagementSection(representation);
assertThat(representation.containsKey("renewalsPolicy"), is(true));
JsonObject renewalsPolicy = representation.getJsonObject("renewalsPolicy");
assertThat(renewalsPolicy.getBoolean("unlimited"), is(true));
assertThat(renewalsPolicy.getString("renewFromId"), is("CURRENT_DUE_DATE"));
assertThat(renewalsPolicy.getBoolean("differentPeriod"), is(true));
assertThat(renewalsPolicy.getJsonObject("period"), matchesPeriod(30, "Days"));
}
Aggregations