Search in sources :

Example 1 with NoticePolicyBuilder

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));
}
Also used : RequestBuilder(api.support.builders.RequestBuilder) CheckInByBarcodeRequestBuilder(api.support.builders.CheckInByBarcodeRequestBuilder) NoticePolicyBuilder(api.support.builders.NoticePolicyBuilder) NoticeConfigurationBuilder(api.support.builders.NoticeConfigurationBuilder) JsonObject(io.vertx.core.json.JsonObject) IndividualResource(api.support.http.IndividualResource) Test(org.junit.jupiter.api.Test)

Example 2 with NoticePolicyBuilder

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));
}
Also used : RequestBuilder(api.support.builders.RequestBuilder) CheckInByBarcodeRequestBuilder(api.support.builders.CheckInByBarcodeRequestBuilder) NoticePolicyBuilder(api.support.builders.NoticePolicyBuilder) NoticeConfigurationBuilder(api.support.builders.NoticeConfigurationBuilder) JsonObject(io.vertx.core.json.JsonObject) CheckInByBarcodeRequestBuilder(api.support.builders.CheckInByBarcodeRequestBuilder) IndividualResource(api.support.http.IndividualResource) Test(org.junit.jupiter.api.Test)

Example 3 with NoticePolicyBuilder

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));
}
Also used : RequestBuilder(api.support.builders.RequestBuilder) CheckInByBarcodeRequestBuilder(api.support.builders.CheckInByBarcodeRequestBuilder) NoticePolicyBuilder(api.support.builders.NoticePolicyBuilder) NoticeConfigurationBuilder(api.support.builders.NoticeConfigurationBuilder) JsonObject(io.vertx.core.json.JsonObject) IndividualResource(api.support.http.IndividualResource) Test(org.junit.jupiter.api.Test)

Example 4 with NoticePolicyBuilder

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());
}
Also used : NoticePolicyBuilder(api.support.builders.NoticePolicyBuilder) NoticeConfigurationBuilder(api.support.builders.NoticeConfigurationBuilder) JsonObject(io.vertx.core.json.JsonObject) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with NoticePolicyBuilder

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);
}
Also used : ItemBuilder(api.support.builders.ItemBuilder) CheckOutByBarcodeRequestBuilder(api.support.builders.CheckOutByBarcodeRequestBuilder) ZonedDateTime(java.time.ZonedDateTime) ClockUtil.getZonedDateTime(org.folio.circulation.support.utils.ClockUtil.getZonedDateTime) NoticePolicyBuilder(api.support.builders.NoticePolicyBuilder) NoticeConfigurationBuilder(api.support.builders.NoticeConfigurationBuilder) JsonObject(io.vertx.core.json.JsonObject) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) UUID(java.util.UUID) 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