use of org.folio.DataImportEventPayload in project mod-inventory by folio-org.
the class MatchInstanceEventHandlerUnitTest method shouldPutMultipleMatchResultToPayloadOnHandleEventPayload.
@Test
public void shouldPutMultipleMatchResultToPayloadOnHandleEventPayload(TestContext testContext) throws UnsupportedEncodingException {
Async async = testContext.async();
List<Instance> matchedInstances = List.of(new Instance(UUID.randomUUID().toString(), "1", "in1", "MARC", "Wonderful", "12334"), new Instance(UUID.randomUUID().toString(), "1", "in2", "MARC", "Wonderful", "12334"));
doAnswer(invocation -> {
Consumer<Success<MultipleRecords<Instance>>> successHandler = invocation.getArgument(2);
Success<MultipleRecords<Instance>> result = new Success<>(new MultipleRecords<>(matchedInstances, 2));
successHandler.accept(result);
return null;
}).when(instanceCollection).findByCql(eq(format("hrid == \"%s\"", INSTANCE_HRID)), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
MatchProfile subMatchProfile = new MatchProfile().withExistingRecordType(INSTANCE).withIncomingRecordType(MARC_BIBLIOGRAPHIC);
EventHandler eventHandler = new MatchInstanceEventHandler(mappingMetadataCache);
HashMap<String, String> context = new HashMap<>();
context.put(MAPPING_PARAMS, LOCATIONS_PARAMS);
context.put(RELATIONS, MATCHING_RELATIONS);
DataImportEventPayload eventPayload = createEventPayload().withContext(context);
eventPayload.getCurrentNode().setChildSnapshotWrappers(List.of(new ProfileSnapshotWrapper().withContent(subMatchProfile).withContentType(MATCH_PROFILE).withReactTo(MATCH)));
eventHandler.handle(eventPayload).whenComplete((processedPayload, throwable) -> testContext.verify(v -> {
testContext.assertNull(throwable);
testContext.assertEquals(1, processedPayload.getEventsChain().size());
testContext.assertEquals(DI_INVENTORY_INSTANCE_MATCHED.value(), processedPayload.getEventType());
assertThat(new JsonArray(processedPayload.getContext().get(MULTI_MATCH_IDS)), hasItems(matchedInstances.get(0).getId(), matchedInstances.get(1).getId()));
async.complete();
}));
}
use of org.folio.DataImportEventPayload in project mod-inventory by folio-org.
the class MatchInstanceEventHandlerUnitTest method shouldFailOnHandleEventPayloadIfFailedCallToInventoryStorage.
@Test
public void shouldFailOnHandleEventPayloadIfFailedCallToInventoryStorage(TestContext testContext) throws UnsupportedEncodingException {
Async async = testContext.async();
doAnswer(ans -> {
Consumer<Failure> callback = ans.getArgument(3);
Failure result = new Failure("Internal Server Error", 500);
callback.accept(result);
return null;
}).when(instanceCollection).findByCql(anyString(), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
EventHandler eventHandler = new MatchInstanceEventHandler(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 MatchInstanceEventHandlerUnitTest method shouldMatchOnHandleEventPayload.
@Test
public void shouldMatchOnHandleEventPayload(TestContext testContext) throws UnsupportedEncodingException {
Async async = testContext.async();
doAnswer(ans -> {
Consumer<Success<MultipleRecords<Instance>>> callback = ans.getArgument(2);
Success<MultipleRecords<Instance>> result = new Success<>(new MultipleRecords<>(singletonList(createInstance()), 1));
callback.accept(result);
return null;
}).when(instanceCollection).findByCql(eq(format("hrid == \"%s\"", INSTANCE_HRID)), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
EventHandler eventHandler = new MatchInstanceEventHandler(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_INSTANCE_MATCHED.value(), updatedEventPayload.getEventType());
async.complete();
});
}
use of org.folio.DataImportEventPayload in project mod-inventory by folio-org.
the class MatchInstanceEventHandlerUnitTest method shouldMatchWithSubConditionBasedOnMultiMatchResultOnHandleEventPayload.
@Test
public void shouldMatchWithSubConditionBasedOnMultiMatchResultOnHandleEventPayload(TestContext testContext) throws UnsupportedEncodingException {
Async async = testContext.async();
List<String> multiMatchResult = List.of(UUID.randomUUID().toString(), UUID.randomUUID().toString());
Instance expectedInstance = createInstance();
doAnswer(invocation -> {
Consumer<Success<MultipleRecords<Instance>>> successHandler = invocation.getArgument(2);
Success<MultipleRecords<Instance>> result = new Success<>(new MultipleRecords<>(singletonList(expectedInstance), 1));
successHandler.accept(result);
return null;
}).when(instanceCollection).findByCql(eq(format("hrid == \"%s\" AND id == (%s OR %s)", INSTANCE_HRID, multiMatchResult.get(0), multiMatchResult.get(1))), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
EventHandler eventHandler = new MatchInstanceEventHandler(mappingMetadataCache);
HashMap<String, String> context = new HashMap<>();
context.put(MULTI_MATCH_IDS, Json.encode(multiMatchResult));
context.put(MAPPING_PARAMS, LOCATIONS_PARAMS);
context.put(RELATIONS, MATCHING_RELATIONS);
DataImportEventPayload eventPayload = createEventPayload().withContext(context);
eventHandler.handle(eventPayload).whenComplete((processedPayload, throwable) -> {
testContext.assertNull(throwable);
testContext.assertEquals(1, processedPayload.getEventsChain().size());
testContext.assertEquals(processedPayload.getEventsChain(), singletonList(DI_SRS_MARC_BIB_RECORD_CREATED.value()));
testContext.assertEquals(DI_INVENTORY_INSTANCE_MATCHED.value(), processedPayload.getEventType());
testContext.assertEquals(new JsonObject(processedPayload.getContext().get(INSTANCE.value())).getString("id"), expectedInstance.getId());
async.complete();
});
}
use of org.folio.DataImportEventPayload in project mod-inventory by folio-org.
the class MatchInstanceEventHandlerUnitTest method shouldFailOnHandleEventPayloadIfMatchedMultipleInstances.
@Test
public void shouldFailOnHandleEventPayloadIfMatchedMultipleInstances(TestContext testContext) throws UnsupportedEncodingException {
Async async = testContext.async();
doAnswer(ans -> {
Consumer<Success<MultipleRecords<Instance>>> callback = ans.getArgument(2);
Success<MultipleRecords<Instance>> result = new Success<>(new MultipleRecords<>(asList(createInstance(), createInstance()), 2));
callback.accept(result);
return null;
}).when(instanceCollection).findByCql(anyString(), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
EventHandler eventHandler = new MatchInstanceEventHandler(mappingMetadataCache);
DataImportEventPayload eventPayload = createEventPayload();
eventHandler.handle(eventPayload).whenComplete((updatedEventPayload, throwable) -> {
testContext.assertNotNull(throwable);
async.complete();
});
}
Aggregations