use of org.folio.rest.jaxrs.model.Record in project mod-inventory by folio-org.
the class CreateHoldingEventHandlerTest method shouldProcessEvent.
@Test
public void shouldProcessEvent() throws IOException, 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());
Instance instance = new Instance(instanceId, "5", String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()));
Record record = new Record().withParsedRecord(new ParsedRecord().withContent(PARSED_CONTENT_WITH_INSTANCE_ID));
HashMap<String, String> context = new HashMap<>();
context.put("INSTANCE", new JsonObject(new ObjectMapper().writer().withDefaultPrettyPrinter().writeValueAsString(instance)).encode());
context.put(MARC_BIBLIOGRAPHIC.value(), Json.encode(record));
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_INVENTORY_HOLDING_CREATED.value()).withJobExecutionId(UUID.randomUUID().toString()).withContext(context).withProfileSnapshot(profileSnapshotWrapper).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0));
CompletableFuture<DataImportEventPayload> future = createHoldingEventHandler.handle(dataImportEventPayload);
DataImportEventPayload actualDataImportEventPayload = future.get(5, TimeUnit.MILLISECONDS);
Assert.assertEquals(DI_INVENTORY_HOLDING_CREATED.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(FOLIO_SOURCE_ID, new JsonObject(actualDataImportEventPayload.getContext().get(HOLDINGS.value())).getString("sourceId"));
}
use of org.folio.rest.jaxrs.model.Record in project mod-inventory by folio-org.
the class CreateHoldingEventHandlerTest method shouldNotProcessEventIfPermanentLocationIdIsNotExistsInContext.
@Test(expected = ExecutionException.class)
public void shouldNotProcessEventIfPermanentLocationIdIsNotExistsInContext() throws IOException, InterruptedException, ExecutionException, TimeoutException {
Reader fakeReader = Mockito.mock(Reader.class);
when(fakeReader.read(any(MappingRule.class))).thenReturn(StringValue.of(""));
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, "8", String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()));
Record record = new Record().withParsedRecord(new ParsedRecord().withContent(PARSED_CONTENT_WITH_INSTANCE_ID));
HashMap<String, String> context = new HashMap<>();
context.put("INSTANCE", new JsonObject(new ObjectMapper().writer().withDefaultPrettyPrinter().writeValueAsString(instance)).encode());
context.put(MARC_BIBLIOGRAPHIC.value(), Json.encode(record));
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_INVENTORY_HOLDING_CREATED.value()).withJobExecutionId(UUID.randomUUID().toString()).withContext(context).withProfileSnapshot(profileSnapshotWrapper).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0));
CompletableFuture<DataImportEventPayload> future = createHoldingEventHandler.handle(dataImportEventPayload);
future.get(5, TimeUnit.MILLISECONDS);
}
use of org.folio.rest.jaxrs.model.Record in project mod-inventory by folio-org.
the class CreateHoldingEventHandlerTest method shouldNotProcessEventWhenRecordToHoldingsFutureFails.
@Test(expected = ExecutionException.class)
public void shouldNotProcessEventWhenRecordToHoldingsFutureFails() throws ExecutionException, InterruptedException, TimeoutException, UnsupportedEncodingException {
when(holdingsIdStorageService.store(any(), any(), any())).thenReturn(Future.failedFuture(new RuntimeException("Something wrong with database!")));
String expectedHoldingId = UUID.randomUUID().toString();
JsonObject holdingAsJson = new JsonObject().put("id", expectedHoldingId);
HashMap<String, String> payloadContext = new HashMap<>();
payloadContext.put(EntityType.MARC_BIBLIOGRAPHIC.value(), Json.encode(new Record()));
payloadContext.put(EntityType.HOLDINGS.value(), holdingAsJson.encode());
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_SRS_MARC_BIB_RECORD_CREATED.value()).withJobExecutionId(UUID.randomUUID().toString()).withContext(payloadContext).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0));
CompletableFuture<DataImportEventPayload> future = createHoldingEventHandler.handle(dataImportEventPayload);
future.get(5, TimeUnit.SECONDS);
}
use of org.folio.rest.jaxrs.model.Record in project mod-inventory by folio-org.
the class CreateHoldingEventHandlerTest method shouldProcessEventIfInstanceIdIsEmptyInInstanceInContextButExistsInMarcBibliographicParsedRecords.
@Test
public void shouldProcessEventIfInstanceIdIsEmptyInInstanceInContextButExistsInMarcBibliographicParsedRecords() 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());
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()).withJobExecutionId(UUID.randomUUID().toString()).withContext(context).withProfileSnapshot(profileSnapshotWrapper).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0));
CompletableFuture<DataImportEventPayload> future = createHoldingEventHandler.handle(dataImportEventPayload);
DataImportEventPayload actualDataImportEventPayload = future.get(5, TimeUnit.MILLISECONDS);
Assert.assertEquals(DI_INVENTORY_HOLDING_CREATED.value(), actualDataImportEventPayload.getEventType());
Assert.assertNotNull(actualDataImportEventPayload.getContext().get(HOLDINGS.value()));
Assert.assertNotNull(new JsonObject(actualDataImportEventPayload.getContext().get(HOLDINGS.value())).getString("id"));
Assert.assertEquals(permanentLocationId, new JsonObject(actualDataImportEventPayload.getContext().get(HOLDINGS.value())).getString("permanentLocationId"));
Assert.assertEquals(FOLIO_SOURCE_ID, new JsonObject(actualDataImportEventPayload.getContext().get(HOLDINGS.value())).getString("sourceId"));
}
use of org.folio.rest.jaxrs.model.Record in project mod-inventory by folio-org.
the class CreateMarcHoldingsEventHandlerTest method shouldThrowExceptionIfChildSnapshotWrappersIsEmpty.
@Test(expected = ExecutionException.class)
public void shouldThrowExceptionIfChildSnapshotWrappersIsEmpty() throws ExecutionException, InterruptedException, TimeoutException, IOException {
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(MARC_HOLDINGS.value(), Json.encode(record));
profileSnapshotWrapper = new ProfileSnapshotWrapper().withId(UUID.randomUUID().toString()).withProfileId(jobProfile.getId()).withContentType(JOB_PROFILE).withContent(jobProfile).withChildSnapshotWrappers(Collections.emptyList());
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_SRS_MARC_HOLDING_RECORD_CREATED.value()).withContext(context).withCurrentNode(profileSnapshotWrapper);
CompletableFuture<DataImportEventPayload> future = createMarcHoldingsEventHandler.handle(dataImportEventPayload);
future.get(10000, TimeUnit.MILLISECONDS);
}
Aggregations