use of org.folio.rest.support.JsonResponse in project mod-circulation-storage by folio-org.
the class LoansApiTest method canFilterByLoanStatus.
@Test
public void canFilterByLoanStatus() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
UUID userId = UUID.randomUUID();
String queryTemplate = "query=userId=%s+and+status.name=%s";
loansClient.create(loanRequest(userId, "Open"));
loansClient.create(loanRequest(userId, "Open"));
loansClient.create(loanRequest(userId, "Closed"));
loansClient.create(loanRequest(userId, "Closed"));
loansClient.create(loanRequest(userId, "Closed"));
loansClient.create(loanRequest(userId, "Closed"));
CompletableFuture<JsonResponse> openSearchComppleted = new CompletableFuture<>();
CompletableFuture<JsonResponse> closedSearchCompleted = new CompletableFuture<>();
client.get(InterfaceUrls.loanStorageUrl(), String.format(queryTemplate, userId, "Open"), StorageTestSuite.TENANT_ID, ResponseHandler.json(openSearchComppleted));
client.get(InterfaceUrls.loanStorageUrl(), String.format(queryTemplate, userId, "Closed"), StorageTestSuite.TENANT_ID, ResponseHandler.json(closedSearchCompleted));
JsonResponse openLoansResponse = openSearchComppleted.get(5, TimeUnit.SECONDS);
JsonResponse closedLoansResponse = closedSearchCompleted.get(5, TimeUnit.SECONDS);
assertThat(String.format("Failed to get open loans: %s", openLoansResponse.getBody()), openLoansResponse.getStatusCode(), is(200));
assertThat(String.format("Failed to get closed loans: %s", closedLoansResponse.getBody()), closedLoansResponse.getStatusCode(), is(200));
JsonObject openLoans = openLoansResponse.getJson();
JsonObject closedLoans = closedLoansResponse.getJson();
JsonArray firstPageLoans = openLoans.getJsonArray("loans");
JsonArray secondPageLoans = closedLoans.getJsonArray("loans");
assertThat(firstPageLoans.size(), is(2));
assertThat(openLoans.getInteger("totalRecords"), is(2));
assertThat(secondPageLoans.size(), is(4));
assertThat(closedLoans.getInteger("totalRecords"), is(4));
}
use of org.folio.rest.support.JsonResponse in project mod-circulation-storage by folio-org.
the class LoansApiTest method cannotCreateALoanWithInvalidDates.
@Test
public void cannotCreateALoanWithInvalidDates() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
JsonObject loanRequest = new LoanRequestBuilder().create();
loanRequest.put("loanDate", "foo").put("returnDate", "bar");
JsonResponse response = loansClient.attemptCreate(loanRequest);
assertThat(String.format("Creating the loan should fail: %s", response.getBody()), response.getStatusCode(), is(HttpURLConnection.HTTP_BAD_REQUEST));
assertThat(response.getBody(), containsString("loan date must be a date time (in RFC3339 format)"));
assertThat(response.getBody(), containsString("return date must be a date time (in RFC3339 format)"));
assertNoLoanEvent(loanRequest.getString("id"));
}
use of org.folio.rest.support.JsonResponse in project mod-circulation-storage by folio-org.
the class PatronNoticePoliciesApiTest method cannotCreatePatronNoticePolicyWithNotUniqueName.
@Test
public void cannotCreatePatronNoticePolicyWithNotUniqueName() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
JsonObject noticePolicy = new JsonObject().put("name", "sample policy");
postPatronNoticePolicy(noticePolicy);
JsonResponse response = postPatronNoticePolicy(noticePolicy);
String code = response.getJson().getJsonArray("errors").getJsonObject(0).getString("code");
assertThat(response.getStatusCode(), is(422));
assertThat(code, is(STATUS_CODE_DUPLICATE_NAME));
}
use of org.folio.rest.support.JsonResponse in project mod-circulation-storage by folio-org.
the class PatronNoticePoliciesApiTest method cannotDeleteNonexistentPatronNoticePolicyId.
@Test
public void cannotDeleteNonexistentPatronNoticePolicyId() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
String id = UUID.randomUUID().toString();
JsonResponse response = deletePatronNoticePolicy(id);
assertThat(response.getStatusCode(), is(404));
assertThat(response.getBody(), is(NOT_FOUND));
}
use of org.folio.rest.support.JsonResponse in project mod-circulation-storage by folio-org.
the class PatronNoticePoliciesApiTest method cannotDeleteInUsePatronNoticePolicy.
@Test
public void cannotDeleteInUsePatronNoticePolicy() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
String inUsePolicyId = "16b88363-0d93-464a-967a-ad5ad0f9187c";
String rulesAsText = "priority: t, s, c, b, a, m, g" + "fallback-policy: l 43198de5-f56a-4a53-a0bd-5a324418967a r 4c6e1fb0-2ef1-4666-bd15-f9190ff89060 " + "n 122b3d2b-4788-4f1e-9117-56daa91cb75c m 1a54b431-2e4f-452d-9cae-9cee66c9a892: " + "l d9cd0bed-1b49-4b5e-a7bd-064b8d177231 r 334e5a9e-94f9-4673-8d1d-ab552863886b n " + inUsePolicyId;
JsonObject circulationRules = new JsonObject().put("rulesAsText", rulesAsText);
CompletableFuture<TextResponse> putCompleted = new CompletableFuture<>();
client.put(rulesStorageUrl(), circulationRules, TENANT_ID, ResponseHandler.text(putCompleted));
putCompleted.get(5, TimeUnit.SECONDS);
JsonResponse response = deletePatronNoticePolicy(inUsePolicyId);
String message = response.getBody();
assertThat(response.getStatusCode(), is(400));
assertThat(message, is("Cannot delete in use notice policy"));
}
Aggregations