Search in sources :

Example 6 with FakePubSub

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());
}
Also used : FakePubSub(api.support.fakes.FakePubSub) UUID(java.util.UUID) IndividualResource(api.support.http.IndividualResource) DeclareItemLostRequestBuilder(api.support.builders.DeclareItemLostRequestBuilder) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with FakePubSub

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));
}
Also used : FakePubSub(api.support.fakes.FakePubSub) LoanBuilder(api.support.builders.LoanBuilder) ZonedDateTime(java.time.ZonedDateTime) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) IndividualResource(api.support.http.IndividualResource) Test(org.junit.jupiter.api.Test)

Example 8 with FakePubSub

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"));
    });
}
Also used : FakePubSub(api.support.fakes.FakePubSub) CoreMatchers.is(org.hamcrest.CoreMatchers.is) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) BeforeEach(org.junit.jupiter.api.BeforeEach) CsvSource(org.junit.jupiter.params.provider.CsvSource) Response(org.folio.circulation.support.http.client.Response) CheckOutResource(api.support.http.CheckOutResource) ValidationErrorMatchers.hasMessage(api.support.matchers.ValidationErrorMatchers.hasMessage) ZonedDateTime(java.time.ZonedDateTime) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) APITests(api.support.APITests) EnumSource(org.junit.jupiter.params.provider.EnumSource) RequestBuilder(api.support.builders.RequestBuilder) FakePubSub(api.support.fakes.FakePubSub) UUIDMatcher.is(api.support.matchers.UUIDMatcher.is) ReorderQueueBuilder(api.support.builders.ReorderQueueBuilder) IndividualResource(api.support.http.IndividualResource) PublishedEvents.byLogEventType(api.support.fakes.PublishedEvents.byLogEventType) Arrays.asList(java.util.Arrays.asList) CoreMatchers.allOf(org.hamcrest.CoreMatchers.allOf) Matchers.hasSize(org.hamcrest.Matchers.hasSize) JsonObject(io.vertx.core.json.JsonObject) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) JsonObjectMatcher.hasJsonPath(api.support.matchers.JsonObjectMatcher.hasJsonPath) REQUEST_REORDERED(org.folio.circulation.domain.representations.logs.LogEventType.REQUEST_REORDERED) UUID(java.util.UUID) ItemResource(api.support.http.ItemResource) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) ValidationErrorMatchers.hasErrorWith(api.support.matchers.ValidationErrorMatchers.hasErrorWith) JsonArray(io.vertx.core.json.JsonArray) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) TlrFeatureStatus(api.support.TlrFeatureStatus) Matchers.contains(org.hamcrest.Matchers.contains) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) LocalDate(java.time.LocalDate) Matcher(org.hamcrest.Matcher) UTC(java.time.ZoneOffset.UTC) Function.identity(java.util.function.Function.identity) Comparator(java.util.Comparator) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource) Awaitility(org.awaitility.Awaitility) JsonObject(io.vertx.core.json.JsonObject) IndividualResource(api.support.http.IndividualResource) ReorderQueueBuilder(api.support.builders.ReorderQueueBuilder) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with FakePubSub

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);
}
Also used : Response(org.folio.circulation.support.http.client.Response) FakePubSub(api.support.fakes.FakePubSub) ZonedDateTime(java.time.ZonedDateTime) JsonObject(io.vertx.core.json.JsonObject) ChangeDueDateRequestBuilder(api.support.builders.ChangeDueDateRequestBuilder) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with FakePubSub

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);
}
Also used : FakePubSub(api.support.fakes.FakePubSub) ZonedDateTime(java.time.ZonedDateTime) ClockUtil.getZonedDateTime(org.folio.circulation.support.utils.ClockUtil.getZonedDateTime) JsonObject(io.vertx.core.json.JsonObject) CheckInByBarcodeRequestBuilder(api.support.builders.CheckInByBarcodeRequestBuilder) IndividualResource(api.support.http.IndividualResource) UUID(java.util.UUID) CheckInByBarcodeResponse(api.support.CheckInByBarcodeResponse) 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