use of org.folio.circulation.domain.RequestQueue in project mod-circulation by folio-org.
the class RollingLoanPolicyCheckOutDueDateCalculationTests method shouldApplyAlternateScheduleWhenQueuedRequestIsHoldAndRolling.
@Test
void shouldApplyAlternateScheduleWhenQueuedRequestIsHoldAndRolling() {
final Period alternateCheckoutLoanPeriod = Period.from(2, "Weeks");
final ZonedDateTime systemTime = ZonedDateTime.of(2019, 6, 14, 11, 23, 43, 0, UTC);
LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().rolling(Period.months(1)).withAlternateCheckoutLoanPeriod(alternateCheckoutLoanPeriod).create()).withDueDateSchedules(new FixedDueDateSchedulesBuilder().addSchedule(FixedDueDateSchedule.wholeYear(systemTime.getYear())).create());
Item item = Item.from(new ItemBuilder().checkOut().withId(UUID.randomUUID()).create());
Loan loan = Loan.from(new LoanBuilder().withItemId(UUID.fromString(item.getItemId())).withLoanDate(systemTime).create());
Request requestOne = Request.from(new RequestBuilder().withId(UUID.randomUUID()).withPosition(1).create());
Request requestTwo = Request.from(new RequestBuilder().withId(UUID.randomUUID()).withStatus(RequestStatus.OPEN_NOT_YET_FILLED.getValue()).hold().withItemId(UUID.fromString(loan.getItemId())).withPosition(2).create());
RequestQueue requestQueue = new RequestQueue(asList(requestOne, requestTwo));
ZonedDateTime calculatedDueDate = loanPolicy.calculateInitialDueDate(loan, requestQueue).value();
String key = "alternateCheckoutLoanPeriod";
ZonedDateTime expectedDueDate = alternateCheckoutLoanPeriod.addTo(systemTime, () -> errorForLoanPeriod(format("the \"%s\" is not recognized", key)), interval -> errorForLoanPeriod(format("the interval \"%s\" in \"%s\" is not recognized", interval, key)), dur -> errorForLoanPeriod(format("the duration \"%s\" in \"%s\" is invalid", dur, key))).value();
assertThat(calculatedDueDate, is(expectedDueDate));
}
use of org.folio.circulation.domain.RequestQueue in project mod-circulation by folio-org.
the class RollingLoanPolicyRenewalDueDateCalculationTests method shouldApplyMinuteIntervalRollingPolicy.
@ParameterizedTest
@ValueSource(strings = { "1", "5", "30", "60", "200" })
void shouldApplyMinuteIntervalRollingPolicy(int duration) {
LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().rolling(Period.minutes(duration)).renewFromSystemDate().unlimitedRenewals().create());
ZonedDateTime loanDate = ZonedDateTime.of(2018, 3, 14, 11, 14, 54, 0, UTC);
Loan loan = loanFor(loanDate, loanDate, 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.plusMinutes(duration)));
}
use of org.folio.circulation.domain.RequestQueue in project mod-circulation by folio-org.
the class RollingLoanPolicyRenewalDueDateCalculationTests method shouldFailWhenNotWithinOneOfProvidedDueDateLimitSchedules.
@Test
void shouldFailWhenNotWithinOneOfProvidedDueDateLimitSchedules() {
// 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().withName("One Month").rolling(Period.months(1)).renewFromCurrentDueDate().limitedBySchedule(UUID.randomUUID()).create()).withDueDateSchedules(new FixedDueDateSchedulesBuilder().addSchedule(FixedDueDateSchedule.wholeMonth(2018, 3)).addSchedule(FixedDueDateSchedule.wholeMonth(2018, 5)).create());
ZonedDateTime loanDate = ZonedDateTime.of(2018, 4, 3, 9, 25, 43, 0, UTC);
Loan loan = loanFor(loanDate, loanDate, loanPolicy);
CirculationErrorHandler errorHandler = new OverridingErrorHandler(null);
renew(loan, getZonedDateTime(), new RequestQueue(Collections.emptyList()), errorHandler);
assertEquals(1, errorHandler.getErrors().size());
assertTrue(matchErrorReason(errorHandler, EXPECTED_REASON_DATE_FALLS_OTSIDE_DATE_RANGES));
}
use of org.folio.circulation.domain.RequestQueue in project mod-circulation by folio-org.
the class RollingLoanPolicyRenewalDueDateCalculationTests method shouldApplyDailyRollingPolicy.
@ParameterizedTest
@ValueSource(strings = { "1", "7", "14", "12", "30", "100" })
void shouldApplyDailyRollingPolicy(int duration) {
LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().rolling(Period.days(duration)).renewFromSystemDate().unlimitedRenewals().create());
ZonedDateTime loanDate = ZonedDateTime.of(2018, 3, 14, 11, 14, 54, 0, UTC);
Loan loan = loanFor(loanDate, loanDate.plusDays(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.plusDays(duration)));
}
use of org.folio.circulation.domain.RequestQueue in project mod-circulation by folio-org.
the class RollingLoanPolicyRenewalDueDateCalculationTests method shouldApplyHourlyRollingPolicy.
@ParameterizedTest
@ValueSource(strings = { "2", "5", "30", "45", "60", "24" })
void shouldApplyHourlyRollingPolicy(int duration) {
LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().rolling(Period.hours(duration)).renewFromSystemDate().unlimitedRenewals().create());
ZonedDateTime loanDate = ZonedDateTime.of(2018, 3, 14, 11, 14, 54, 0, UTC);
Loan loan = loanFor(loanDate, loanDate.plusHours(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.plusHours(duration)));
}
Aggregations