use of org.folio.rest.support.builders.LoanRequestBuilder in project mod-circulation-storage by folio-org.
the class LoansApiTest method returnDateIsMandatoryForClosedLoans.
@Test
@Ignore("Should conditional field validation be done in a storage module?")
public void returnDateIsMandatoryForClosedLoans() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
DateTime loanDate = new DateTime(2017, 3, 1, 13, 25, 46, 232, DateTimeZone.UTC);
IndividualResource loan = loansClient.create(new LoanRequestBuilder().withLoanDate(loanDate).withDueDate(loanDate.plus(Period.days(14))).create());
LoanRequestBuilder returnedLoan = LoanRequestBuilder.from(loan.copyJson()).closed();
CompletableFuture<TextResponse> putCompleted = new CompletableFuture<>();
client.put(InterfaceUrls.loanStorageUrl(String.format("/%s", loan.getId())), returnedLoan.create(), StorageTestSuite.TENANT_ID, ResponseHandler.text(putCompleted));
TextResponse response = putCompleted.get(5, TimeUnit.SECONDS);
assertThat(String.format("Should have failed to update loan: %s", response.getBody()), response.getStatusCode(), is(HttpURLConnection.HTTP_BAD_REQUEST));
assertThat(response.getBody(), containsString("return date is mandatory to close a loan"));
}
use of org.folio.rest.support.builders.LoanRequestBuilder in project mod-circulation-storage by folio-org.
the class LoansApiTest method canCreateMultipleOpenLoansForDifferentItems.
@Test
public void canCreateMultipleOpenLoansForDifferentItems() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
UUID firstItemId = UUID.randomUUID();
UUID secondItemId = UUID.randomUUID();
JsonObject firstLoanRequest = new LoanRequestBuilder().withItemId(firstItemId).open().create();
loansClient.create(firstLoanRequest);
JsonObject firstLoan = loansClient.getById(firstLoanRequest.getString("id")).getJson();
JsonObject secondLoanRequest = new LoanRequestBuilder().withItemId(secondItemId).open().create();
loansClient.create(secondLoanRequest);
JsonObject secondLoan = loansClient.getById(secondLoanRequest.getString("id")).getJson();
assertCreateEventForLoan(firstLoan);
assertCreateEventForLoan(secondLoan);
}
use of org.folio.rest.support.builders.LoanRequestBuilder in project mod-circulation-storage by folio-org.
the class LoansApiTest method canSearchByLoanStatus.
@Test
public void canSearchByLoanStatus() throws Exception {
final IndividualResource openLoan = loansClient.create(new LoanRequestBuilder().checkedOut());
loansClient.create(new LoanRequestBuilder().checkedIn());
final List<String> openLoans = loansClient.getMany("status.name==Open").getRecords().stream().map(json -> json.getString("id")).collect(Collectors.toList());
assertThat(openLoans, hasSize(1));
assertThat(openLoans, hasItem(openLoan.getId()));
}
use of org.folio.rest.support.builders.LoanRequestBuilder in project mod-circulation-storage by folio-org.
the class LoansApiTest method cannotCreateOpenLoanWithoutUserIdViaPut.
@Test
public void cannotCreateOpenLoanWithoutUserIdViaPut() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
final UUID loanId = UUID.randomUUID();
final LoanRequestBuilder loanRequest = new LoanRequestBuilder().withId(loanId).open().withNoUserId();
final JsonResponse putResponse = loansClient.attemptCreateOrReplace(loanId.toString(), loanRequest);
assertThat(putResponse, isValidationResponseWhich(hasMessage("Open loan must have a user ID")));
assertNoLoanEvent(loanId.toString());
}
use of org.folio.rest.support.builders.LoanRequestBuilder 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));
}
Aggregations