use of org.folio.HoldingsRecord in project mod-inventory by folio-org.
the class MatchHoldingEventHandlerUnitTest method shouldFailOnHandleEventPayloadIfMatchedMultipleHoldings.
@Test
public void shouldFailOnHandleEventPayloadIfMatchedMultipleHoldings(TestContext testContext) throws UnsupportedEncodingException {
Async async = testContext.async();
doAnswer(ans -> {
Consumer<Success<MultipleRecords<HoldingsRecord>>> callback = ans.getArgument(2);
Success<MultipleRecords<HoldingsRecord>> result = new Success<>(new MultipleRecords<>(asList(createHolding(), createHolding()), 2));
callback.accept(result);
return null;
}).when(holdingCollection).findByCql(anyString(), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
EventHandler eventHandler = new MatchHoldingEventHandler(mappingMetadataCache);
DataImportEventPayload eventPayload = createEventPayload();
eventHandler.handle(eventPayload).whenComplete((updatedEventPayload, throwable) -> {
testContext.assertNotNull(throwable);
async.complete();
});
}
use of org.folio.HoldingsRecord 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.HoldingsRecord in project mod-inventory by folio-org.
the class CreateHoldingEventHandlerTest method setUp.
@Before
public void setUp() throws UnsupportedEncodingException {
MockitoAnnotations.initMocks(this);
MappingManager.clearReaderFactories();
createHoldingEventHandler = new CreateHoldingEventHandler(storage, mappingMetadataCache, holdingsIdStorageService);
doAnswer(invocationOnMock -> {
MultipleRecords result = new MultipleRecords<>(new ArrayList<>(), 0);
Consumer<Success<MultipleRecords>> successHandler = invocationOnMock.getArgument(2);
successHandler.accept(new Success<>(result));
return null;
}).when(holdingsRecordsCollection).findByCql(anyString(), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
doAnswer(invocationOnMock -> {
HoldingsRecord holdingsRecord = invocationOnMock.getArgument(0);
Consumer<Success<HoldingsRecord>> successHandler = invocationOnMock.getArgument(1);
successHandler.accept(new Success<>(holdingsRecord));
return null;
}).when(holdingsRecordsCollection).add(any(), any(Consumer.class), any(Consumer.class));
doAnswer(invocationOnMock -> {
RecordToEntity recordToItem = RecordToEntity.builder().recordId(RECORD_ID).entityId(ITEM_ID).build();
return Future.succeededFuture(recordToItem);
}).when(holdingsIdStorageService).store(any(), any(), any());
when(mappingMetadataCache.get(anyString(), any(Context.class))).thenReturn(Future.succeededFuture(Optional.of(new MappingMetadataDto().withMappingRules(new JsonObject().encode()).withMappingParams(Json.encode(new MappingParameters())))));
}
use of org.folio.HoldingsRecord in project mod-inventory by folio-org.
the class CreateMarcHoldingsEventHandlerTest method shouldNotProcessEventIfInstanceNotFoundByMarcHoldingsHrid.
@Test
public void shouldNotProcessEventIfInstanceNotFoundByMarcHoldingsHrid() throws IOException {
doAnswer(invocationOnMock -> {
MultipleRecords<Instance> result = new MultipleRecords<>(new ArrayList<>(), 1);
Consumer<Success<MultipleRecords<Instance>>> successHandler = invocationOnMock.getArgument(2);
successHandler.accept(new Success<>(result));
return null;
}).when(instanceRecordCollection).findByCql(anyString(), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
when(storage.getHoldingsRecordCollection(any())).thenReturn(holdingsRecordsCollection);
when(storage.getInstanceCollection(any())).thenReturn(instanceRecordCollection);
HoldingsRecord holdings = new HoldingsRecord().withId(String.valueOf(UUID.randomUUID())).withHrid(String.valueOf(UUID.randomUUID())).withInstanceId(String.valueOf(UUID.randomUUID())).withSourceId(String.valueOf(UUID.randomUUID())).withHoldingsTypeId(String.valueOf(UUID.randomUUID())).withPermanentLocationId(PERMANENT_LOCATION_ID);
var parsedHoldingsRecord = new JsonObject(TestUtil.readFileFromPath(PARSED_HOLDINGS_RECORD));
Record record = new Record().withParsedRecord(new ParsedRecord().withContent(parsedHoldingsRecord.encode()));
HashMap<String, String> context = new HashMap<>();
context.put("HOLDINGS", new JsonObject(new ObjectMapper().writer().withDefaultPrettyPrinter().writeValueAsString(holdings)).encode());
context.put(MARC_HOLDINGS.value(), Json.encode(record));
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_SRS_MARC_HOLDING_RECORD_CREATED.value()).withJobExecutionId(UUID.randomUUID().toString()).withOkapiUrl(mockServer.baseUrl()).withContext(context).withProfileSnapshot(profileSnapshotWrapper).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0));
CompletableFuture<DataImportEventPayload> future = createMarcHoldingsEventHandler.handle(dataImportEventPayload);
ExecutionException exception = Assert.assertThrows(ExecutionException.class, future::get);
Assert.assertEquals("No instance id found for marc holdings with hrid: in00000000315", exception.getCause().getMessage());
}
use of org.folio.HoldingsRecord in project mod-inventory by folio-org.
the class UpdateHoldingEventHandlerTest method shouldNotProcessEventIfHoldingIdIsNotExistsInContext.
@Test(expected = ExecutionException.class)
public void shouldNotProcessEventIfHoldingIdIsNotExistsInContext() throws InterruptedException, ExecutionException, TimeoutException {
Reader fakeReader = Mockito.mock(Reader.class);
String permanentLocationId = UUID.randomUUID().toString();
when(fakeReader.read(any(MappingRule.class))).thenReturn(StringValue.of(permanentLocationId));
when(fakeReaderFactory.createReader()).thenReturn(fakeReader);
when(storage.getHoldingsRecordCollection(any())).thenReturn(holdingsRecordsCollection);
MappingManager.registerReaderFactory(fakeReaderFactory);
MappingManager.registerWriterFactory(new HoldingWriterFactory());
String hrid = UUID.randomUUID().toString();
String instanceId = String.valueOf(UUID.randomUUID());
HoldingsRecord holdingsRecord = new HoldingsRecord().withInstanceId(instanceId).withHrid(hrid).withPermanentLocationId(permanentLocationId);
HashMap<String, String> context = new HashMap<>();
Record record = new Record().withParsedRecord(new ParsedRecord().withContent(PARSED_CONTENT_WITH_INSTANCE_ID));
context.put(MARC_BIBLIOGRAPHIC.value(), Json.encode(record));
context.put(HOLDINGS.value(), Json.encode(holdingsRecord));
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_INVENTORY_HOLDING_UPDATED.value()).withContext(context).withProfileSnapshot(profileSnapshotWrapper).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0));
CompletableFuture<DataImportEventPayload> future = updateHoldingEventHandler.handle(dataImportEventPayload);
future.get(5, TimeUnit.MILLISECONDS);
}
Aggregations