use of org.folio.DataImportEventPayload in project mod-inventory by folio-org.
the class MatchItemEventHandlerUnitTest method shouldReturnFalseOnIsEligibleIfCurrentNodeTypeIsNotMatchProfile.
@Test
public void shouldReturnFalseOnIsEligibleIfCurrentNodeTypeIsNotMatchProfile() {
EventHandler eventHandler = new MatchItemEventHandler(mappingMetadataCache);
DataImportEventPayload eventPayload = new DataImportEventPayload().withCurrentNode(new ProfileSnapshotWrapper().withContentType(MAPPING_PROFILE));
assertFalse(eventHandler.isEligible(eventPayload));
}
use of org.folio.DataImportEventPayload in project mod-inventory by folio-org.
the class MatchItemEventHandlerUnitTest method shouldPutMultipleMatchResultToPayloadOnHandleEventPayload.
@Test
public void shouldPutMultipleMatchResultToPayloadOnHandleEventPayload(TestContext testContext) throws UnsupportedEncodingException {
Async async = testContext.async();
List<Item> matchedItems = List.of(new Item(ITEM_ID, "1", HOLDING_ID, new Status(ItemStatusName.AVAILABLE), UUID.randomUUID().toString(), UUID.randomUUID().toString(), new JsonObject()), new Item(UUID.randomUUID().toString(), "1", HOLDING_ID, new Status(ItemStatusName.AVAILABLE), UUID.randomUUID().toString(), UUID.randomUUID().toString(), new JsonObject()));
doAnswer(invocation -> {
Consumer<Success<MultipleRecords<Item>>> callback = invocation.getArgument(2);
Success<MultipleRecords<Item>> result = new Success<>(new MultipleRecords<>(matchedItems, 2));
callback.accept(result);
return null;
}).when(itemCollection).findByCql(eq(format("hrid == \"%s\"", ITEM_HRID)), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
EventHandler eventHandler = new MatchItemEventHandler(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(new MatchProfile().withExistingRecordType(ITEM).withIncomingRecordType(MARC_BIBLIOGRAPHIC)).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_ITEM_MATCHED.value(), processedPayload.getEventType());
assertThat(new JsonArray(processedPayload.getContext().get(MULTI_MATCH_IDS)), hasItems(matchedItems.get(0).getId(), matchedItems.get(1).getId()));
async.complete();
}));
}
use of org.folio.DataImportEventPayload in project mod-inventory by folio-org.
the class CreateInstanceEventHandlerTest method shouldNotProcessEventIfContextIsEmpty.
@Test(expected = ExecutionException.class)
public void shouldNotProcessEventIfContextIsEmpty() throws InterruptedException, ExecutionException, TimeoutException {
Reader fakeReader = Mockito.mock(Reader.class);
String instanceTypeId = UUID.randomUUID().toString();
String title = "titleValue";
when(fakeReader.read(any(MappingRule.class))).thenReturn(StringValue.of(instanceTypeId), StringValue.of(title));
when(fakeReaderFactory.createReader()).thenReturn(fakeReader);
when(storage.getInstanceCollection(any())).thenReturn(instanceRecordCollection);
MappingManager.registerReaderFactory(fakeReaderFactory);
MappingManager.registerWriterFactory(new InstanceWriterFactory());
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_INVENTORY_INSTANCE_CREATED.value()).withContext(new HashMap<>()).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0)).withTenant(TENANT_ID).withOkapiUrl(mockServer.baseUrl()).withToken(TOKEN).withJobExecutionId(UUID.randomUUID().toString());
CompletableFuture<DataImportEventPayload> future = createInstanceEventHandler.handle(dataImportEventPayload);
future.get(5, TimeUnit.MILLISECONDS);
}
use of org.folio.DataImportEventPayload in project mod-inventory by folio-org.
the class CreateInstanceEventHandlerTest method shouldReturnFailedFutureIfCurrentActionProfileHasNoMappingProfile.
@Test
public void shouldReturnFailedFutureIfCurrentActionProfileHasNoMappingProfile() {
HashMap<String, String> context = new HashMap<>();
context.put(MARC_BIBLIOGRAPHIC.value(), Json.encode(new Record().withParsedRecord(new ParsedRecord().withContent(PARSED_CONTENT))));
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_SRS_MARC_BIB_RECORD_CREATED.value()).withContext(context).withCurrentNode(new ProfileSnapshotWrapper().withContentType(ACTION_PROFILE).withContent(actionProfile));
CompletableFuture<DataImportEventPayload> future = createInstanceEventHandler.handle(dataImportEventPayload);
ExecutionException exception = Assert.assertThrows(ExecutionException.class, future::get);
Assert.assertEquals("Action profile to create an Instance requires a mapping profile by jobExecutionId: 'null' and recordId: 'null'", exception.getCause().getMessage());
}
use of org.folio.DataImportEventPayload in project mod-inventory by folio-org.
the class CreateInstanceEventHandlerTest method shouldNotProcessEventIfMArcBibliographicIsNotExistsInContext.
@Test(expected = ExecutionException.class)
public void shouldNotProcessEventIfMArcBibliographicIsNotExistsInContext() throws InterruptedException, ExecutionException, TimeoutException {
Reader fakeReader = Mockito.mock(Reader.class);
String instanceTypeId = UUID.randomUUID().toString();
String title = "titleValue";
when(fakeReader.read(any(MappingRule.class))).thenReturn(StringValue.of(instanceTypeId), StringValue.of(title));
when(fakeReaderFactory.createReader()).thenReturn(fakeReader);
when(storage.getInstanceCollection(any())).thenReturn(instanceRecordCollection);
MappingManager.registerReaderFactory(fakeReaderFactory);
MappingManager.registerWriterFactory(new InstanceWriterFactory());
HashMap<String, String> context = new HashMap<>();
context.put("InvalidField", Json.encode(new Record()));
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_INVENTORY_INSTANCE_CREATED.value()).withContext(context).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0)).withTenant(TENANT_ID).withOkapiUrl(mockServer.baseUrl()).withToken(TOKEN).withJobExecutionId(UUID.randomUUID().toString());
CompletableFuture<DataImportEventPayload> future = createInstanceEventHandler.handle(dataImportEventPayload);
future.get(5, TimeUnit.MILLISECONDS);
}
Aggregations