use of org.folio.circulation.domain.representations.logs.LogEventType.NOTICE_ERROR in project mod-circulation by folio-org.
the class DueDateNotRealTimeScheduledNoticesProcessingTests method processingTakesNoticesLimitedByConfiguration.
@Test
void processingTakesNoticesLimitedByConfiguration() {
Period beforePeriod = Period.weeks(1);
JsonObject uponAtDueDateNoticeConfig = new NoticeConfigurationBuilder().withTemplateId(TEMPLATE_ID).withDueDateEvent().withBeforeTiming(beforePeriod).sendInRealTime(false).create();
NoticePolicyBuilder noticePolicy = new NoticePolicyBuilder().withName("Policy with due date notices").withLoanNotices(Collections.singletonList(uponAtDueDateNoticeConfig));
use(noticePolicy);
IndividualResource james = usersFixture.james();
IndividualResource steve = usersFixture.steve();
IndividualResource rebecca = usersFixture.rebecca();
// Generate several loans
for (int i = 0; i < 4; i++) {
String baseBarcode = Integer.toString(i);
checkOutFixture.checkOutByBarcode(itemsFixture.basedUponNod(b -> b.withBarcode(baseBarcode + "1")), james);
checkOutFixture.checkOutByBarcode(itemsFixture.basedUponNod((b -> b.withBarcode(baseBarcode + "2"))), steve);
checkOutFixture.checkOutByBarcode(itemsFixture.basedUponNod((b -> b.withBarcode(baseBarcode + "3"))), rebecca);
}
verifyNumberOfScheduledNotices(12);
int noticesLimitConfig = 10;
configClient.create(ConfigurationExample.schedulerNoticesLimitConfiguration(Integer.toString(noticesLimitConfig)));
// Should fetch 10 notices, when total records is 12
// So that notices for one of the users should not be processed
final ZonedDateTime runTime = ClockUtil.getZonedDateTime().plusDays(15);
mockClockManagerToReturnFixedDateTime(runTime);
scheduledNoticeProcessingClient.runDueDateNotRealTimeNoticesProcessing(runTime);
long numberOfUniqueUserIds = scheduledNoticesClient.getAll().stream().map(notice -> notice.getString("recipientUserId")).distinct().count();
assertThat(numberOfUniqueUserIds, is(1L));
verifyNumberOfSentNotices(2);
verifyNumberOfScheduledNotices(4);
verifyNumberOfPublishedEvents(NOTICE, 2);
verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
}
use of org.folio.circulation.domain.representations.logs.LogEventType.NOTICE_ERROR in project mod-circulation by folio-org.
the class EndExpiredPatronActionSessionTests method patronHasSomeSessionsAndOnlySessionsWithSameActionTypeShouldBeExpiredByTimeout.
@Test
void patronHasSomeSessionsAndOnlySessionsWithSameActionTypeShouldBeExpiredByTimeout() {
IndividualResource james = usersFixture.james();
ItemResource nod = itemsFixture.basedUponNod();
ItemResource interestingTimes = itemsFixture.basedUponInterestingTimes();
checkOutFixture.checkOutByBarcode(nod, james);
checkOutFixture.checkOutByBarcode(interestingTimes, james);
checkInFixture.checkInByBarcode(nod);
checkInFixture.checkInByBarcode(interestingTimes);
expiredEndSessionClient.deleteAll();
List<JsonObject> sessions = patronSessionRecordsClient.getAll();
assertThat(sessions, hasSize(4));
String patronId = sessions.stream().filter(session -> session.getMap().get(ACTION_TYPE).equals(PatronActionType.CHECK_IN.getRepresentation())).findFirst().map(session -> session.getString(PATRON_ID)).orElse("");
createExpiredEndSession(patronId, CHECK_IN);
expiredSessionProcessingClient.runRequestExpiredSessionsProcessing(204);
waitAtMost(1, SECONDS).until(patronSessionRecordsClient::getAll, hasSize(2));
verifyNumberOfSentNotices(1);
verifyNumberOfPublishedEvents(NOTICE, 1);
verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
}
use of org.folio.circulation.domain.representations.logs.LogEventType.NOTICE_ERROR in project mod-circulation by folio-org.
the class EndExpiredPatronActionSessionTests method patronHasSeveralSessionsAndOnlyOneShouldBeExpiredByTimeout.
@Test
void patronHasSeveralSessionsAndOnlyOneShouldBeExpiredByTimeout() {
IndividualResource james = usersFixture.james();
ItemResource nod = itemsFixture.basedUponNod();
ItemResource interestingTimes = itemsFixture.basedUponInterestingTimes();
checkOutFixture.checkOutByBarcode(nod, james);
checkOutFixture.checkOutByBarcode(interestingTimes, james);
checkInFixture.checkInByBarcode(nod);
expiredEndSessionClient.deleteAll();
List<JsonObject> sessions = patronSessionRecordsClient.getAll();
assertThat(sessions, hasSize(3));
String patronId = sessions.stream().filter(session -> session.getMap().get(ACTION_TYPE).equals(PatronActionType.CHECK_IN.getRepresentation())).findFirst().map(session -> session.getString(PATRON_ID)).orElse("");
createExpiredEndSession(patronId, CHECK_IN);
expiredSessionProcessingClient.runRequestExpiredSessionsProcessing(204);
waitAtMost(1, SECONDS).until(patronSessionRecordsClient::getAll, hasSize(2));
verifyNumberOfSentNotices(1);
verifyNumberOfPublishedEvents(NOTICE, 1);
verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
}
use of org.folio.circulation.domain.representations.logs.LogEventType.NOTICE_ERROR 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);
}
use of org.folio.circulation.domain.representations.logs.LogEventType.NOTICE_ERROR in project mod-circulation by folio-org.
the class EndExpiredPatronActionSessionTests method patronNoticeContextContainsUserTokensWhenNoticeIsTriggeredByExpiredSession.
@Test
void patronNoticeContextContainsUserTokensWhenNoticeIsTriggeredByExpiredSession() {
IndividualResource james = usersFixture.james();
ItemResource nod = itemsFixture.basedUponNod();
checkOutFixture.checkOutByBarcode(nod, james);
patronSessionRecordsClient.getAll().stream().filter(session -> session.getMap().get(ACTION_TYPE).equals(PatronActionType.CHECK_OUT.getRepresentation())).map(session -> session.getString(PATRON_ID)).forEach(patronId -> createExpiredEndSession(patronId, CHECK_OUT));
expiredSessionProcessingClient.runRequestExpiredSessionsProcessing(204);
waitAtMost(1, SECONDS).until(patronSessionRecordsClient::getAll, empty());
verifyNumberOfSentNotices(1);
verifyNumberOfPublishedEvents(NOTICE, 1);
verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
assertThat(FakeModNotify.getFirstSentPatronNotice(), hasEmailNoticeProperties(james.getId(), CHECK_OUT_TEMPLATE_ID, TemplateContextMatchers.getUserContextMatchers(james)));
}
Aggregations