Search in sources :

Example 1 with FixedDueDateSchedulesBuilder

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

the class OverrideRenewByBarcodeTests method canOverrideRenewalWhenDateFallsOutsideOfTheDateRangesInTheFixedLoanPolicyAndDueDateIsSpecified.

@Test
void canOverrideRenewalWhenDateFallsOutsideOfTheDateRangesInTheFixedLoanPolicyAndDueDateIsSpecified() {
    IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
    final IndividualResource jessica = usersFixture.jessica();
    ZonedDateTime loanDueDate = ZonedDateTime.of(2018, 4, 21, 11, 21, 43, 0, UTC);
    final IndividualResource loan = checkOutFixture.checkOutByBarcode(smallAngryPlanet, jessica, loanDueDate);
    final UUID loanId = loan.getId();
    FixedDueDateSchedulesBuilder fixedDueDateSchedules = new FixedDueDateSchedulesBuilder().withName("Fixed Due Date Schedule").addSchedule(wholeMonth(2018, 2));
    final UUID fixedDueDateSchedulesId = loanPoliciesFixture.createSchedule(fixedDueDateSchedules).getId();
    LoanPolicyBuilder currentDueDateRollingPolicy = new LoanPolicyBuilder().withName("Current Due Date Rolling Policy").fixed(fixedDueDateSchedulesId).renewFromCurrentDueDate();
    final IndividualResource loanPolicy = loanPoliciesFixture.create(currentDueDateRollingPolicy);
    UUID dueDateLimitedPolicyId = loanPolicy.getId();
    use(currentDueDateRollingPolicy);
    loansFixture.attemptRenewal(422, smallAngryPlanet, jessica);
    final OkapiHeaders okapiHeaders = buildOkapiHeadersWithPermissions(OVERRIDE_RENEWAL_PERMISSION);
    ZonedDateTime newDueDate = ClockUtil.getZonedDateTime().plusWeeks(1);
    final JsonObject renewedLoan = loansFixture.overrideRenewalByBarcode(smallAngryPlanet, jessica, OVERRIDE_COMMENT, formatDateTime(newDueDate), okapiHeaders).getJson();
    assertThat(renewedLoan.getString("id"), is(loanId.toString()));
    verifyRenewedLoan(smallAngryPlanet, jessica, renewedLoan);
    assertThat("renewal count should be incremented", renewedLoan.getInteger("renewalCount"), is(1));
    // TODO loanpolicyname is not stored, possible bug?
    assertThat("last loan policy should be stored", renewedLoan.getString("loanPolicyId"), is(dueDateLimitedPolicyId.toString()));
    assertThat("due date should be 2 months from previous due date", renewedLoan.getString("dueDate"), isEquivalentTo(newDueDate));
    smallAngryPlanet = itemsClient.get(smallAngryPlanet);
    assertThat(smallAngryPlanet, hasItemStatus(ItemBuilder.CHECKED_OUT));
}
Also used : OkapiHeaders(api.support.http.OkapiHeaders) FixedDueDateSchedulesBuilder(api.support.builders.FixedDueDateSchedulesBuilder) ZonedDateTime(java.time.ZonedDateTime) JsonObject(io.vertx.core.json.JsonObject) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) IndividualResource(api.support.http.IndividualResource) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 2 with FixedDueDateSchedulesBuilder

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

the class OverrideRenewByBarcodeTests method canOverrideRenewalWhenDateFallsOutsideOfTheDateRangesInTheRollingLoanPolicy.

@Test
void canOverrideRenewalWhenDateFallsOutsideOfTheDateRangesInTheRollingLoanPolicy() {
    final ZonedDateTime renewalDate = ClockUtil.getZonedDateTime();
    IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
    final IndividualResource jessica = usersFixture.jessica();
    ZonedDateTime loanDueDate = ZonedDateTime.of(2018, 4, 21, 11, 21, 43, 0, UTC);
    final IndividualResource loan = checkOutFixture.checkOutByBarcode(smallAngryPlanet, jessica, loanDueDate);
    final UUID loanId = loan.getId();
    FixedDueDateSchedulesBuilder fixedDueDateSchedules = new FixedDueDateSchedulesBuilder().withName("Fixed Due Date Schedule").addSchedule(wholeMonth(2018, 2)).addSchedule(forDay(renewalDate));
    final UUID fixedDueDateSchedulesId = loanPoliciesFixture.createSchedule(fixedDueDateSchedules).getId();
    LoanPolicyBuilder currentDueDateRollingPolicy = new LoanPolicyBuilder().withName("Current Due Date Rolling Policy").rolling(Period.months(2)).limitedBySchedule(fixedDueDateSchedulesId).renewFromCurrentDueDate();
    use(currentDueDateRollingPolicy);
    Response response = loansFixture.attemptRenewal(422, smallAngryPlanet, jessica);
    assertThat(response.getJson(), hasErrorWith(allOf(hasMessage("renewal date falls outside of date ranges in the loan policy"))));
    final ZonedDateTime newDueDate = loanDueDate.plusWeeks(3).plusMonths(2);
    final OkapiHeaders okapiHeaders = buildOkapiHeadersWithPermissions(OVERRIDE_RENEWAL_PERMISSION);
    final JsonObject renewedLoan = loansFixture.overrideRenewalByBarcode(smallAngryPlanet, jessica, OVERRIDE_COMMENT, formatDateTime(newDueDate), okapiHeaders).getJson();
    assertThat(renewedLoan.getString("id"), is(loanId.toString()));
    verifyRenewedLoan(smallAngryPlanet, jessica, renewedLoan);
    assertThat("renewal count should be incremented", renewedLoan.getInteger("renewalCount"), is(1));
    assertThat("due date should be 1st of Feb 2019", renewedLoan.getString("dueDate"), isEquivalentTo(newDueDate));
}
Also used : Response(org.folio.circulation.support.http.client.Response) OkapiHeaders(api.support.http.OkapiHeaders) FixedDueDateSchedulesBuilder(api.support.builders.FixedDueDateSchedulesBuilder) ZonedDateTime(java.time.ZonedDateTime) JsonObject(io.vertx.core.json.JsonObject) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) IndividualResource(api.support.http.IndividualResource) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 3 with FixedDueDateSchedulesBuilder

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

the class RenewalAPITests method canRenewUsingAlternateDueDateLimitedRollingLoanPolicy.

@Test
void canRenewUsingAlternateDueDateLimitedRollingLoanPolicy() {
    FixedDueDateSchedulesBuilder dueDateLimitSchedule = new FixedDueDateSchedulesBuilder().withName("March Only Due Date Limit").addSchedule(wholeMonth(2018, 3));
    final UUID dueDateLimitScheduleId = loanPoliciesFixture.createSchedule(dueDateLimitSchedule).getId();
    LoanPolicyBuilder dueDateLimitedPolicy = new LoanPolicyBuilder().withName("Due Date Limited Rolling Policy").rolling(Period.weeks(3)).renewFromCurrentDueDate().renewWith(Period.days(8), dueDateLimitScheduleId);
    final IndividualResource loanPolicy = loanPoliciesFixture.create(dueDateLimitedPolicy);
    use(dueDateLimitedPolicy);
    IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
    final IndividualResource steve = usersFixture.steve();
    final ZonedDateTime loanDate = ZonedDateTime.of(2018, 3, 4, 11, 43, 54, 0, UTC);
    checkOutFixture.checkOutByBarcode(new CheckOutByBarcodeRequestBuilder().forItem(smallAngryPlanet).to(steve).on(loanDate).at(UUID.randomUUID()));
    final IndividualResource response = renew(smallAngryPlanet, steve);
    final JsonObject loan = response.getJson();
    loanHasLoanPolicyProperties(loan, loanPolicy);
    assertThat("due date should be limited by schedule", loan.getString("dueDate"), isEquivalentTo(ZonedDateTime.of(2018, 3, 31, 23, 59, 59, 0, UTC)));
}
Also used : CheckOutByBarcodeRequestBuilder(api.support.builders.CheckOutByBarcodeRequestBuilder) FixedDueDateSchedulesBuilder(api.support.builders.FixedDueDateSchedulesBuilder) ZonedDateTime(java.time.ZonedDateTime) ClockUtil.getZonedDateTime(org.folio.circulation.support.utils.ClockUtil.getZonedDateTime) JsonObject(io.vertx.core.json.JsonObject) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) UUID(java.util.UUID) IndividualResource(api.support.http.IndividualResource) Test(org.junit.jupiter.api.Test)

Example 4 with FixedDueDateSchedulesBuilder

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

the class RenewalAPITests method cannotRenewWhenNonRenewableFixedPolicy.

@Test
void cannotRenewWhenNonRenewableFixedPolicy() {
    IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
    final IndividualResource jessica = usersFixture.jessica();
    // TODO: Replace with better example when can fix system date
    FixedDueDateSchedulesBuilder todayOnlySchedules = new FixedDueDateSchedulesBuilder().withName("Today Only Due Date Limit").addSchedule(FixedDueDateSchedule.todayOnly());
    final UUID todayOnlySchedulesId = loanPoliciesFixture.createSchedule(todayOnlySchedules).getId();
    LoanPolicyBuilder limitedRenewalsPolicy = new LoanPolicyBuilder().withName("Non Renewable Policy").fixed(todayOnlySchedulesId).notRenewable();
    UUID notRenewablePolicyId = loanPoliciesFixture.create(limitedRenewalsPolicy).getId();
    use(limitedRenewalsPolicy);
    checkOutFixture.checkOutByBarcode(smallAngryPlanet, jessica, getZonedDateTime());
    final Response response = attemptRenewal(smallAngryPlanet, jessica);
    assertThat(response.getJson(), hasErrorWith(allOf(hasMessage("loan is not renewable"), hasLoanPolicyIdParameter(notRenewablePolicyId), hasLoanPolicyNameParameter("Non Renewable Policy"))));
    assertThat(getOverridableBlockNames(response), hasItem("renewalDueDateRequiredBlock"));
}
Also used : Response(org.folio.circulation.support.http.client.Response) FixedDueDateSchedulesBuilder(api.support.builders.FixedDueDateSchedulesBuilder) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) IndividualResource(api.support.http.IndividualResource) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 5 with FixedDueDateSchedulesBuilder

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

the class RenewalAPITests method canRenewFromCurrentDueDateWhenDueDateFallsWithinRangeOfAlternateDueDateLimit.

@Test
void canRenewFromCurrentDueDateWhenDueDateFallsWithinRangeOfAlternateDueDateLimit() {
    FixedDueDateSchedulesBuilder dueDateLimitSchedule = new FixedDueDateSchedulesBuilder().withName("Alternate Due Date Limit").addSchedule(wholeMonth(2019, 3)).addSchedule(wholeMonth(2019, 5));
    ZonedDateTime expectedDueDate = ZonedDateTime.of(2019, 5, 31, 23, 59, 59, 0, UTC);
    final UUID dueDateLimitScheduleId = loanPoliciesFixture.createSchedule(dueDateLimitSchedule).getId();
    LoanPolicyBuilder dueDateLimitedPolicy = new LoanPolicyBuilder().withName("Due Date Limited Rolling Policy").rolling(Period.months(1)).renewFromCurrentDueDate().renewWith(Period.months(1), dueDateLimitScheduleId);
    final IndividualResource loanPolicy = loanPoliciesFixture.create(dueDateLimitedPolicy);
    UUID dueDateLimitedPolicyId = loanPolicy.getId();
    checkRenewalAttempt(expectedDueDate, dueDateLimitedPolicyId);
}
Also used : FixedDueDateSchedulesBuilder(api.support.builders.FixedDueDateSchedulesBuilder) ZonedDateTime(java.time.ZonedDateTime) ClockUtil.getZonedDateTime(org.folio.circulation.support.utils.ClockUtil.getZonedDateTime) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) UUID(java.util.UUID) IndividualResource(api.support.http.IndividualResource) Test(org.junit.jupiter.api.Test)

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