Search in sources :

Example 26 with ItemResource

use of api.support.http.ItemResource 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 27 with ItemResource

use of api.support.http.ItemResource 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 28 with ItemResource

use of api.support.http.ItemResource in project mod-circulation by folio-org.

the class EndExpiredPatronActionSessionTests method expiredSessionClosedWithSuccessWhenPatronGroupIdIsNull.

@Test
void expiredSessionClosedWithSuccessWhenPatronGroupIdIsNull() {
    IndividualResource james = usersFixture.james();
    ItemResource nod = itemsFixture.basedUponNod();
    checkOutFixture.checkOutByBarcode(nod, james);
    JsonObject user = james.getJson();
    user.put("patronGroup", null);
    usersClient.replace(james.getId(), user);
    List<JsonObject> sessions = patronSessionRecordsClient.getAll();
    assertThat(sessions, hasSize(1));
    String patronId = sessions.get(0).getString(PATRON_ID);
    createExpiredEndSession(patronId, CHECK_OUT);
    expiredSessionProcessingClient.runRequestExpiredSessionsProcessing(204);
    assertThat(patronSessionRecordsClient.getAll(), empty());
}
Also used : JsonObject(io.vertx.core.json.JsonObject) IndividualResource(api.support.http.IndividualResource) ItemResource(api.support.http.ItemResource) Test(org.junit.jupiter.api.Test)

Example 29 with ItemResource

use of api.support.http.ItemResource in project mod-circulation by folio-org.

the class EndExpiredPatronActionSessionTests method expiredSessionWithNonExistentLoanShouldBeEnded.

@Test
void expiredSessionWithNonExistentLoanShouldBeEnded() {
    IndividualResource james = usersFixture.james();
    ItemResource nod = itemsFixture.basedUponNod();
    checkOutFixture.checkOutByBarcode(nod, james);
    expiredEndSessionClient.deleteAll();
    List<JsonObject> sessions = patronSessionRecordsClient.getAll();
    assertThat(sessions, hasSize(1));
    String loanId = sessions.get(0).getString(LOAN_ID);
    String patronId = sessions.get(0).getString(PATRON_ID);
    loansFixture.deleteLoan(UUID.fromString(loanId));
    createExpiredEndSession(patronId, CHECK_OUT);
    expiredSessionProcessingClient.runRequestExpiredSessionsProcessing(204);
    waitAtLeast(1, SECONDS).until(patronSessionRecordsClient::getAll, empty());
    verifyNumberOfSentNotices(0);
    verifyNumberOfPublishedEvents(NOTICE, 0);
    verifyNumberOfPublishedEvents(NOTICE_ERROR, 1);
}
Also used : JsonObject(io.vertx.core.json.JsonObject) IndividualResource(api.support.http.IndividualResource) ItemResource(api.support.http.ItemResource) Test(org.junit.jupiter.api.Test)

Example 30 with ItemResource

use of api.support.http.ItemResource in project mod-circulation by folio-org.

the class RequestsAPICreationTests method setupPagedItem.

public static ItemResource setupPagedItem(IndividualResource requestPickupServicePoint, ItemsFixture itemsFixture, ResourceClient requestClient, UsersFixture usersFixture) {
    final ItemResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
    final IndividualResource pagedRequest = requestClient.create(new RequestBuilder().page().forItem(smallAngryPlanet).withPickupServicePointId(requestPickupServicePoint.getId()).by(usersFixture.james()));
    JsonObject requestedItem = pagedRequest.getJson().getJsonObject("item");
    assertThat(requestedItem.getString("status"), is(ItemStatus.PAGED.getValue()));
    return smallAngryPlanet;
}
Also used : MoveRequestBuilder(api.support.builders.MoveRequestBuilder) RequestBuilder(api.support.builders.RequestBuilder) JsonObject(io.vertx.core.json.JsonObject) IndividualResource(api.support.http.IndividualResource) ItemResource(api.support.http.ItemResource)

Aggregations

ItemResource (api.support.http.ItemResource)232 Test (org.junit.jupiter.api.Test)218 IndividualResource (api.support.http.IndividualResource)189 JsonObject (io.vertx.core.json.JsonObject)138 UUID (java.util.UUID)127 RequestBuilder (api.support.builders.RequestBuilder)117 Response (org.folio.circulation.support.http.client.Response)89 ZonedDateTime (java.time.ZonedDateTime)81 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)61 NoticePolicyBuilder (api.support.builders.NoticePolicyBuilder)40 ClockUtil.getZonedDateTime (org.folio.circulation.support.utils.ClockUtil.getZonedDateTime)39 NoticeConfigurationBuilder (api.support.builders.NoticeConfigurationBuilder)38 MoveRequestBuilder (api.support.builders.MoveRequestBuilder)36 CheckInByBarcodeRequestBuilder (api.support.builders.CheckInByBarcodeRequestBuilder)32 LoanPolicyBuilder (api.support.builders.LoanPolicyBuilder)27 ItemBuilder (api.support.builders.ItemBuilder)21 CheckOutByBarcodeRequestBuilder (api.support.builders.CheckOutByBarcodeRequestBuilder)13 UserResource (api.support.http.UserResource)13 HashMap (java.util.HashMap)13 Matcher (org.hamcrest.Matcher)13