Search in sources :

Example 1 with FakePubSub

use of api.support.fakes.FakePubSub in project mod-circulation by folio-org.

the class CheckOutByBarcodeTests method itemCheckedOutEventIsPublishedWithGracePeriodDefinedInLoanPolicy.

private void itemCheckedOutEventIsPublishedWithGracePeriodDefinedInLoanPolicy(IndividualResource loanPolicy) {
    use(defaultRollingPolicies().loanPolicy(loanPolicy));
    IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
    final IndividualResource steve = usersFixture.steve();
    final IndividualResource response = checkOutFixture.checkOutByBarcode(new CheckOutByBarcodeRequestBuilder().forItem(smallAngryPlanet).to(steve).on(getZonedDateTime()).at(UUID.randomUUID()));
    final JsonObject loan = response.getJson();
    final var publishedEvents = Awaitility.await().atMost(1, TimeUnit.SECONDS).until(FakePubSub::getPublishedEvents, hasSize(2));
    final var checkedOutEvent = publishedEvents.findFirst(byEventType(ITEM_CHECKED_OUT));
    assertThat(checkedOutEvent, isValidItemCheckedOutEvent(loan, loanPolicy));
    final var checkOutLogEvent = publishedEvents.findFirst(byLogEventType(CHECK_OUT));
    assertThat(checkOutLogEvent, isValidCheckOutLogEvent(loan, LogEventType.CHECK_OUT));
    assertThatPublishedLoanLogRecordEventsAreValid(loan);
}
Also used : FakePubSub(api.support.fakes.FakePubSub) CheckOutByBarcodeRequestBuilder(api.support.builders.CheckOutByBarcodeRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) IndividualResource(api.support.http.IndividualResource)

Example 2 with FakePubSub

use of api.support.fakes.FakePubSub in project mod-circulation by folio-org.

the class CheckOutByBarcodeTests method canOverrideCheckOutWhenItemNotLoanableBlockIsPresent.

@Test
void canOverrideCheckOutWhenItemNotLoanableBlockIsPresent() {
    final OkapiHeaders okapiHeaders = buildOkapiHeadersWithPermissions(OVERRIDE_ITEM_NOT_LOANABLE_BLOCK_PERMISSION);
    setNotLoanablePolicy();
    IndividualResource item = itemsFixture.basedUponSmallAngryPlanet();
    Response responseBlocked = checkOutFixture.attemptCheckOutByBarcode(new CheckOutByBarcodeRequestBuilder().forItem(item).to(usersFixture.steve()).at(UUID.randomUUID()).on(TEST_LOAN_DATE).withOverrideBlocks(new CheckOutBlockOverrides().withComment(TEST_COMMENT).create()), okapiHeaders);
    assertThat(responseBlocked.getJson(), hasErrorWith(allOf(hasMessage("Item is not loanable"), hasParameter("loanPolicyName", "Not Loanable Policy"))));
    JsonObject loan = checkOutFixture.checkOutByBarcode(new CheckOutByBarcodeRequestBuilder().forItem(item).to(usersFixture.steve()).at(UUID.randomUUID()).on(TEST_LOAN_DATE).withOverrideBlocks(new CheckOutBlockOverrides().withItemNotLoanableBlockOverride(new ItemNotLoanableBlockOverrideBuilder().withDueDate(TEST_DUE_DATE).create()).withComment(TEST_COMMENT).create()), okapiHeaders).getJson();
    item = itemsClient.get(item);
    assertThat(item, hasItemStatus(CHECKED_OUT));
    assertThat(loan.getString("actionComment"), is(TEST_COMMENT));
    assertThat(loan.getString("action"), is(CHECKED_OUT_THROUGH_OVERRIDE));
    final var publishedEvents = Awaitility.await().atMost(1, TimeUnit.SECONDS).until(FakePubSub::getPublishedEvents, hasSize(2));
    final var checkOutLogEvent = publishedEvents.findFirst(byLogEventType(LogEventType.CHECK_OUT_THROUGH_OVERRIDE.value()));
    assertThat(checkOutLogEvent, isValidCheckOutLogEvent(loan, CHECK_OUT_THROUGH_OVERRIDE));
}
Also used : OkapiHeaders(api.support.http.OkapiHeaders) Response(org.folio.circulation.support.http.client.Response) FakePubSub(api.support.fakes.FakePubSub) CheckOutByBarcodeRequestBuilder(api.support.builders.CheckOutByBarcodeRequestBuilder) CheckOutBlockOverrides(api.support.builders.CheckOutBlockOverrides) JsonObject(io.vertx.core.json.JsonObject) ItemNotLoanableBlockOverrideBuilder(api.support.builders.ItemNotLoanableBlockOverrideBuilder) IndividualResource(api.support.http.IndividualResource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 3 with FakePubSub

use of api.support.fakes.FakePubSub in project mod-circulation by folio-org.

the class ClaimItemReturnedAPITests method itemClaimedReturnedEventIsPublished.

@Test
void itemClaimedReturnedEventIsPublished() {
    final ZonedDateTime dateTime = ClockUtil.getZonedDateTime();
    final Response response = claimItemReturnedFixture.claimItemReturned(new ClaimItemReturnedRequestBuilder().forLoan(loanId).withItemClaimedReturnedDate(dateTime));
    assertLoanAndItem(response, null, dateTime);
    // Five events are expected: one for check-out one for log event, one for the claim
    // and one for log records
    final var publishedEvents = Awaitility.await().atMost(1, TimeUnit.SECONDS).until(FakePubSub::getPublishedEvents, hasSize(4));
    final var event = publishedEvents.findFirst(byEventType(ITEM_CLAIMED_RETURNED));
    assertThat(event, isValidItemClaimedReturnedEvent(loan.getJson()));
    assertThatPublishedLoanLogRecordEventsAreValid(loansClient.getById(loan.getId()).getJson());
}
Also used : Response(org.folio.circulation.support.http.client.Response) FakePubSub(api.support.fakes.FakePubSub) ClockUtil.getZonedDateTime(org.folio.circulation.support.utils.ClockUtil.getZonedDateTime) ZonedDateTime(java.time.ZonedDateTime) ClaimItemReturnedRequestBuilder(api.support.builders.ClaimItemReturnedRequestBuilder) Test(org.junit.jupiter.api.Test)

Example 4 with FakePubSub

use of api.support.fakes.FakePubSub in project mod-circulation by folio-org.

the class RequestsAPICreationTests method canCreateTlrRecallForInstanceWithSingleItemAndTwoLoans.

@Test
void canCreateTlrRecallForInstanceWithSingleItemAndTwoLoans() {
    reconfigureTlrFeature(TlrFeatureStatus.ENABLED);
    final ItemResource item = itemsFixture.basedUponSmallAngryPlanet();
    final IndividualResource requestPickupServicePoint = servicePointsFixture.cd1();
    IndividualResource initialLoan = checkOutFixture.checkOutByBarcode(item, usersFixture.jessica());
    checkInFixture.checkInByBarcode(item);
    IndividualResource dueDateChangeLoan = checkOutFixture.checkOutByBarcode(item, usersFixture.jessica());
    requestsClient.create(new RequestBuilder().recall().withNoHoldingsRecordId().withNoItemId().titleRequestLevel().withInstanceId(item.getInstanceId()).withPickupServicePointId(requestPickupServicePoint.getId()).withRequesterId(usersFixture.james().getId()));
    PublishedEvents publishedEvents = Awaitility.await().atMost(1, TimeUnit.SECONDS).until(FakePubSub::getPublishedEvents, hasSize(9));
    JsonObject loanWithoutChange = loansClient.get(initialLoan.getId()).getJson();
    assertNull(loanWithoutChange.getString("dueDateChangedByRecall"));
    JsonObject updatedLoan = loansClient.get(dueDateChangeLoan.getId()).getJson();
    assertThat(updatedLoan.getString("dueDateChangedByRecall"), true);
    JsonObject event = publishedEvents.findFirst(byEventType("LOAN_DUE_DATE_CHANGED"));
    assertThat(event, isValidLoanDueDateChangedEvent(updatedLoan));
    assertThat(new JsonObject(event.getString("eventPayload")).getBoolean("dueDateChangedByRecall"), equalTo(true));
}
Also used : FakePubSub(api.support.fakes.FakePubSub) MoveRequestBuilder(api.support.builders.MoveRequestBuilder) RequestBuilder(api.support.builders.RequestBuilder) PublishedEvents(api.support.fakes.PublishedEvents) PatronNoticeTestHelper.verifyNumberOfPublishedEvents(api.support.utl.PatronNoticeTestHelper.verifyNumberOfPublishedEvents) JsonObject(io.vertx.core.json.JsonObject) IndividualResource(api.support.http.IndividualResource) ItemResource(api.support.http.ItemResource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 5 with FakePubSub

use of api.support.fakes.FakePubSub in project mod-circulation by folio-org.

the class RenewalAPITests method dueDateChangedEventIsPublished.

@Test
void dueDateChangedEventIsPublished() {
    IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
    final IndividualResource jessica = usersFixture.jessica();
    checkOutFixture.checkOutByBarcode(smallAngryPlanet, jessica, ZonedDateTime.of(2018, 4, 21, 11, 21, 43, 0, UTC));
    final JsonObject renewedLoan = renew(smallAngryPlanet, jessica).getJson();
    // There should be five events published - first for "check out",
    // second one for log event, third for "change due date",
    // fourth one for "log record", and fifth one for "renewed".
    final var publishedEvents = Awaitility.await().atMost(1, TimeUnit.SECONDS).until(FakePubSub::getPublishedEvents, hasSize(5));
    final var event = publishedEvents.findFirst(byEventType(LOAN_DUE_DATE_CHANGED));
    assertThat(event, isValidLoanDueDateChangedEvent(renewedLoan));
    assertThatPublishedLoanLogRecordEventsAreValid(renewedLoan);
    final var renewedEvent = publishedEvents.findFirst(byLogAction(ITEM_RENEWED));
    assertThat(renewedEvent, isValidRenewedEvent(renewedLoan));
}
Also used : FakePubSub(api.support.fakes.FakePubSub) JsonObject(io.vertx.core.json.JsonObject) IndividualResource(api.support.http.IndividualResource) Test(org.junit.jupiter.api.Test)

Aggregations

FakePubSub (api.support.fakes.FakePubSub)18 Test (org.junit.jupiter.api.Test)17 IndividualResource (api.support.http.IndividualResource)13 JsonObject (io.vertx.core.json.JsonObject)12 Response (org.folio.circulation.support.http.client.Response)10 ZonedDateTime (java.time.ZonedDateTime)7 ItemResource (api.support.http.ItemResource)6 UUID (java.util.UUID)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 RequestBuilder (api.support.builders.RequestBuilder)4 CheckOutByBarcodeRequestBuilder (api.support.builders.CheckOutByBarcodeRequestBuilder)3 APITests (api.support.APITests)2 CheckInByBarcodeResponse (api.support.CheckInByBarcodeResponse)2 LoanPolicyBuilder (api.support.builders.LoanPolicyBuilder)2 MoveRequestBuilder (api.support.builders.MoveRequestBuilder)2 ValidationErrorMatchers.hasErrorWith (api.support.matchers.ValidationErrorMatchers.hasErrorWith)2 ValidationErrorMatchers.hasMessage (api.support.matchers.ValidationErrorMatchers.hasMessage)2 List (java.util.List)2 TimeUnit (java.util.concurrent.TimeUnit)2 lombok.val (lombok.val)2