use of org.folio.rest.support.JsonResponse in project mod-circulation-storage by folio-org.
the class LoanPoliciesApiTest method getById.
private JsonResponse getById(UUID id) throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
URL getInstanceUrl = loanPolicyStorageUrl(String.format("/%s", id));
CompletableFuture<JsonResponse> getCompleted = new CompletableFuture<>();
client.get(getInstanceUrl, StorageTestSuite.TENANT_ID, ResponseHandler.json(getCompleted));
return getCompleted.get(5, TimeUnit.SECONDS);
}
use of org.folio.rest.support.JsonResponse in project mod-circulation-storage by folio-org.
the class LoanPoliciesApiTest method canPageLoanPolicies.
@Test
public void canPageLoanPolicies() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
createLoanPolicy(defaultRollingPolicy().create());
createLoanPolicy(defaultRollingPolicy().create());
createLoanPolicy(defaultRollingPolicy().create());
createLoanPolicy(defaultRollingPolicy().create());
createLoanPolicy(defaultRollingPolicy().create());
createLoanPolicy(defaultRollingPolicy().create());
createLoanPolicy(defaultRollingPolicy().create());
CompletableFuture<JsonResponse> firstPageCompleted = new CompletableFuture<>();
CompletableFuture<JsonResponse> secondPageCompleted = new CompletableFuture<>();
client.get(loanPolicyStorageUrl() + "?limit=4", StorageTestSuite.TENANT_ID, ResponseHandler.json(firstPageCompleted));
client.get(loanPolicyStorageUrl() + "?limit=4&offset=4", StorageTestSuite.TENANT_ID, ResponseHandler.json(secondPageCompleted));
JsonResponse firstPageResponse = firstPageCompleted.get(5, TimeUnit.SECONDS);
JsonResponse secondPageResponse = secondPageCompleted.get(5, TimeUnit.SECONDS);
MatcherAssert.assertThat(String.format("Failed to get first page of loan policies: %s", firstPageResponse.getBody()), firstPageResponse.getStatusCode(), is(200));
MatcherAssert.assertThat(String.format("Failed to get second page of loans policies: %s", secondPageResponse.getBody()), secondPageResponse.getStatusCode(), is(200));
JsonObject firstPage = firstPageResponse.getJson();
JsonObject secondPage = secondPageResponse.getJson();
JsonArray firstPageLoans = firstPage.getJsonArray("loanPolicies");
JsonArray secondPageLoans = secondPage.getJsonArray("loanPolicies");
MatcherAssert.assertThat(firstPageLoans.size(), is(4));
MatcherAssert.assertThat(firstPage.getInteger("totalRecords"), is(7));
MatcherAssert.assertThat(secondPageLoans.size(), is(3));
MatcherAssert.assertThat(secondPage.getInteger("totalRecords"), is(7));
}
use of org.folio.rest.support.JsonResponse in project mod-circulation-storage by folio-org.
the class LoanPoliciesApiTest method cannotCreateLoanPolicyWithItemLimitBelowMinimum.
@Test
public void cannotCreateLoanPolicyWithItemLimitBelowMinimum() 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", 0);
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 greater than or equal to 1"));
assertThat(parameters.getString("key"), is("loansPolicy.itemLimit"));
assertThat(parameters.getString("value"), is("0"));
}
use of org.folio.rest.support.JsonResponse in project mod-circulation-storage by folio-org.
the class LoanPoliciesApiTest method cannotUseRenewalsPeriodForFixedProfile.
@Test
public void cannotUseRenewalsPeriodForFixedProfile() throws Exception {
DateTime from = DateTime.now().minusMonths(3);
DateTime to = DateTime.now().plusMonths(3);
DateTime dueDate = to.plusDays(15);
IndividualResource fixedDueDateSchedule = createFixedDueDateSchedule("semester fixed policy test", from, to, dueDate);
LoanPolicyRequestBuilder loanPolicy = emptyPolicy().fixed(fixedDueDateSchedule.getId()).withAlternateFixedDueDateScheduleId(fixedDueDateSchedule.getId()).withName("test").withRenewalPeriod(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("Period in RenewalsPolicy 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 canCreateALoanPolicyWithoutAnId.
@Test
public void canCreateALoanPolicyWithoutAnId() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
CompletableFuture<JsonResponse> createCompleted = new CompletableFuture<>();
JsonObject loanPolicyRequest = defaultRollingPolicy().withNoId().create();
client.post(loanPolicyStorageUrl(), loanPolicyRequest, StorageTestSuite.TENANT_ID, ResponseHandler.json(createCompleted));
JsonResponse response = createCompleted.get(5, TimeUnit.SECONDS);
assertThat(String.format("Failed to create loan policy: %s", response.getBody()), response, matchesCreated());
JsonObject representation = response.getJson();
assertThat(representation.getString("id"), is(notNullValue()));
}
Aggregations