Search in sources :

Example 96 with Loan

use of org.folio.circulation.domain.Loan in project mod-circulation by folio-org.

the class RollingLoanPolicyRenewalDueDateCalculationTests method shouldApplyMonthlyRollingPolicy.

@ParameterizedTest
@ValueSource(strings = { "1", "8", "12", "15" })
void shouldApplyMonthlyRollingPolicy(int duration) {
    LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().rolling(Period.months(duration)).renewFromSystemDate().unlimitedRenewals().create());
    ZonedDateTime loanDate = ZonedDateTime.of(2018, 3, 14, 11, 14, 54, 0, UTC);
    Loan loan = loanFor(loanDate, loanDate.plusMonths(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.plusMonths(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 97 with Loan

use of org.folio.circulation.domain.Loan in project mod-circulation by folio-org.

the class RollingLoanPolicyRenewalDueDateCalculationTests method shouldFailWhenNoPeriodIntervalProvided.

@Test
void shouldFailWhenNoPeriodIntervalProvided() {
    final JsonObject representation = new LoanPolicyBuilder().rolling(Period.from(5, "Weeks")).withName("Invalid Loan Policy").create();
    representation.getJsonObject("loansPolicy").getJsonObject("period").remove("intervalId");
    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 98 with Loan

use of org.folio.circulation.domain.Loan in project mod-circulation by folio-org.

the class RollingLoanPolicyRenewalDueDateCalculationTests 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.days(15)).limitedBySchedule(UUID.randomUUID()).renewFromCurrentDueDate().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, loanDate.plusDays(15), loanPolicy);
    CirculationErrorHandler errorHandler = new OverridingErrorHandler(null);
    Result<Loan> result = renew(loan, getZonedDateTime(), new RequestQueue(Collections.emptyList()), errorHandler);
    assertThat(result.value().getDueDate(), is(ZonedDateTime.of(2018, 4, 10, 23, 59, 59, 0, UTC)));
}
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 99 with Loan

use of org.folio.circulation.domain.Loan in project mod-circulation by folio-org.

the class RollingLoanPolicyRenewalDueDateCalculationTests method shouldNotTruncateDueDateWhenWithinDueDateLimitScheduleButInitialDateIsSooner.

@Test
void shouldNotTruncateDueDateWhenWithinDueDateLimitScheduleButInitialDateIsSooner() {
    // 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.days(6)).limitedBySchedule(UUID.randomUUID()).renewFromCurrentDueDate().create()).withDueDateSchedules(new FixedDueDateSchedulesBuilder().addSchedule(FixedDueDateSchedule.wholeMonth(2018, 3)).create());
    ZonedDateTime loanDate = ZonedDateTime.of(2018, 3, 11, 16, 21, 43, 0, UTC);
    Loan loan = loanFor(loanDate, loanDate.plusDays(6), loanPolicy);
    Result<Loan> result = renew(loan, getZonedDateTime(), new RequestQueue(Collections.emptyList()), new OverridingErrorHandler(null));
    assertThat(result.value().getDueDate(), is(ZonedDateTime.of(2018, 3, 23, 16, 21, 43, 0, UTC)));
}
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) 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 100 with Loan

use of org.folio.circulation.domain.Loan in project mod-circulation by folio-org.

the class RollingLoanPolicyRenewalDueDateCalculationTests method shouldFailWhenRenewalWouldMeanEarlierDueDate.

@Test
void shouldFailWhenRenewalWouldMeanEarlierDueDate() {
    LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().rolling(Period.weeks(2)).withName("Example Rolling Loan Policy").renewFromSystemDate().renewWith(Period.days(3)).create());
    final ZonedDateTime initialDueDate = ZonedDateTime.of(2018, 1, 17, 13, 45, 21, 0, UTC);
    Loan loan = new LoanBuilder().open().withLoanDate(ZonedDateTime.of(2018, 1, 20, 13, 45, 21, 0, UTC)).withDueDate(initialDueDate).asDomainObject().withLoanPolicy(loanPolicy);
    ZonedDateTime renewalDate = initialDueDate.minusDays(4);
    CirculationErrorHandler errorHandler = new OverridingErrorHandler(null);
    renew(loan, renewalDate, new RequestQueue(Collections.emptyList()), errorHandler);
    assertTrue(matchErrorReason(errorHandler, RENEWAL_WOULD_NOT_CHANGE_THE_DUE_DATE));
}
Also used : LoanBuilder(api.support.builders.LoanBuilder) 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

Loan (org.folio.circulation.domain.Loan)133 ZonedDateTime (java.time.ZonedDateTime)89 Test (org.junit.jupiter.api.Test)77 LoanPolicyBuilder (api.support.builders.LoanPolicyBuilder)70 RequestQueue (org.folio.circulation.domain.RequestQueue)48 FixedDueDateSchedulesBuilder (api.support.builders.FixedDueDateSchedulesBuilder)39 OverridingErrorHandler (org.folio.circulation.resources.handlers.error.OverridingErrorHandler)39 JsonObject (io.vertx.core.json.JsonObject)37 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)32 CirculationErrorHandler (org.folio.circulation.resources.handlers.error.CirculationErrorHandler)30 Result (org.folio.circulation.support.results.Result)26 CompletableFuture (java.util.concurrent.CompletableFuture)23 Result.succeeded (org.folio.circulation.support.results.Result.succeeded)21 LoanRepository (org.folio.circulation.infrastructure.storage.loans.LoanRepository)20 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)19 ClockUtil.getZonedDateTime (org.folio.circulation.support.utils.ClockUtil.getZonedDateTime)19 UserRepository (org.folio.circulation.infrastructure.storage.users.UserRepository)17 RoutingContext (io.vertx.ext.web.RoutingContext)15 Clients (org.folio.circulation.support.Clients)15 HttpClient (io.vertx.core.http.HttpClient)14