Search in sources :

Example 1 with FixedDueDateSchedule

use of api.support.builders.FixedDueDateSchedule in project mod-circulation by folio-org.

the class RequestsAPILoanRenewalTests method validationErrorWhenRenewalPeriodForHoldsSpecifiedForFixedPolicy.

@Test
void validationErrorWhenRenewalPeriodForHoldsSpecifiedForFixedPolicy() {
    final ZonedDateTime from = getZonedDateTime().minusMonths(3);
    final ZonedDateTime to = getZonedDateTime().plusMonths(3);
    final ZonedDateTime dueDate = to.plusDays(15);
    final ItemResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
    final IndividualResource rebecca = usersFixture.rebecca();
    checkOutFixture.checkOutByBarcode(smallAngryPlanet, rebecca);
    IndividualResource schedule = loanPoliciesFixture.createSchedule(new FixedDueDateSchedulesBuilder().withId(UUID.randomUUID()).withName("Can circulate schedule").withDescription("descr").addSchedule(new FixedDueDateSchedule(from, to, dueDate)));
    JsonObject holds = new JsonObject().put("renewItemsWithRequest", true).put("alternateRenewalLoanPeriod", Period.weeks(10).asJson());
    LoanPolicyBuilder loanPolicy = new LoanPolicyBuilder().fixed(schedule.getId()).withName("Fixed with holds").withDescription("Fixed policy with holds").withHolds(holds);
    loanPoliciesFixture.create(loanPolicy);
    useWithActiveNotice(loanPolicy);
    requestsFixture.place(new RequestBuilder().hold().forItem(smallAngryPlanet).withPickupServicePointId(servicePointsFixture.cd1().getId()).by(usersFixture.charlotte()));
    Response response = loansFixture.attemptRenewal(422, smallAngryPlanet, rebecca);
    assertThat(response.getJson(), hasErrorWith(hasMessage("Item's loan policy has fixed profile but alternative renewal period for holds is specified")));
}
Also used : Response(org.folio.circulation.support.http.client.Response) FixedDueDateSchedulesBuilder(api.support.builders.FixedDueDateSchedulesBuilder) RequestBuilder(api.support.builders.RequestBuilder) ClockUtil.getZonedDateTime(org.folio.circulation.support.utils.ClockUtil.getZonedDateTime) ZonedDateTime(java.time.ZonedDateTime) JsonObject(io.vertx.core.json.JsonObject) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) IndividualResource(api.support.http.IndividualResource) ItemResource(api.support.http.ItemResource) FixedDueDateSchedule(api.support.builders.FixedDueDateSchedule) Test(org.junit.jupiter.api.Test)

Example 2 with FixedDueDateSchedule

use of api.support.builders.FixedDueDateSchedule 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 3 with FixedDueDateSchedule

use of api.support.builders.FixedDueDateSchedule 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 4 with FixedDueDateSchedule

use of api.support.builders.FixedDueDateSchedule in project mod-circulation by folio-org.

the class FixedLoanPolicyCheckOutDueDateCalculationTests method shouldUseOnlyScheduleAvailableWhenLoanDateTimeAfterMidnightAndTimeZoneIsNotUTC.

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

Example 5 with FixedDueDateSchedule

use of api.support.builders.FixedDueDateSchedule in project mod-circulation by folio-org.

the class FixedLoanPolicyCheckOutDueDateCalculationTests method shouldUseFirstScheduleAvailableWhenLoanDateFits.

@Test
void shouldUseFirstScheduleAvailableWhenLoanDateFits() {
    final FixedDueDateSchedule expectedSchedule = FixedDueDateSchedule.wholeMonth(2018, 1);
    LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().fixed(UUID.randomUUID()).create()).withDueDateSchedules(new FixedDueDateSchedulesBuilder().addSchedule(expectedSchedule).addSchedule(FixedDueDateSchedule.wholeMonth(2018, 2)).addSchedule(FixedDueDateSchedule.wholeMonth(2018, 3)).create());
    ZonedDateTime loanDate = ZonedDateTime.of(2018, 1, 8, 11, 14, 54, 0, UTC);
    Loan loan = loanFor(loanDate);
    final Result<ZonedDateTime> calculationResult = loanPolicy.calculateInitialDueDate(loan, null);
    assertThat(calculationResult.value(), is(expectedSchedule.due));
}
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)

Aggregations

FixedDueDateSchedule (api.support.builders.FixedDueDateSchedule)14 FixedDueDateSchedulesBuilder (api.support.builders.FixedDueDateSchedulesBuilder)14 LoanPolicyBuilder (api.support.builders.LoanPolicyBuilder)14 ZonedDateTime (java.time.ZonedDateTime)14 Test (org.junit.jupiter.api.Test)14 Loan (org.folio.circulation.domain.Loan)9 IndividualResource (api.support.http.IndividualResource)5 JsonObject (io.vertx.core.json.JsonObject)5 ClockUtil.getZonedDateTime (org.folio.circulation.support.utils.ClockUtil.getZonedDateTime)5 RequestBuilder (api.support.builders.RequestBuilder)4 ItemResource (api.support.http.ItemResource)4 RequestQueue (org.folio.circulation.domain.RequestQueue)4 OverridingErrorHandler (org.folio.circulation.resources.handlers.error.OverridingErrorHandler)4 Response (org.folio.circulation.support.http.client.Response)2 LoanBuilder (api.support.builders.LoanBuilder)1 ZoneOffset (java.time.ZoneOffset)1 UUID (java.util.UUID)1