Search in sources :

Example 1 with DateFormatUtil

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);
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) NOTICE(org.folio.circulation.domain.representations.logs.LogEventType.NOTICE) BeforeEach(org.junit.jupiter.api.BeforeEach) JsonObjectMatcher.toStringMatcher(api.support.matchers.JsonObjectMatcher.toStringMatcher) Arrays(java.util.Arrays) ZonedDateTime(java.time.ZonedDateTime) APITests(api.support.APITests) FakePubSub(api.support.fakes.FakePubSub) PatronNoticeTestHelper.verifyNumberOfScheduledNotices(api.support.utl.PatronNoticeTestHelper.verifyNumberOfScheduledNotices) DateFormatUtil.parseDateTime(org.folio.circulation.support.utils.DateFormatUtil.parseDateTime) Pair(org.apache.commons.lang3.tuple.Pair) IndividualResource(api.support.http.IndividualResource) Period(org.folio.circulation.domain.policy.Period) NoticePolicyBuilder(api.support.builders.NoticePolicyBuilder) JsonObject(io.vertx.core.json.JsonObject) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ZoneOffset(java.time.ZoneOffset) DateTimeUtil.isSameMillis(org.folio.circulation.support.utils.DateTimeUtil.isSameMillis) PatronNoticeTestHelper.verifyNumberOfPublishedEvents(api.support.utl.PatronNoticeTestHelper.verifyNumberOfPublishedEvents) DateFormatUtil(org.folio.circulation.support.utils.DateFormatUtil) NOTICE_ERROR(org.folio.circulation.domain.representations.logs.LogEventType.NOTICE_ERROR) DateTimeUtil.atStartOfDay(org.folio.circulation.support.utils.DateTimeUtil.atStartOfDay) CoreMatchers.hasItems(org.hamcrest.CoreMatchers.hasItems) TemplateContextMatchers.getLoanPolicyContextMatchersForUnlimitedRenewals(api.support.fixtures.TemplateContextMatchers.getLoanPolicyContextMatchersForUnlimitedRenewals) TemplateContextMatchers.getMultipleLoansContextMatcher(api.support.fixtures.TemplateContextMatchers.getMultipleLoansContextMatcher) NoticeConfigurationBuilder(api.support.builders.NoticeConfigurationBuilder) FakeModNotify(api.support.fakes.FakeModNotify) lombok.val(lombok.val) UUID(java.util.UUID) UserBuilder(api.support.builders.UserBuilder) ItemResource(api.support.http.ItemResource) PatronNoticeMatcher.hasEmailNoticeProperties(api.support.matchers.PatronNoticeMatcher.hasEmailNoticeProperties) ConfigurationExample(api.support.fixtures.ConfigurationExample) ZoneId(java.time.ZoneId) PatronNoticeTestHelper.verifyNumberOfSentNotices(api.support.utl.PatronNoticeTestHelper.verifyNumberOfSentNotices) Test(org.junit.jupiter.api.Test) MatcherAssert(org.hamcrest.MatcherAssert) ClockUtil(org.folio.circulation.support.utils.ClockUtil) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Matcher(org.hamcrest.Matcher) Collections(java.util.Collections) DateFormatUtil(org.folio.circulation.support.utils.DateFormatUtil) 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) IndividualResource(api.support.http.IndividualResource) Test(org.junit.jupiter.api.Test)

Aggregations

APITests (api.support.APITests)1 NoticeConfigurationBuilder (api.support.builders.NoticeConfigurationBuilder)1 NoticePolicyBuilder (api.support.builders.NoticePolicyBuilder)1 UserBuilder (api.support.builders.UserBuilder)1 FakeModNotify (api.support.fakes.FakeModNotify)1 FakePubSub (api.support.fakes.FakePubSub)1 ConfigurationExample (api.support.fixtures.ConfigurationExample)1 TemplateContextMatchers.getLoanPolicyContextMatchersForUnlimitedRenewals (api.support.fixtures.TemplateContextMatchers.getLoanPolicyContextMatchersForUnlimitedRenewals)1 TemplateContextMatchers.getMultipleLoansContextMatcher (api.support.fixtures.TemplateContextMatchers.getMultipleLoansContextMatcher)1 IndividualResource (api.support.http.IndividualResource)1 ItemResource (api.support.http.ItemResource)1 JsonObjectMatcher.toStringMatcher (api.support.matchers.JsonObjectMatcher.toStringMatcher)1 PatronNoticeMatcher.hasEmailNoticeProperties (api.support.matchers.PatronNoticeMatcher.hasEmailNoticeProperties)1 PatronNoticeTestHelper.verifyNumberOfPublishedEvents (api.support.utl.PatronNoticeTestHelper.verifyNumberOfPublishedEvents)1 PatronNoticeTestHelper.verifyNumberOfScheduledNotices (api.support.utl.PatronNoticeTestHelper.verifyNumberOfScheduledNotices)1 PatronNoticeTestHelper.verifyNumberOfSentNotices (api.support.utl.PatronNoticeTestHelper.verifyNumberOfSentNotices)1 JsonObject (io.vertx.core.json.JsonObject)1 ZoneId (java.time.ZoneId)1 ZoneOffset (java.time.ZoneOffset)1 ZonedDateTime (java.time.ZonedDateTime)1