Search in sources :

Example 16 with ItemRequestBuilder

use of org.folio.rest.support.builders.ItemRequestBuilder in project mod-inventory-storage by folio-org.

the class InventoryHierarchyViewTest method canGetHoldingWhenAllItemForItAreSuppressed.

@Test
public void canGetHoldingWhenAllItemForItAreSuppressed() throws InterruptedException, ExecutionException, TimeoutException {
    // given
    // one instance, 1 holding with 2 not suppressed items, 1 holding with 1 suppressed item
    UUID instanceId = UUID.fromString(predefinedInstance.getString("id"));
    UUID holdingId = createHolding(instanceId, mainLibraryLocationId, null);
    JsonObject item = new ItemRequestBuilder().forHolding(holdingId).withBarcode("21734").withTemporaryLocation(mainLibraryLocationId).withItemLevelCallNumber("item suppressed call number").withMaterialType(journalMaterialTypeId).withPermanentLoanType(canCirculateLoanTypeId).withDiscoverySuppress(true).create();
    super.createItem(item);
    // when
    params.put(QUERY_PARAM_NAME_SKIP_SUPPRESSED_FROM_DISCOVERY_RECORDS, "true");
    JsonObject instancesData = getInventoryHierarchyInstances(params).get(0);
    JsonArray holdings = (JsonArray) instancesData.getValue("holdings");
    JsonArray items = (JsonArray) instancesData.getValue("items");
    // then
    assertEquals(2, holdings.getList().size());
    assertEquals(2, items.getList().size());
}
Also used : JsonArray(io.vertx.core.json.JsonArray) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) ItemRequestBuilder(org.folio.rest.support.builders.ItemRequestBuilder) Test(org.junit.Test)

Example 17 with ItemRequestBuilder

use of org.folio.rest.support.builders.ItemRequestBuilder in project mod-inventory-storage by folio-org.

the class ItemCallNumberNormalizedTest method createRecords.

@BeforeClass
public static void createRecords() throws Exception {
    final IndividualResource instance = instancesClient.create(smallAngryPlanet(UUID.randomUUID()));
    final IndividualResource holdings = holdingsClient.create(new HoldingRequestBuilder().forInstance(instance.getId()).withPermanentLocation(mainLibraryLocationId));
    for (String[] callNumberComponents : callNumberData()) {
        itemsClient.create(new ItemRequestBuilder().forHolding(holdings.getId()).withPermanentLoanType(canCirculateLoanTypeId).withMaterialType(bookMaterialTypeId).withItemLevelCallNumberPrefix(callNumberComponents[0]).withItemLevelCallNumber(callNumberComponents[1]).withItemLevelCallNumberSuffix(callNumberComponents[2]));
    }
}
Also used : HoldingRequestBuilder(org.folio.rest.support.builders.HoldingRequestBuilder) IndividualResource(org.folio.rest.support.IndividualResource) ItemRequestBuilder(org.folio.rest.support.builders.ItemRequestBuilder) BeforeClass(org.junit.BeforeClass)

Example 18 with ItemRequestBuilder

use of org.folio.rest.support.builders.ItemRequestBuilder in project mod-inventory-storage by folio-org.

the class InstanceStorageTest method canSearchByTitleAndBarcodeWithMissingHoldingsAndItemsAndStillGetInstances.

// This is intended to demonstrate that instances without holdings or items
// are not excluded from searching
@Test
public void canSearchByTitleAndBarcodeWithMissingHoldingsAndItemsAndStillGetInstances() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException, UnsupportedEncodingException {
    UUID smallAngryPlanetInstanceId = UUID.randomUUID();
    UUID mainLibrarySmallAngryHoldingId = UUID.randomUUID();
    createInstance(smallAngryPlanet(smallAngryPlanetInstanceId));
    createHoldings(new HoldingRequestBuilder().withId(mainLibrarySmallAngryHoldingId).withPermanentLocation(mainLibraryLocationId).forInstance(smallAngryPlanetInstanceId).create());
    createItem(new ItemRequestBuilder().forHolding(mainLibrarySmallAngryHoldingId).withBarcode("706949453641").withPermanentLoanType(canCirculateLoanTypeId).withMaterialType(bookMaterialTypeId).create());
    UUID nodInstanceId = UUID.randomUUID();
    createInstance(nod(nodInstanceId));
    CompletableFuture<Response> searchCompleted = new CompletableFuture<>();
    String url = instancesStorageUrl("").toString() + "?query=" + urlEncode("item.barcode=706949453641* or title=Nod*");
    client.get(url, TENANT_ID, json(searchCompleted));
    Response searchResponse = searchCompleted.get(5, SECONDS);
    assertThat(searchResponse.getStatusCode(), is(200));
    JsonObject responseBody = searchResponse.getJson();
    assertThat(responseBody.getInteger(TOTAL_RECORDS_KEY), is(2));
    List<JsonObject> foundInstances = JsonArrayHelper.toList(responseBody.getJsonArray(INSTANCES_KEY));
    assertThat(foundInstances.size(), is(2));
    Optional<JsonObject> firstInstance = foundInstances.stream().filter(instance -> instance.getString("id").equals(smallAngryPlanetInstanceId.toString())).findFirst();
    Optional<JsonObject> secondInstance = foundInstances.stream().filter(instance -> instance.getString("id").equals(nodInstanceId.toString())).findFirst();
    assertThat("Instance with barcode should be found", firstInstance.isPresent(), is(true));
    assertThat("Instance with title and no holding or items, should be found", secondInstance.isPresent(), is(true));
}
Also used : JsonErrorResponse(org.folio.rest.support.JsonErrorResponse) InstancesBatchResponse(org.folio.rest.jaxrs.model.InstancesBatchResponse) Response(org.folio.rest.support.Response) HttpURLConnection(java.net.HttpURLConnection) ResponseHandler(org.folio.rest.support.ResponseHandler) Arrays(java.util.Arrays) TENANT_ID(org.folio.rest.api.StorageTestSuite.TENANT_ID) Matchers.not(org.hamcrest.Matchers.not) StringUtils(org.apache.commons.lang3.StringUtils) HoldingRequestBuilder(org.folio.rest.support.builders.HoldingRequestBuilder) DomainEventAssertions.assertRemoveAllEventForInstance(org.folio.rest.support.matchers.DomainEventAssertions.assertRemoveAllEventForInstance) JsonObject(io.vertx.core.json.JsonObject) DomainEventAssertions.assertNoEvent(org.folio.rest.support.matchers.DomainEventAssertions.assertNoEvent) Errors(org.folio.rest.jaxrs.model.Errors) HttpResponseMatchers.errorParametersValueIs(org.folio.rest.support.HttpResponseMatchers.errorParametersValueIs) Seconds.seconds(org.joda.time.Seconds.seconds) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ItemRequestBuilder(org.folio.rest.support.builders.ItemRequestBuilder) Set(java.util.Set) DomainEventAssertions.assertCreateEventForInstances(org.folio.rest.support.matchers.DomainEventAssertions.assertCreateEventForInstances) PostgresClient(org.folio.rest.persist.PostgresClient) JsonErrorResponse(org.folio.rest.support.JsonErrorResponse) IOUtils(org.apache.commons.io.IOUtils) Stream(java.util.stream.Stream) Logger(org.apache.logging.log4j.Logger) MarcJson(org.folio.rest.jaxrs.model.MarcJson) Publication(org.folio.rest.jaxrs.model.Publication) JsonObjectMatchers.hasSoleMessageContaining(org.folio.rest.support.JsonObjectMatchers.hasSoleMessageContaining) Async(io.vertx.ext.unit.Async) DateTimeMatchers.withinSecondsBeforeNow(org.folio.rest.support.matchers.DateTimeMatchers.withinSecondsBeforeNow) InterfaceUrls.instancesStorageBatchInstancesUrl(org.folio.rest.support.http.InterfaceUrls.instancesStorageBatchInstancesUrl) RunWith(org.junit.runner.RunWith) AdditionalHttpStatusCodes(org.folio.rest.support.AdditionalHttpStatusCodes) JsonObjectMatchers.identifierMatches(org.folio.rest.support.JsonObjectMatchers.identifierMatches) HTTP_OK(java.net.HttpURLConnection.HTTP_OK) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) DomainEventAssertions.assertRemoveEventForInstance(org.folio.rest.support.matchers.DomainEventAssertions.assertRemoveEventForInstance) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) Before(org.junit.Before) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) Vertx(io.vertx.core.Vertx) DomainEventAssertions.assertCreateEventForInstance(org.folio.rest.support.matchers.DomainEventAssertions.assertCreateEventForInstance) IOException(java.io.IOException) Test(org.junit.Test) ExecutionException(java.util.concurrent.ExecutionException) JsonArray(io.vertx.core.json.JsonArray) PgUtil(org.folio.rest.persist.PgUtil) InstancesBatchResponse(org.folio.rest.jaxrs.model.InstancesBatchResponse) IsNull.notNullValue(org.hamcrest.core.IsNull.notNullValue) DateTimeMatchers.hasIsoFormat(org.folio.rest.support.matchers.DateTimeMatchers.hasIsoFormat) Assert.assertEquals(org.junit.Assert.assertEquals) CoreMatchers.is(org.hamcrest.CoreMatchers.is) TestContext(io.vertx.ext.unit.TestContext) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) InterfaceUrls.holdingsStorageUrl(org.folio.rest.support.http.InterfaceUrls.holdingsStorageUrl) Response(org.folio.rest.support.Response) Matchers.either(org.hamcrest.Matchers.either) URL(java.net.URL) IsIterableContainingInAnyOrder.containsInAnyOrder(org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder) Instance(org.folio.rest.jaxrs.model.Instance) TimeoutException(java.util.concurrent.TimeoutException) InterfaceUrls.natureOfContentTermsUrl(org.folio.rest.support.http.InterfaceUrls.natureOfContentTermsUrl) OptimisticLocking(org.folio.rest.support.db.OptimisticLocking) DomainEventAssertions.assertUpdateEventForInstance(org.folio.rest.support.matchers.DomainEventAssertions.assertUpdateEventForInstance) JsonArrayHelper(org.folio.rest.support.JsonArrayHelper) InterfaceUrls.instancesStorageSyncUrl(org.folio.rest.support.http.InterfaceUrls.instancesStorageSyncUrl) After(org.junit.After) Assert.fail(org.junit.Assert.fail) Matchers.lessThanOrEqualTo(org.hamcrest.Matchers.lessThanOrEqualTo) UUID(java.util.UUID) ResponseHandler.text(org.folio.rest.support.ResponseHandler.text) Collectors(java.util.stream.Collectors) List(java.util.List) PostgresErrorMessageMatchers.isMaximumSequenceValueError(org.folio.rest.support.matchers.PostgresErrorMessageMatchers.isMaximumSequenceValueError) Optional(java.util.Optional) StringUtil.urlEncode(org.folio.util.StringUtil.urlEncode) Matchers.anyOf(org.hamcrest.Matchers.anyOf) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InterfaceUrls.itemsStorageUrl(org.folio.rest.support.http.InterfaceUrls.itemsStorageUrl) HttpResponseMatchers.statusCodeIs(org.folio.rest.support.HttpResponseMatchers.statusCodeIs) CompletableFuture(java.util.concurrent.CompletableFuture) IndividualResource(org.folio.rest.support.IndividualResource) HashSet(java.util.HashSet) PostgresErrorMessageMatchers.isUniqueViolation(org.folio.rest.support.matchers.PostgresErrorMessageMatchers.isUniqueViolation) InterfaceUrls.instancesStorageUrl(org.folio.rest.support.http.InterfaceUrls.instancesStorageUrl) CoreMatchers.allOf(org.hamcrest.CoreMatchers.allOf) PublicationPeriod(org.folio.rest.jaxrs.model.PublicationPeriod) NatureOfContentTerm(org.folio.rest.jaxrs.model.NatureOfContentTerm) MalformedURLException(java.net.MalformedURLException) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) Matchers.both(org.hamcrest.Matchers.both) TimeUnit(java.util.concurrent.TimeUnit) HttpResponseMatchers.errorMessageContains(org.folio.rest.support.HttpResponseMatchers.errorMessageContains) HttpStatus(org.folio.HttpStatus) ResponseHandler.json(org.folio.rest.support.ResponseHandler.json) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) SECONDS(java.util.concurrent.TimeUnit.SECONDS) CompletableFuture(java.util.concurrent.CompletableFuture) HoldingRequestBuilder(org.folio.rest.support.builders.HoldingRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) UUID(java.util.UUID) ItemRequestBuilder(org.folio.rest.support.builders.ItemRequestBuilder) Test(org.junit.Test)

Example 19 with ItemRequestBuilder

use of org.folio.rest.support.builders.ItemRequestBuilder in project mod-inventory-storage by folio-org.

the class InstanceStorageTest method canSearchByBarcode.

@Test
public void canSearchByBarcode() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    UUID expectedInstanceId = UUID.randomUUID();
    UUID expectedHoldingId = UUID.randomUUID();
    createInstance(smallAngryPlanet(expectedInstanceId));
    createHoldings(new HoldingRequestBuilder().withId(expectedHoldingId).withPermanentLocation(mainLibraryLocationId).forInstance(expectedInstanceId).create());
    createItem(new ItemRequestBuilder().forHolding(expectedHoldingId).withBarcode("706949453641").withPermanentLoanType(canCirculateLoanTypeId).withMaterialType(bookMaterialTypeId).create());
    UUID otherInstanceId = UUID.randomUUID();
    UUID otherHoldingId = UUID.randomUUID();
    createInstance(nod(otherInstanceId));
    createHoldings(new HoldingRequestBuilder().withId(otherHoldingId).forInstance(otherInstanceId).withPermanentLocation(mainLibraryLocationId).create());
    createItem(new ItemRequestBuilder().forHolding(expectedHoldingId).withMaterialType(bookMaterialTypeId).withPermanentLoanType(canCirculateLoanTypeId).withBarcode("766043059304").create());
    // Use == as exact match is intended for barcode
    canSort("item.barcode==706949453641", "Long Way to a Small Angry Planet");
}
Also used : HoldingRequestBuilder(org.folio.rest.support.builders.HoldingRequestBuilder) UUID(java.util.UUID) ItemRequestBuilder(org.folio.rest.support.builders.ItemRequestBuilder) Test(org.junit.Test)

Aggregations

ItemRequestBuilder (org.folio.rest.support.builders.ItemRequestBuilder)19 UUID (java.util.UUID)17 Test (org.junit.Test)17 JsonObject (io.vertx.core.json.JsonObject)10 IndividualResource (org.folio.rest.support.IndividualResource)8 Response (org.folio.rest.support.Response)6 HoldingRequestBuilder (org.folio.rest.support.builders.HoldingRequestBuilder)6 JsonErrorResponse (org.folio.rest.support.JsonErrorResponse)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5 JsonArray (io.vertx.core.json.JsonArray)3 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 Parameters (junitparams.Parameters)2 StatisticalCodeBuilder (org.folio.rest.support.builders.StatisticalCodeBuilder)2 Vertx (io.vertx.core.Vertx)1 Async (io.vertx.ext.unit.Async)1 TestContext (io.vertx.ext.unit.TestContext)1 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)1 IOException (java.io.IOException)1