use of org.folio.circulation.domain.Loan in project mod-circulation by folio-org.
the class RollingLoanPolicyRenewalDueDateCalculationTests method shouldApplyMonthlyRollingPolicy.
@ParameterizedTest
@ValueSource(strings = { "1", "8", "12", "15" })
void shouldApplyMonthlyRollingPolicy(int duration) {
LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().rolling(Period.months(duration)).renewFromSystemDate().unlimitedRenewals().create());
ZonedDateTime loanDate = ZonedDateTime.of(2018, 3, 14, 11, 14, 54, 0, UTC);
Loan loan = loanFor(loanDate, loanDate.plusMonths(duration), loanPolicy);
ZonedDateTime systemDate = ZonedDateTime.of(2018, 6, 1, 21, 32, 11, 0, UTC);
Result<Loan> result = renew(loan, systemDate, new RequestQueue(Collections.emptyList()), new OverridingErrorHandler(null));
assertThat(result.value().getDueDate(), is(systemDate.plusMonths(duration)));
}
use of org.folio.circulation.domain.Loan in project mod-circulation by folio-org.
the class RollingLoanPolicyRenewalDueDateCalculationTests method shouldFailWhenNoPeriodIntervalProvided.
@Test
void shouldFailWhenNoPeriodIntervalProvided() {
final JsonObject representation = new LoanPolicyBuilder().rolling(Period.from(5, "Weeks")).withName("Invalid Loan Policy").create();
representation.getJsonObject("loansPolicy").getJsonObject("period").remove("intervalId");
LoanPolicy loanPolicy = LoanPolicy.from(representation);
ZonedDateTime loanDate = ZonedDateTime.of(2018, 3, 14, 11, 14, 54, 0, UTC);
Loan loan = loanFor(loanDate, loanDate, loanPolicy);
CirculationErrorHandler errorHandler = new OverridingErrorHandler(null);
renew(loan, getZonedDateTime(), new RequestQueue(Collections.emptyList()), errorHandler);
assertTrue(matchErrorReason(errorHandler, LOAN_PERIOD_IN_THE_LOAN_POLICY_IS_NOT_RECOGNISED));
}
use of org.folio.circulation.domain.Loan in project mod-circulation by folio-org.
the class RollingLoanPolicyRenewalDueDateCalculationTests method shouldTruncateDueDateWhenWithinDueDateLimitSchedule.
@Test
void shouldTruncateDueDateWhenWithinDueDateLimitSchedule() {
// TODO: Slight hack to use the same builder, the schedule is fed in later
// TODO: Introduce builder for individual schedules
LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().rolling(Period.days(15)).limitedBySchedule(UUID.randomUUID()).renewFromCurrentDueDate().create()).withDueDateSchedules(new FixedDueDateSchedulesBuilder().addSchedule(FixedDueDateSchedule.wholeMonth(2018, 3, ZonedDateTime.of(2018, 4, 10, 23, 59, 59, 0, UTC))).create());
ZonedDateTime loanDate = ZonedDateTime.of(2018, 3, 14, 11, 14, 54, 0, UTC);
Loan loan = loanFor(loanDate, loanDate.plusDays(15), loanPolicy);
CirculationErrorHandler errorHandler = new OverridingErrorHandler(null);
Result<Loan> result = renew(loan, getZonedDateTime(), new RequestQueue(Collections.emptyList()), errorHandler);
assertThat(result.value().getDueDate(), is(ZonedDateTime.of(2018, 4, 10, 23, 59, 59, 0, UTC)));
}
use of org.folio.circulation.domain.Loan in project mod-circulation by folio-org.
the class RollingLoanPolicyRenewalDueDateCalculationTests method shouldNotTruncateDueDateWhenWithinDueDateLimitScheduleButInitialDateIsSooner.
@Test
void shouldNotTruncateDueDateWhenWithinDueDateLimitScheduleButInitialDateIsSooner() {
// TODO: Slight hack to use the same builder, the schedule is fed in later
// TODO: Introduce builder for individual schedules
LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().rolling(Period.days(6)).limitedBySchedule(UUID.randomUUID()).renewFromCurrentDueDate().create()).withDueDateSchedules(new FixedDueDateSchedulesBuilder().addSchedule(FixedDueDateSchedule.wholeMonth(2018, 3)).create());
ZonedDateTime loanDate = ZonedDateTime.of(2018, 3, 11, 16, 21, 43, 0, UTC);
Loan loan = loanFor(loanDate, loanDate.plusDays(6), loanPolicy);
Result<Loan> result = renew(loan, getZonedDateTime(), new RequestQueue(Collections.emptyList()), new OverridingErrorHandler(null));
assertThat(result.value().getDueDate(), is(ZonedDateTime.of(2018, 3, 23, 16, 21, 43, 0, UTC)));
}
use of org.folio.circulation.domain.Loan in project mod-circulation by folio-org.
the class RollingLoanPolicyRenewalDueDateCalculationTests method shouldFailWhenRenewalWouldMeanEarlierDueDate.
@Test
void shouldFailWhenRenewalWouldMeanEarlierDueDate() {
LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().rolling(Period.weeks(2)).withName("Example Rolling Loan Policy").renewFromSystemDate().renewWith(Period.days(3)).create());
final ZonedDateTime initialDueDate = ZonedDateTime.of(2018, 1, 17, 13, 45, 21, 0, UTC);
Loan loan = new LoanBuilder().open().withLoanDate(ZonedDateTime.of(2018, 1, 20, 13, 45, 21, 0, UTC)).withDueDate(initialDueDate).asDomainObject().withLoanPolicy(loanPolicy);
ZonedDateTime renewalDate = initialDueDate.minusDays(4);
CirculationErrorHandler errorHandler = new OverridingErrorHandler(null);
renew(loan, renewalDate, new RequestQueue(Collections.emptyList()), errorHandler);
assertTrue(matchErrorReason(errorHandler, RENEWAL_WOULD_NOT_CHANGE_THE_DUE_DATE));
}
Aggregations