Search in sources :

Example 21 with Item

use of org.folio.inventory.domain.items.Item in project mod-inventory by folio-org.

the class ExternalItemCollectionExamples method anItemCanBeFoundById.

@Test
public void anItemCanBeFoundById() throws InterruptedException, ExecutionException, TimeoutException {
    CompletableFuture<Item> firstAddFuture = new CompletableFuture<>();
    CompletableFuture<Item> secondAddFuture = new CompletableFuture<>();
    collection.add(smallAngryPlanet, succeed(firstAddFuture), fail(firstAddFuture));
    collection.add(nod, succeed(secondAddFuture), fail(secondAddFuture));
    Item addedItem = getOnCompletion(firstAddFuture);
    Item otherAddedItem = getOnCompletion(secondAddFuture);
    CompletableFuture<Item> findFuture = new CompletableFuture<>();
    CompletableFuture<Item> otherFindFuture = new CompletableFuture<>();
    collection.findById(addedItem.id, succeed(findFuture), fail(findFuture));
    collection.findById(otherAddedItem.id, succeed(otherFindFuture), fail(otherFindFuture));
    Item foundItem = getOnCompletion(findFuture);
    Item otherFoundItem = getOnCompletion(otherFindFuture);
    assertThat(foundItem, notNullValue());
    assertThat(foundItem.getBarcode(), is("036000291452"));
    assertThat(foundItem.getStatus().getName(), is(ItemStatusName.AVAILABLE));
    assertThat(foundItem.getMaterialTypeId(), is(bookMaterialTypeId));
    assertThat(foundItem.getPermanentLoanTypeId(), is(canCirculateLoanTypeId));
    assertThat(foundItem.getTemporaryLocationId(), is(annexLibraryLocationId));
    assertThat(otherFoundItem, notNullValue());
    assertThat(otherFoundItem.getBarcode(), is("565578437802"));
    assertThat(otherFoundItem.getStatus().getName(), is(ItemStatusName.AVAILABLE));
    assertThat(otherFoundItem.getMaterialTypeId(), is(bookMaterialTypeId));
    assertThat(otherFoundItem.getPermanentLoanTypeId(), is(canCirculateLoanTypeId));
    assertThat(otherFoundItem.getTemporaryLocationId(), is(annexLibraryLocationId));
}
Also used : Item(org.folio.inventory.domain.items.Item) CompletableFuture(java.util.concurrent.CompletableFuture) Test(org.junit.Test)

Example 22 with Item

use of org.folio.inventory.domain.items.Item in project mod-inventory by folio-org.

the class ExternalItemCollectionExamples method allItemsCanBePaged.

@Test
public void allItemsCanBePaged() throws InterruptedException, ExecutionException, TimeoutException {
    WaitForAllFutures<Item> allAdded = new WaitForAllFutures<>();
    collection.add(smallAngryPlanet, allAdded.notifySuccess(), v -> {
    });
    collection.add(nod, allAdded.notifySuccess(), v -> {
    });
    collection.add(uprooted, allAdded.notifySuccess(), v -> {
    });
    collection.add(temeraire, allAdded.notifySuccess(), v -> {
    });
    collection.add(interestingTimes, allAdded.notifySuccess(), v -> {
    });
    allAdded.waitForCompletion();
    CompletableFuture<MultipleRecords<Item>> firstPageFuture = new CompletableFuture<>();
    CompletableFuture<MultipleRecords<Item>> secondPageFuture = new CompletableFuture<>();
    collection.findAll(new PagingParameters(3, 0), succeed(firstPageFuture), fail(secondPageFuture));
    collection.findAll(new PagingParameters(3, 3), succeed(secondPageFuture), fail(secondPageFuture));
    MultipleRecords<Item> firstPage = getOnCompletion(firstPageFuture);
    MultipleRecords<Item> secondPage = getOnCompletion(secondPageFuture);
    assertThat(firstPage.records.size(), is(3));
    assertThat(secondPage.records.size(), is(2));
    assertThat(firstPage.totalRecords, is(5));
    assertThat(secondPage.totalRecords, is(5));
}
Also used : Item(org.folio.inventory.domain.items.Item) CompletableFuture(java.util.concurrent.CompletableFuture) PagingParameters(org.folio.inventory.common.api.request.PagingParameters) WaitForAllFutures(org.folio.inventory.common.WaitForAllFutures) MultipleRecords(org.folio.inventory.common.domain.MultipleRecords) Test(org.junit.Test)

Example 23 with Item

use of org.folio.inventory.domain.items.Item in project mod-inventory by folio-org.

the class ExternalItemCollectionExamples method anItemCanBeAddedWithAnId.

@Test
public void anItemCanBeAddedWithAnId() throws InterruptedException, ExecutionException, TimeoutException {
    CompletableFuture<Item> addFinished = new CompletableFuture<>();
    String itemId = UUID.randomUUID().toString();
    Item itemWithId = smallAngryPlanet.copyWithNewId(itemId);
    collection.add(itemWithId, succeed(addFinished), fail(addFinished));
    Item added = getOnCompletion(addFinished);
    assertThat(added.id, is(itemId));
}
Also used : Item(org.folio.inventory.domain.items.Item) CompletableFuture(java.util.concurrent.CompletableFuture) Test(org.junit.Test)

Example 24 with Item

use of org.folio.inventory.domain.items.Item in project mod-inventory by folio-org.

the class ExternalItemCollectionExamples method itemsCanBeFoundByBarcode.

@Test
public void itemsCanBeFoundByBarcode() throws InterruptedException, ExecutionException, TimeoutException, UnsupportedEncodingException {
    CompletableFuture<Item> firstAddFuture = new CompletableFuture<>();
    CompletableFuture<Item> secondAddFuture = new CompletableFuture<>();
    CompletableFuture<Item> thirdAddFuture = new CompletableFuture<>();
    collection.add(smallAngryPlanet, succeed(firstAddFuture), fail(firstAddFuture));
    collection.add(nod, succeed(secondAddFuture), fail(secondAddFuture));
    collection.add(uprooted, succeed(thirdAddFuture), fail(thirdAddFuture));
    CompletableFuture<Void> allAddsFuture = CompletableFuture.allOf(firstAddFuture, secondAddFuture, thirdAddFuture);
    getOnCompletion(allAddsFuture);
    Item addedSmallAngryPlanet = getOnCompletion(firstAddFuture);
    CompletableFuture<MultipleRecords<Item>> findFuture = new CompletableFuture<>();
    collection.findByCql("barcode==036000291452", new PagingParameters(10, 0), succeed(findFuture), fail(findFuture));
    MultipleRecords<Item> wrappedItems = getOnCompletion(findFuture);
    assertThat(wrappedItems.records.size(), is(1));
    assertThat(wrappedItems.totalRecords, is(1));
    assertThat(wrappedItems.records.stream().findFirst().get().id, is(addedSmallAngryPlanet.id));
}
Also used : Item(org.folio.inventory.domain.items.Item) CompletableFuture(java.util.concurrent.CompletableFuture) PagingParameters(org.folio.inventory.common.api.request.PagingParameters) MultipleRecords(org.folio.inventory.common.domain.MultipleRecords) Test(org.junit.Test)

Example 25 with Item

use of org.folio.inventory.domain.items.Item in project mod-inventory by folio-org.

the class InProcessItemStatusValidatorTest method itemCanBeMarkedAsInProcessWhenInAcceptableSourceStatus.

@SneakyThrows
@Parameters({ "Aged to lost", "Available", "Awaiting pickup", "Awaiting delivery", "Checked out", "Claimed returned", "Declared lost", "In process (non-requestable)", "In transit", "Intellectual item", "Long missing", "Lost and paid", "Missing", "On order", "Order closed", "Paged", "Restricted", "Unavailable", "Unknown", "Withdrawn" })
@Test
public void itemCanBeMarkedAsInProcessWhenInAcceptableSourceStatus(String sourceStatus) {
    final var targetValidator = validators.getValidator(IN_PROCESS);
    final var item = new Item(null, null, null, new Status(ItemStatusName.forName(sourceStatus)), null, null, null);
    final var validationFuture = targetValidator.refuseItemWhenNotInAcceptableSourceStatus(item);
    validationFuture.get(1, TimeUnit.SECONDS);
    // Validator responds with a successful future when valid
    assertThat(validationFuture.isDone()).isTrue();
}
Also used : Status(org.folio.inventory.domain.items.Status) Item(org.folio.inventory.domain.items.Item) Parameters(junitparams.Parameters) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Aggregations

Item (org.folio.inventory.domain.items.Item)74 Test (org.junit.Test)59 Status (org.folio.inventory.domain.items.Status)41 Parameters (junitparams.Parameters)32 JsonObject (io.vertx.core.json.JsonObject)28 PagingParameters (org.folio.inventory.common.api.request.PagingParameters)28 MultipleRecords (org.folio.inventory.common.domain.MultipleRecords)26 Success (org.folio.inventory.common.domain.Success)24 DataImportEventPayload (org.folio.DataImportEventPayload)23 HashMap (java.util.HashMap)20 Consumer (java.util.function.Consumer)20 CompletableFuture (java.util.concurrent.CompletableFuture)16 Record (org.folio.rest.jaxrs.model.Record)14 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)13 ItemCollection (org.folio.inventory.domain.items.ItemCollection)12 Storage (org.folio.inventory.storage.Storage)11 EventHandler (org.folio.processing.events.services.handler.EventHandler)11 List (java.util.List)9 Collectors (java.util.stream.Collectors)9 HoldingsRecord (org.folio.HoldingsRecord)9