Search in sources :

Example 16 with RequestQueue

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

the class RollingLoanPolicyCheckOutDueDateCalculationTests method shouldApplyAlternateScheduleWhenQueuedRequestIsHoldAndRolling.

@Test
void shouldApplyAlternateScheduleWhenQueuedRequestIsHoldAndRolling() {
    final Period alternateCheckoutLoanPeriod = Period.from(2, "Weeks");
    final ZonedDateTime systemTime = ZonedDateTime.of(2019, 6, 14, 11, 23, 43, 0, UTC);
    LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().rolling(Period.months(1)).withAlternateCheckoutLoanPeriod(alternateCheckoutLoanPeriod).create()).withDueDateSchedules(new FixedDueDateSchedulesBuilder().addSchedule(FixedDueDateSchedule.wholeYear(systemTime.getYear())).create());
    Item item = Item.from(new ItemBuilder().checkOut().withId(UUID.randomUUID()).create());
    Loan loan = Loan.from(new LoanBuilder().withItemId(UUID.fromString(item.getItemId())).withLoanDate(systemTime).create());
    Request requestOne = Request.from(new RequestBuilder().withId(UUID.randomUUID()).withPosition(1).create());
    Request requestTwo = Request.from(new RequestBuilder().withId(UUID.randomUUID()).withStatus(RequestStatus.OPEN_NOT_YET_FILLED.getValue()).hold().withItemId(UUID.fromString(loan.getItemId())).withPosition(2).create());
    RequestQueue requestQueue = new RequestQueue(asList(requestOne, requestTwo));
    ZonedDateTime calculatedDueDate = loanPolicy.calculateInitialDueDate(loan, requestQueue).value();
    String key = "alternateCheckoutLoanPeriod";
    ZonedDateTime expectedDueDate = alternateCheckoutLoanPeriod.addTo(systemTime, () -> errorForLoanPeriod(format("the \"%s\" is not recognized", key)), interval -> errorForLoanPeriod(format("the interval \"%s\" in \"%s\" is not recognized", interval, key)), dur -> errorForLoanPeriod(format("the duration \"%s\" in \"%s\" is invalid", dur, key))).value();
    assertThat(calculatedDueDate, is(expectedDueDate));
}
Also used : FailureMatcher.hasValidationFailure(api.support.matchers.FailureMatcher.hasValidationFailure) CoreMatchers.is(org.hamcrest.CoreMatchers.is) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) ZonedDateTime(java.time.ZonedDateTime) Request(org.folio.circulation.domain.Request) HashMap(java.util.HashMap) RequestBuilder(api.support.builders.RequestBuilder) Item(org.folio.circulation.domain.Item) ItemBuilder(api.support.builders.ItemBuilder) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) FixedDueDateSchedulesBuilder(api.support.builders.FixedDueDateSchedulesBuilder) JsonObject(io.vertx.core.json.JsonObject) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) RequestQueue(org.folio.circulation.domain.RequestQueue) ValueSource(org.junit.jupiter.params.provider.ValueSource) Loan(org.folio.circulation.domain.Loan) LoanBuilder(api.support.builders.LoanBuilder) UUID(java.util.UUID) ValidationError(org.folio.circulation.support.http.server.ValidationError) Result(org.folio.circulation.support.results.Result) String.format(java.lang.String.format) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) FixedDueDateSchedule(api.support.builders.FixedDueDateSchedule) RequestStatus(org.folio.circulation.domain.RequestStatus) UTC(java.time.ZoneOffset.UTC) LoanBuilder(api.support.builders.LoanBuilder) RequestBuilder(api.support.builders.RequestBuilder) Request(org.folio.circulation.domain.Request) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) Item(org.folio.circulation.domain.Item) ItemBuilder(api.support.builders.ItemBuilder) FixedDueDateSchedulesBuilder(api.support.builders.FixedDueDateSchedulesBuilder) Loan(org.folio.circulation.domain.Loan) ZonedDateTime(java.time.ZonedDateTime) RequestQueue(org.folio.circulation.domain.RequestQueue) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 17 with RequestQueue

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

the class RollingLoanPolicyRenewalDueDateCalculationTests method shouldApplyMinuteIntervalRollingPolicy.

@ParameterizedTest
@ValueSource(strings = { "1", "5", "30", "60", "200" })
void shouldApplyMinuteIntervalRollingPolicy(int duration) {
    LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().rolling(Period.minutes(duration)).renewFromSystemDate().unlimitedRenewals().create());
    ZonedDateTime loanDate = ZonedDateTime.of(2018, 3, 14, 11, 14, 54, 0, UTC);
    Loan loan = loanFor(loanDate, loanDate, 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.plusMinutes(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 18 with RequestQueue

use of org.folio.circulation.domain.RequestQueue 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));
}
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 19 with RequestQueue

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

the class RollingLoanPolicyRenewalDueDateCalculationTests method shouldApplyDailyRollingPolicy.

@ParameterizedTest
@ValueSource(strings = { "1", "7", "14", "12", "30", "100" })
void shouldApplyDailyRollingPolicy(int duration) {
    LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().rolling(Period.days(duration)).renewFromSystemDate().unlimitedRenewals().create());
    ZonedDateTime loanDate = ZonedDateTime.of(2018, 3, 14, 11, 14, 54, 0, UTC);
    Loan loan = loanFor(loanDate, loanDate.plusDays(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.plusDays(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 20 with RequestQueue

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

the class RollingLoanPolicyRenewalDueDateCalculationTests method shouldApplyHourlyRollingPolicy.

@ParameterizedTest
@ValueSource(strings = { "2", "5", "30", "45", "60", "24" })
void shouldApplyHourlyRollingPolicy(int duration) {
    LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().rolling(Period.hours(duration)).renewFromSystemDate().unlimitedRenewals().create());
    ZonedDateTime loanDate = ZonedDateTime.of(2018, 3, 14, 11, 14, 54, 0, UTC);
    Loan loan = loanFor(loanDate, loanDate.plusHours(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.plusHours(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)

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