Search in sources :

Example 1 with TlrFeatureStatus

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

the class RequestQueueResourceTest method shouldReorderQueueSuccessfully.

@ParameterizedTest
@CsvSource(value = { "ENABLED, 1, 2, 3, 4", "ENABLED, 1, 2, 4, 3", "ENABLED, 2, 1, 3, 4", "ENABLED, 2, 1, 4, 3", "ENABLED, 4, 3, 2, 1", "ENABLED, 4, 3, 1, 2", "ENABLED, 3, 4, 2, 1", "ENABLED, 3, 4, 1, 2", "DISABLED, 1, 2, 3, 4", "DISABLED, 1, 2, 4, 3", "DISABLED, 2, 1, 3, 4", "DISABLED, 2, 1, 4, 3", "DISABLED, 4, 3, 2, 1", "DISABLED, 4, 3, 1, 2", "DISABLED, 3, 4, 2, 1", "DISABLED, 3, 4, 1, 2", "NOT_CONFIGURED, 1, 2, 3, 4", "NOT_CONFIGURED, 1, 2, 4, 3", "NOT_CONFIGURED, 2, 1, 3, 4", "NOT_CONFIGURED, 2, 1, 4, 3", "NOT_CONFIGURED, 4, 3, 2, 1", "NOT_CONFIGURED, 4, 3, 1, 2", "NOT_CONFIGURED, 3, 4, 2, 1", "NOT_CONFIGURED, 3, 4, 1, 2" })
void shouldReorderQueueSuccessfully(String tlrFeatureStatusString, int firstPosition, int secondPosition, int thirdPosition, int fourthPosition) {
    TlrFeatureStatus tlrFeatureStatus = TlrFeatureStatus.valueOf(tlrFeatureStatusString);
    reconfigureTlrFeature(tlrFeatureStatus);
    checkOutFixture.checkOutByBarcode(item, rebecca);
    IndividualResource firstHoldRequest = holdRequestForDefaultItem(steve);
    IndividualResource secondHoldRequest = holdRequestForDefaultItem(james);
    IndividualResource firstRecallRequest = recallRequestForDefaultItem(charlotte);
    IndividualResource secondRecallRequest = recallRequestForDefaultItem(jessica);
    JsonObject reorderQueueBody = new ReorderQueueBuilder().addReorderRequest(firstHoldRequest.getId().toString(), firstPosition).addReorderRequest(secondHoldRequest.getId().toString(), secondPosition).addReorderRequest(firstRecallRequest.getId().toString(), thirdPosition).addReorderRequest(secondRecallRequest.getId().toString(), fourthPosition).create();
    JsonObject response;
    if (tlrFeatureStatus == TlrFeatureStatus.ENABLED) {
        response = requestQueueFixture.reorderQueueForInstance(item.getInstanceId().toString(), reorderQueueBody);
    } else {
        response = requestQueueFixture.reorderQueueForItem(item.getId().toString(), reorderQueueBody);
    }
    verifyQueueUpdatedForItem(reorderQueueBody, response);
}
Also used : TlrFeatureStatus(api.support.TlrFeatureStatus) JsonObject(io.vertx.core.json.JsonObject) IndividualResource(api.support.http.IndividualResource) ReorderQueueBuilder(api.support.builders.ReorderQueueBuilder) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with TlrFeatureStatus

use of api.support.TlrFeatureStatus 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 3 with TlrFeatureStatus

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

the class RequestQueueResourceTest method refuseWhenPositionsAreNotSequential.

@ParameterizedTest
@CsvSource(value = { "ENABLED, 1, 2, 5, 4", "ENABLED, 0, 2, 3, 4", "ENABLED, 6, 2, 3, 1", "ENABLED, 70, 0, 10, 2", "ENABLED, 1, 3, 4, 5", "ENABLED, 1, 2, 4, 5", "ENABLED, 1, 2, 3, 5", "DISABLED, 1, 2, 5, 4", "DISABLED, 0, 2, 3, 4", "DISABLED, 6, 2, 3, 1", "DISABLED, 70, 0, 10, 2", "DISABLED, 1, 3, 4, 5", "DISABLED, 1, 2, 4, 5", "DISABLED, 1, 2, 3, 5", "NOT_CONFIGURED, 1, 2, 5, 4", "NOT_CONFIGURED, 0, 2, 3, 4", "NOT_CONFIGURED, 6, 2, 3, 1", "NOT_CONFIGURED, 70, 0, 10, 2", "NOT_CONFIGURED, 1, 3, 4, 5", "NOT_CONFIGURED, 1, 2, 4, 5", "NOT_CONFIGURED, 1, 2, 3, 5" })
void refuseWhenPositionsAreNotSequential(String tlrFeatureStatusString, int firstPosition, int secondPosition, int thirdPosition, int fourthPosition) {
    TlrFeatureStatus tlrFeatureStatus = TlrFeatureStatus.valueOf(tlrFeatureStatusString);
    reconfigureTlrFeature(tlrFeatureStatus);
    checkOutFixture.checkOutByBarcode(item, rebecca);
    IndividualResource firstHoldRequest = holdRequestForDefaultItem(steve);
    IndividualResource secondHoldRequest = holdRequestForDefaultItem(james);
    IndividualResource firstRecallRequest = recallRequestForDefaultItem(charlotte);
    IndividualResource secondRecallRequest = recallRequestForDefaultItem(jessica);
    JsonObject reorderQueueBody = new ReorderQueueBuilder().addReorderRequest(firstHoldRequest.getId().toString(), firstPosition).addReorderRequest(secondHoldRequest.getId().toString(), secondPosition).addReorderRequest(firstRecallRequest.getId().toString(), thirdPosition).addReorderRequest(secondRecallRequest.getId().toString(), fourthPosition).create();
    Response response;
    if (tlrFeatureStatus == TlrFeatureStatus.ENABLED) {
        response = requestQueueFixture.attemptReorderQueueForInstance(item.getInstanceId().toString(), reorderQueueBody);
    } else {
        response = requestQueueFixture.attemptReorderQueueForItem(item.getId().toString(), reorderQueueBody);
    }
    verifyValidationFailure(response, is("Positions must have sequential order."));
}
Also used : Response(org.folio.circulation.support.http.client.Response) TlrFeatureStatus(api.support.TlrFeatureStatus) JsonObject(io.vertx.core.json.JsonObject) IndividualResource(api.support.http.IndividualResource) ReorderQueueBuilder(api.support.builders.ReorderQueueBuilder) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

TlrFeatureStatus (api.support.TlrFeatureStatus)3 ReorderQueueBuilder (api.support.builders.ReorderQueueBuilder)3 IndividualResource (api.support.http.IndividualResource)3 JsonObject (io.vertx.core.json.JsonObject)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 CsvSource (org.junit.jupiter.params.provider.CsvSource)3 Response (org.folio.circulation.support.http.client.Response)2 APITests (api.support.APITests)1 RequestBuilder (api.support.builders.RequestBuilder)1 FakePubSub (api.support.fakes.FakePubSub)1 PublishedEvents.byLogEventType (api.support.fakes.PublishedEvents.byLogEventType)1 CheckOutResource (api.support.http.CheckOutResource)1 ItemResource (api.support.http.ItemResource)1 JsonObjectMatcher.hasJsonPath (api.support.matchers.JsonObjectMatcher.hasJsonPath)1 UUIDMatcher.is (api.support.matchers.UUIDMatcher.is)1 ValidationErrorMatchers.hasErrorWith (api.support.matchers.ValidationErrorMatchers.hasErrorWith)1 ValidationErrorMatchers.hasMessage (api.support.matchers.ValidationErrorMatchers.hasMessage)1 JsonArray (io.vertx.core.json.JsonArray)1 LocalDate (java.time.LocalDate)1 UTC (java.time.ZoneOffset.UTC)1