Search in sources :

Example 6 with RequestQueue

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

use of org.folio.circulation.domain.RequestQueue 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 8 with RequestQueue

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

Example 9 with RequestQueue

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

the class FixedLoanPolicyRenewalDueDateCalculationTests 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());
    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 10 with RequestQueue

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

the class FixedLoanPolicyRenewalDueDateCalculationTests method shouldFailWhenLoanDateIsAfterAllSchedules.

@Test
void shouldFailWhenLoanDateIsAfterAllSchedules() {
    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(2018, 4, 1, 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

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