Search in sources :

Example 21 with Loan

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

the class FixedLoanPolicyCheckOutDueDateCalculationTests method shouldUseOnlyScheduleAvailableWhenLoanDateTimeAfterMidnight.

@Test
void shouldUseOnlyScheduleAvailableWhenLoanDateTimeAfterMidnight() {
    LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().fixed(UUID.randomUUID()).create()).withDueDateSchedules(new FixedDueDateSchedulesBuilder().addSchedule(new FixedDueDateSchedule(ZonedDateTime.of(2020, 11, 1, 0, 0, 0, 0, UTC), ZonedDateTime.of(2020, 11, 2, 0, 0, 0, 0, UTC), ZonedDateTime.of(2020, 11, 2, 0, 0, 0, 0, UTC))).create());
    ZonedDateTime loanDate = ZonedDateTime.of(2020, 11, 2, 12, 30, 30, 0, UTC);
    Loan loan = loanFor(loanDate);
    final Result<ZonedDateTime> calculationResult = loanPolicy.calculateInitialDueDate(loan, null);
    final var expectedInitialDueDate = ZonedDateTime.of(2020, 11, 2, 0, 0, 0, 0, UTC);
    assertThat(calculationResult.succeeded(), is(true));
    assertThat(calculationResult.value(), is(expectedInitialDueDate));
}
Also used : FixedDueDateSchedulesBuilder(api.support.builders.FixedDueDateSchedulesBuilder) Loan(org.folio.circulation.domain.Loan) ZonedDateTime(java.time.ZonedDateTime) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) FixedDueDateSchedule(api.support.builders.FixedDueDateSchedule) Test(org.junit.jupiter.api.Test)

Example 22 with Loan

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

the class FixedLoanPolicyCheckOutDueDateCalculationTests method shouldFailWhenLoanDateIsBeforeOnlyScheduleAvailable.

@Test
void shouldFailWhenLoanDateIsBeforeOnlyScheduleAvailable() {
    LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().fixed(UUID.randomUUID()).withName("Example Fixed Schedule Loan Policy").create()).withDueDateSchedules(new FixedDueDateSchedulesBuilder().addSchedule(FixedDueDateSchedule.wholeYear(2018)).create());
    ZonedDateTime loanDate = ZonedDateTime.of(2017, 12, 30, 14, 32, 21, 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)

Example 23 with Loan

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

the class FixedLoanPolicyRenewalDueDateCalculationTests method shouldFailWhenRenewalWouldMeanEarlierDueDate.

@Test
void shouldFailWhenRenewalWouldMeanEarlierDueDate() {
    LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().fixed(UUID.randomUUID()).withName("Example Fixed Schedule Loan Policy").create()).withDueDateSchedules(new FixedDueDateSchedulesBuilder().addSchedule(FixedDueDateSchedule.wholeMonth(2018, 1)).create());
    Loan loan = new LoanBuilder().open().withLoanDate(ZonedDateTime.of(2018, 1, 20, 13, 45, 21, 0, UTC)).withDueDate(ZonedDateTime.of(2018, 2, 28, 23, 59, 59, 0, UTC)).asDomainObject().withLoanPolicy(loanPolicy);
    ZonedDateTime renewalDate = ZonedDateTime.of(2018, 1, 3, 8, 12, 32, 0, UTC);
    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) 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 24 with Loan

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

the class FixedLoanPolicyRenewalDueDateCalculationTests method shouldFailWhenLoanDateIsAfterOnlyScheduleAvailable.

@Test
void shouldFailWhenLoanDateIsAfterOnlyScheduleAvailable() {
    LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().fixed(UUID.randomUUID()).withName("Example Fixed Schedule Loan Policy").create()).withDueDateSchedules(new FixedDueDateSchedulesBuilder().addSchedule(FixedDueDateSchedule.wholeYear(2018)).create());
    Loan loan = existingLoan(loanPolicy);
    ZonedDateTime renewalDate = ZonedDateTime.of(2019, 1, 1, 8, 10, 45, 0, UTC);
    RequestQueue requestQueue = new RequestQueue(Collections.emptyList());
    CirculationErrorHandler errorHandler = new OverridingErrorHandler(null);
    renew(loan, renewalDate, requestQueue, 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 25 with Loan

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

the class FixedLoanPolicyRenewalDueDateCalculationTests method shouldFailWhenLoanDateIsInBetweenSchedules.

@Test
void shouldFailWhenLoanDateIsInBetweenSchedules() {
    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, 3)).create());
    Loan loan = existingLoan(loanPolicy);
    ZonedDateTime renewalDate = ZonedDateTime.of(2018, 2, 18, 6, 34, 21, 0, UTC);
    CirculationErrorHandler errorHandler = new OverridingErrorHandler(null);
    renew(loan, renewalDate, new RequestQueue(Collections.emptyList()), errorHandler);
    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)

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