Search in sources :

Example 16 with LoanPolicyBuilder

use of api.support.builders.LoanPolicyBuilder 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 17 with LoanPolicyBuilder

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

the class OverrideRenewByBarcodeTests method cannotOverrideRenewalWhenItemIsNotLoanableAndNewDueDateIsNotSpecified.

@Test
void cannotOverrideRenewalWhenItemIsNotLoanableAndNewDueDateIsNotSpecified() {
    IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
    final IndividualResource jessica = usersFixture.jessica();
    ZonedDateTime loanDueDate = ZonedDateTime.of(2018, 4, 21, 11, 21, 43, 0, UTC);
    checkOutFixture.checkOutByBarcode(smallAngryPlanet, jessica, loanDueDate);
    LoanPolicyBuilder notLoanablePolicy = new LoanPolicyBuilder().withName("Not Loanable Policy").withLoanable(false);
    createLoanPolicyAndSetAsFallback(notLoanablePolicy);
    JsonObject renewalResponse = loansFixture.attemptRenewal(422, smallAngryPlanet, jessica).getJson();
    assertThat(renewalResponse, hasErrorWith(allOf(hasMessage(ITEM_IS_NOT_LOANABLE_MESSAGE))));
    Response response = loansFixture.attemptOverride(smallAngryPlanet, jessica, OVERRIDE_COMMENT, null);
    assertThat(response.getJson(), hasErrorWith(allOf(hasMessage("New due date must be specified when due date calculation fails"))));
}
Also used : Response(org.folio.circulation.support.http.client.Response) ZonedDateTime(java.time.ZonedDateTime) JsonObject(io.vertx.core.json.JsonObject) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) IndividualResource(api.support.http.IndividualResource) Test(org.junit.jupiter.api.Test)

Example 18 with LoanPolicyBuilder

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

the class OverrideRenewByBarcodeTests method canOverrideRenewalWhenItemIsNotRenewableAndNewDueDateIsNotSpecified.

@Test
void canOverrideRenewalWhenItemIsNotRenewableAndNewDueDateIsNotSpecified() {
    IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
    final IndividualResource jessica = usersFixture.jessica();
    ZonedDateTime loanDueDate = ZonedDateTime.of(2018, 4, 21, 11, 21, 43, 0, UTC);
    checkOutFixture.checkOutByBarcode(smallAngryPlanet, jessica, loanDueDate);
    LoanPolicyBuilder nonRenewablePolicy = new LoanPolicyBuilder().withName("Non Renewable Policy").rolling(Period.days(2)).notRenewable();
    use(nonRenewablePolicy);
    loansFixture.attemptRenewal(422, smallAngryPlanet, jessica);
    Response response = loansFixture.attemptOverride(smallAngryPlanet, jessica, OVERRIDE_COMMENT, null);
    assertThat(response.getJson(), hasErrorWith(allOf(hasMessage("New due date must be specified when due date calculation fails"))));
}
Also used : Response(org.folio.circulation.support.http.client.Response) ZonedDateTime(java.time.ZonedDateTime) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) IndividualResource(api.support.http.IndividualResource) Test(org.junit.jupiter.api.Test)

Example 19 with LoanPolicyBuilder

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

the class RenewalAPITests method canRenewLoanWithAnotherLoanPolicyName.

@Test
void canRenewLoanWithAnotherLoanPolicyName() {
    IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
    final IndividualResource jessica = usersFixture.jessica();
    final String policyName = "Limited Renewals Policy";
    LoanPolicyBuilder limitedRenewalsPolicy = new LoanPolicyBuilder().withName(policyName).rolling(Period.days(2)).renewFromCurrentDueDate().limitedRenewals(3);
    final IndividualResource loanPolicyResponse = loanPoliciesFixture.create(limitedRenewalsPolicy);
    IndividualResource loan = checkOutFixture.checkOutByBarcode(smallAngryPlanet, jessica, ZonedDateTime.of(2019, 4, 21, 11, 21, 43, 0, UTC));
    loanHasLoanPolicyProperties(loan.getJson(), loanPoliciesFixture.canCirculateRolling());
    use(limitedRenewalsPolicy);
    loan = renew(smallAngryPlanet, jessica);
    loanHasLoanPolicyProperties(loan.getJson(), loanPolicyResponse);
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) IndividualResource(api.support.http.IndividualResource) Test(org.junit.jupiter.api.Test)

Example 20 with LoanPolicyBuilder

use of api.support.builders.LoanPolicyBuilder 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)

Aggregations

LoanPolicyBuilder (api.support.builders.LoanPolicyBuilder)199 Test (org.junit.jupiter.api.Test)173 ZonedDateTime (java.time.ZonedDateTime)135 IndividualResource (api.support.http.IndividualResource)97 JsonObject (io.vertx.core.json.JsonObject)87 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)79 Loan (org.folio.circulation.domain.Loan)70 FixedDueDateSchedulesBuilder (api.support.builders.FixedDueDateSchedulesBuilder)64 UUID (java.util.UUID)63 ClockUtil.getZonedDateTime (org.folio.circulation.support.utils.ClockUtil.getZonedDateTime)57 OverridingErrorHandler (org.folio.circulation.resources.handlers.error.OverridingErrorHandler)50 CirculationErrorHandler (org.folio.circulation.resources.handlers.error.CirculationErrorHandler)39 RequestQueue (org.folio.circulation.domain.RequestQueue)37 RequestBuilder (api.support.builders.RequestBuilder)34 Response (org.folio.circulation.support.http.client.Response)32 ItemResource (api.support.http.ItemResource)25 CheckOutByBarcodeRequestBuilder (api.support.builders.CheckOutByBarcodeRequestBuilder)23 LoanBuilder (api.support.builders.LoanBuilder)18 FixedDueDateSchedule (api.support.builders.FixedDueDateSchedule)16 NoticePolicyBuilder (api.support.builders.NoticePolicyBuilder)16