use of org.folio.rest.support.JsonResponse in project mod-circulation-storage by folio-org.
the class LoansApiTest method canSearchByUserId.
@Test
public void canSearchByUserId() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
UUID firstUserId = UUID.randomUUID();
UUID secondUserId = UUID.randomUUID();
String queryTemplate = InterfaceUrls.loanStorageUrl() + "?query=userId='%s'";
loansClient.create(new LoanRequestBuilder().withUserId(firstUserId).create());
loansClient.create(new LoanRequestBuilder().withUserId(firstUserId).create());
loansClient.create(new LoanRequestBuilder().withUserId(firstUserId).create());
loansClient.create(new LoanRequestBuilder().withUserId(firstUserId).create());
loansClient.create(new LoanRequestBuilder().withUserId(secondUserId).create());
loansClient.create(new LoanRequestBuilder().withUserId(secondUserId).create());
loansClient.create(new LoanRequestBuilder().withUserId(secondUserId).create());
CompletableFuture<JsonResponse> firstUserSearchCompleted = new CompletableFuture<>();
CompletableFuture<JsonResponse> secondUserSeatchCompleted = new CompletableFuture<>();
client.get(String.format(queryTemplate, firstUserId), StorageTestSuite.TENANT_ID, ResponseHandler.json(firstUserSearchCompleted));
client.get(String.format(queryTemplate, secondUserId), StorageTestSuite.TENANT_ID, ResponseHandler.json(secondUserSeatchCompleted));
JsonResponse firstPageResponse = firstUserSearchCompleted.get(5, TimeUnit.SECONDS);
JsonResponse secondPageResponse = secondUserSeatchCompleted.get(5, TimeUnit.SECONDS);
assertThat(String.format("Failed to get loans for first user: %s", firstPageResponse.getBody()), firstPageResponse.getStatusCode(), is(200));
assertThat(String.format("Failed to get loans for second user: %s", secondPageResponse.getBody()), secondPageResponse.getStatusCode(), is(200));
JsonObject firstPage = firstPageResponse.getJson();
JsonObject secondPage = secondPageResponse.getJson();
JsonArray firstPageLoans = firstPage.getJsonArray("loans");
JsonArray secondPageLoans = secondPage.getJsonArray("loans");
assertThat(firstPageLoans.size(), is(4));
assertThat(firstPage.getInteger("totalRecords"), is(4));
assertThat(secondPageLoans.size(), is(3));
assertThat(secondPage.getInteger("totalRecords"), is(3));
}
use of org.folio.rest.support.JsonResponse in project mod-circulation-storage by folio-org.
the class LoansApiTest method cannotCreateMultipleOpenLoansForSameItem.
@Test
public void cannotCreateMultipleOpenLoansForSameItem() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
UUID itemId = UUID.randomUUID();
JsonObject firstLoanRequest = new LoanRequestBuilder().withItemId(itemId).open().create();
loansClient.create(firstLoanRequest);
JsonObject firstLoan = loansClient.getById(firstLoanRequest.getString("id")).getJson();
JsonObject secondLoanRequest = new LoanRequestBuilder().withItemId(itemId).open().create();
JsonResponse response = loansClient.attemptCreate(secondLoanRequest);
assertThat(response, isValidationResponseWhich(hasMessage("Cannot have more than one open loan for the same item")));
assertCreateEventForLoan(firstLoan);
assertNoLoanEvent(secondLoanRequest.getString("id"));
}
use of org.folio.rest.support.JsonResponse in project mod-circulation-storage by folio-org.
the class LoansApiTest method canDeleteALoan.
@Test
public void canDeleteALoan() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
UUID id = UUID.randomUUID();
IndividualResource loanResouce = loansClient.create(new LoanRequestBuilder().withId(id).create());
loansClient.deleteById(id);
JsonResponse getResponse = loansClient.attemptGetById(id);
assertThat(getResponse, isNotFound());
JsonObject loan = loanResouce.getJson();
assertCreateEventForLoan(loan);
assertRemoveEventForLoan(loan);
}
use of org.folio.rest.support.JsonResponse in project mod-circulation-storage by folio-org.
the class LoansApiTest method cannotProvideAdditionalPropertiesInLoanStatus.
@Test
public void cannotProvideAdditionalPropertiesInLoanStatus() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
UUID id = UUID.randomUUID();
JsonObject requestWithAdditionalProperty = new LoanRequestBuilder().withId(id).create();
requestWithAdditionalProperty.getJsonObject("status").put("somethingAdditional", "foo");
JsonResponse response = loansClient.attemptCreate(requestWithAdditionalProperty);
assertThat(response, isValidationResponseWhich(hasMessageContaining("Unrecognized field")));
assertNoLoanEvent(id.toString());
}
use of org.folio.rest.support.JsonResponse in project mod-circulation-storage by folio-org.
the class LoansApiTest method cannotCreateALoanWithoutAction.
@Test
public void cannotCreateALoanWithoutAction() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
JsonObject loanRequest = new LoanRequestBuilder().create();
loanRequest.remove("action");
JsonResponse response = loansClient.attemptCreate(loanRequest);
assertThat(response, isValidationResponseWhich(allOf(// any server language
anyOf(hasMessage("must not be null"), hasMessage("darf nicht null sein")), hasParameter("action", "null"))));
assertNoLoanEvent(loanRequest.getString("id"));
}
Aggregations