Search in sources :

Example 71 with NoticePolicyBuilder

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

the class RenewalAPITests method renewalNoticeIsSentWhenPolicyDefinesRenewalNoticeConfiguration.

@Test
void renewalNoticeIsSentWhenPolicyDefinesRenewalNoticeConfiguration() {
    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()));
    IndividualResource loanAfterRenewal = loansFixture.renewLoan(smallAngryPlanet, steve);
    verifyNumberOfSentNotices(1);
    verifyNumberOfPublishedEvents(NOTICE, 1);
    verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
    int expectedRenewalLimit = 3;
    int expectedRenewalsRemaining = 2;
    Map<String, Matcher<String>> noticeContextMatchers = new HashMap<>();
    noticeContextMatchers.putAll(TemplateContextMatchers.getUserContextMatchers(steve));
    noticeContextMatchers.putAll(TemplateContextMatchers.getItemContextMatchers(smallAngryPlanet, true));
    noticeContextMatchers.putAll(TemplateContextMatchers.getLoanContextMatchers(loanAfterRenewal));
    noticeContextMatchers.putAll(TemplateContextMatchers.getLoanPolicyContextMatchers(expectedRenewalLimit, expectedRenewalsRemaining));
    assertThat(FakeModNotify.getSentPatronNotices(), hasItems(hasEmailNoticeProperties(steve.getId(), renewalTemplateId, noticeContextMatchers)));
}
Also used : CheckOutByBarcodeRequestBuilder(api.support.builders.CheckOutByBarcodeRequestBuilder) OverdueFineMatcher(api.support.matchers.OverdueFineMatcher) Matcher(org.hamcrest.Matcher) HashMap(java.util.HashMap) JsonObject(io.vertx.core.json.JsonObject) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) IndividualResource(api.support.http.IndividualResource) ItemResource(api.support.http.ItemResource) ItemBuilder(api.support.builders.ItemBuilder) ZonedDateTime(java.time.ZonedDateTime) ClockUtil.getZonedDateTime(org.folio.circulation.support.utils.ClockUtil.getZonedDateTime) NoticePolicyBuilder(api.support.builders.NoticePolicyBuilder) NoticeConfigurationBuilder(api.support.builders.NoticeConfigurationBuilder) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 72 with NoticePolicyBuilder

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

the class RequestsAPIUpdatingTests method cancellationReasonPublicDescriptionIsUsedAsReasonForCancellationToken.

@Test
void cancellationReasonPublicDescriptionIsUsedAsReasonForCancellationToken() {
    UUID requestCancellationTemplateId = UUID.randomUUID();
    JsonObject requestCancellationConfiguration = new NoticeConfigurationBuilder().withTemplateId(requestCancellationTemplateId).withEventType(REQUEST_CANCELLATION).create();
    NoticePolicyBuilder noticePolicy = new NoticePolicyBuilder().withName("Policy with request cancellation notice").withLoanNotices(Collections.singletonList(requestCancellationConfiguration));
    useFallbackPolicies(loanPoliciesFixture.canCirculateRolling().getId(), requestPoliciesFixture.allowAllRequestPolicy().getId(), noticePoliciesFixture.create(noticePolicy).getId(), overdueFinePoliciesFixture.facultyStandard().getId(), lostItemFeePoliciesFixture.facultyStandard().getId());
    final ItemResource temeraire = itemsFixture.basedUponTemeraire();
    final IndividualResource requester = usersFixture.steve();
    ZonedDateTime requestDate = ZonedDateTime.of(2017, 7, 22, 10, 22, 54, 0, UTC);
    final IndividualResource exampleServicePoint = servicePointsFixture.cd1();
    IndividualResource createdRequest = requestsClient.create(new RequestBuilder().page().withRequestDate(requestDate).forItem(temeraire).by(requester).fulfilToHoldShelf().withPickupServicePointId(exampleServicePoint.getId()).withRequestExpiration(LocalDate.of(2017, 7, 30)).withHoldShelfExpiration(LocalDate.of(2017, 8, 31)));
    final IndividualResource itemNotAvailable = cancellationReasonsFixture.itemNotAvailable();
    JsonObject updatedRequest = RequestBuilder.from(createdRequest).cancelled().withCancellationReasonId(itemNotAvailable.getId()).withCancellationAdditionalInformation("Cancellation info").create();
    requestsClient.replace(createdRequest.getId(), updatedRequest);
    verifyNumberOfSentNotices(1);
    verifyNumberOfPublishedEvents(NOTICE, 1);
    verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
    Map<String, Matcher<String>> noticeContextMatchers = new HashMap<>();
    noticeContextMatchers.putAll(TemplateContextMatchers.getUserContextMatchers(requester));
    noticeContextMatchers.putAll(TemplateContextMatchers.getItemContextMatchers(temeraire, true));
    noticeContextMatchers.putAll(TemplateContextMatchers.getRequestContextMatchers(updatedRequest));
    noticeContextMatchers.putAll(TemplateContextMatchers.getCancelledRequestContextMatchers(updatedRequest));
    noticeContextMatchers.put("request.reasonForCancellation", is(itemNotAvailable.getJson().getString(CANCELLATION_REASON_PUBLIC_DESCRIPTION)));
    assertThat(FakeModNotify.getSentPatronNotices(), hasItems(hasEmailNoticeProperties(requester.getId(), requestCancellationTemplateId, noticeContextMatchers)));
}
Also used : RequestBuilder(api.support.builders.RequestBuilder) ZonedDateTime(java.time.ZonedDateTime) Matcher(org.hamcrest.Matcher) HashMap(java.util.HashMap) NoticePolicyBuilder(api.support.builders.NoticePolicyBuilder) NoticeConfigurationBuilder(api.support.builders.NoticeConfigurationBuilder) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) IndividualResource(api.support.http.IndividualResource) ItemResource(api.support.http.ItemResource) Test(org.junit.jupiter.api.Test)

Example 73 with NoticePolicyBuilder

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

the class CancelRequestTests method patronNoticeIsNotSentWhenPatronNoticeRequestFails.

@Test
void patronNoticeIsNotSentWhenPatronNoticeRequestFails() {
    UUID requestCancelledTemplateId = UUID.randomUUID();
    NoticePolicyBuilder noticePolicy = new NoticePolicyBuilder().withName("test policy").withLoanNotices(Collections.singletonList(new NoticeConfigurationBuilder().withTemplateId(requestCancelledTemplateId).withEventType("Request cancellation").create()));
    useFallbackPolicies(loanPoliciesFixture.canCirculateRolling().getId(), requestPoliciesFixture.allowAllRequestPolicy().getId(), noticePoliciesFixture.create(noticePolicy).getId(), overdueFinePoliciesFixture.facultyStandard().getId(), lostItemFeePoliciesFixture.facultyStandard().getId());
    UUID id = UUID.randomUUID();
    UUID pickupServicePointId = servicePointsFixture.cd1().getId();
    ItemResource item = itemsFixture.basedUponSmallAngryPlanet();
    IndividualResource requester = usersFixture.steve();
    ZonedDateTime requestDate = ZonedDateTime.of(2017, 7, 22, 10, 22, 54, 0, UTC);
    IndividualResource request = requestsFixture.place(new RequestBuilder().withId(id).open().page().forItem(item).by(requester).withRequestDate(requestDate).fulfilToHoldShelf().withRequestExpiration(LocalDate.of(2017, 7, 30)).withHoldShelfExpiration(LocalDate.of(2017, 8, 31)).withPickupServicePointId(pickupServicePointId).withTags(new RequestBuilder.Tags(asList("new", "important"))));
    verifyNumberOfSentNotices(0);
    verifyNumberOfPublishedEvents(NOTICE, 0);
    verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
    FakeModNotify.setFailPatronNoticesWithBadRequest(true);
    requestsFixture.cancelRequest(request);
    verifyNumberOfSentNotices(0);
    verifyNumberOfPublishedEvents(NOTICE, 0);
    verifyNumberOfPublishedEvents(NOTICE_ERROR, 1);
}
Also used : RequestBuilder(api.support.builders.RequestBuilder) ClockUtil.getZonedDateTime(org.folio.circulation.support.utils.ClockUtil.getZonedDateTime) ZonedDateTime(java.time.ZonedDateTime) NoticePolicyBuilder(api.support.builders.NoticePolicyBuilder) NoticeConfigurationBuilder(api.support.builders.NoticeConfigurationBuilder) UUID(java.util.UUID) IndividualResource(api.support.http.IndividualResource) ItemResource(api.support.http.ItemResource) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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