use of org.folio.inventory.domain.items.Item in project mod-inventory by folio-org.
the class UpdateItemEventHandlerTest method shouldReturnFailedWhenOLError.
@Test(expected = ExecutionException.class)
public void shouldReturnFailedWhenOLError() throws UnsupportedEncodingException, InterruptedException, ExecutionException, TimeoutException {
// given
doAnswer(invocationOnMock -> {
MultipleRecords<Item> result = new MultipleRecords<>(new ArrayList<>(), 0);
Consumer<Success<MultipleRecords<Item>>> successHandler = invocationOnMock.getArgument(2);
successHandler.accept(new Success<>(result));
return null;
}).when(mockedItemCollection).findByCql(anyString(), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
doAnswer(invocationOnMock -> {
Consumer<Failure> failureHandler = invocationOnMock.getArgument(2);
failureHandler.accept(new Failure("Cannot update record 601a8dc4-dee7-48eb-b03f-d02fdf0debd0 because it has been changed (optimistic locking): Stored _version is 2, _version of request is 1", 409));
return null;
}).when(mockedItemCollection).update(any(), any(), any());
Item returnedItem = new Item(existingItemJson.getString("id"), "2", UUID.randomUUID().toString(), "test", new Status(AVAILABLE), UUID.randomUUID().toString(), UUID.randomUUID().toString(), new JsonObject());
when(mockedItemCollection.findById(anyString())).thenReturn(CompletableFuture.completedFuture(returnedItem));
HashMap<String, String> payloadContext = new HashMap<>();
payloadContext.put(MARC_BIBLIOGRAPHIC.value(), Json.encode(new Record()));
payloadContext.put(ITEM.value(), existingItemJson.encode());
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_INVENTORY_ITEM_MATCHED.value()).withJobExecutionId(UUID.randomUUID().toString()).withContext(payloadContext).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0));
// when
CompletableFuture<DataImportEventPayload> future = updateItemHandler.handle(dataImportEventPayload);
// then
future.get(5, TimeUnit.SECONDS);
}
use of org.folio.inventory.domain.items.Item in project mod-inventory by folio-org.
the class UpdateItemEventHandlerTest method shouldReturnFailedFutureAndUpdateItemExceptStatusWhenStatusCanNotBeUpdated.
@Test
@Parameters({ "Aged to lost", "Awaiting delivery", "Awaiting pickup", "Checked out", "Claimed returned", "Declared lost", "Paged" })
public void shouldReturnFailedFutureAndUpdateItemExceptStatusWhenStatusCanNotBeUpdated(String protectedItemStatus) throws UnsupportedEncodingException {
// given
doAnswer(invocationOnMock -> {
MultipleRecords<Item> result = new MultipleRecords<>(new ArrayList<>(), 0);
Consumer<Success<MultipleRecords<Item>>> successHandler = invocationOnMock.getArgument(2);
successHandler.accept(new Success<>(result));
return null;
}).when(mockedItemCollection).findByCql(anyString(), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
String expectedItemBarcode = "BC-123123";
MappingRule barcodeMappingRule = mappingProfile.getMappingDetails().getMappingFields().get(1);
when(fakeReader.read(eq(barcodeMappingRule))).thenReturn(StringValue.of(expectedItemBarcode));
existingItemJson.put(STATUS_KEY, new JsonObject().put("name", protectedItemStatus));
HashMap<String, String> payloadContext = new HashMap<>();
payloadContext.put(MARC_BIBLIOGRAPHIC.value(), Json.encode(new Record()));
payloadContext.put(ITEM.value(), existingItemJson.encode());
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_INVENTORY_ITEM_MATCHED.value()).withJobExecutionId(UUID.randomUUID().toString()).withContext(payloadContext).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0));
// when
CompletableFuture<DataImportEventPayload> future = updateItemHandler.handle(dataImportEventPayload);
// then
Assert.assertTrue(future.isCompletedExceptionally());
JsonObject updatedItem = new JsonObject(payloadContext.get(ITEM.value()));
Assert.assertEquals(protectedItemStatus, updatedItem.getJsonObject(STATUS_KEY).getString("name"));
Assert.assertEquals(expectedItemBarcode, updatedItem.getString(ItemUtil.BARCODE));
}
use of org.folio.inventory.domain.items.Item in project mod-inventory by folio-org.
the class UpdateItemEventHandlerTest method shouldReturnFailedFutureWhenBarcodeToUpdatedAssignedToAnotherItem.
@Test(expected = ExecutionException.class)
public void shouldReturnFailedFutureWhenBarcodeToUpdatedAssignedToAnotherItem() throws InterruptedException, ExecutionException, TimeoutException, UnsupportedEncodingException {
// given
doAnswer(invocationOnMock -> {
Item itemByCql = new Item(null, null, null, new Status(AVAILABLE), null, null, null);
MultipleRecords<Item> result = new MultipleRecords<>(Collections.singletonList(itemByCql), 0);
Consumer<Success<MultipleRecords<Item>>> successHandler = invocationOnMock.getArgument(2);
successHandler.accept(new Success<>(result));
return null;
}).when(mockedItemCollection).findByCql(anyString(), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
HashMap<String, String> payloadContext = new HashMap<>();
payloadContext.put(MARC_BIBLIOGRAPHIC.value(), Json.encode(new Record()));
payloadContext.put(ITEM.value(), existingItemJson.encode());
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_INVENTORY_ITEM_MATCHED.value()).withJobExecutionId(UUID.randomUUID().toString()).withContext(payloadContext).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0));
// when
CompletableFuture<DataImportEventPayload> future = updateItemHandler.handle(dataImportEventPayload);
// then
future.get(5, TimeUnit.SECONDS);
}
use of org.folio.inventory.domain.items.Item in project mod-inventory by folio-org.
the class ItemRepresentationTest method jsonContainsVersion.
@Test
public void jsonContainsVersion() throws Throwable {
WebContext webContext = when(mock(WebContext.class).absoluteUrl(any())).thenReturn(new URL("http://localhost")).getMock();
JsonObject instance = new JsonObject().put("contributors", new JsonArray());
Item item = new Item(UUID.randomUUID().toString(), "123", null, new Status(ItemStatusName.AVAILABLE), null, null, null);
JsonObject json = new ItemRepresentation("items").toJson(item, null, instance, null, null, null, null, null, null, webContext);
assertThat(json.getString("_version"), is("123"));
}
use of org.folio.inventory.domain.items.Item in project mod-inventory by folio-org.
the class ExternalItemCollectionExamples method anItemCanBeDeleted.
@Test
public void anItemCanBeDeleted() throws InterruptedException, ExecutionException, TimeoutException {
addSomeExamples(collection);
CompletableFuture<Item> itemToBeDeletedFuture = new CompletableFuture<>();
collection.add(temeraire(), succeed(itemToBeDeletedFuture), fail(itemToBeDeletedFuture));
Item itemToBeDeleted = itemToBeDeletedFuture.get();
CompletableFuture<Void> deleted = new CompletableFuture<>();
collection.delete(itemToBeDeleted.id, succeed(deleted), fail(deleted));
waitForCompletion(deleted);
CompletableFuture<Item> findFuture = new CompletableFuture<>();
collection.findById(itemToBeDeleted.id, succeed(findFuture), fail(findFuture));
assertThat(findFuture.get(), is(nullValue()));
CompletableFuture<MultipleRecords<Item>> findAllFuture = new CompletableFuture<>();
collection.findAll(PagingParameters.defaults(), succeed(findAllFuture), fail(findAllFuture));
MultipleRecords<Item> wrappedItems = getOnCompletion(findAllFuture);
List<Item> allItems = wrappedItems.records;
assertThat(allItems.size(), is(3));
assertThat(wrappedItems.totalRecords, is(3));
}
Aggregations