use of org.folio.circulation.support.utils.DateFormatUtil in project mod-circulation by folio-org.
the class DueDateNotRealTimeScheduledNoticesProcessingTests method beforeRecurringNoticesAreRescheduled.
@Test
void beforeRecurringNoticesAreRescheduled() {
configClient.create(ConfigurationExample.utcTimezoneConfiguration());
Period beforePeriod = Period.weeks(1);
Period recurringPeriod = Period.days(1);
JsonObject uponAtDueDateNoticeConfig = new NoticeConfigurationBuilder().withTemplateId(TEMPLATE_ID).withDueDateEvent().withBeforeTiming(beforePeriod).recurring(recurringPeriod).sendInRealTime(false).create();
NoticePolicyBuilder noticePolicy = new NoticePolicyBuilder().withName("Policy with due date notices").withLoanNotices(Collections.singletonList(uponAtDueDateNoticeConfig));
use(noticePolicy);
ZonedDateTime loanDate = ZonedDateTime.of(2019, 8, 23, 10, 30, 0, 0, ZoneOffset.UTC);
IndividualResource james = usersFixture.james();
IndividualResource nodToJamesLoan = checkOutFixture.checkOutByBarcode(itemsFixture.basedUponNod(), james, loanDate);
checkOutFixture.checkOutByBarcode(itemsFixture.basedUponInterestingTimes(), james, loanDate);
verifyNumberOfScheduledNotices(2);
ZonedDateTime dueDate = parseDateTime(nodToJamesLoan.getJson().getString("dueDate"));
ZonedDateTime timeForNoticeToBeSent = dueDate.minusWeeks(1);
ZonedDateTime nextDayAfterBeforeNoticeShouldBeSend = atStartOfDay(timeForNoticeToBeSent).plusDays(1);
scheduledNoticeProcessingClient.runDueDateNotRealTimeNoticesProcessing(nextDayAfterBeforeNoticeShouldBeSend);
ZonedDateTime newNextRunTime = recurringPeriod.plusDate(timeForNoticeToBeSent);
assertTrue(scheduledNoticesClient.getAll().stream().map(entries -> entries.getString("nextRunTime")).map(DateFormatUtil::parseDateTime).allMatch(d -> isSameMillis(newNextRunTime, d)), "all scheduled notices are rescheduled");
verifyNumberOfSentNotices(1);
verifyNumberOfScheduledNotices(2);
verifyNumberOfPublishedEvents(NOTICE, 1);
verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
}
Aggregations