Search in sources :

Example 26 with Period

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

the class DueDateScheduledNoticesTests method noticesShouldBeRescheduledAfterRenewal.

@Test
void noticesShouldBeRescheduledAfterRenewal() {
    UUID beforeTemplateId = UUID.randomUUID();
    Period beforePeriod = Period.days(2);
    Period beforeRecurringPeriod = Period.hours(6);
    UUID uponAtTemplateId = UUID.randomUUID();
    UUID afterTemplateId = UUID.randomUUID();
    Period afterPeriod = Period.days(3);
    Period afterRecurringPeriod = Period.hours(4);
    JsonObject beforeDueDateNoticeConfiguration = new NoticeConfigurationBuilder().withTemplateId(beforeTemplateId).withDueDateEvent().withBeforeTiming(beforePeriod).recurring(beforeRecurringPeriod).sendInRealTime(true).create();
    JsonObject uponAtDueDateNoticeConfiguration = new NoticeConfigurationBuilder().withTemplateId(uponAtTemplateId).withDueDateEvent().withUponAtTiming().sendInRealTime(false).create();
    JsonObject afterDueDateNoticeConfiguration = new NoticeConfigurationBuilder().withTemplateId(afterTemplateId).withDueDateEvent().withAfterTiming(afterPeriod).recurring(afterRecurringPeriod).sendInRealTime(true).create();
    NoticePolicyBuilder noticePolicy = new NoticePolicyBuilder().withName("Policy with due date notices").withLoanNotices(Arrays.asList(beforeDueDateNoticeConfiguration, uponAtDueDateNoticeConfiguration, afterDueDateNoticeConfiguration));
    use(noticePolicy);
    IndividualResource item = itemsFixture.basedUponSmallAngryPlanet();
    final IndividualResource borrower = usersFixture.steve();
    final IndividualResource loan = checkOutFixture.checkOutByBarcode(item, borrower);
    checkOutFixture.checkOutByBarcode(itemsFixture.basedUponNod(), usersFixture.jessica());
    verifyNumberOfScheduledNotices(6);
    IndividualResource renewedLoan = loansFixture.renewLoan(item, borrower);
    ZonedDateTime dueDateAfterRenewal = getDateTimeProperty(renewedLoan.getJson(), "dueDate");
    Matcher<Iterable<JsonObject>> scheduledNoticesAfterRenewalMatcher = hasItems(hasScheduledLoanNotice(loan.getId(), beforePeriod.minusDate(dueDateAfterRenewal), BEFORE_TIMING, beforeTemplateId, beforeRecurringPeriod, true), hasScheduledLoanNotice(loan.getId(), dueDateAfterRenewal, UPON_AT_TIMING, uponAtTemplateId, null, false), hasScheduledLoanNotice(loan.getId(), afterPeriod.plusDate(dueDateAfterRenewal), AFTER_TIMING, afterTemplateId, afterRecurringPeriod, true));
    Awaitility.await().atMost(1, TimeUnit.SECONDS).until(scheduledNoticesClient::getAll, scheduledNoticesAfterRenewalMatcher);
    verifyNumberOfScheduledNotices(6);
}
Also used : ZonedDateTime(java.time.ZonedDateTime) NoticePolicyBuilder(api.support.builders.NoticePolicyBuilder) NoticeConfigurationBuilder(api.support.builders.NoticeConfigurationBuilder) Period(org.folio.circulation.domain.policy.Period) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) IndividualResource(api.support.http.IndividualResource) Test(org.junit.jupiter.api.Test)

Example 27 with Period

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

the class LostItemPolicyTest method shouldAgeToLostIfAgeToLostPeriodHasPassedSinceDueDateAndItemRecalled.

@ParameterizedTest
@CsvSource(value = { "Minutes, 43", "Hours, 12", "Days, 29", "Weeks, 1", "Months, 5" })
void shouldAgeToLostIfAgeToLostPeriodHasPassedSinceDueDateAndItemRecalled(String interval, int duration) {
    final Period period = from(duration, interval);
    final LostItemPolicy lostItemPolicy = lostItemPolicyWithRecallAgePeriod(period);
    final ZonedDateTime loanDueDate = period.minusDate(getZonedDateTime()).minusSeconds(1);
    assertTrue(lostItemPolicy.canAgeLoanToLost(true, loanDueDate));
}
Also used : ClockUtil.getZonedDateTime(org.folio.circulation.support.utils.ClockUtil.getZonedDateTime) ZonedDateTime(java.time.ZonedDateTime) Period(org.folio.circulation.domain.policy.Period) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 28 with Period

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

the class LostItemPolicyTest method shouldRefundLostFeesIfPeriodIsPassing.

@ParameterizedTest
@CsvSource(value = { "Minutes, 656", "Hours, 6", "Days, 98", "Weeks, 43", "Months, 5" })
void shouldRefundLostFeesIfPeriodIsPassing(String interval, int duration) {
    final Period period = from(duration, interval);
    final LostItemFeePolicyBuilder builder = new LostItemFeePolicyBuilder().withFeeRefundInterval(period);
    final LostItemPolicy lostItemPolicy = LostItemPolicy.from(builder.create());
    final ZonedDateTime now = ZonedDateTime.of(2022, 3, 27, 11, 25, 35, 0, ZoneId.of("UTC"));
    setClock(fixed(now.toInstant(), ZoneOffset.UTC));
    final ZonedDateTime lostDateTime = period.minusDate(now);
    assertTrue(lostItemPolicy.shouldRefundFees(lostDateTime));
}
Also used : LostItemFeePolicyBuilder(api.support.builders.LostItemFeePolicyBuilder) ClockUtil.getZonedDateTime(org.folio.circulation.support.utils.ClockUtil.getZonedDateTime) ZonedDateTime(java.time.ZonedDateTime) Period(org.folio.circulation.domain.policy.Period) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 29 with Period

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

the class LostItemPolicyTest method shouldAgeToLostIfAgeToLostPeriodHasPassedSinceDueDateAndItemNotRecalled.

@ParameterizedTest
@CsvSource(value = { "Minutes, 43", "Hours, 12", "Days, 29", "Weeks, 1", "Months, 5" })
void shouldAgeToLostIfAgeToLostPeriodHasPassedSinceDueDateAndItemNotRecalled(String interval, int duration) {
    final Period period = from(duration, interval);
    final LostItemPolicy lostItemPolicy = lostItemPolicyWithAgePeriod(period);
    final ZonedDateTime loanDueDate = period.minusDate(getZonedDateTime()).minusSeconds(1);
    assertTrue(lostItemPolicy.canAgeLoanToLost(false, loanDueDate));
}
Also used : ClockUtil.getZonedDateTime(org.folio.circulation.support.utils.ClockUtil.getZonedDateTime) ZonedDateTime(java.time.ZonedDateTime) Period(org.folio.circulation.domain.policy.Period) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 30 with Period

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

the class LostItemPolicyTest method canCalculateBillingDateWhenPatronIsBilledImmediatelyForNotRecalledItem.

@ParameterizedTest
@CsvSource(value = { "Minutes, 0", "Hours, 0", "Days, 0", "Weeks, 0", "Months, 0", "null, null" }, nullValues = { "null" })
public void canCalculateBillingDateWhenPatronIsBilledImmediatelyForNotRecalledItem(String interval, Integer duration) {
    final Period billPatronInterval = duration == null && interval == null ? null : Period.from(duration, interval);
    final ZonedDateTime agedToLostDate = getZonedDateTime();
    final LostItemPolicy lostItemPolicy = LostItemPolicy.from(new LostItemFeePolicyBuilder().withPatronBilledAfterItemAgedToLost(billPatronInterval).withSetCost(10.0).doNotChargeProcessingFeeWhenAgedToLost().create());
    final ZonedDateTime actualBillingDate = lostItemPolicy.calculateDateTimeWhenPatronBilledForAgedToLost(false, agedToLostDate);
    assertThat(actualBillingDate, is(agedToLostDate));
}
Also used : ClockUtil.getZonedDateTime(org.folio.circulation.support.utils.ClockUtil.getZonedDateTime) ZonedDateTime(java.time.ZonedDateTime) LostItemFeePolicyBuilder(api.support.builders.LostItemFeePolicyBuilder) Period(org.folio.circulation.domain.policy.Period) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Period (org.folio.circulation.domain.policy.Period)33 ZonedDateTime (java.time.ZonedDateTime)25 Test (org.junit.jupiter.api.Test)17 ClockUtil.getZonedDateTime (org.folio.circulation.support.utils.ClockUtil.getZonedDateTime)16 IndividualResource (api.support.http.IndividualResource)15 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 JsonObject (io.vertx.core.json.JsonObject)14 NoticeConfigurationBuilder (api.support.builders.NoticeConfigurationBuilder)10 NoticePolicyBuilder (api.support.builders.NoticePolicyBuilder)10 LostItemFeePolicyBuilder (api.support.builders.LostItemFeePolicyBuilder)9 UUID (java.util.UUID)9 CsvSource (org.junit.jupiter.params.provider.CsvSource)8 LoanPolicyBuilder (api.support.builders.LoanPolicyBuilder)7 RequestBuilder (api.support.builders.RequestBuilder)5 CheckOutByBarcodeRequestBuilder (api.support.builders.CheckOutByBarcodeRequestBuilder)4 ItemResource (api.support.http.ItemResource)3 NOTICE (org.folio.circulation.domain.representations.logs.LogEventType.NOTICE)3 NOTICE_ERROR (org.folio.circulation.domain.representations.logs.LogEventType.NOTICE_ERROR)3 APITests (api.support.APITests)2 UserBuilder (api.support.builders.UserBuilder)2