use of org.folio.circulation.domain.Loan in project mod-circulation by folio-org.
the class FixedLoanPolicyCheckOutDueDateCalculationTests method shouldUseOnlyScheduleAvailableWhenLoanDateTimeAfterMidnight.
@Test
void shouldUseOnlyScheduleAvailableWhenLoanDateTimeAfterMidnight() {
LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().fixed(UUID.randomUUID()).create()).withDueDateSchedules(new FixedDueDateSchedulesBuilder().addSchedule(new FixedDueDateSchedule(ZonedDateTime.of(2020, 11, 1, 0, 0, 0, 0, UTC), ZonedDateTime.of(2020, 11, 2, 0, 0, 0, 0, UTC), ZonedDateTime.of(2020, 11, 2, 0, 0, 0, 0, UTC))).create());
ZonedDateTime loanDate = ZonedDateTime.of(2020, 11, 2, 12, 30, 30, 0, UTC);
Loan loan = loanFor(loanDate);
final Result<ZonedDateTime> calculationResult = loanPolicy.calculateInitialDueDate(loan, null);
final var expectedInitialDueDate = ZonedDateTime.of(2020, 11, 2, 0, 0, 0, 0, UTC);
assertThat(calculationResult.succeeded(), is(true));
assertThat(calculationResult.value(), is(expectedInitialDueDate));
}
use of org.folio.circulation.domain.Loan in project mod-circulation by folio-org.
the class FixedLoanPolicyCheckOutDueDateCalculationTests method shouldFailWhenLoanDateIsBeforeOnlyScheduleAvailable.
@Test
void shouldFailWhenLoanDateIsBeforeOnlyScheduleAvailable() {
LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().fixed(UUID.randomUUID()).withName("Example Fixed Schedule Loan Policy").create()).withDueDateSchedules(new FixedDueDateSchedulesBuilder().addSchedule(FixedDueDateSchedule.wholeYear(2018)).create());
ZonedDateTime loanDate = ZonedDateTime.of(2017, 12, 30, 14, 32, 21, 0, UTC);
Loan loan = loanFor(loanDate);
final Result<ZonedDateTime> result = loanPolicy.calculateInitialDueDate(loan, null);
assertThat(result, hasValidationFailure("loan date falls outside of the date ranges in the loan policy"));
}
use of org.folio.circulation.domain.Loan in project mod-circulation by folio-org.
the class FixedLoanPolicyRenewalDueDateCalculationTests method shouldFailWhenRenewalWouldMeanEarlierDueDate.
@Test
void shouldFailWhenRenewalWouldMeanEarlierDueDate() {
LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().fixed(UUID.randomUUID()).withName("Example Fixed Schedule Loan Policy").create()).withDueDateSchedules(new FixedDueDateSchedulesBuilder().addSchedule(FixedDueDateSchedule.wholeMonth(2018, 1)).create());
Loan loan = new LoanBuilder().open().withLoanDate(ZonedDateTime.of(2018, 1, 20, 13, 45, 21, 0, UTC)).withDueDate(ZonedDateTime.of(2018, 2, 28, 23, 59, 59, 0, UTC)).asDomainObject().withLoanPolicy(loanPolicy);
ZonedDateTime renewalDate = ZonedDateTime.of(2018, 1, 3, 8, 12, 32, 0, UTC);
CirculationErrorHandler errorHandler = new OverridingErrorHandler(null);
renew(loan, renewalDate, new RequestQueue(Collections.emptyList()), errorHandler);
assertTrue(matchErrorReason(errorHandler, RENEWAL_WOULD_NOT_CHANGE_THE_DUE_DATE));
}
use of org.folio.circulation.domain.Loan in project mod-circulation by folio-org.
the class FixedLoanPolicyRenewalDueDateCalculationTests method shouldFailWhenLoanDateIsAfterOnlyScheduleAvailable.
@Test
void shouldFailWhenLoanDateIsAfterOnlyScheduleAvailable() {
LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().fixed(UUID.randomUUID()).withName("Example Fixed Schedule Loan Policy").create()).withDueDateSchedules(new FixedDueDateSchedulesBuilder().addSchedule(FixedDueDateSchedule.wholeYear(2018)).create());
Loan loan = existingLoan(loanPolicy);
ZonedDateTime renewalDate = ZonedDateTime.of(2019, 1, 1, 8, 10, 45, 0, UTC);
RequestQueue requestQueue = new RequestQueue(Collections.emptyList());
CirculationErrorHandler errorHandler = new OverridingErrorHandler(null);
renew(loan, renewalDate, requestQueue, errorHandler);
assertEquals(1, errorHandler.getErrors().size());
assertTrue(matchErrorReason(errorHandler, EXPECTED_REASON_DATE_FALLS_OUTSIDE_DATE_RANGES));
}
use of org.folio.circulation.domain.Loan in project mod-circulation by folio-org.
the class FixedLoanPolicyRenewalDueDateCalculationTests method shouldFailWhenLoanDateIsInBetweenSchedules.
@Test
void shouldFailWhenLoanDateIsInBetweenSchedules() {
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, 3)).create());
Loan loan = existingLoan(loanPolicy);
ZonedDateTime renewalDate = ZonedDateTime.of(2018, 2, 18, 6, 34, 21, 0, UTC);
CirculationErrorHandler errorHandler = new OverridingErrorHandler(null);
renew(loan, renewalDate, new RequestQueue(Collections.emptyList()), errorHandler);
assertTrue(matchErrorReason(errorHandler, EXPECTED_REASON_DATE_FALLS_OUTSIDE_DATE_RANGES));
}
Aggregations