Search in sources :

Example 26 with FixedDueDateSchedulesBuilder

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)));
}
Also used : FixedDueDateSchedulesBuilder(api.support.builders.FixedDueDateSchedulesBuilder) Loan(org.folio.circulation.domain.Loan) ZonedDateTime(java.time.ZonedDateTime) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 27 with FixedDueDateSchedulesBuilder

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"));
}
Also used : FixedDueDateSchedulesBuilder(api.support.builders.FixedDueDateSchedulesBuilder) Loan(org.folio.circulation.domain.Loan) ZonedDateTime(java.time.ZonedDateTime) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 28 with FixedDueDateSchedulesBuilder

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));
}
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 29 with FixedDueDateSchedulesBuilder

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));
}
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 30 with FixedDueDateSchedulesBuilder

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));
}
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

FixedDueDateSchedulesBuilder (api.support.builders.FixedDueDateSchedulesBuilder)64 LoanPolicyBuilder (api.support.builders.LoanPolicyBuilder)64 Test (org.junit.jupiter.api.Test)63 ZonedDateTime (java.time.ZonedDateTime)61 Loan (org.folio.circulation.domain.Loan)39 RequestQueue (org.folio.circulation.domain.RequestQueue)23 IndividualResource (api.support.http.IndividualResource)22 UUID (java.util.UUID)22 OverridingErrorHandler (org.folio.circulation.resources.handlers.error.OverridingErrorHandler)22 ClockUtil.getZonedDateTime (org.folio.circulation.support.utils.ClockUtil.getZonedDateTime)20 CirculationErrorHandler (org.folio.circulation.resources.handlers.error.CirculationErrorHandler)17 FixedDueDateSchedule (api.support.builders.FixedDueDateSchedule)16 JsonObject (io.vertx.core.json.JsonObject)14 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 CheckOutByBarcodeRequestBuilder (api.support.builders.CheckOutByBarcodeRequestBuilder)9 LoanBuilder (api.support.builders.LoanBuilder)7 RequestBuilder (api.support.builders.RequestBuilder)7 Response (org.folio.circulation.support.http.client.Response)7 ItemResource (api.support.http.ItemResource)5 ItemBuilder (api.support.builders.ItemBuilder)2