use of api.support.fakes.FakePubSub in project mod-circulation by folio-org.
the class DeclareLostAPITests method declaredLostEventIsPublished.
@Test
void declaredLostEventIsPublished() {
UUID servicePointId = servicePointsFixture.cd1().getId();
final IndividualResource loanIndividualResource = checkOutFixture.checkOutByBarcode(itemsFixture.basedUponNod(), usersFixture.jessica());
final DeclareItemLostRequestBuilder builder = new DeclareItemLostRequestBuilder().forLoanId(loanIndividualResource.getId()).on(getZonedDateTime()).withServicePointId(servicePointId).withNoComment();
declareLostFixtures.declareItemLost(builder);
// There should be five events published - "check out", "log event", "declared lost"
// and one "log record"
final var publishedEvents = Awaitility.await().atMost(1, SECONDS).until(FakePubSub::getPublishedEvents, hasSize(4));
final var event = publishedEvents.findFirst(byEventType(EventTypeMatchers.ITEM_DECLARED_LOST));
final var loan = loanIndividualResource.getJson();
assertThat(event, isValidItemDeclaredLostEvent(loan));
verifyNumberOfPublishedEvents(LOAN_CLOSED, 0);
assertThatPublishedLoanLogRecordEventsAreValid(loansClient.getById(UUID.fromString(loan.getString("id"))).getJson());
}
use of api.support.fakes.FakePubSub in project mod-circulation by folio-org.
the class LoanAPITests method dueDateChangedEventIsPublishedOnCreate.
@Test
void dueDateChangedEventIsPublishedOnCreate() {
UUID id = UUID.randomUUID();
IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet(item -> item.withEnumeration("v.70:no.1-6").withChronology("1987:Jan.-June").withVolume("testVolume"));
UUID itemId = smallAngryPlanet.getId();
IndividualResource user = usersFixture.charlotte();
UUID userId = user.getId();
ZonedDateTime loanDate = ZonedDateTime.of(2017, 2, 27, 10, 23, 43, 0, UTC);
ZonedDateTime dueDate = ZonedDateTime.of(2017, 3, 29, 10, 23, 43, 0, UTC);
IndividualResource response = loansFixture.createLoan(new LoanBuilder().withId(id).open().withUserId(userId).withItemId(itemId).withLoanDate(loanDate).withDueDate(dueDate));
JsonObject loan = response.getJson();
final var publishedEvents = Awaitility.await().atMost(1, TimeUnit.SECONDS).until(FakePubSub::getPublishedEvents, hasSize(2));
final var event = publishedEvents.findFirst(byEventType("LOAN_DUE_DATE_CHANGED"));
assertThat(event, isValidLoanDueDateChangedEvent(loan));
}
use of api.support.fakes.FakePubSub in project mod-circulation by folio-org.
the class RequestQueueResourceTest method logRecordEventIsPublished.
@ParameterizedTest
@EnumSource(TlrFeatureStatus.class)
void logRecordEventIsPublished(TlrFeatureStatus tlrFeatureStatus) {
reconfigureTlrFeature(tlrFeatureStatus);
checkOutFixture.checkOutByBarcode(item, rebecca);
IndividualResource firstHoldRequest = holdRequestForDefaultItem(steve);
IndividualResource secondHoldRequest = holdRequestForDefaultItem(james);
IndividualResource firstRecallRequest = recallRequestForDefaultItem(charlotte);
IndividualResource secondRecallRequest = recallRequestForDefaultItem(jessica);
JsonObject reorderQueue = new ReorderQueueBuilder().addReorderRequest(firstHoldRequest.getId().toString(), 1).addReorderRequest(secondHoldRequest.getId().toString(), 4).addReorderRequest(firstRecallRequest.getId().toString(), 2).addReorderRequest(secondRecallRequest.getId().toString(), 3).create();
JsonObject response;
if (tlrFeatureStatus == TlrFeatureStatus.ENABLED) {
response = requestQueueFixture.reorderQueueForInstance(item.getInstanceId().toString(), reorderQueue);
} else {
response = requestQueueFixture.reorderQueueForItem(item.getId().toString(), reorderQueue);
}
verifyQueueUpdatedForItem(reorderQueue, response);
// TODO: understand why
int numberOfPublishedEvents = 17;
final var publishedEvents = Awaitility.await().atMost(1, TimeUnit.SECONDS).until(FakePubSub::getPublishedEvents, hasSize(numberOfPublishedEvents));
final var reorderedLogEvents = publishedEvents.filterToList(byLogEventType(REQUEST_REORDERED.value()));
assertThat(reorderedLogEvents, hasSize(1));
List<JsonObject> reorderedRequests = new JsonObject(JsonObject.mapFrom(reorderedLogEvents.get(0)).getString("eventPayload")).getJsonObject("payload").getJsonObject("requests").getJsonArray("reordered").stream().map(o -> (JsonObject) o).collect(toList());
assertThat(reorderedRequests, hasSize(3));
reorderedRequests.forEach(r -> {
assertNotNull(r.getInteger("position"));
assertNotNull(r.getInteger("previousPosition"));
assertNotEquals(r.getInteger("position"), r.getInteger("previousPosition"));
});
}
use of api.support.fakes.FakePubSub in project mod-circulation by folio-org.
the class ChangeDueDateAPITests method dueDateChangedEventIsPublished.
@Test
void dueDateChangedEventIsPublished() {
final ZonedDateTime newDueDate = dueDate.plusDays(14);
changeDueDateFixture.changeDueDate(new ChangeDueDateRequestBuilder().forLoan(loan.getId()).withDueDate(newDueDate));
Response response = loansClient.getById(loan.getId());
JsonObject updatedLoan = response.getJson();
// There should be three five published - first one for "check out",
// second one for "log event", third one for "change due date"
// and one "log record"
final var publishedEvents = Awaitility.await().atMost(1, SECONDS).until(FakePubSub::getPublishedEvents, hasSize(4));
final var event = publishedEvents.findFirst(byEventType(LOAN_DUE_DATE_CHANGED));
assertThat(event, isValidLoanDueDateChangedEvent(updatedLoan));
assertThatPublishedLoanLogRecordEventsAreValid(updatedLoan);
}
use of api.support.fakes.FakePubSub in project mod-circulation by folio-org.
the class CheckInByBarcodeTests method itemCheckedInEventIsPublished.
@Test
void itemCheckedInEventIsPublished() {
final IndividualResource james = usersFixture.james();
final UUID checkInServicePointId = servicePointsFixture.cd1().getId();
final IndividualResource homeLocation = locationsFixture.basedUponExampleLocation(item -> item.withPrimaryServicePoint(checkInServicePointId));
final IndividualResource nod = itemsFixture.basedUponNod(item -> item.withPermanentLocation(homeLocation.getId()));
ZonedDateTime checkOutDate = ZonedDateTime.of(2020, 1, 18, 18, 0, 0, 0, UTC);
ZonedDateTime checkInDate = ZonedDateTime.of(2020, 1, 22, 15, 30, 0, 0, UTC);
checkOutFixture.checkOutByBarcode(nod, james, checkOutDate);
CheckInByBarcodeResponse checkInResponse = checkInFixture.checkInByBarcode(new CheckInByBarcodeRequestBuilder().forItem(nod).on(checkInDate).at(checkInServicePointId));
JsonObject checkedInLoan = checkInResponse.getLoan();
// There should be four events published - first ones for "check out" and check out log event, second ones for "check in" and check in log event
final var publishedEvents = waitAtMost(2, SECONDS).until(FakePubSub::getPublishedEvents, hasSize(4));
final var checkedInEvent = publishedEvents.findFirst(byEventType(ITEM_CHECKED_IN.name()));
assertThat(checkedInEvent, isValidItemCheckedInEvent(checkedInLoan));
final var checkInLogEvent = publishedEvents.findFirst(byLogEventType(CHECK_IN.value()));
assertThat(checkInLogEvent, isValidCheckInLogEvent(checkedInLoan));
assertThatPublishedLoanLogRecordEventsAreValid(checkedInLoan);
}
Aggregations