Search in sources :

Example 6 with NoticePolicyBuilder

use of api.support.builders.NoticePolicyBuilder 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);
}
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) 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)

Example 7 with NoticePolicyBuilder

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

the class DueDateNotRealTimeScheduledNoticesProcessingTests method noticeIsNotSentOrDeletedWhenPatronNoticeRequestFails.

@Test
void noticeIsNotSentOrDeletedWhenPatronNoticeRequestFails() {
    JsonObject uponAtDueDateNoticeConfig = new NoticeConfigurationBuilder().withTemplateId(TEMPLATE_ID).withDueDateEvent().withUponAtTiming().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();
    ItemResource nod = itemsFixture.basedUponNod();
    IndividualResource nodToJamesLoan = checkOutFixture.checkOutByBarcode(nod, james, loanDate);
    verifyNumberOfScheduledNotices(1);
    ZonedDateTime dueDate = parseDateTime(nodToJamesLoan.getJson().getString("dueDate"));
    ZonedDateTime afterLoanDueDateTime = dueDate.plusDays(1);
    FakeModNotify.setFailPatronNoticesWithBadRequest(true);
    scheduledNoticeProcessingClient.runDueDateNotRealTimeNoticesProcessing(afterLoanDueDateTime);
    verifyNumberOfSentNotices(0);
    verifyNumberOfScheduledNotices(1);
    verifyNumberOfPublishedEvents(NOTICE, 0);
    verifyNumberOfPublishedEvents(NOTICE_ERROR, 1);
}
Also used : ZonedDateTime(java.time.ZonedDateTime) NoticePolicyBuilder(api.support.builders.NoticePolicyBuilder) NoticeConfigurationBuilder(api.support.builders.NoticeConfigurationBuilder) JsonObject(io.vertx.core.json.JsonObject) IndividualResource(api.support.http.IndividualResource) ItemResource(api.support.http.ItemResource) Test(org.junit.jupiter.api.Test)

Example 8 with NoticePolicyBuilder

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

the class DueDateNotRealTimeScheduledNoticesProcessingTests method uponAtDueDateNoticesShouldBeSentInGroups.

@Test
void uponAtDueDateNoticesShouldBeSentInGroups() {
    JsonObject uponAtDueDateNoticeConfig = new NoticeConfigurationBuilder().withTemplateId(TEMPLATE_ID).withDueDateEvent().withUponAtTiming().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();
    ItemResource nod = itemsFixture.basedUponNod();
    ItemResource interestingTimes = itemsFixture.basedUponInterestingTimes();
    IndividualResource nodToJamesLoan = checkOutFixture.checkOutByBarcode(nod, james, loanDate);
    IndividualResource interestingTimesToJamesLoan = checkOutFixture.checkOutByBarcode(interestingTimes, james, loanDate);
    IndividualResource rebecca = usersFixture.rebecca();
    ItemResource temeraire = itemsFixture.basedUponTemeraire();
    ItemResource dunkirk = itemsFixture.basedUponDunkirk();
    IndividualResource temeraireToRebeccaLoan = checkOutFixture.checkOutByBarcode(temeraire, rebecca, loanDate);
    IndividualResource dunkirkToRebeccaLoan = checkOutFixture.checkOutByBarcode(dunkirk, rebecca, loanDate);
    verifyNumberOfScheduledNotices(4);
    ZonedDateTime dueDate = parseDateTime(nodToJamesLoan.getJson().getString("dueDate"));
    ZonedDateTime afterLoanDueDateTime = dueDate.plusDays(1);
    scheduledNoticeProcessingClient.runDueDateNotRealTimeNoticesProcessing(afterLoanDueDateTime);
    final var loanPolicyMatcher = toStringMatcher(getLoanPolicyContextMatchersForUnlimitedRenewals());
    final var noticeToJamesContextMatcher = getMultipleLoansContextMatcher(james, Arrays.asList(Pair.of(nodToJamesLoan, nod), Pair.of(interestingTimesToJamesLoan, interestingTimes)), loanPolicyMatcher);
    final var noticeToRebeccaContextMatcher = getMultipleLoansContextMatcher(rebecca, Arrays.asList(Pair.of(temeraireToRebeccaLoan, temeraire), Pair.of(dunkirkToRebeccaLoan, dunkirk)), loanPolicyMatcher);
    assertThat(FakeModNotify.getSentPatronNotices(), hasItems(hasEmailNoticeProperties(james.getId(), TEMPLATE_ID, noticeToJamesContextMatcher), hasEmailNoticeProperties(rebecca.getId(), TEMPLATE_ID, noticeToRebeccaContextMatcher)));
    verifyNumberOfSentNotices(2);
    verifyNumberOfScheduledNotices(0);
    verifyNumberOfPublishedEvents(NOTICE, 2);
    verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
}
Also used : ZonedDateTime(java.time.ZonedDateTime) NoticePolicyBuilder(api.support.builders.NoticePolicyBuilder) NoticeConfigurationBuilder(api.support.builders.NoticeConfigurationBuilder) JsonObject(io.vertx.core.json.JsonObject) IndividualResource(api.support.http.IndividualResource) ItemResource(api.support.http.ItemResource) Test(org.junit.jupiter.api.Test)

Example 9 with NoticePolicyBuilder

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

the class DueDateNotRealTimeScheduledNoticesProcessingTests method missingReferencedEntitiesDoNotBlockProcessing.

@Test
void missingReferencedEntitiesDoNotBlockProcessing() {
    JsonObject uponAtDueDateNoticeConfig = new NoticeConfigurationBuilder().withTemplateId(TEMPLATE_ID).withDueDateEvent().withUponAtTiming().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);
    // users
    val james = usersFixture.james();
    val steve = usersFixture.steve();
    val jessica = usersFixture.jessica();
    // items
    ItemResource nod = itemsFixture.basedUponNod();
    ItemResource temeraire = itemsFixture.basedUponTemeraire();
    ItemResource planet = itemsFixture.basedUponSmallAngryPlanet();
    ItemResource times = itemsFixture.basedUponInterestingTimes();
    ItemResource uprooted = itemsFixture.basedUponUprooted();
    ItemResource dunkirk = itemsFixture.basedUponDunkirk();
    // loans
    IndividualResource nodToJames = checkOutFixture.checkOutByBarcode(nod, james, loanDate.plusHours(1));
    IndividualResource temeraireToJames = checkOutFixture.checkOutByBarcode(temeraire, james, loanDate.plusHours(2));
    IndividualResource planetToJames = checkOutFixture.checkOutByBarcode(planet, james, loanDate.plusHours(3));
    checkOutFixture.checkOutByBarcode(times, steve, loanDate.plusHours(4));
    IndividualResource uprootedToSteve = checkOutFixture.checkOutByBarcode(uprooted, steve, loanDate.plusHours(5));
    checkOutFixture.checkOutByBarcode(dunkirk, jessica, loanDate.plusHours(6));
    loansClient.delete(temeraireToJames);
    itemsClient.delete(times);
    usersFixture.remove(jessica);
    verifyNumberOfScheduledNotices(6);
    ZonedDateTime dueDate = parseDateTime(nodToJames.getJson().getString("dueDate"));
    scheduledNoticeProcessingClient.runDueDateNotRealTimeNoticesProcessing(dueDate.plusDays(1));
    Matcher<? super String> loanPolicyMatcher = toStringMatcher(getLoanPolicyContextMatchersForUnlimitedRenewals());
    Matcher<? super String> noticeToJamesContextMatcher = getMultipleLoansContextMatcher(james, Arrays.asList(Pair.of(nodToJames, nod), Pair.of(planetToJames, planet)), loanPolicyMatcher);
    Matcher<? super String> noticeToSteveContextMatcher = getMultipleLoansContextMatcher(steve, Collections.singletonList(Pair.of(uprootedToSteve, uprooted)), loanPolicyMatcher);
    MatcherAssert.assertThat(FakeModNotify.getSentPatronNotices(), hasItems(hasEmailNoticeProperties(james.getId(), TEMPLATE_ID, noticeToJamesContextMatcher), hasEmailNoticeProperties(steve.getId(), TEMPLATE_ID, noticeToSteveContextMatcher)));
    verifyNumberOfSentNotices(2);
    verifyNumberOfScheduledNotices(0);
    verifyNumberOfPublishedEvents(NOTICE, 2);
    verifyNumberOfPublishedEvents(NOTICE_ERROR, 3);
}
Also used : lombok.val(lombok.val) ZonedDateTime(java.time.ZonedDateTime) NoticePolicyBuilder(api.support.builders.NoticePolicyBuilder) NoticeConfigurationBuilder(api.support.builders.NoticeConfigurationBuilder) JsonObject(io.vertx.core.json.JsonObject) IndividualResource(api.support.http.IndividualResource) ItemResource(api.support.http.ItemResource) Test(org.junit.jupiter.api.Test)

Example 10 with NoticePolicyBuilder

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

the class DueDateNotRealTimeScheduledNoticesProcessingTests method noticeIsDeletedIfReferencedLoanDoesNotExist.

@Test
void noticeIsDeletedIfReferencedLoanDoesNotExist() {
    JsonObject uponAtDueDateNoticeConfig = new NoticeConfigurationBuilder().withTemplateId(TEMPLATE_ID).withDueDateEvent().withUponAtTiming().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();
    ItemResource nod = itemsFixture.basedUponNod();
    IndividualResource nodToJamesLoan = checkOutFixture.checkOutByBarcode(nod, james, loanDate);
    loansStorageClient.delete(nodToJamesLoan);
    verifyNumberOfScheduledNotices(1);
    ZonedDateTime dueDate = parseDateTime(nodToJamesLoan.getJson().getString("dueDate"));
    ZonedDateTime afterLoanDueDateTime = dueDate.plusDays(1);
    scheduledNoticeProcessingClient.runDueDateNotRealTimeNoticesProcessing(afterLoanDueDateTime);
    verifyNumberOfSentNotices(0);
    verifyNumberOfScheduledNotices(0);
    verifyNumberOfPublishedEvents(NOTICE, 0);
    verifyNumberOfPublishedEvents(NOTICE_ERROR, 1);
}
Also used : ZonedDateTime(java.time.ZonedDateTime) NoticePolicyBuilder(api.support.builders.NoticePolicyBuilder) NoticeConfigurationBuilder(api.support.builders.NoticeConfigurationBuilder) JsonObject(io.vertx.core.json.JsonObject) IndividualResource(api.support.http.IndividualResource) ItemResource(api.support.http.ItemResource) Test(org.junit.jupiter.api.Test)

Aggregations

NoticePolicyBuilder (api.support.builders.NoticePolicyBuilder)73 NoticeConfigurationBuilder (api.support.builders.NoticeConfigurationBuilder)64 Test (org.junit.jupiter.api.Test)63 JsonObject (io.vertx.core.json.JsonObject)58 ZonedDateTime (java.time.ZonedDateTime)53 IndividualResource (api.support.http.IndividualResource)51 UUID (java.util.UUID)47 ItemResource (api.support.http.ItemResource)37 RequestBuilder (api.support.builders.RequestBuilder)28 ClockUtil.getZonedDateTime (org.folio.circulation.support.utils.ClockUtil.getZonedDateTime)21 CheckInByBarcodeRequestBuilder (api.support.builders.CheckInByBarcodeRequestBuilder)18 LoanPolicyBuilder (api.support.builders.LoanPolicyBuilder)16 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)14 ItemBuilder (api.support.builders.ItemBuilder)11 Period (org.folio.circulation.domain.policy.Period)11 Matcher (org.hamcrest.Matcher)11 CheckOutByBarcodeRequestBuilder (api.support.builders.CheckOutByBarcodeRequestBuilder)10 MoveRequestBuilder (api.support.builders.MoveRequestBuilder)9 HashMap (java.util.HashMap)9 lombok.val (lombok.val)8