use of org.folio.inventory.domain.items.Item in project mod-inventory by folio-org.
the class CreateItemEventHandlerTest method shouldReturnFailedFutureIfInventoryStorageErrorExists.
@Test(expected = ExecutionException.class)
public void shouldReturnFailedFutureIfInventoryStorageErrorExists() throws InterruptedException, ExecutionException, TimeoutException, UnsupportedEncodingException {
// given
RecordToEntity recordToItem = RecordToEntity.builder().recordId(RECORD_ID).entityId(ITEM_ID).build();
when(itemIdStorageService.store(any(), any(), any())).thenReturn(Future.succeededFuture(recordToItem));
Mockito.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("Smth error", 400));
return null;
}).when(mockedItemCollection).add(any(), any(), any());
MappingManager.registerReaderFactory(fakeReaderFactory);
MappingManager.registerWriterFactory(new ItemWriterFactory());
String expectedHoldingId = UUID.randomUUID().toString();
JsonObject holdingAsJson = new JsonObject().put("id", expectedHoldingId);
HashMap<String, String> payloadContext = new HashMap<>();
payloadContext.put(EntityType.MARC_BIBLIOGRAPHIC.value(), Json.encode(new Record()));
payloadContext.put(EntityType.HOLDINGS.value(), holdingAsJson.encode());
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_SRS_MARC_BIB_RECORD_CREATED.value()).withJobExecutionId(UUID.randomUUID().toString()).withContext(payloadContext).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0));
// when
CompletableFuture<DataImportEventPayload> future = createItemHandler.handle(dataImportEventPayload);
future.get(5, TimeUnit.SECONDS);
}
use of org.folio.inventory.domain.items.Item in project mod-inventory by folio-org.
the class CreateItemEventHandlerTest method shouldNotRequestWhenCreatedItemHasEmptyBarcode.
@Test
public void shouldNotRequestWhenCreatedItemHasEmptyBarcode() throws UnsupportedEncodingException {
// given
Mockito.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));
MappingManager.registerReaderFactory(fakeReaderFactory);
MappingManager.registerWriterFactory(new ItemWriterFactory());
JsonObject holdingAsJson = new JsonObject().put("id", UUID.randomUUID().toString());
HashMap<String, String> payloadContext = new HashMap<>();
payloadContext.put(EntityType.MARC_BIBLIOGRAPHIC.value(), Json.encode(new Record()));
payloadContext.put(EntityType.HOLDINGS.value(), holdingAsJson.encode());
MappingProfile mappingProfile = new MappingProfile().withId(UUID.randomUUID().toString()).withName("Prelim item from MARC").withIncomingRecordType(EntityType.MARC_BIBLIOGRAPHIC).withExistingRecordType(ITEM).withMappingDetails(new MappingDetail().withMappingFields(Arrays.asList(new MappingRule().withPath("item.status.name").withValue("\"statusExpression\"").withEnabled("true"), new MappingRule().withPath("item.permanentLoanType.id").withValue("\"permanentLoanTypeExpression\"").withEnabled("true"), new MappingRule().withPath("item.materialType.id").withValue("\"materialTypeExpression\"").withEnabled("true"))));
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_SRS_MARC_BIB_RECORD_CREATED.value()).withJobExecutionId(UUID.randomUUID().toString()).withContext(payloadContext).withCurrentNode(new ProfileSnapshotWrapper().withProfileId(actionProfile.getId()).withContentType(ACTION_PROFILE).withContent(JsonObject.mapFrom(actionProfile).getMap()).withChildSnapshotWrappers(Collections.singletonList(new ProfileSnapshotWrapper().withProfileId(mappingProfile.getId()).withContentType(MAPPING_PROFILE).withContent(JsonObject.mapFrom(mappingProfile).getMap()))));
// when
createItemHandler.handle(dataImportEventPayload);
// then
verify(mockedItemCollection, Mockito.times(0)).findByCql(anyString(), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
}
use of org.folio.inventory.domain.items.Item in project mod-inventory by folio-org.
the class CreateItemEventHandlerTest method shouldCreateItemAndFillInHoldingsRecordIdFromHoldingsEntity.
@Test
public void shouldCreateItemAndFillInHoldingsRecordIdFromHoldingsEntity() throws UnsupportedEncodingException, InterruptedException, ExecutionException, TimeoutException {
// given
RecordToEntity recordToItem = RecordToEntity.builder().recordId(RECORD_ID).entityId(ITEM_ID).build();
when(itemIdStorageService.store(any(), any(), any())).thenReturn(Future.succeededFuture(recordToItem));
Mockito.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));
Mockito.doAnswer(invocationOnMock -> {
Item item = invocationOnMock.getArgument(0);
Consumer<Success<Item>> successHandler = invocationOnMock.getArgument(1);
successHandler.accept(new Success<>(item));
return null;
}).when(mockedItemCollection).add(any(), any(Consumer.class), any(Consumer.class));
MappingManager.registerReaderFactory(fakeReaderFactory);
MappingManager.registerWriterFactory(new ItemWriterFactory());
String expectedHoldingId = UUID.randomUUID().toString();
JsonObject holdingAsJson = new JsonObject().put("id", expectedHoldingId);
HashMap<String, String> payloadContext = new HashMap<>();
payloadContext.put(EntityType.MARC_BIBLIOGRAPHIC.value(), Json.encode(new Record()));
payloadContext.put(EntityType.HOLDINGS.value(), holdingAsJson.encode());
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_SRS_MARC_BIB_RECORD_CREATED.value()).withJobExecutionId(UUID.randomUUID().toString()).withContext(payloadContext).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0));
// when
CompletableFuture<DataImportEventPayload> future = createItemHandler.handle(dataImportEventPayload);
// then
DataImportEventPayload eventPayload = future.get(5, TimeUnit.SECONDS);
Assert.assertEquals(DI_INVENTORY_ITEM_CREATED.value(), eventPayload.getEventType());
Assert.assertNotNull(eventPayload.getContext().get(ITEM.value()));
JsonObject createdItem = new JsonObject(eventPayload.getContext().get(ITEM.value()));
Assert.assertNotNull(createdItem.getJsonObject("status").getString("name"));
Assert.assertNotNull(createdItem.getString("permanentLoanTypeId"));
Assert.assertNotNull(createdItem.getString("materialTypeId"));
Assert.assertEquals(expectedHoldingId, createdItem.getString("holdingId"));
}
use of org.folio.inventory.domain.items.Item in project mod-inventory by folio-org.
the class UpdateItemEventHandlerTest method shouldUpdateItemWithNewStatusIfHoldingAlreadyInPayload.
@Test
public void shouldUpdateItemWithNewStatusIfHoldingAlreadyInPayload() 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));
HashMap<String, String> payloadContext = new HashMap<>();
payloadContext.put(MARC_BIBLIOGRAPHIC.value(), Json.encode(new Record()));
payloadContext.put(ITEM.value(), existingItemJson.encode());
payloadContext.put(HOLDINGS.value(), "{notEmptyValue}");
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
DataImportEventPayload eventPayload = future.get(5, TimeUnit.SECONDS);
Assert.assertEquals(DI_INVENTORY_ITEM_UPDATED, DataImportEventTypes.fromValue(eventPayload.getEventType()));
Assert.assertNotNull(eventPayload.getContext().get(ITEM.value()));
JsonObject updatedItem = new JsonObject(eventPayload.getContext().get(ITEM.value()));
Assert.assertEquals(existingItemJson.getString("id"), updatedItem.getString("id"));
Assert.assertEquals(existingItemJson.getString(HRID_KEY), updatedItem.getString(HRID_KEY));
Assert.assertEquals(getNestedProperty(existingItemJson, "permanentLoanType", "id"), updatedItem.getString("permanentLoanTypeId"));
Assert.assertEquals(getNestedProperty(existingItemJson, "materialType", "id"), updatedItem.getString("materialTypeId"));
Assert.assertEquals(existingItemJson.getString("holdingsRecordId"), updatedItem.getString("holdingsRecordId"));
Assert.assertEquals(IN_PROCESS.value(), updatedItem.getJsonObject(STATUS_KEY).getString("name"));
Assert.assertNotNull(eventPayload.getContext().get(HOLDINGS.value()));
}
use of org.folio.inventory.domain.items.Item in project mod-inventory by folio-org.
the class UpdateItemEventHandlerTest method shouldUpdateItemWithNewStatus.
@Test
public void shouldUpdateItemWithNewStatus() 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));
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
DataImportEventPayload eventPayload = future.get(5, TimeUnit.SECONDS);
Assert.assertEquals(DI_INVENTORY_ITEM_UPDATED, DataImportEventTypes.fromValue(eventPayload.getEventType()));
Assert.assertNotNull(eventPayload.getContext().get(ITEM.value()));
JsonObject updatedItem = new JsonObject(eventPayload.getContext().get(ITEM.value()));
Assert.assertEquals(existingItemJson.getString("id"), updatedItem.getString("id"));
Assert.assertEquals(existingItemJson.getString(HRID_KEY), updatedItem.getString(HRID_KEY));
Assert.assertEquals(getNestedProperty(existingItemJson, "permanentLoanType", "id"), updatedItem.getString("permanentLoanTypeId"));
Assert.assertEquals(getNestedProperty(existingItemJson, "materialType", "id"), updatedItem.getString("materialTypeId"));
Assert.assertEquals(existingItemJson.getString("holdingsRecordId"), updatedItem.getString("holdingsRecordId"));
Assert.assertEquals(IN_PROCESS.value(), updatedItem.getJsonObject(STATUS_KEY).getString("name"));
Assert.assertNotNull(eventPayload.getContext().get(HOLDINGS.value()));
}
Aggregations