use of org.folio.rest.support.builders.LoanRequestBuilder in project mod-circulation-storage by folio-org.
the class LoansApiTest method omittedStatusFromReplacedLoanDefaultsToOpen.
@Test
public void omittedStatusFromReplacedLoanDefaultsToOpen() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
IndividualResource loan = loansClient.create(new LoanRequestBuilder().open().create());
JsonObject createdLoan = loan.copyJson();
LoanRequestBuilder returnedLoan = LoanRequestBuilder.from(createdLoan).withNoStatus();
loansClient.replace(loan.getId(), returnedLoan);
JsonObject updatedLoan = loansClient.getById(UUID.fromString(loan.getId())).getJson();
assertThat(updatedLoan, isOpen());
assertCreateEventForLoan(createdLoan);
assertUpdateEventForLoan(createdLoan, updatedLoan);
}
use of org.folio.rest.support.builders.LoanRequestBuilder in project mod-circulation-storage by folio-org.
the class LoansApiTest method canCreateAnAlreadyClosedLoan.
@Test
public void canCreateAnAlreadyClosedLoan() throws InterruptedException, ExecutionException, TimeoutException, MalformedURLException {
UUID id = UUID.randomUUID();
UUID itemId = UUID.randomUUID();
UUID userId = UUID.randomUUID();
UUID proxyUserId = UUID.randomUUID();
DateTime loanDate = new DateTime(2017, 2, 27, 10, 23, 43, DateTimeZone.UTC);
DateTime dueDate = new DateTime(2017, 3, 29, 10, 23, 43, DateTimeZone.UTC);
DateTime returnDate = new DateTime(2017, 4, 1, 11, 35, 0, DateTimeZone.UTC);
DateTime systemReturnDate = new DateTime(2017, 4, 1, 12, 0, 0, DateTimeZone.UTC);
JsonObject loanRequest = new LoanRequestBuilder().withId(id).withUserId(userId).withProxyUserId(proxyUserId).withItemId(itemId).withLoanDate(loanDate).withDueDate(dueDate).withReturnDate(returnDate).withSystemReturnDate(systemReturnDate).closed().create();
JsonObject loan = loansClient.create(loanRequest).getJson();
assertThat("return date does not match", loan.getString("returnDate"), is("2017-04-01T11:35:00.000Z"));
assertThat("system return date does not match", loan.getString("systemReturnDate"), is("2017-04-01T12:00:00.000+00:00"));
assertCreateEventForLoan(loan);
}
use of org.folio.rest.support.builders.LoanRequestBuilder in project mod-circulation-storage by folio-org.
the class LoansApiTest method canSearchByLoanAgedToLostBillingDate.
@Test
public void canSearchByLoanAgedToLostBillingDate() throws Exception {
final DateTime today = DateTime.now();
final DateTime yesterday = today.minusDays(1);
final DateTime tomorrow = today.plusDays(1);
loansClient.create(new LoanRequestBuilder().withAgedToLostDelayedBilling(true, yesterday, DateTime.now()));
final IndividualResource loanToBillTomorrow = loansClient.create(new LoanRequestBuilder().withAgedToLostDelayedBilling(false, tomorrow, DateTime.now()));
final List<String> filteredLoans = loansClient.getMany(String.format("agedToLostDelayedBilling.dateLostItemShouldBeBilled > \"%s\"", today)).getRecords().stream().map(json -> json.getString("id")).collect(Collectors.toList());
assertThat(filteredLoans, hasSize(1));
assertThat(filteredLoans, hasItem(loanToBillTomorrow.getId()));
}
use of org.folio.rest.support.builders.LoanRequestBuilder in project mod-circulation-storage by folio-org.
the class LoansApiTest method canRenewALoan.
@Test
public void canRenewALoan() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
DateTime loanDate = new DateTime(2017, DateTimeConstants.MARCH, 1, 13, 25, 46, DateTimeZone.UTC);
IndividualResource loan = loansClient.create(new LoanRequestBuilder().withLoanDate(loanDate).withDueDate(loanDate.plus(Period.days(14))).create());
JsonObject createdLoan = loan.getJson();
LoanRequestBuilder returnedLoan = LoanRequestBuilder.from(createdLoan).withDueDate(new DateTime(2017, DateTimeConstants.MARCH, 30, 13, 25, 46, DateTimeZone.UTC)).withAction("renewed").withActionComment("test action comment").withItemStatus("Checked out").withRenewalCount(1);
loansClient.replace(loan.getId(), returnedLoan);
JsonObject updatedLoan = loansClient.getById(UUID.fromString(loan.getId())).getJson();
assertThat(updatedLoan.getString("dueDate"), is("2017-03-30T13:25:46.000+00:00"));
assertThat(updatedLoan, isOpen());
assertThat("action is not renewed", updatedLoan.getString("action"), is("renewed"));
assertThat("action comment is incorrect", updatedLoan.getString("actionComment"), is("test action comment"));
assertThat("renewal count is not 1", updatedLoan.getInteger("renewalCount"), is(1));
assertThat("item status is not checked out", updatedLoan.getString("itemStatus"), is("Checked out"));
assertCreateEventForLoan(createdLoan);
assertUpdateEventForLoan(createdLoan, updatedLoan);
}
use of org.folio.rest.support.builders.LoanRequestBuilder 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"));
}
Aggregations