use of org.folio.DataImportEventPayload in project mod-inventory by folio-org.
the class MatchInstanceEventHandlerUnitTest method shouldReturnFalseOnIsEligibleIfNullCurrentNode.
@Test
public void shouldReturnFalseOnIsEligibleIfNullCurrentNode() {
EventHandler eventHandler = new MatchInstanceEventHandler(mappingMetadataCache);
DataImportEventPayload eventPayload = new DataImportEventPayload();
assertFalse(eventHandler.isEligible(eventPayload));
}
use of org.folio.DataImportEventPayload in project mod-inventory by folio-org.
the class MatchItemEventHandlerUnitTest method shouldNotMatchOnHandleEventPayload.
@Test
public void shouldNotMatchOnHandleEventPayload(TestContext testContext) throws UnsupportedEncodingException {
Async async = testContext.async();
doAnswer(ans -> {
Consumer<Success<MultipleRecords<Item>>> callback = ans.getArgument(2);
Success<MultipleRecords<Item>> result = new Success<>(new MultipleRecords<>(new ArrayList<>(), 0));
callback.accept(result);
return null;
}).when(itemCollection).findByCql(anyString(), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
EventHandler eventHandler = new MatchItemEventHandler(mappingMetadataCache);
DataImportEventPayload eventPayload = createEventPayload();
eventHandler.handle(eventPayload).whenComplete((updatedEventPayload, throwable) -> {
testContext.assertNull(throwable);
testContext.assertEquals(1, updatedEventPayload.getEventsChain().size());
testContext.assertEquals(updatedEventPayload.getEventsChain(), singletonList(DI_SRS_MARC_BIB_RECORD_CREATED.value()));
testContext.assertEquals(DI_INVENTORY_ITEM_NOT_MATCHED.value(), updatedEventPayload.getEventType());
async.complete();
});
}
use of org.folio.DataImportEventPayload in project mod-inventory by folio-org.
the class MatchItemEventHandlerUnitTest method shouldFailOnHandleEventPayloadIfMatchedMultipleItems.
@Test
public void shouldFailOnHandleEventPayloadIfMatchedMultipleItems(TestContext testContext) throws UnsupportedEncodingException {
Async async = testContext.async();
doAnswer(ans -> {
Consumer<Success<MultipleRecords<Item>>> callback = ans.getArgument(2);
Success<MultipleRecords<Item>> result = new Success<>(new MultipleRecords<>(asList(createItem(), createItem()), 2));
callback.accept(result);
return null;
}).when(itemCollection).findByCql(anyString(), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
EventHandler eventHandler = new MatchItemEventHandler(mappingMetadataCache);
DataImportEventPayload eventPayload = createEventPayload();
eventHandler.handle(eventPayload).whenComplete((updatedEventPayload, throwable) -> {
testContext.assertNotNull(throwable);
async.complete();
});
}
use of org.folio.DataImportEventPayload in project mod-inventory by folio-org.
the class MatchItemEventHandlerUnitTest method shouldMatchWithSubMatchByItemOnHandleEventPayload.
@Test
public void shouldMatchWithSubMatchByItemOnHandleEventPayload(TestContext testContext) throws UnsupportedEncodingException {
Async async = testContext.async();
doAnswer(ans -> {
Consumer<Success<MultipleRecords<Item>>> callback = ans.getArgument(2);
Success<MultipleRecords<Item>> result = new Success<>(new MultipleRecords<>(singletonList(createItem()), 1));
callback.accept(result);
return null;
}).when(itemCollection).findByCql(eq(format("hrid == \"%s\" AND id == \"%s\"", ITEM_HRID, ITEM_ID)), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
EventHandler eventHandler = new MatchItemEventHandler(mappingMetadataCache);
HashMap<String, String> context = new HashMap<>();
context.put(EntityType.ITEM.value(), JsonObject.mapFrom(createItem()).encode());
context.put(MAPPING_PARAMS, LOCATIONS_PARAMS);
context.put(RELATIONS, MATCHING_RELATIONS);
DataImportEventPayload eventPayload = createEventPayload().withContext(context);
eventHandler.handle(eventPayload).whenComplete((updatedEventPayload, throwable) -> {
testContext.assertNull(throwable);
testContext.assertEquals(1, updatedEventPayload.getEventsChain().size());
testContext.assertEquals(updatedEventPayload.getEventsChain(), singletonList(DI_SRS_MARC_BIB_RECORD_CREATED.value()));
testContext.assertEquals(DI_INVENTORY_ITEM_MATCHED.value(), updatedEventPayload.getEventType());
async.complete();
});
}
use of org.folio.DataImportEventPayload in project mod-inventory by folio-org.
the class MatchItemEventHandlerUnitTest method shouldMatchWithSubMatchByHoldingOnHandleEventPayload.
@Test
public void shouldMatchWithSubMatchByHoldingOnHandleEventPayload(TestContext testContext) throws UnsupportedEncodingException {
Async async = testContext.async();
doAnswer(ans -> {
Consumer<Success<MultipleRecords<Item>>> callback = ans.getArgument(2);
Success<MultipleRecords<Item>> result = new Success<>(new MultipleRecords<>(singletonList(createItem()), 1));
callback.accept(result);
return null;
}).when(itemCollection).findByCql(eq(format("hrid == \"%s\" AND holdingsRecordId == \"%s\"", ITEM_HRID, HOLDING_ID)), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
EventHandler eventHandler = new MatchItemEventHandler(mappingMetadataCache);
HashMap<String, String> context = new HashMap<>();
context.put(EntityType.HOLDINGS.value(), JsonObject.mapFrom(new HoldingsRecord().withId(HOLDING_ID)).encode());
context.put(MAPPING_PARAMS, LOCATIONS_PARAMS);
context.put(RELATIONS, MATCHING_RELATIONS);
DataImportEventPayload eventPayload = createEventPayload().withContext(context);
eventHandler.handle(eventPayload).whenComplete((updatedEventPayload, throwable) -> {
testContext.assertNull(throwable);
testContext.assertEquals(1, updatedEventPayload.getEventsChain().size());
testContext.assertEquals(updatedEventPayload.getEventsChain(), singletonList(DI_SRS_MARC_BIB_RECORD_CREATED.value()));
testContext.assertEquals(DI_INVENTORY_ITEM_MATCHED.value(), updatedEventPayload.getEventType());
async.complete();
});
}
Aggregations