use of org.folio.circulation.domain.RequestQueue in project mod-circulation by folio-org.
the class RollingLoanPolicyRenewalDueDateCalculationTests method shouldFailWhenNoPeriodDurationProvided.
@Test
void shouldFailWhenNoPeriodDurationProvided() {
final JsonObject representation = new LoanPolicyBuilder().rolling(Period.from(5, "Weeks")).withName("Invalid Loan Policy").create();
representation.getJsonObject("loansPolicy").getJsonObject("period").remove("duration");
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.RequestQueue 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 org.folio.circulation.domain.RequestQueue in project mod-circulation by folio-org.
the class RollingLoanPolicyRenewalDueDateCalculationTests method creteRequestQueue.
private RequestQueue creteRequestQueue(String requestId, RequestType requestType) {
JsonObject requestRepresentation = new JsonObject().put("id", requestId).put("requestType", requestType.getValue());
RequestQueue requestQueue = new RequestQueue(new ArrayList<>());
requestQueue.add(Request.from(requestRepresentation));
return requestQueue;
}
use of org.folio.circulation.domain.RequestQueue in project mod-circulation by folio-org.
the class RollingLoanPolicyRenewalDueDateCalculationTests method shouldApplyWeeklyRollingPolicy.
@ParameterizedTest
@ValueSource(strings = { "1", "2", "3", "4", "5" })
void shouldApplyWeeklyRollingPolicy(int duration) {
LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().rolling(Period.weeks(duration)).renewFromSystemDate().unlimitedRenewals().create());
ZonedDateTime loanDate = ZonedDateTime.of(2018, 3, 14, 11, 14, 54, 0, UTC);
Loan loan = loanFor(loanDate, loanDate.plusWeeks(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.plusWeeks(duration)));
}
use of org.folio.circulation.domain.RequestQueue 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