use of api.support.builders.NoticePolicyBuilder in project mod-circulation by folio-org.
the class RequestScheduledNoticesTests method requestExpirationBeforeNoticeShouldBeScheduledWhenCreatedRequestIsSetToExpire.
@Test
void requestExpirationBeforeNoticeShouldBeScheduledWhenCreatedRequestIsSetToExpire() {
JsonObject requestNotice = new NoticeConfigurationBuilder().withTemplateId(templateId).withRequestExpirationEvent().withBeforeTiming(Period.days(3)).sendInRealTime(true).create();
NoticePolicyBuilder noticePolicyBuilder = new NoticePolicyBuilder().withName("request policy").withRequestNotices(Collections.singletonList(requestNotice));
useDefaultRollingPoliciesAndOnlyAllowPageRequests(noticePolicyBuilder);
final var requestExpiration = ClockUtil.getZonedDateTime().toLocalDate().plusMonths(3);
IndividualResource request = requestsFixture.place(new RequestBuilder().page().forItem(item).withRequesterId(requester.getId()).withRequestDate(ClockUtil.getZonedDateTime()).withStatus(OPEN_NOT_YET_FILLED).withPickupServicePoint(pickupServicePoint).withRequestExpiration(requestExpiration));
Awaitility.await().atMost(1, TimeUnit.SECONDS).until(scheduledNoticesClient::getAll, hasSize(1));
List<JsonObject> scheduledNotices = scheduledNoticesClient.getAll();
assertThat(scheduledNotices.size(), is(1));
JsonObject scheduledNotice = scheduledNotices.get(0);
JsonObject noticeConfig = scheduledNotice.getJsonObject("noticeConfig");
assertThat(scheduledNotice.getString("requestId"), is(request.getId().toString()));
assertThat(scheduledNotice.getString("triggeringEvent"), is("Request expiration"));
assertThat(scheduledNotice.getString("nextRunTime"), isEquivalentTo(atEndOfDay(requestExpiration, UTC).minusDays(3)));
assertThat(noticeConfig.getString("timing"), is("Before"));
assertThat(noticeConfig.getString("templateId"), is(templateId.toString()));
assertThat(noticeConfig.getString("format"), is("Email"));
assertThat(noticeConfig.getBoolean("sendInRealTime"), is(true));
}
use of api.support.builders.NoticePolicyBuilder in project mod-circulation by folio-org.
the class RequestScheduledNoticesTests method holdShelfExpirationNoticeShouldBeScheduledOnCheckIn.
@Test
void holdShelfExpirationNoticeShouldBeScheduledOnCheckIn() {
JsonObject requestNotice = new NoticeConfigurationBuilder().withTemplateId(templateId).withHoldShelfExpirationEvent().withUponAtTiming().sendInRealTime(true).create();
NoticePolicyBuilder noticePolicyBuilder = new NoticePolicyBuilder().withName("request policy").withRequestNotices(Collections.singletonList(requestNotice));
useDefaultRollingPoliciesAndOnlyAllowPageRequests(noticePolicyBuilder);
final var requestExpiration = ClockUtil.getZonedDateTime().toLocalDate().plusMonths(3);
RequestBuilder requestBuilder = new RequestBuilder().page().forItem(item).withRequesterId(requester.getId()).withRequestDate(ClockUtil.getZonedDateTime()).withStatus(OPEN_NOT_YET_FILLED).withPickupServicePoint(pickupServicePoint).withRequestExpiration(requestExpiration);
IndividualResource request = requestsFixture.place(requestBuilder);
CheckInByBarcodeRequestBuilder checkInByBarcodeRequestBuilder = new CheckInByBarcodeRequestBuilder().forItem(item).withItemBarcode(item.getBarcode()).at(pickupServicePoint);
checkInFixture.checkInByBarcode(checkInByBarcodeRequestBuilder);
String holdShelfExpirationDate = requestsClient.get(request).getJson().getString(HOLD_SHELF_EXPIRATION_DATE);
Awaitility.await().atMost(1, TimeUnit.SECONDS).until(scheduledNoticesClient::getAll, hasSize(1));
List<JsonObject> scheduledNotices = scheduledNoticesClient.getAll();
assertThat(scheduledNotices.size(), is(1));
JsonObject scheduledNotice = scheduledNotices.get(0);
JsonObject noticeConfig = scheduledNotice.getJsonObject("noticeConfig");
assertThat(scheduledNotice.getString("requestId"), is(request.getId().toString()));
assertThat(scheduledNotice.getString("triggeringEvent"), is("Hold expiration"));
assertThat(scheduledNotice.getString("nextRunTime"), is(holdShelfExpirationDate));
assertThat(noticeConfig.getString("timing"), is("Upon At"));
assertThat(noticeConfig.getString("templateId"), is(templateId.toString()));
assertThat(noticeConfig.getString("format"), is("Email"));
assertThat(noticeConfig.getBoolean("sendInRealTime"), is(true));
}
use of api.support.builders.NoticePolicyBuilder in project mod-circulation by folio-org.
the class RequestScheduledNoticesTests method requestExpirationUponAtNoticeShouldBeRescheduledWhenUpdatedRequestIsSetToExpire.
@Test
void requestExpirationUponAtNoticeShouldBeRescheduledWhenUpdatedRequestIsSetToExpire() {
JsonObject requestNotice = new NoticeConfigurationBuilder().withTemplateId(templateId).withRequestExpirationEvent().withUponAtTiming().sendInRealTime(true).create();
NoticePolicyBuilder noticePolicyBuilder = new NoticePolicyBuilder().withName("request policy").withRequestNotices(Collections.singletonList(requestNotice));
useDefaultRollingPoliciesAndOnlyAllowPageRequests(noticePolicyBuilder);
final var requestExpiration = ClockUtil.getZonedDateTime().toLocalDate().plusMonths(3);
RequestBuilder requestBuilder = new RequestBuilder().page().forItem(item).withRequesterId(requester.getId()).withRequestDate(ClockUtil.getZonedDateTime()).withStatus(OPEN_NOT_YET_FILLED).withPickupServicePoint(pickupServicePoint).withRequestExpiration(requestExpiration);
IndividualResource request = requestsFixture.place(requestBuilder);
Awaitility.await().atMost(1, TimeUnit.SECONDS).until(scheduledNoticesClient::getAll, hasSize(1));
List<JsonObject> scheduledNotices = scheduledNoticesClient.getAll();
assertThat(scheduledNotices.size(), is(1));
JsonObject scheduledNotice = scheduledNotices.get(0);
JsonObject noticeConfig = scheduledNotice.getJsonObject("noticeConfig");
assertThat(scheduledNotice.getString("requestId"), is(request.getId().toString()));
assertThat(scheduledNotice.getString("triggeringEvent"), is("Request expiration"));
assertThat(scheduledNotice.getString("nextRunTime"), isEquivalentTo(atEndOfDay(requestExpiration, UTC)));
assertThat(noticeConfig.getString("timing"), is("Upon At"));
assertThat(noticeConfig.getString("templateId"), is(templateId.toString()));
assertThat(noticeConfig.getString("format"), is("Email"));
assertThat(noticeConfig.getBoolean("sendInRealTime"), is(true));
requestsClient.replace(request.getId(), requestBuilder.withRequestExpiration(requestExpiration.plusDays(1)));
Awaitility.await().atMost(1, TimeUnit.SECONDS).until(scheduledNoticesClient::getAll, hasSize(1));
scheduledNotices = scheduledNoticesClient.getAll();
assertThat(scheduledNotices.size(), is(1));
scheduledNotice = scheduledNotices.get(0);
noticeConfig = scheduledNotice.getJsonObject("noticeConfig");
assertThat(scheduledNotice.getString("requestId"), is(request.getId().toString()));
assertThat(scheduledNotice.getString("triggeringEvent"), is("Request expiration"));
assertThat(scheduledNotice.getString("nextRunTime"), isEquivalentTo(atEndOfDay(requestExpiration, UTC).plusDays(1)));
assertThat(noticeConfig.getString("timing"), is("Upon At"));
assertThat(noticeConfig.getString("templateId"), is(templateId.toString()));
assertThat(noticeConfig.getString("format"), is("Email"));
assertThat(noticeConfig.getBoolean("sendInRealTime"), is(true));
}
use of api.support.builders.NoticePolicyBuilder in project mod-circulation by folio-org.
the class PatronActionSessionTests method beforeEach.
@BeforeEach
public void beforeEach() {
JsonObject checkOutNoticeConfig = new NoticeConfigurationBuilder().withTemplateId(CHECK_OUT_NOTICE_TEMPLATE_ID).withCheckOutEvent().create();
JsonObject checkInNoticeConfig = new NoticeConfigurationBuilder().withTemplateId(CHECK_IN_NOTICE_TEMPLATE_ID).withCheckInEvent().create();
NoticePolicyBuilder noticePolicy = new NoticePolicyBuilder().withName("Policy with check-out notice").withLoanNotices(Arrays.asList(checkOutNoticeConfig, checkInNoticeConfig));
useFallbackPolicies(loanPoliciesFixture.canCirculateRolling().getId(), requestPoliciesFixture.allowAllRequestPolicy().getId(), noticePoliciesFixture.create(noticePolicy).getId(), overdueFinePoliciesFixture.facultyStandard().getId(), lostItemFeePoliciesFixture.facultyStandard().getId());
}
use of api.support.builders.NoticePolicyBuilder in project mod-circulation by folio-org.
the class RenewalAPITests method renewalNoticeIsNotSentWhenPatronNoticeRequestFails.
@Test
void renewalNoticeIsNotSentWhenPatronNoticeRequestFails() {
UUID renewalTemplateId = UUID.randomUUID();
JsonObject renewalNoticeConfiguration = new NoticeConfigurationBuilder().withTemplateId(renewalTemplateId).withRenewalEvent().create();
JsonObject checkInNoticeConfiguration = new NoticeConfigurationBuilder().withTemplateId(UUID.randomUUID()).withCheckInEvent().create();
NoticePolicyBuilder policyWithRenewalNotice = new NoticePolicyBuilder().withName("Policy with renewal notice").withLoanNotices(Arrays.asList(renewalNoticeConfiguration, checkInNoticeConfiguration));
LoanPolicyBuilder limitedRenewalsLoanPolicy = new LoanPolicyBuilder().withName("Limited renewals loan policy").rolling(Period.months(1)).limitedRenewals(3);
use(limitedRenewalsLoanPolicy, policyWithRenewalNotice);
ItemBuilder itemBuilder = ItemExamples.basedUponSmallAngryPlanet(materialTypesFixture.book().getId(), loanTypesFixture.canCirculate().getId(), StringUtils.EMPTY, "ItemPrefix", "ItemSuffix", "");
ItemResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet(itemBuilder, itemsFixture.thirdFloorHoldings());
final IndividualResource steve = usersFixture.steve();
final ZonedDateTime loanDate = ZonedDateTime.of(2018, 3, 18, 11, 43, 54, 0, UTC);
checkOutFixture.checkOutByBarcode(new CheckOutByBarcodeRequestBuilder().forItem(smallAngryPlanet).to(steve).on(loanDate).at(UUID.randomUUID()));
FakeModNotify.setFailPatronNoticesWithBadRequest(true);
loansFixture.renewLoan(smallAngryPlanet, steve);
verifyNumberOfSentNotices(0);
verifyNumberOfPublishedEvents(NOTICE, 0);
verifyNumberOfPublishedEvents(NOTICE_ERROR, 1);
}
Aggregations