Search in sources :

Example 21 with RequestQueue

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));
}
Also used : Loan(org.folio.circulation.domain.Loan) ClockUtil.getZonedDateTime(org.folio.circulation.support.utils.ClockUtil.getZonedDateTime) ZonedDateTime(java.time.ZonedDateTime) RequestQueue(org.folio.circulation.domain.RequestQueue) JsonObject(io.vertx.core.json.JsonObject) CirculationErrorHandler(org.folio.circulation.resources.handlers.error.CirculationErrorHandler) OverridingErrorHandler(org.folio.circulation.resources.handlers.error.OverridingErrorHandler) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 22 with RequestQueue

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));
}
Also used : FixedDueDateSchedulesBuilder(api.support.builders.FixedDueDateSchedulesBuilder) Loan(org.folio.circulation.domain.Loan) ClockUtil.getZonedDateTime(org.folio.circulation.support.utils.ClockUtil.getZonedDateTime) ZonedDateTime(java.time.ZonedDateTime) RequestQueue(org.folio.circulation.domain.RequestQueue) CirculationErrorHandler(org.folio.circulation.resources.handlers.error.CirculationErrorHandler) OverridingErrorHandler(org.folio.circulation.resources.handlers.error.OverridingErrorHandler) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 23 with RequestQueue

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;
}
Also used : RequestQueue(org.folio.circulation.domain.RequestQueue) JsonObject(io.vertx.core.json.JsonObject)

Example 24 with 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)));
}
Also used : Loan(org.folio.circulation.domain.Loan) ClockUtil.getZonedDateTime(org.folio.circulation.support.utils.ClockUtil.getZonedDateTime) ZonedDateTime(java.time.ZonedDateTime) RequestQueue(org.folio.circulation.domain.RequestQueue) OverridingErrorHandler(org.folio.circulation.resources.handlers.error.OverridingErrorHandler) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 25 with RequestQueue

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));
}
Also used : FixedDueDateSchedulesBuilder(api.support.builders.FixedDueDateSchedulesBuilder) Loan(org.folio.circulation.domain.Loan) ClockUtil.getZonedDateTime(org.folio.circulation.support.utils.ClockUtil.getZonedDateTime) ZonedDateTime(java.time.ZonedDateTime) RequestQueue(org.folio.circulation.domain.RequestQueue) CirculationErrorHandler(org.folio.circulation.resources.handlers.error.CirculationErrorHandler) OverridingErrorHandler(org.folio.circulation.resources.handlers.error.OverridingErrorHandler) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

RequestQueue (org.folio.circulation.domain.RequestQueue)53 Loan (org.folio.circulation.domain.Loan)45 ZonedDateTime (java.time.ZonedDateTime)39 LoanPolicyBuilder (api.support.builders.LoanPolicyBuilder)37 OverridingErrorHandler (org.folio.circulation.resources.handlers.error.OverridingErrorHandler)37 Test (org.junit.jupiter.api.Test)31 CirculationErrorHandler (org.folio.circulation.resources.handlers.error.CirculationErrorHandler)27 FixedDueDateSchedulesBuilder (api.support.builders.FixedDueDateSchedulesBuilder)23 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)18 ClockUtil.getZonedDateTime (org.folio.circulation.support.utils.ClockUtil.getZonedDateTime)17 JsonObject (io.vertx.core.json.JsonObject)16 LoanBuilder (api.support.builders.LoanBuilder)11 Result (org.folio.circulation.support.results.Result)8 FixedDueDateSchedule (api.support.builders.FixedDueDateSchedule)6 Item (org.folio.circulation.domain.Item)6 Request (org.folio.circulation.domain.Request)6 UpdateRequestQueue (org.folio.circulation.domain.UpdateRequestQueue)6 ValueSource (org.junit.jupiter.params.provider.ValueSource)6 CompletableFuture (java.util.concurrent.CompletableFuture)5 ValidationErrorFailure (org.folio.circulation.support.ValidationErrorFailure)5