Search in sources :

Example 1 with HTTP_CREATED

use of org.folio.HttpStatus.HTTP_CREATED in project mod-inventory-storage by folio-org.

the class HoldingsStorageTest method canPostSynchronousBatchWithExistingIdWithUpsertTrue.

@Test
public void canPostSynchronousBatchWithExistingIdWithUpsertTrue() {
    final String existingHrId = UUID.randomUUID().toString();
    final JsonArray holdingsArray1 = threeHoldings();
    final JsonArray holdingsArray2 = threeHoldings();
    holdingsArray1.getJsonObject(1).put("id", existingHrId);
    holdingsArray2.getJsonObject(1).put("id", existingHrId);
    final Response firstResponse = postSynchronousBatch("?upsert=true", holdingsArray1);
    final JsonObject existingHrBeforeUpdate = getById(existingHrId).getJson();
    final Response secondResponse = postSynchronousBatch("?upsert=true", holdingsArray2);
    assertThat(firstResponse, statusCodeIs(HTTP_CREATED));
    assertThat(secondResponse, statusCodeIs(HTTP_CREATED));
    Stream.concat(holdingsArray1.stream(), holdingsArray2.stream()).map(json -> ((JsonObject) json).getString("id")).filter(id -> !id.equals(existingHrId)).map(this::getById).map(Response::getJson).forEach(DomainEventAssertions::assertCreateEventForHolding);
    await().untilAsserted(() -> {
        var newHr = getById(existingHrId).getJson();
        final String id = newHr.getString("id");
        final String instanceId = newHr.getString("instanceId");
        assertThat(getHoldingsEvents(instanceId, id).size(), greaterThan(0));
        assertUpdateEvent(getLastHoldingEvent(instanceId, id), existingHrBeforeUpdate, newHr);
    });
}
Also used : JsonArray(io.vertx.core.json.JsonArray) HttpURLConnection(java.net.HttpURLConnection) CoreMatchers.is(org.hamcrest.CoreMatchers.is) TENANT_ID(org.folio.rest.api.StorageTestSuite.TENANT_ID) URL(java.net.URL) IsIterableContainingInAnyOrder.containsInAnyOrder(org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder) TimeoutException(java.util.concurrent.TimeoutException) StringUtils(org.apache.commons.lang3.StringUtils) OptimisticLocking(org.folio.rest.support.db.OptimisticLocking) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) DomainEventAssertions.assertUpdateEvent(org.folio.rest.support.matchers.DomainEventAssertions.assertUpdateEvent) After(org.junit.After) HoldingRequestBuilder(org.folio.rest.support.builders.HoldingRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) JUnitParamsRunner(junitparams.JUnitParamsRunner) Assert.fail(org.junit.Assert.fail) Errors(org.folio.rest.jaxrs.model.Errors) Awaitility.await(org.awaitility.Awaitility.await) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Predicate(java.util.function.Predicate) ItemRequestBuilder(org.folio.rest.support.builders.ItemRequestBuilder) Set(java.util.Set) UUID(java.util.UUID) ResponseHandler.text(org.folio.rest.support.ResponseHandler.text) Collectors(java.util.stream.Collectors) PostgresClient(org.folio.rest.persist.PostgresClient) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Stream(java.util.stream.Stream) PostgresErrorMessageMatchers.isMaximumSequenceValueError(org.folio.rest.support.matchers.PostgresErrorMessageMatchers.isMaximumSequenceValueError) HTTP_CREATED(org.folio.HttpStatus.HTTP_CREATED) org.folio.rest.support(org.folio.rest.support) HTTP_UNPROCESSABLE_ENTITY(org.folio.HttpStatus.HTTP_UNPROCESSABLE_ENTITY) Parameters(junitparams.Parameters) JsonObjectMatchers.hasSoleMessageContaining(org.folio.rest.support.JsonObjectMatchers.hasSoleMessageContaining) RunWith(org.junit.runner.RunWith) CompletableFuture(java.util.concurrent.CompletableFuture) DomainEventAssertions(org.folio.rest.support.matchers.DomainEventAssertions) DomainEventAssertions.assertUpdateEventForHolding(org.folio.rest.support.matchers.DomainEventAssertions.assertUpdateEventForHolding) IsIterableContaining.hasItem(org.hamcrest.core.IsIterableContaining.hasItem) DomainEventAssertions.assertRemoveEventForHolding(org.folio.rest.support.matchers.DomainEventAssertions.assertRemoveEventForHolding) HttpResponseMatchers(org.folio.rest.support.HttpResponseMatchers) DomainEventAssertions.assertRemoveAllEventForHolding(org.folio.rest.support.matchers.DomainEventAssertions.assertRemoveAllEventForHolding) CoreMatchers.allOf(org.hamcrest.CoreMatchers.allOf) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Before(org.junit.Before) ITEM_LEVEL_CALL_NUMBER_TYPE(org.folio.rest.api.ItemEffectiveCallNumberComponentsTest.ITEM_LEVEL_CALL_NUMBER_TYPE) InterfaceUrls(org.folio.rest.support.http.InterfaceUrls) DomainEventAssertions.assertNoUpdateEventForHolding(org.folio.rest.support.matchers.DomainEventAssertions.assertNoUpdateEventForHolding) FakeKafkaConsumer.getHoldingsEvents(org.folio.rest.support.kafka.FakeKafkaConsumer.getHoldingsEvents) FakeKafkaConsumer.getLastHoldingEvent(org.folio.rest.support.kafka.FakeKafkaConsumer.getLastHoldingEvent) MalformedURLException(java.net.MalformedURLException) CoreMatchers.hasItems(org.hamcrest.CoreMatchers.hasItems) Vertx(io.vertx.core.Vertx) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) Matchers.both(org.hamcrest.Matchers.both) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) JsonArray(io.vertx.core.json.JsonArray) Ignore(org.junit.Ignore) HttpStatus(org.folio.HttpStatus) ResponseHandler.json(org.folio.rest.support.ResponseHandler.json) LogManager(org.apache.logging.log4j.LogManager) SECONDS(java.util.concurrent.TimeUnit.SECONDS) DomainEventAssertions.assertCreateEventForHolding(org.folio.rest.support.matchers.DomainEventAssertions.assertCreateEventForHolding) Assert.assertEquals(org.junit.Assert.assertEquals) JsonObject(io.vertx.core.json.JsonObject) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) DomainEventAssertions(org.folio.rest.support.matchers.DomainEventAssertions) Test(org.junit.Test)

Example 2 with HTTP_CREATED

use of org.folio.HttpStatus.HTTP_CREATED in project mod-inventory-storage by folio-org.

the class ItemStorageTest method canPostSynchronousBatchWithGeneratedHRID.

@Test
public void canPostSynchronousBatchWithGeneratedHRID() {
    log.info("Starting canPostSynchronousBatchWithGeneratedHRID");
    setItemSequence(1);
    final JsonArray itemsArray = threeItems();
    assertThat(postSynchronousBatch(itemsArray), statusCodeIs(HTTP_CREATED));
    for (Object item : itemsArray) {
        assertExists((JsonObject) item);
    }
    itemsArray.stream().map(o -> (JsonObject) o).forEach(item -> {
        final Response response = getById(item.getString("id"));
        assertExists(response, item);
        assertHRIDRange(response, "it00000000001", "it00000000003");
    });
    log.info("Finished canPostSynchronousBatchWithGeneratedHRID");
}
Also used : JsonArray(io.vertx.core.json.JsonArray) CoreMatchers.is(org.hamcrest.CoreMatchers.is) HttpURLConnection(java.net.HttpURLConnection) ResponseHandler(org.folio.rest.support.ResponseHandler) InterfaceUrls.holdingsStorageUrl(org.folio.rest.support.http.InterfaceUrls.holdingsStorageUrl) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) Arrays(java.util.Arrays) Response(org.folio.rest.support.Response) DateTimeZone(org.joda.time.DateTimeZone) TENANT_ID(org.folio.rest.api.StorageTestSuite.TENANT_ID) DomainEventAssertions.assertUpdateEventForItem(org.folio.rest.support.matchers.DomainEventAssertions.assertUpdateEventForItem) SneakyThrows(lombok.SneakyThrows) URL(java.net.URL) Date(java.util.Date) IsIterableContainingInAnyOrder.containsInAnyOrder(org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder) ZonedDateTime(java.time.ZonedDateTime) TimeoutException(java.util.concurrent.TimeoutException) DomainEventAssertions.assertCreateEventForItem(org.folio.rest.support.matchers.DomainEventAssertions.assertCreateEventForItem) OptimisticLocking(org.folio.rest.support.db.OptimisticLocking) UNPROCESSABLE_ENTITY(org.folio.rest.support.AdditionalHttpStatusCodes.UNPROCESSABLE_ENTITY) JsonArrayHelper(org.folio.rest.support.JsonArrayHelper) StatisticalCodeBuilder(org.folio.rest.support.builders.StatisticalCodeBuilder) After(org.junit.After) JsonObjectMatchers.validationErrorMatches(org.folio.rest.support.JsonObjectMatchers.validationErrorMatches) Assert.fail(org.junit.Assert.fail) JsonObject(io.vertx.core.json.JsonObject) JUnitParamsRunner(junitparams.JUnitParamsRunner) Errors(org.folio.rest.jaxrs.model.Errors) HttpResponseMatchers.errorParametersValueIs(org.folio.rest.support.HttpResponseMatchers.errorParametersValueIs) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Matchers.lessThanOrEqualTo(org.hamcrest.Matchers.lessThanOrEqualTo) ItemRequestBuilder(org.folio.rest.support.builders.ItemRequestBuilder) Set(java.util.Set) JsonArrayHelper.toList(org.folio.rest.support.JsonArrayHelper.toList) UUID(java.util.UUID) ResponseHandler.text(org.folio.rest.support.ResponseHandler.text) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) PostgresClient(org.folio.rest.persist.PostgresClient) JsonErrorResponse(org.folio.rest.support.JsonErrorResponse) List(java.util.List) ResponseHandler.empty(org.folio.rest.support.ResponseHandler.empty) Stream(java.util.stream.Stream) Logger(org.apache.logging.log4j.Logger) PostgresErrorMessageMatchers.isMaximumSequenceValueError(org.folio.rest.support.matchers.PostgresErrorMessageMatchers.isMaximumSequenceValueError) HTTP_CREATED(org.folio.HttpStatus.HTTP_CREATED) StringUtil.urlEncode(org.folio.util.StringUtil.urlEncode) HTTP_UNPROCESSABLE_ENTITY(org.folio.HttpStatus.HTTP_UNPROCESSABLE_ENTITY) Parameters(junitparams.Parameters) JsonObjectMatchers.hasSoleMessageContaining(org.folio.rest.support.JsonObjectMatchers.hasSoleMessageContaining) Item(org.folio.rest.jaxrs.model.Item) CoreMatchers.anyOf(org.hamcrest.CoreMatchers.anyOf) LastCheckIn(org.folio.rest.jaxrs.model.LastCheckIn) DomainEventAssertions.assertRemoveAllEventForItem(org.folio.rest.support.matchers.DomainEventAssertions.assertRemoveAllEventForItem) CoreMatchers.not(org.hamcrest.CoreMatchers.not) RunWith(org.junit.runner.RunWith) InterfaceUrls.itemsStorageUrl(org.folio.rest.support.http.InterfaceUrls.itemsStorageUrl) AdditionalHttpStatusCodes(org.folio.rest.support.AdditionalHttpStatusCodes) HttpResponseMatchers.statusCodeIs(org.folio.rest.support.HttpResponseMatchers.statusCodeIs) CompletableFuture(java.util.concurrent.CompletableFuture) IndividualResource(org.folio.rest.support.IndividualResource) Matchers.arrayContainingInAnyOrder(org.hamcrest.Matchers.arrayContainingInAnyOrder) HTTP_OK(java.net.HttpURLConnection.HTTP_OK) DomainEventAssertions(org.folio.rest.support.matchers.DomainEventAssertions) InterfaceUrls.itemsStorageSyncUrl(org.folio.rest.support.http.InterfaceUrls.itemsStorageSyncUrl) HTTP_INTERNAL_ERROR(java.net.HttpURLConnection.HTTP_INTERNAL_ERROR) InterfaceUrls.instancesStorageUrl(org.folio.rest.support.http.InterfaceUrls.instancesStorageUrl) CoreMatchers.allOf(org.hamcrest.CoreMatchers.allOf) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) ITEM_LEVEL_CALL_NUMBER_TYPE(org.folio.rest.api.ItemEffectiveCallNumberComponentsTest.ITEM_LEVEL_CALL_NUMBER_TYPE) Before(org.junit.Before) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) MalformedURLException(java.net.MalformedURLException) CoreMatchers.hasItems(org.hamcrest.CoreMatchers.hasItems) DateTime(org.joda.time.DateTime) Vertx(io.vertx.core.Vertx) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ResponseMatcher.hasValidationError(org.folio.rest.support.matchers.ResponseMatcher.hasValidationError) DomainEventAssertions.assertRemoveEventForItem(org.folio.rest.support.matchers.DomainEventAssertions.assertRemoveEventForItem) Matchers.both(org.hamcrest.Matchers.both) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) JsonArray(io.vertx.core.json.JsonArray) Items(org.folio.rest.jaxrs.model.Items) HttpResponseMatchers.errorMessageContains(org.folio.rest.support.HttpResponseMatchers.errorMessageContains) IsNull.notNullValue(org.hamcrest.core.IsNull.notNullValue) HttpStatus(org.folio.HttpStatus) ResponseHandler.json(org.folio.rest.support.ResponseHandler.json) LogManager(org.apache.logging.log4j.LogManager) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Assert.assertEquals(org.junit.Assert.assertEquals) Response(org.folio.rest.support.Response) JsonErrorResponse(org.folio.rest.support.JsonErrorResponse) JsonObject(io.vertx.core.json.JsonObject) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 3 with HTTP_CREATED

use of org.folio.HttpStatus.HTTP_CREATED in project mod-inventory-storage by folio-org.

the class HoldingsStorageTest method canPostSynchronousBatchWithGeneratedHRID.

@Test
public void canPostSynchronousBatchWithGeneratedHRID() {
    log.info("Starting canPostSynchronousBatchWithGeneratedHRID");
    setHoldingsSequence(1);
    final JsonArray holdingsArray = threeHoldings();
    assertThat(postSynchronousBatch(holdingsArray), statusCodeIs(HTTP_CREATED));
    holdingsArray.stream().map(o -> (JsonObject) o).forEach(holdings -> {
        final Response response = getById(holdings.getString("id"));
        assertExists(response, holdings);
        assertHRIDRange(response, "ho00000000001", "ho00000000003");
        JsonObject body = response.getJson();
        assertEquals(body.getString("effectiveLocationId"), body.getString("permanentLocationId"));
    });
    log.info("Finished canPostSynchronousBatchWithGeneratedHRID");
}
Also used : JsonArray(io.vertx.core.json.JsonArray) HttpURLConnection(java.net.HttpURLConnection) CoreMatchers.is(org.hamcrest.CoreMatchers.is) TENANT_ID(org.folio.rest.api.StorageTestSuite.TENANT_ID) URL(java.net.URL) IsIterableContainingInAnyOrder.containsInAnyOrder(org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder) TimeoutException(java.util.concurrent.TimeoutException) StringUtils(org.apache.commons.lang3.StringUtils) OptimisticLocking(org.folio.rest.support.db.OptimisticLocking) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) DomainEventAssertions.assertUpdateEvent(org.folio.rest.support.matchers.DomainEventAssertions.assertUpdateEvent) After(org.junit.After) HoldingRequestBuilder(org.folio.rest.support.builders.HoldingRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) JUnitParamsRunner(junitparams.JUnitParamsRunner) Assert.fail(org.junit.Assert.fail) Errors(org.folio.rest.jaxrs.model.Errors) Awaitility.await(org.awaitility.Awaitility.await) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Predicate(java.util.function.Predicate) ItemRequestBuilder(org.folio.rest.support.builders.ItemRequestBuilder) Set(java.util.Set) UUID(java.util.UUID) ResponseHandler.text(org.folio.rest.support.ResponseHandler.text) Collectors(java.util.stream.Collectors) PostgresClient(org.folio.rest.persist.PostgresClient) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Stream(java.util.stream.Stream) PostgresErrorMessageMatchers.isMaximumSequenceValueError(org.folio.rest.support.matchers.PostgresErrorMessageMatchers.isMaximumSequenceValueError) HTTP_CREATED(org.folio.HttpStatus.HTTP_CREATED) org.folio.rest.support(org.folio.rest.support) HTTP_UNPROCESSABLE_ENTITY(org.folio.HttpStatus.HTTP_UNPROCESSABLE_ENTITY) Parameters(junitparams.Parameters) JsonObjectMatchers.hasSoleMessageContaining(org.folio.rest.support.JsonObjectMatchers.hasSoleMessageContaining) RunWith(org.junit.runner.RunWith) CompletableFuture(java.util.concurrent.CompletableFuture) DomainEventAssertions(org.folio.rest.support.matchers.DomainEventAssertions) DomainEventAssertions.assertUpdateEventForHolding(org.folio.rest.support.matchers.DomainEventAssertions.assertUpdateEventForHolding) IsIterableContaining.hasItem(org.hamcrest.core.IsIterableContaining.hasItem) DomainEventAssertions.assertRemoveEventForHolding(org.folio.rest.support.matchers.DomainEventAssertions.assertRemoveEventForHolding) HttpResponseMatchers(org.folio.rest.support.HttpResponseMatchers) DomainEventAssertions.assertRemoveAllEventForHolding(org.folio.rest.support.matchers.DomainEventAssertions.assertRemoveAllEventForHolding) CoreMatchers.allOf(org.hamcrest.CoreMatchers.allOf) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Before(org.junit.Before) ITEM_LEVEL_CALL_NUMBER_TYPE(org.folio.rest.api.ItemEffectiveCallNumberComponentsTest.ITEM_LEVEL_CALL_NUMBER_TYPE) InterfaceUrls(org.folio.rest.support.http.InterfaceUrls) DomainEventAssertions.assertNoUpdateEventForHolding(org.folio.rest.support.matchers.DomainEventAssertions.assertNoUpdateEventForHolding) FakeKafkaConsumer.getHoldingsEvents(org.folio.rest.support.kafka.FakeKafkaConsumer.getHoldingsEvents) FakeKafkaConsumer.getLastHoldingEvent(org.folio.rest.support.kafka.FakeKafkaConsumer.getLastHoldingEvent) MalformedURLException(java.net.MalformedURLException) CoreMatchers.hasItems(org.hamcrest.CoreMatchers.hasItems) Vertx(io.vertx.core.Vertx) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) Matchers.both(org.hamcrest.Matchers.both) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) JsonArray(io.vertx.core.json.JsonArray) Ignore(org.junit.Ignore) HttpStatus(org.folio.HttpStatus) ResponseHandler.json(org.folio.rest.support.ResponseHandler.json) LogManager(org.apache.logging.log4j.LogManager) SECONDS(java.util.concurrent.TimeUnit.SECONDS) DomainEventAssertions.assertCreateEventForHolding(org.folio.rest.support.matchers.DomainEventAssertions.assertCreateEventForHolding) Assert.assertEquals(org.junit.Assert.assertEquals) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Aggregations

Vertx (io.vertx.core.Vertx)3 JsonArray (io.vertx.core.json.JsonArray)3 JsonObject (io.vertx.core.json.JsonObject)3 HttpURLConnection (java.net.HttpURLConnection)3 MalformedURLException (java.net.MalformedURLException)3 URL (java.net.URL)3 List (java.util.List)3 Set (java.util.Set)3 UUID (java.util.UUID)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 ExecutionException (java.util.concurrent.ExecutionException)3 TimeUnit (java.util.concurrent.TimeUnit)3 SECONDS (java.util.concurrent.TimeUnit.SECONDS)3 TimeoutException (java.util.concurrent.TimeoutException)3 Collectors (java.util.stream.Collectors)3 Stream (java.util.stream.Stream)3 JUnitParamsRunner (junitparams.JUnitParamsRunner)3 Parameters (junitparams.Parameters)3 LogManager (org.apache.logging.log4j.LogManager)3 Logger (org.apache.logging.log4j.Logger)3