use of api.support.builders.FixedDueDateSchedulesBuilder in project mod-circulation by folio-org.
the class RollingLoanPolicyCheckOutDueDateCalculationTests 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.months(1)).limitedBySchedule(UUID.randomUUID()).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);
final Result<ZonedDateTime> result = loanPolicy.calculateInitialDueDate(loan, null);
assertThat(result.value(), is(ZonedDateTime.of(2018, 4, 10, 23, 59, 59, 0, UTC)));
}
use of api.support.builders.FixedDueDateSchedulesBuilder in project mod-circulation by folio-org.
the class RollingLoanPolicyCheckOutDueDateCalculationTests 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)).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);
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 api.support.builders.FixedDueDateSchedulesBuilder 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 api.support.builders.FixedDueDateSchedulesBuilder in project mod-circulation by folio-org.
the class RollingLoanPolicyRenewalDueDateCalculationTests method shouldFailWhenNoDueDateLimitSchedules.
@Test
void shouldFailWhenNoDueDateLimitSchedules() {
// 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.months(1)).withName("One Month").renewFromCurrentDueDate().limitedBySchedule(UUID.randomUUID()).create()).withDueDateSchedules(new FixedDueDateSchedulesBuilder().create());
ZonedDateTime loanDate = ZonedDateTime.of(2018, 4, 3, 9, 25, 43, 0, UTC);
Loan loan = loanFor(loanDate, loanDate, loanPolicy);
RequestQueue requestQueue = new RequestQueue(Collections.emptyList());
CirculationErrorHandler errorHandler = new OverridingErrorHandler(null);
renew(loan, getZonedDateTime(), requestQueue, errorHandler);
assertTrue(matchErrorReason(errorHandler, EXPECTED_REASON_DATE_FALLS_OTSIDE_DATE_RANGES));
}
use of api.support.builders.FixedDueDateSchedulesBuilder in project mod-circulation by folio-org.
the class RollingLoanPolicyRenewalDueDateCalculationTests method multipleRenewalFailuresWhenDateFallsOutsideDateRangesAndItemHasOpenRecallRequest.
@Test
void multipleRenewalFailuresWhenDateFallsOutsideDateRangesAndItemHasOpenRecallRequest() {
LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().rolling(Period.months(1)).withName("One Month").renewFromCurrentDueDate().limitedBySchedule(UUID.randomUUID()).create()).withDueDateSchedules(new FixedDueDateSchedulesBuilder().create());
ZonedDateTime loanDate = ZonedDateTime.of(2018, 3, 2, 9, 10, 45, 0, UTC);
Loan loan = loanFor(loanDate, loanDate, loanPolicy);
String requestId = UUID.randomUUID().toString();
RequestQueue requestQueue = creteRequestQueue(requestId, RequestType.RECALL);
CirculationErrorHandler errorHandler = new OverridingErrorHandler(null);
renew(loan, getZonedDateTime(), requestQueue, errorHandler);
assertEquals(2, errorHandler.getErrors().size());
assertTrue(matchErrorReason(errorHandler, EXPECTED_REASON_DATE_FALLS_OTSIDE_DATE_RANGES));
assertTrue(matchErrorReason(errorHandler, EXPECTED_REASON_OPEN_RECALL_REQUEST));
}
Aggregations