Search in sources :

Example 11 with RequestQueue

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

the class FixedLoanPolicyRenewalDueDateCalculationTests method shouldUseMiddleScheduleAvailableWhenLoanDateFits.

@Test
void shouldUseMiddleScheduleAvailableWhenLoanDateFits() {
    final FixedDueDateSchedule expectedSchedule = FixedDueDateSchedule.wholeMonth(2018, 2);
    LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().fixed(UUID.randomUUID()).create()).withDueDateSchedules(new FixedDueDateSchedulesBuilder().addSchedule(FixedDueDateSchedule.wholeMonth(2018, 1)).addSchedule(expectedSchedule).addSchedule(FixedDueDateSchedule.wholeMonth(2018, 3)).create());
    Loan loan = existingLoan(loanPolicy);
    ZonedDateTime renewalDate = ZonedDateTime.of(2018, 2, 27, 16, 23, 43, 0, UTC);
    Result<Loan> result = renew(loan, renewalDate, new RequestQueue(Collections.emptyList()), new OverridingErrorHandler(null));
    assertThat(result.value().getDueDate(), is(expectedSchedule.due));
}
Also used : FixedDueDateSchedulesBuilder(api.support.builders.FixedDueDateSchedulesBuilder) Loan(org.folio.circulation.domain.Loan) ZonedDateTime(java.time.ZonedDateTime) RequestQueue(org.folio.circulation.domain.RequestQueue) OverridingErrorHandler(org.folio.circulation.resources.handlers.error.OverridingErrorHandler) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) FixedDueDateSchedule(api.support.builders.FixedDueDateSchedule) Test(org.junit.jupiter.api.Test)

Example 12 with RequestQueue

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

the class FixedLoanPolicyRenewalDueDateCalculationTests method shouldUseOnlyScheduleAvailableWhenLoanDateFits.

@Test
void shouldUseOnlyScheduleAvailableWhenLoanDateFits() {
    LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().fixed(UUID.randomUUID()).create()).withDueDateSchedules(new FixedDueDateSchedulesBuilder().addSchedule(FixedDueDateSchedule.wholeYear(2018)).create());
    Loan loan = existingLoan(loanPolicy);
    ZonedDateTime renewalDate = ZonedDateTime.of(2018, 3, 14, 11, 14, 54, 0, UTC);
    String requestId = UUID.randomUUID().toString();
    RequestQueue requestQueue = creteRequestQueue(requestId, RequestType.PAGE);
    CirculationErrorHandler errorHandler = new OverridingErrorHandler(null);
    Result<Loan> result = renew(loan, renewalDate, requestQueue, errorHandler);
    final ZonedDateTime expectedDate = atStartOfDay(LocalDate.of(2018, 12, 31), UTC).plusDays(1).minusSeconds(1);
    assertThat(result.value().getDueDate(), is(expectedDate));
}
Also used : FixedDueDateSchedulesBuilder(api.support.builders.FixedDueDateSchedulesBuilder) Loan(org.folio.circulation.domain.Loan) 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)

Example 13 with RequestQueue

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

the class FixedLoanPolicyRenewalDueDateCalculationTests method shouldFailWhenLoanDateIsBeforeAllSchedules.

@Test
void shouldFailWhenLoanDateIsBeforeAllSchedules() {
    LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().fixed(UUID.randomUUID()).withName("Example Fixed Schedule Loan Policy").create()).withDueDateSchedules(new FixedDueDateSchedulesBuilder().addSchedule(FixedDueDateSchedule.wholeMonth(2018, 1)).addSchedule(FixedDueDateSchedule.wholeMonth(2018, 2)).addSchedule(FixedDueDateSchedule.wholeMonth(2018, 3)).create());
    Loan loan = existingLoan(loanPolicy);
    ZonedDateTime renewalDate = ZonedDateTime.of(2017, 12, 30, 14, 32, 21, 0, UTC);
    CirculationErrorHandler errorHandler = new OverridingErrorHandler(null);
    renew(loan, renewalDate, new RequestQueue(Collections.emptyList()), errorHandler);
    assertEquals(1, errorHandler.getErrors().size());
    assertTrue(matchErrorReason(errorHandler, EXPECTED_REASON_DATE_FALLS_OUTSIDE_DATE_RANGES));
}
Also used : FixedDueDateSchedulesBuilder(api.support.builders.FixedDueDateSchedulesBuilder) Loan(org.folio.circulation.domain.Loan) 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)

Example 14 with RequestQueue

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

the class FixedLoanPolicyRenewalDueDateCalculationTests method shouldFailWhenRenewalWouldMeanEarlierDueDateAndReachedRenewalLimit.

@Test
void shouldFailWhenRenewalWouldMeanEarlierDueDateAndReachedRenewalLimit() {
    LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().fixed(UUID.randomUUID()).withName("Example Fixed Schedule Loan Policy").limitedRenewals(1).create()).withDueDateSchedules(new FixedDueDateSchedulesBuilder().addSchedule(FixedDueDateSchedule.wholeMonth(2018, 1)).addSchedule(FixedDueDateSchedule.wholeMonth(2018, 2)).create());
    Loan loan = new LoanBuilder().open().withLoanDate(ZonedDateTime.of(2018, 1, 20, 13, 45, 21, 0, UTC)).withDueDate(ZonedDateTime.of(2018, 1, 31, 23, 59, 59, 0, UTC)).asDomainObject().withLoanPolicy(loanPolicy);
    CirculationErrorHandler errorHandler = new OverridingErrorHandler(null);
    loan = renew(loan, ZonedDateTime.of(2018, 2, 1, 11, 23, 43, 0, UTC), new RequestQueue(Collections.emptyList()), errorHandler).value();
    ZonedDateTime renewalDate = ZonedDateTime.of(2018, 3, 5, 8, 12, 32, 0, UTC);
    renew(loan, renewalDate, new RequestQueue(Collections.emptyList()), errorHandler);
    assertTrue(matchErrorReason(errorHandler, EXPECTED_REASON_DATE_FALLS_OUTSIDE_DATE_RANGES));
    assertTrue(matchErrorReason(errorHandler, LOAN_AT_MAXIMUM_RENEWAL_NUMBER));
    assertEquals(2, errorHandler.getErrors().size());
}
Also used : LoanBuilder(api.support.builders.LoanBuilder) FixedDueDateSchedulesBuilder(api.support.builders.FixedDueDateSchedulesBuilder) Loan(org.folio.circulation.domain.Loan) 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)

Example 15 with RequestQueue

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

the class FixedLoanPolicyRenewalDueDateCalculationTests method multipleRenewalFailuresWhenLoanHasReachedMaximumNumberOfRenewalsAndOpenRecallRequest.

@Test
void multipleRenewalFailuresWhenLoanHasReachedMaximumNumberOfRenewalsAndOpenRecallRequest() {
    LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().fixed(UUID.randomUUID()).withName("Example Fixed Schedule Loan Policy").limitedRenewals(1).create()).withDueDateSchedules(new FixedDueDateSchedulesBuilder().addSchedule(FixedDueDateSchedule.wholeMonth(2018, 1)).addSchedule(FixedDueDateSchedule.wholeMonth(2018, 2)).create());
    Loan loan = new LoanBuilder().open().withLoanDate(ZonedDateTime.of(2018, 1, 20, 13, 45, 21, 0, UTC)).withDueDate(ZonedDateTime.of(2018, 1, 31, 23, 59, 59, 0, UTC)).asDomainObject().withLoanPolicy(loanPolicy);
    CirculationErrorHandler errorHandler = new OverridingErrorHandler(null);
    loan = renew(loan, ZonedDateTime.of(2018, 2, 1, 11, 23, 43, 0, UTC), new RequestQueue(Collections.emptyList()), errorHandler).value();
    ZonedDateTime renewalDate = ZonedDateTime.of(2018, 3, 5, 8, 12, 32, 0, UTC);
    String requestId = UUID.randomUUID().toString();
    RequestQueue requestQueue = creteRequestQueue(requestId, RequestType.RECALL);
    renew(loan, renewalDate, requestQueue, errorHandler);
    assertTrue(matchErrorReason(errorHandler, EXPECTED_REASON_DATE_FALLS_OUTSIDE_DATE_RANGES));
    assertTrue(matchErrorReason(errorHandler, LOAN_AT_MAXIMUM_RENEWAL_NUMBER));
    assertTrue(matchErrorReason(errorHandler, LOAN_AT_MAXIMUM_RENEWAL_NUMBER));
}
Also used : LoanBuilder(api.support.builders.LoanBuilder) FixedDueDateSchedulesBuilder(api.support.builders.FixedDueDateSchedulesBuilder) Loan(org.folio.circulation.domain.Loan) 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)

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