Search in sources :

Example 21 with LoanPolicyBuilder

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

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

the class RenewalAPITests method cannotRenewWhenRenewalLimitReached.

@Test
void cannotRenewWhenRenewalLimitReached() {
    IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
    final IndividualResource jessica = usersFixture.jessica();
    LoanPolicyBuilder limitedRenewalsPolicy = new LoanPolicyBuilder().withName("Limited Renewals Policy").rolling(Period.days(2)).renewFromCurrentDueDate().limitedRenewals(3);
    UUID limitedRenewalsPolicyId = loanPoliciesFixture.create(limitedRenewalsPolicy).getId();
    use(limitedRenewalsPolicy);
    checkOutFixture.checkOutByBarcode(smallAngryPlanet, jessica, ZonedDateTime.of(2018, 4, 21, 11, 21, 43, 0, UTC));
    renew(smallAngryPlanet, jessica);
    renew(smallAngryPlanet, jessica);
    renew(smallAngryPlanet, jessica);
    final Response response = attemptRenewal(smallAngryPlanet, jessica);
    assertThat(response.getJson(), hasErrorWith(allOf(hasMessage("loan at maximum renewal number"), hasLoanPolicyIdParameter(limitedRenewalsPolicyId), hasLoanPolicyNameParameter("Limited Renewals Policy"))));
}
Also used : Response(org.folio.circulation.support.http.client.Response) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) IndividualResource(api.support.http.IndividualResource) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 23 with LoanPolicyBuilder

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

Example 24 with LoanPolicyBuilder

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

the class RenewalAPITests method renewalNoticeIsNotSentWhenPatronNoticeRequestFails.

@Test
void renewalNoticeIsNotSentWhenPatronNoticeRequestFails() {
    UUID renewalTemplateId = UUID.randomUUID();
    JsonObject renewalNoticeConfiguration = new NoticeConfigurationBuilder().withTemplateId(renewalTemplateId).withRenewalEvent().create();
    JsonObject checkInNoticeConfiguration = new NoticeConfigurationBuilder().withTemplateId(UUID.randomUUID()).withCheckInEvent().create();
    NoticePolicyBuilder policyWithRenewalNotice = new NoticePolicyBuilder().withName("Policy with renewal notice").withLoanNotices(Arrays.asList(renewalNoticeConfiguration, checkInNoticeConfiguration));
    LoanPolicyBuilder limitedRenewalsLoanPolicy = new LoanPolicyBuilder().withName("Limited renewals loan policy").rolling(Period.months(1)).limitedRenewals(3);
    use(limitedRenewalsLoanPolicy, policyWithRenewalNotice);
    ItemBuilder itemBuilder = ItemExamples.basedUponSmallAngryPlanet(materialTypesFixture.book().getId(), loanTypesFixture.canCirculate().getId(), StringUtils.EMPTY, "ItemPrefix", "ItemSuffix", "");
    ItemResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet(itemBuilder, itemsFixture.thirdFloorHoldings());
    final IndividualResource steve = usersFixture.steve();
    final ZonedDateTime loanDate = ZonedDateTime.of(2018, 3, 18, 11, 43, 54, 0, UTC);
    checkOutFixture.checkOutByBarcode(new CheckOutByBarcodeRequestBuilder().forItem(smallAngryPlanet).to(steve).on(loanDate).at(UUID.randomUUID()));
    FakeModNotify.setFailPatronNoticesWithBadRequest(true);
    loansFixture.renewLoan(smallAngryPlanet, steve);
    verifyNumberOfSentNotices(0);
    verifyNumberOfPublishedEvents(NOTICE, 0);
    verifyNumberOfPublishedEvents(NOTICE_ERROR, 1);
}
Also used : ItemBuilder(api.support.builders.ItemBuilder) CheckOutByBarcodeRequestBuilder(api.support.builders.CheckOutByBarcodeRequestBuilder) ZonedDateTime(java.time.ZonedDateTime) ClockUtil.getZonedDateTime(org.folio.circulation.support.utils.ClockUtil.getZonedDateTime) NoticePolicyBuilder(api.support.builders.NoticePolicyBuilder) NoticeConfigurationBuilder(api.support.builders.NoticeConfigurationBuilder) JsonObject(io.vertx.core.json.JsonObject) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) UUID(java.util.UUID) IndividualResource(api.support.http.IndividualResource) ItemResource(api.support.http.ItemResource) Test(org.junit.jupiter.api.Test)

Example 25 with LoanPolicyBuilder

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

the class RenewalAPITests method multipleRenewalFailuresWhenLoanHasReachedMaximumNumberOfRenewalsAndOpenRecallRequest.

@Test
void multipleRenewalFailuresWhenLoanHasReachedMaximumNumberOfRenewalsAndOpenRecallRequest() {
    IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
    final IndividualResource jessica = usersFixture.jessica();
    LoanPolicyBuilder limitedRenewalsPolicy = new LoanPolicyBuilder().withName("Limited Renewals Policy").rolling(Period.days(2)).renewFromCurrentDueDate().limitedRenewals(3);
    UUID limitedRenewalsPolicyId = loanPoliciesFixture.create(limitedRenewalsPolicy).getId();
    use(limitedRenewalsPolicy);
    checkOutFixture.checkOutByBarcode(smallAngryPlanet, jessica, ZonedDateTime.of(2018, 4, 21, 11, 21, 43, 0, UTC));
    renew(smallAngryPlanet, jessica);
    renew(smallAngryPlanet, jessica);
    renew(smallAngryPlanet, jessica);
    requestsFixture.place(new RequestBuilder().recall().forItem(smallAngryPlanet).withPickupServicePointId(servicePointsFixture.cd1().getId()).by(usersFixture.charlotte()));
    final Response response = attemptRenewal(smallAngryPlanet, jessica);
    assertThat(response.getJson(), hasErrorWith(allOf(hasMessage("loan at maximum renewal number"), hasLoanPolicyIdParameter(limitedRenewalsPolicyId), hasLoanPolicyNameParameter("Limited Renewals Policy"))));
    assertThat(response.getJson(), hasErrorWith(hasMessage("items cannot be renewed when there is an active recall request")));
}
Also used : Response(org.folio.circulation.support.http.client.Response) RenewByBarcodeRequestBuilder(api.support.builders.RenewByBarcodeRequestBuilder) CheckOutByBarcodeRequestBuilder(api.support.builders.CheckOutByBarcodeRequestBuilder) ClaimItemReturnedRequestBuilder(api.support.builders.ClaimItemReturnedRequestBuilder) RequestBuilder(api.support.builders.RequestBuilder) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) IndividualResource(api.support.http.IndividualResource) UUID(java.util.UUID) 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