use of org.folio.HoldingsRecord in project mod-inventory by folio-org.
the class UpdateHoldingEventHandlerTest method shouldProcessEvent.
@Test
public void shouldProcessEvent() 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 instanceId = String.valueOf(UUID.randomUUID());
String holdingId = UUID.randomUUID().toString();
String hrid = UUID.randomUUID().toString();
HoldingsRecord holdingsRecord = new HoldingsRecord().withId(holdingId).withInstanceId(instanceId).withHrid(hrid).withPermanentLocationId(permanentLocationId);
Record record = new Record().withParsedRecord(new ParsedRecord().withContent(PARSED_CONTENT_WITH_INSTANCE_ID));
HashMap<String, String> context = new HashMap<>();
context.put(HOLDINGS.value(), Json.encode(holdingsRecord));
context.put(MARC_BIBLIOGRAPHIC.value(), Json.encode(record));
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_INVENTORY_HOLDING_UPDATED.value()).withJobExecutionId(UUID.randomUUID().toString()).withContext(context).withProfileSnapshot(profileSnapshotWrapper).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0));
CompletableFuture<DataImportEventPayload> future = updateHoldingEventHandler.handle(dataImportEventPayload);
DataImportEventPayload actualDataImportEventPayload = future.get(5, TimeUnit.MILLISECONDS);
Assert.assertEquals(DI_INVENTORY_HOLDING_UPDATED.value(), actualDataImportEventPayload.getEventType());
Assert.assertNotNull(actualDataImportEventPayload.getContext().get(HOLDINGS.value()));
Assert.assertNotNull(new JsonObject(actualDataImportEventPayload.getContext().get(HOLDINGS.value())).getString("id"));
Assert.assertEquals(instanceId, new JsonObject(actualDataImportEventPayload.getContext().get(HOLDINGS.value())).getString("instanceId"));
Assert.assertEquals(permanentLocationId, new JsonObject(actualDataImportEventPayload.getContext().get(HOLDINGS.value())).getString("permanentLocationId"));
Assert.assertEquals(hrid, new JsonObject(actualDataImportEventPayload.getContext().get(HOLDINGS.value())).getString("hrid"));
Assert.assertEquals(holdingId, new JsonObject(actualDataImportEventPayload.getContext().get(HOLDINGS.value())).getString("id"));
}
use of org.folio.HoldingsRecord in project mod-inventory by folio-org.
the class UpdateHoldingEventHandlerTest method shouldNotProcessEventIfInstanceIdIsNotExistsInContext.
@Test(expected = ExecutionException.class)
public void shouldNotProcessEventIfInstanceIdIsNotExistsInContext() throws InterruptedException, ExecutionException, TimeoutException {
Reader fakeReader = 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 holdingId = UUID.randomUUID().toString();
String hrid = UUID.randomUUID().toString();
HoldingsRecord holdingsRecord = new HoldingsRecord().withId(holdingId).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);
}
use of org.folio.HoldingsRecord in project mod-inventory by folio-org.
the class UpdateHoldingEventHandlerTest method shouldNotProcessEventIfPermanentLocationIdIsNotExistsInContext.
@Test(expected = ExecutionException.class)
public void shouldNotProcessEventIfPermanentLocationIdIsNotExistsInContext() throws InterruptedException, ExecutionException, TimeoutException {
Reader fakeReader = 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 holdingId = UUID.randomUUID().toString();
String hrid = UUID.randomUUID().toString();
String instanceId = String.valueOf(UUID.randomUUID());
HoldingsRecord holdingsRecord = new HoldingsRecord().withId(holdingId).withHrid(hrid).withInstanceId(instanceId);
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);
}
use of org.folio.HoldingsRecord in project mod-inventory by folio-org.
the class UpdateHoldingEventHandlerTest method shouldReturnFailedFutureIfCurrentActionProfileHasNoMappingProfile.
@Test
public void shouldReturnFailedFutureIfCurrentActionProfileHasNoMappingProfile() {
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(new HoldingsRecord()));
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_INVENTORY_HOLDING_MATCHED.value()).withContext(context).withCurrentNode(new ProfileSnapshotWrapper().withContent(JsonObject.mapFrom(actionProfile).getMap()).withContentType(ACTION_PROFILE));
CompletableFuture<DataImportEventPayload> future = updateHoldingEventHandler.handle(dataImportEventPayload);
ExecutionException exception = Assert.assertThrows(ExecutionException.class, future::get);
Assert.assertEquals(ACTION_HAS_NO_MAPPING_MSG, exception.getCause().getMessage());
}
use of org.folio.HoldingsRecord in project mod-inventory by folio-org.
the class QuickMarcKafkaHandlerTest method setUp.
@Before
public void setUp() throws IOException {
bibMappingRules = new JsonObject(TestUtil.readFileFromPath(BIB_MAPPING_RULES_PATH));
holdingsMappingRules = new JsonObject(TestUtil.readFileFromPath(HOLDINGS_MAPPING_RULES_PATH));
authorityMappingRules = new JsonObject(TestUtil.readFileFromPath(AUTHORITY_MAPPING_RULES_PATH));
existingInstance = Instance.fromJson(new JsonObject(TestUtil.readFileFromPath(INSTANCE_PATH)));
existingHoldings = new JsonObject(TestUtil.readFileFromPath(HOLDINGS_PATH)).mapTo(HoldingsRecord.class);
existingAuthority = new JsonObject(TestUtil.readFileFromPath(AUTHORITY_PATH)).mapTo(Authority.class);
bibRecord = Json.decodeValue(TestUtil.readFileFromPath(BIB_RECORD_PATH), Record.class);
bibRecord.getParsedRecord().withContent(JsonObject.mapFrom(bibRecord.getParsedRecord().getContent()).encode());
holdingsRecord = Json.decodeValue(TestUtil.readFileFromPath(HOLDINGS_RECORD_PATH), Record.class);
holdingsRecord.getParsedRecord().withContent(JsonObject.mapFrom(holdingsRecord.getParsedRecord().getContent()).encode());
authorityRecord = Json.decodeValue(TestUtil.readFileFromPath(AUTHORITY_RECORD_PATH), Record.class);
authorityRecord.getParsedRecord().withContent(JsonObject.mapFrom(authorityRecord.getParsedRecord().getContent()).encode());
mocks = MockitoAnnotations.openMocks(this);
when(mockedStorage.getInstanceCollection(any(Context.class))).thenReturn(mockedInstanceCollection);
when(mockedStorage.getHoldingsRecordCollection(any(Context.class))).thenReturn(mockedHoldingsRecordCollection);
when(mockedStorage.getAuthorityRecordCollection(any(Context.class))).thenReturn(mockedAuthorityRecordCollection);
doAnswer(invocationOnMock -> {
Consumer<Success<Instance>> successHandler = invocationOnMock.getArgument(1);
successHandler.accept(new Success<>(existingInstance));
return null;
}).when(mockedInstanceCollection).findById(anyString(), any(), any());
doAnswer(invocationOnMock -> {
Consumer<Success<HoldingsRecord>> successHandler = invocationOnMock.getArgument(1);
successHandler.accept(new Success<>(existingHoldings));
return null;
}).when(mockedHoldingsRecordCollection).findById(anyString(), any(), any());
doAnswer(invocationOnMock -> {
Instance instance = invocationOnMock.getArgument(0);
Consumer<Success<Instance>> successHandler = invocationOnMock.getArgument(1);
successHandler.accept(new Success<>(instance));
return null;
}).when(mockedInstanceCollection).update(any(Instance.class), any(), any());
doAnswer(invocationOnMock -> {
HoldingsRecord instance = invocationOnMock.getArgument(0);
Consumer<Success<HoldingsRecord>> successHandler = invocationOnMock.getArgument(1);
successHandler.accept(new Success<>(instance));
return null;
}).when(mockedHoldingsRecordCollection).update(any(HoldingsRecord.class), any(), any());
doAnswer(invocationOnMock -> {
Authority authority = invocationOnMock.getArgument(0);
Consumer<Success<Authority>> successHandler = invocationOnMock.getArgument(1);
successHandler.accept(new Success<>(authority));
return null;
}).when(mockedAuthorityRecordCollection).update(any(Authority.class), any(), any());
when(okapiHttpClient.get(anyString())).thenReturn(CompletableFuture.completedFuture(new Response(200, new JsonObject().encode(), null, null)));
when(okapiHttpClient.put(anyString(), any(JsonObject.class))).thenReturn(CompletableFuture.completedFuture(new Response(204, null, null, null)));
String[] hostAndPort = cluster.getBrokerList().split(":");
kafkaConfig = KafkaConfig.builder().envId("env").kafkaHost(hostAndPort[0]).kafkaPort(hostAndPort[1]).maxRequestSize(1048576).build();
PrecedingSucceedingTitlesHelper precedingSucceedingTitlesHelper = new PrecedingSucceedingTitlesHelper(context -> okapiHttpClient);
handler = new QuickMarcKafkaHandler(vertx, mockedStorage, 100, kafkaConfig, precedingSucceedingTitlesHelper);
when(kafkaRecord.headers()).thenReturn(List.of(KafkaHeader.header(XOkapiHeaders.TENANT.toLowerCase(), TENANT_ID), KafkaHeader.header(XOkapiHeaders.URL.toLowerCase(), OKAPI_URL)));
}
Aggregations