use of org.folio.MappingMetadataDto in project mod-inventory by folio-org.
the class MarcBibInstanceHridSetKafkaHandlerTest method setUp.
@Before
public void setUp() throws IOException {
mappingRules = new JsonObject(TestUtil.readFileFromPath(MAPPING_RULES_PATH));
existingInstance = Instance.fromJson(new JsonObject(TestUtil.readFileFromPath(INSTANCE_PATH)));
record = Json.decodeValue(TestUtil.readFileFromPath(RECORD_PATH), Record.class);
record.getParsedRecord().withContent(JsonObject.mapFrom(record.getParsedRecord().getContent()).encode());
mocks = MockitoAnnotations.openMocks(this);
when(mockedStorage.getInstanceCollection(any(Context.class))).thenReturn(mockedInstanceCollection);
doAnswer(invocationOnMock -> {
Consumer<Success<Instance>> successHandler = invocationOnMock.getArgument(1);
successHandler.accept(new Success<>(existingInstance));
return null;
}).when(mockedInstanceCollection).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());
Mockito.when(mappingMetadataCache.get(anyString(), any(Context.class))).thenReturn(Future.succeededFuture(Optional.of(new MappingMetadataDto().withMappingRules(mappingRules.encode()).withMappingParams(Json.encode(new MappingParameters())))));
marcBibInstanceHridSetKafkaHandler = new MarcBibInstanceHridSetKafkaHandler(new InstanceUpdateDelegate(mockedStorage), mappingMetadataCache);
}
use of org.folio.MappingMetadataDto in project mod-inventory by folio-org.
the class MarcHoldingsRecordHridSetKafkaHandlerTest method setUp.
@Before
public void setUp() throws IOException {
mappingRules = new JsonObject(TestUtil.readFileFromPath(MAPPING_RULES_PATH));
existingHoldingsRecord = new JsonObject(TestUtil.readFileFromPath(HOLDINGS_PATH)).mapTo(HoldingsRecord.class);
record = Json.decodeValue(TestUtil.readFileFromPath(RECORD_PATH), Record.class);
record.getParsedRecord().withContent(JsonObject.mapFrom(record.getParsedRecord().getContent()).encode());
mocks = MockitoAnnotations.openMocks(this);
when(mockedStorage.getHoldingsRecordCollection(any(Context.class))).thenReturn(mockedHoldingsCollection);
doAnswer(invocationOnMock -> {
Consumer<Success<HoldingsRecord>> successHandler = invocationOnMock.getArgument(1);
successHandler.accept(new Success<>(existingHoldingsRecord));
return null;
}).when(mockedHoldingsCollection).findById(anyString(), any(), any());
doAnswer(invocationOnMock -> {
HoldingsRecord holdingsRecord = invocationOnMock.getArgument(0);
Consumer<Success<HoldingsRecord>> successHandler = invocationOnMock.getArgument(1);
successHandler.accept(new Success<>(holdingsRecord));
return null;
}).when(mockedHoldingsCollection).update(any(HoldingsRecord.class), any(), any());
List<HoldingsType> holdings = new ArrayList<>();
holdings.add(new HoldingsType().withName("testingnote$a").withId("5f694a63-1bd4-4002-9f38-09170eb7aa62"));
MappingParameters mappingParameters = new MappingParameters();
mappingParameters.withHoldingsTypes(holdings);
WireMock.stubFor(get(new UrlPathPattern(new RegexPattern(MAPPING_METADATA_URL + "/.*"), true)).willReturn(WireMock.ok().withBody(Json.encode(new MappingMetadataDto().withMappingParams(Json.encode(mappingParameters)).withMappingRules(mappingRules.encode())))));
MappingMetadataCache mappingMetadataCache = new MappingMetadataCache(vertx, vertx.createHttpClient(), 3600);
marcHoldingsRecordHridSetKafkaHandler = new MarcHoldingsRecordHridSetKafkaHandler(new HoldingsUpdateDelegate(mockedStorage), mappingMetadataCache);
this.okapiHeaders = List.of(KafkaHeader.header(OKAPI_TENANT_HEADER, "diku"), KafkaHeader.header(OKAPI_URL_HEADER, mockServer.baseUrl()));
}
use of org.folio.MappingMetadataDto in project mod-inventory by folio-org.
the class MatchAuthorityEventHandlerUnitTest method setUp.
@Before
public void setUp() {
MatchValueReaderFactory.clearReaderFactory();
MatchValueLoaderFactory.clearLoaderFactory();
MockitoAnnotations.initMocks(this);
when(marcValueReader.isEligibleForEntityType(MARC_AUTHORITY)).thenReturn(true);
when(storage.getAuthorityRecordCollection(any(Context.class))).thenReturn(collection);
when(marcValueReader.read(any(DataImportEventPayload.class), any(MatchDetail.class))).thenReturn(StringValue.of(PERSONAL_NAME));
MatchValueReaderFactory.register(marcValueReader);
MatchValueLoaderFactory.register(loader);
when(mappingMetadataCache.get(anyString(), any(Context.class))).thenReturn(Future.succeededFuture(Optional.of(new MappingMetadataDto().withMappingRules(new JsonObject().encode()).withMappingParams(new JsonObject().encode()))));
}
use of org.folio.MappingMetadataDto in project mod-inventory by folio-org.
the class MatchHoldingEventHandlerUnitTest method shouldMatchOnHandleEventPayload.
@Test
public void shouldMatchOnHandleEventPayload(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<>(singletonList(createHolding()), 1));
callback.accept(result);
return null;
}).when(holdingCollection).findByCql(eq(format("hrid == \"%s\"", HOLDING_HRID)), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
when(mappingMetadataCache.get(anyString(), any(Context.class))).thenReturn(Future.succeededFuture(Optional.of(new MappingMetadataDto().withMappingRules(new JsonObject().encode()).withMappingParams(LOCATIONS_PARAMS))));
EventHandler eventHandler = new MatchHoldingEventHandler(mappingMetadataCache);
DataImportEventPayload eventPayload = createEventPayload();
eventHandler.handle(eventPayload).whenComplete((updatedEventPayload, throwable) -> {
testContext.assertNull(throwable);
testContext.assertEquals(1, updatedEventPayload.getEventsChain().size());
testContext.assertEquals(updatedEventPayload.getEventsChain(), singletonList(DI_SRS_MARC_BIB_RECORD_CREATED.value()));
testContext.assertEquals(DI_INVENTORY_HOLDING_MATCHED.value(), updatedEventPayload.getEventType());
async.complete();
});
}
use of org.folio.MappingMetadataDto in project mod-inventory by folio-org.
the class ReplaceInstanceEventHandlerTest method setUp.
@Before
public void setUp() throws IOException {
MockitoAnnotations.openMocks(this);
MappingManager.clearReaderFactories();
JsonObject mappingRules = new JsonObject(TestUtil.readFileFromPath(MAPPING_RULES_PATH));
WireMock.stubFor(get(new UrlPathPattern(new RegexPattern(MAPPING_METADATA_URL + "/.*"), true)).willReturn(WireMock.ok().withBody(Json.encode(new MappingMetadataDto().withMappingParams(Json.encode(new MappingParameters())).withMappingRules(mappingRules.toString())))));
precedingSucceedingTitlesHelper = Mockito.spy(new PrecedingSucceedingTitlesHelper(ctxt -> mockedClient));
Vertx vertx = Vertx.vertx();
replaceInstanceEventHandler = new ReplaceInstanceEventHandler(storage, precedingSucceedingTitlesHelper, new MappingMetadataCache(vertx, vertx.createHttpClient(new HttpClientOptions().setConnectTimeout(3000)), 3600));
doAnswer(invocationOnMock -> {
Instance instanceRecord = invocationOnMock.getArgument(0);
Consumer<Success<Instance>> successHandler = invocationOnMock.getArgument(1);
successHandler.accept(new Success<>(instanceRecord));
return null;
}).when(instanceRecordCollection).update(any(), any(Consumer.class), any(Consumer.class));
doAnswer(invocationOnMock -> completedStage(createResponse(201, null))).when(mockedClient).post(any(URL.class), any(JsonObject.class));
doAnswer(invocationOnMock -> completedStage(createResponse(200, new JsonObject().encode()))).when(mockedClient).get(anyString());
doAnswer(invocationOnMock -> completedStage(createResponse(204, null))).when(mockedClient).delete(anyString());
}
Aggregations