use of org.folio.circulation.domain.RequestQueue in project mod-circulation by folio-org.
the class FixedLoanPolicyRenewalDueDateCalculationTests method shouldUseMiddleScheduleAvailableWhenLoanDateFits.
@Test
void shouldUseMiddleScheduleAvailableWhenLoanDateFits() {
final FixedDueDateSchedule expectedSchedule = FixedDueDateSchedule.wholeMonth(2018, 2);
LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().fixed(UUID.randomUUID()).create()).withDueDateSchedules(new FixedDueDateSchedulesBuilder().addSchedule(FixedDueDateSchedule.wholeMonth(2018, 1)).addSchedule(expectedSchedule).addSchedule(FixedDueDateSchedule.wholeMonth(2018, 3)).create());
Loan loan = existingLoan(loanPolicy);
ZonedDateTime renewalDate = ZonedDateTime.of(2018, 2, 27, 16, 23, 43, 0, UTC);
Result<Loan> result = renew(loan, renewalDate, new RequestQueue(Collections.emptyList()), new OverridingErrorHandler(null));
assertThat(result.value().getDueDate(), is(expectedSchedule.due));
}
use of org.folio.circulation.domain.RequestQueue in project mod-circulation by folio-org.
the class FixedLoanPolicyRenewalDueDateCalculationTests method shouldUseOnlyScheduleAvailableWhenLoanDateFits.
@Test
void shouldUseOnlyScheduleAvailableWhenLoanDateFits() {
LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().fixed(UUID.randomUUID()).create()).withDueDateSchedules(new FixedDueDateSchedulesBuilder().addSchedule(FixedDueDateSchedule.wholeYear(2018)).create());
Loan loan = existingLoan(loanPolicy);
ZonedDateTime renewalDate = ZonedDateTime.of(2018, 3, 14, 11, 14, 54, 0, UTC);
String requestId = UUID.randomUUID().toString();
RequestQueue requestQueue = creteRequestQueue(requestId, RequestType.PAGE);
CirculationErrorHandler errorHandler = new OverridingErrorHandler(null);
Result<Loan> result = renew(loan, renewalDate, requestQueue, errorHandler);
final ZonedDateTime expectedDate = atStartOfDay(LocalDate.of(2018, 12, 31), UTC).plusDays(1).minusSeconds(1);
assertThat(result.value().getDueDate(), is(expectedDate));
}
use of org.folio.circulation.domain.RequestQueue in project mod-circulation by folio-org.
the class FixedLoanPolicyRenewalDueDateCalculationTests method shouldFailWhenLoanDateIsBeforeAllSchedules.
@Test
void shouldFailWhenLoanDateIsBeforeAllSchedules() {
LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().fixed(UUID.randomUUID()).withName("Example Fixed Schedule Loan Policy").create()).withDueDateSchedules(new FixedDueDateSchedulesBuilder().addSchedule(FixedDueDateSchedule.wholeMonth(2018, 1)).addSchedule(FixedDueDateSchedule.wholeMonth(2018, 2)).addSchedule(FixedDueDateSchedule.wholeMonth(2018, 3)).create());
Loan loan = existingLoan(loanPolicy);
ZonedDateTime renewalDate = ZonedDateTime.of(2017, 12, 30, 14, 32, 21, 0, UTC);
CirculationErrorHandler errorHandler = new OverridingErrorHandler(null);
renew(loan, renewalDate, new RequestQueue(Collections.emptyList()), errorHandler);
assertEquals(1, errorHandler.getErrors().size());
assertTrue(matchErrorReason(errorHandler, EXPECTED_REASON_DATE_FALLS_OUTSIDE_DATE_RANGES));
}
use of org.folio.circulation.domain.RequestQueue in project mod-circulation by folio-org.
the class FixedLoanPolicyRenewalDueDateCalculationTests method shouldFailWhenRenewalWouldMeanEarlierDueDateAndReachedRenewalLimit.
@Test
void shouldFailWhenRenewalWouldMeanEarlierDueDateAndReachedRenewalLimit() {
LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().fixed(UUID.randomUUID()).withName("Example Fixed Schedule Loan Policy").limitedRenewals(1).create()).withDueDateSchedules(new FixedDueDateSchedulesBuilder().addSchedule(FixedDueDateSchedule.wholeMonth(2018, 1)).addSchedule(FixedDueDateSchedule.wholeMonth(2018, 2)).create());
Loan loan = new LoanBuilder().open().withLoanDate(ZonedDateTime.of(2018, 1, 20, 13, 45, 21, 0, UTC)).withDueDate(ZonedDateTime.of(2018, 1, 31, 23, 59, 59, 0, UTC)).asDomainObject().withLoanPolicy(loanPolicy);
CirculationErrorHandler errorHandler = new OverridingErrorHandler(null);
loan = renew(loan, ZonedDateTime.of(2018, 2, 1, 11, 23, 43, 0, UTC), new RequestQueue(Collections.emptyList()), errorHandler).value();
ZonedDateTime renewalDate = ZonedDateTime.of(2018, 3, 5, 8, 12, 32, 0, UTC);
renew(loan, renewalDate, new RequestQueue(Collections.emptyList()), errorHandler);
assertTrue(matchErrorReason(errorHandler, EXPECTED_REASON_DATE_FALLS_OUTSIDE_DATE_RANGES));
assertTrue(matchErrorReason(errorHandler, LOAN_AT_MAXIMUM_RENEWAL_NUMBER));
assertEquals(2, errorHandler.getErrors().size());
}
use of org.folio.circulation.domain.RequestQueue in project mod-circulation by folio-org.
the class FixedLoanPolicyRenewalDueDateCalculationTests method multipleRenewalFailuresWhenLoanHasReachedMaximumNumberOfRenewalsAndOpenRecallRequest.
@Test
void multipleRenewalFailuresWhenLoanHasReachedMaximumNumberOfRenewalsAndOpenRecallRequest() {
LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().fixed(UUID.randomUUID()).withName("Example Fixed Schedule Loan Policy").limitedRenewals(1).create()).withDueDateSchedules(new FixedDueDateSchedulesBuilder().addSchedule(FixedDueDateSchedule.wholeMonth(2018, 1)).addSchedule(FixedDueDateSchedule.wholeMonth(2018, 2)).create());
Loan loan = new LoanBuilder().open().withLoanDate(ZonedDateTime.of(2018, 1, 20, 13, 45, 21, 0, UTC)).withDueDate(ZonedDateTime.of(2018, 1, 31, 23, 59, 59, 0, UTC)).asDomainObject().withLoanPolicy(loanPolicy);
CirculationErrorHandler errorHandler = new OverridingErrorHandler(null);
loan = renew(loan, ZonedDateTime.of(2018, 2, 1, 11, 23, 43, 0, UTC), new RequestQueue(Collections.emptyList()), errorHandler).value();
ZonedDateTime renewalDate = ZonedDateTime.of(2018, 3, 5, 8, 12, 32, 0, UTC);
String requestId = UUID.randomUUID().toString();
RequestQueue requestQueue = creteRequestQueue(requestId, RequestType.RECALL);
renew(loan, renewalDate, requestQueue, errorHandler);
assertTrue(matchErrorReason(errorHandler, EXPECTED_REASON_DATE_FALLS_OUTSIDE_DATE_RANGES));
assertTrue(matchErrorReason(errorHandler, LOAN_AT_MAXIMUM_RENEWAL_NUMBER));
assertTrue(matchErrorReason(errorHandler, LOAN_AT_MAXIMUM_RENEWAL_NUMBER));
}
Aggregations