use of org.folio.rest.jaxrs.model.EntityType.INSTANCE 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.rest.jaxrs.model.EntityType.INSTANCE in project mod-inventory by folio-org.
the class MarcBibModifiedPostProcessingEventHandlerTest method shouldUpdateInstance.
@Test
public void shouldUpdateInstance() throws InterruptedException, ExecutionException, TimeoutException {
// given
HashMap<String, String> payloadContext = new HashMap<>();
payloadContext.put(MARC_BIBLIOGRAPHIC.value(), Json.encode(record));
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_SRS_MARC_BIB_RECORD_MODIFIED_READY_FOR_POST_PROCESSING.value()).withJobExecutionId(UUID.randomUUID().toString()).withContext(payloadContext).withOkapiUrl(OKAPI_URL).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0));
// when
CompletableFuture<DataImportEventPayload> future = marcBibModifiedEventHandler.handle(dataImportEventPayload);
DataImportEventPayload eventPayload = future.get(5, TimeUnit.SECONDS);
JsonObject instanceJson = new JsonObject(eventPayload.getContext().get(INSTANCE.value()));
Instance updatedInstance = Instance.fromJson(instanceJson);
// then
Assert.assertEquals(existingInstance.getId(), instanceJson.getString("id"));
Assert.assertEquals("Victorian environmental nightmares and something else/", updatedInstance.getIndexTitle());
Assert.assertNotNull(updatedInstance.getIdentifiers().stream().filter(i -> "(OCoLC)1060180367".equals(i.value)).findFirst().get());
Assert.assertNotNull(updatedInstance.getContributors().stream().filter(c -> "Mazzeno, Laurence W., 1234566".equals(c.name)).findFirst().get());
Assert.assertEquals("b5968c9e-cddc-4576-99e3-8e60aed8b0dd", updatedInstance.getStatisticalCodeIds().get(0));
Assert.assertEquals("b5968c9e-cddc-4576-99e3-8e60aed8b0cf", updatedInstance.getNatureOfContentTermIds().get(0));
Assert.assertNotNull(updatedInstance.getSubjects());
Assert.assertEquals(1, updatedInstance.getSubjects().size());
Assert.assertTrue(updatedInstance.getSubjects().get(0).contains("additional subfield"));
Assert.assertFalse(updatedInstance.getSubjects().get(0).contains("Environmentalism in literature"));
Assert.assertNotNull(updatedInstance.getNotes());
Assert.assertEquals("Adding a note", updatedInstance.getNotes().get(0).note);
}
Aggregations