Search in sources :

Example 16 with NoticeConfigurationBuilder

use of api.support.builders.NoticeConfigurationBuilder 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 17 with NoticeConfigurationBuilder

use of api.support.builders.NoticeConfigurationBuilder 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)

Example 18 with NoticeConfigurationBuilder

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

the class DueDateScheduledNoticesTests method checkOutSchedulesDifferentBeforeDueDateNotices.

@Test
void checkOutSchedulesDifferentBeforeDueDateNotices() {
    UUID firstBeforeTemplateId = UUID.randomUUID();
    Period firstBeforePeriod = Period.weeks(1);
    UUID secondBeforeTemplateId = UUID.randomUUID();
    Period secondBeforePeriod = Period.hours(12);
    JsonObject firstBeforeDueDateNoticeConfiguration = new NoticeConfigurationBuilder().withTemplateId(firstBeforeTemplateId).withDueDateEvent().withBeforeTiming(firstBeforePeriod).sendInRealTime(false).create();
    JsonObject secondBeforeDueDateNoticeConfiguration = new NoticeConfigurationBuilder().withTemplateId(secondBeforeTemplateId).withDueDateEvent().withBeforeTiming(secondBeforePeriod).sendInRealTime(true).create();
    NoticePolicyBuilder noticePolicy = new NoticePolicyBuilder().withName("Policy with before due date notices").withLoanNotices(Arrays.asList(firstBeforeDueDateNoticeConfiguration, secondBeforeDueDateNoticeConfiguration));
    use(noticePolicy);
    IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
    final IndividualResource steve = usersFixture.steve();
    final ZonedDateTime loanDate = ZonedDateTime.of(2018, 3, 18, 11, 43, 54, 0, UTC);
    final IndividualResource loan = checkOutFixture.checkOutByBarcode(new CheckOutByBarcodeRequestBuilder().forItem(smallAngryPlanet).to(steve).on(loanDate).at(UUID.randomUUID()));
    ZonedDateTime dueDate = getDateTimeProperty(loan.getJson(), "dueDate");
    verifyNumberOfScheduledNotices(2);
    List<JsonObject> scheduledNotices = scheduledNoticesClient.getAll();
    assertThat(scheduledNotices, hasItems(hasScheduledLoanNotice(loan.getId(), firstBeforePeriod.minusDate(dueDate), BEFORE_TIMING, firstBeforeTemplateId, null, false), hasScheduledLoanNotice(loan.getId(), secondBeforePeriod.minusDate(dueDate), BEFORE_TIMING, secondBeforeTemplateId, null, true)));
}
Also used : CheckOutByBarcodeRequestBuilder(api.support.builders.CheckOutByBarcodeRequestBuilder) 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 19 with NoticeConfigurationBuilder

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

the class DueDateScheduledNoticesTests method noticesShouldBeRescheduledAfterRecall.

@Test
void noticesShouldBeRescheduledAfterRecall() {
    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));
    LoanPolicyBuilder loanPolicy = new LoanPolicyBuilder().withName("Can Circulate Rolling for recall").rolling(Period.weeks(3)).withRecallsMinimumGuaranteedLoanPeriod(Period.weeks(2));
    use(loanPolicy, 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);
    requestsFixture.place(new RequestBuilder().open().recall().forItem(item).by(usersFixture.james()).withPickupServicePointId(servicePointsFixture.cd1().getId()));
    IndividualResource loanAfterRecall = loansClient.get(loan.getId());
    ZonedDateTime dueDateAfterRecall = getDateTimeProperty(loanAfterRecall.getJson(), "dueDate");
    Matcher<Iterable<JsonObject>> scheduledNoticesAfterRecallMatcher = hasItems(hasScheduledLoanNotice(loan.getId(), beforePeriod.minusDate(dueDateAfterRecall), BEFORE_TIMING, beforeTemplateId, beforeRecurringPeriod, true), hasScheduledLoanNotice(loan.getId(), dueDateAfterRecall, UPON_AT_TIMING, uponAtTemplateId, null, false), hasScheduledLoanNotice(loan.getId(), afterPeriod.plusDate(dueDateAfterRecall), AFTER_TIMING, afterTemplateId, afterRecurringPeriod, true));
    Awaitility.await().atMost(1, TimeUnit.SECONDS).until(scheduledNoticesClient::getAll, scheduledNoticesAfterRecallMatcher);
    verifyNumberOfScheduledNotices(6);
}
Also used : RequestBuilder(api.support.builders.RequestBuilder) CheckOutByBarcodeRequestBuilder(api.support.builders.CheckOutByBarcodeRequestBuilder) 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) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) UUID(java.util.UUID) IndividualResource(api.support.http.IndividualResource) Test(org.junit.jupiter.api.Test)

Example 20 with NoticeConfigurationBuilder

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

the class DueDateScheduledNoticesTests method noticesShouldBeRescheduledAfterRenewalOverride.

@Test
void noticesShouldBeRescheduledAfterRenewalOverride() {
    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));
    LoanPolicyBuilder loanPolicy = new LoanPolicyBuilder().withName("Not renewable").rolling(Period.weeks(3)).notRenewable();
    use(loanPolicy, noticePolicy);
    IndividualResource item = itemsFixture.basedUponSmallAngryPlanet();
    final IndividualResource borrower = usersFixture.steve();
    final IndividualResource loan = checkOutFixture.checkOutByBarcode(item, borrower);
    ZonedDateTime dueDate = getDateTimeProperty(loan.getJson(), "dueDate");
    checkOutFixture.checkOutByBarcode(itemsFixture.basedUponNod(), usersFixture.jessica());
    verifyNumberOfScheduledNotices(6);
    ZonedDateTime dueDateAfterRenewal = dueDate.plusWeeks(3);
    final OkapiHeaders okapiHeaders = buildOkapiHeadersWithPermissions(OVERRIDE_RENEWAL_PERMISSION);
    loansFixture.overrideRenewalByBarcode(item, borrower, "Renewal comment", dueDateAfterRenewal.toString(), okapiHeaders);
    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 : OkapiHeaders(api.support.http.OkapiHeaders) 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) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) UUID(java.util.UUID) IndividualResource(api.support.http.IndividualResource) Test(org.junit.jupiter.api.Test)

Aggregations

NoticeConfigurationBuilder (api.support.builders.NoticeConfigurationBuilder)75 JsonObject (io.vertx.core.json.JsonObject)66 Test (org.junit.jupiter.api.Test)66 NoticePolicyBuilder (api.support.builders.NoticePolicyBuilder)64 IndividualResource (api.support.http.IndividualResource)57 ZonedDateTime (java.time.ZonedDateTime)52 UUID (java.util.UUID)41 RequestBuilder (api.support.builders.RequestBuilder)37 ItemResource (api.support.http.ItemResource)37 CheckInByBarcodeRequestBuilder (api.support.builders.CheckInByBarcodeRequestBuilder)27 ClockUtil.getZonedDateTime (org.folio.circulation.support.utils.ClockUtil.getZonedDateTime)21 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)21 LoanPolicyBuilder (api.support.builders.LoanPolicyBuilder)12 ItemBuilder (api.support.builders.ItemBuilder)11 Period (org.folio.circulation.domain.policy.Period)11 Matcher (org.hamcrest.Matcher)11 HashMap (java.util.HashMap)9 CheckOutByBarcodeRequestBuilder (api.support.builders.CheckOutByBarcodeRequestBuilder)8 MoveRequestBuilder (api.support.builders.MoveRequestBuilder)8 lombok.val (lombok.val)8