use of org.folio.rest.jaxrs.model.ProfileSnapshotWrapper in project mod-inventory by folio-org.
the class MatchHoldingEventHandlerUnitTest 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.rest.jaxrs.model.ProfileSnapshotWrapper in project mod-inventory by folio-org.
the class MatchHoldingEventHandlerUnitTest method shouldPutMultipleMatchResultToPayloadOnHandleEventPayload.
@Test
public void shouldPutMultipleMatchResultToPayloadOnHandleEventPayload(TestContext testContext) throws UnsupportedEncodingException {
Async async = testContext.async();
List<HoldingsRecord> matchedHoldings = List.of(new HoldingsRecord().withId(HOLDING_ID), new HoldingsRecord().withId(UUID.randomUUID().toString()));
doAnswer(invocation -> {
Consumer<Success<MultipleRecords<HoldingsRecord>>> successHandler = invocation.getArgument(2);
Success<MultipleRecords<HoldingsRecord>> result = new Success<>(new MultipleRecords<>(matchedHoldings, 2));
successHandler.accept(result);
return null;
}).when(holdingCollection).findByCql(eq(format("hrid == \"%s\"", HOLDING_HRID)), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
EventHandler eventHandler = new MatchHoldingEventHandler(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(HOLDINGS).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_HOLDING_MATCHED.value(), processedPayload.getEventType());
assertThat(new JsonArray(processedPayload.getContext().get(MULTI_MATCH_IDS)), hasItems(matchedHoldings.get(0).getId(), matchedHoldings.get(1).getId()));
async.complete();
}));
}
use of org.folio.rest.jaxrs.model.ProfileSnapshotWrapper in project mod-inventory by folio-org.
the class CreateAuthorityEventHandlerTest method isEligibleShouldReturnFalseIfCurrentNodeIsNotActionProfile.
@Test
public void isEligibleShouldReturnFalseIfCurrentNodeIsNotActionProfile() {
ProfileSnapshotWrapper profileSnapshotWrapper = new ProfileSnapshotWrapper().withId(UUID.randomUUID().toString()).withProfileId(jobProfile.getId()).withContentType(JOB_PROFILE).withContent(jobProfile);
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_SRS_MARC_AUTHORITY_RECORD_CREATED.value()).withContext(new HashMap<>()).withCurrentNode(profileSnapshotWrapper);
assertFalse(createMarcAuthoritiesEventHandler.isEligible(dataImportEventPayload));
}
use of org.folio.rest.jaxrs.model.ProfileSnapshotWrapper in project mod-inventory by folio-org.
the class CreateHoldingEventHandlerTest method shouldReturnFailedFutureIfCurrentActionProfileHasNoMappingProfile.
@Test
public void shouldReturnFailedFutureIfCurrentActionProfileHasNoMappingProfile() {
Record record = new Record().withParsedRecord(new ParsedRecord().withContent(PARSED_CONTENT_WITH_INSTANCE_ID));
HashMap<String, String> context = new HashMap<>();
context.put(MARC_BIBLIOGRAPHIC.value(), Json.encode(record));
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_INVENTORY_HOLDING_CREATED.value()).withContext(context).withCurrentNode(new ProfileSnapshotWrapper().withContent(JsonObject.mapFrom(mappingProfile).getMap()).withContentType(ACTION_PROFILE));
CompletableFuture<DataImportEventPayload> future = createHoldingEventHandler.handle(dataImportEventPayload);
ExecutionException exception = Assert.assertThrows(ExecutionException.class, future::get);
Assert.assertEquals(ACTION_HAS_NO_MAPPING_MSG, exception.getCause().getMessage());
}
use of org.folio.rest.jaxrs.model.ProfileSnapshotWrapper in project mod-inventory by folio-org.
the class CreateHoldingEventHandlerTest method shouldNotProcessEventIfHoldingRecordIsInvalid.
@Test(expected = ExecutionException.class)
public void shouldNotProcessEventIfHoldingRecordIsInvalid() throws IOException, InterruptedException, ExecutionException, TimeoutException {
Reader fakeReader = Mockito.mock(Reader.class);
MappingProfile mappingProfile = new MappingProfile().withId(UUID.randomUUID().toString()).withName("Prelim item from MARC").withIncomingRecordType(EntityType.MARC_BIBLIOGRAPHIC).withExistingRecordType(EntityType.HOLDINGS).withMappingDetails(new MappingDetail().withMappingFields(Lists.newArrayList(new MappingRule().withPath("permanentLocationId").withValue("permanentLocationExpression"), new MappingRule().withPath("invalidField").withValue("invalidFieldValue"))));
ProfileSnapshotWrapper profileSnapshotWrapper = new ProfileSnapshotWrapper().withId(UUID.randomUUID().toString()).withProfileId(jobProfile.getId()).withContentType(JOB_PROFILE).withContent(jobProfile).withChildSnapshotWrappers(Collections.singletonList(new ProfileSnapshotWrapper().withProfileId(actionProfile.getId()).withContentType(ACTION_PROFILE).withContent(actionProfile).withChildSnapshotWrappers(Collections.singletonList(new ProfileSnapshotWrapper().withProfileId(mappingProfile.getId()).withContentType(MAPPING_PROFILE).withContent(JsonObject.mapFrom(mappingProfile).getMap())))));
when(fakeReader.read(any(MappingRule.class))).thenReturn(StringValue.of(UUID.randomUUID().toString()), StringValue.of(UUID.randomUUID().toString()));
when(fakeReaderFactory.createReader()).thenReturn(fakeReader);
when(storage.getHoldingsRecordCollection(any())).thenReturn(holdingsRecordsCollection);
MappingManager.registerReaderFactory(fakeReaderFactory);
MappingManager.registerWriterFactory(new HoldingWriterFactory());
String instanceId = String.valueOf(UUID.randomUUID());
Instance instance = new Instance(instanceId, "7", String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()));
HashMap<String, String> context = new HashMap<>();
context.put("INSTANCE", new JsonObject(new ObjectMapper().writer().withDefaultPrettyPrinter().writeValueAsString(instance)).encode());
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_INVENTORY_HOLDING_CREATED.value()).withContext(context).withProfileSnapshot(profileSnapshotWrapper).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0));
CompletableFuture<DataImportEventPayload> future = createHoldingEventHandler.handle(dataImportEventPayload);
future.get(5, TimeUnit.MILLISECONDS);
}
Aggregations