use of org.folio.MappingMetadataDto in project mod-inventory by folio-org.
the class MatchHoldingEventHandlerUnitTest method setUp.
@Before
public void setUp() {
MatchValueReaderFactory.clearReaderFactory();
MatchValueLoaderFactory.clearLoaderFactory();
MockitoAnnotations.initMocks(this);
when(marcValueReader.isEligibleForEntityType(MARC_BIBLIOGRAPHIC)).thenReturn(true);
when(storage.getHoldingsRecordCollection(any(Context.class))).thenReturn(holdingCollection);
when(marcValueReader.read(any(DataImportEventPayload.class), any(MatchDetail.class))).thenReturn(StringValue.of(HOLDING_HRID));
MatchValueReaderFactory.register(marcValueReader);
MatchValueLoaderFactory.register(holdingLoader);
when(mappingMetadataCache.get(anyString(), any(Context.class))).thenReturn(Future.succeededFuture(Optional.of(new MappingMetadataDto().withMappingRules(new JsonObject().encode()).withMappingParams(LOCATIONS_PARAMS))));
}
use of org.folio.MappingMetadataDto in project mod-inventory by folio-org.
the class CreateAuthorityEventHandlerTest method setUp.
@Before
public void setUp() throws IOException {
MockitoAnnotations.openMocks(this);
MappingManager.clearReaderFactories();
MappingMetadataCache mappingMetadataCache = new MappingMetadataCache(vertx, vertx.createHttpClient(), 3600);
createMarcAuthoritiesEventHandler = new CreateAuthorityEventHandler(storage, mappingMetadataCache, authorityIdStorageService);
JsonObject mappingRules = new JsonObject(TestUtil.readFileFromPath(MAPPING_RULES_PATH));
doAnswer(invocationOnMock -> {
Authority authority = invocationOnMock.getArgument(0);
Consumer<Success<Authority>> successHandler = invocationOnMock.getArgument(1);
successHandler.accept(new Success<>(authority));
return null;
}).when(authorityCollection).add(any(), any(), any());
doAnswer(invocationOnMock -> {
RecordToEntity recordToItem = RecordToEntity.builder().recordId(RECORD_ID).entityId(AUTHORITY_ID).build();
return Future.succeededFuture(recordToItem);
}).when(authorityIdStorageService).store(any(), any(), any());
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.encode())))));
doAnswer(invocationOnMock -> completedStage(new Response(HttpStatus.SC_CREATED, null, null, null))).when(mockedClient).post(any(URL.class), any(JsonObject.class));
}
use of org.folio.MappingMetadataDto 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.MappingMetadataDto in project mod-inventory by folio-org.
the class CreateInstanceEventHandlerTest 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())))));
Vertx vertx = Vertx.vertx();
createInstanceEventHandler = new CreateInstanceEventHandler(storage, new PrecedingSucceedingTitlesHelper(context -> mockedClient), new MappingMetadataCache(vertx, vertx.createHttpClient(new HttpClientOptions().setConnectTimeout(3000)), 3600), instanceIdStorageService);
doAnswer(invocationOnMock -> {
Instance instanceRecord = invocationOnMock.getArgument(0);
Consumer<Success<Instance>> successHandler = invocationOnMock.getArgument(1);
successHandler.accept(new Success<>(instanceRecord));
return null;
}).when(instanceRecordCollection).add(any(), any(Consumer.class), any(Consumer.class));
doAnswer(invocationOnMock -> completedStage(createdResponse())).when(mockedClient).post(any(URL.class), any(JsonObject.class));
}
use of org.folio.MappingMetadataDto in project mod-inventory by folio-org.
the class MarcBibModifiedPostProcessingEventHandlerTest 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());
when(mockedStorage.getInstanceCollection(any(Context.class))).thenReturn(mockedInstanceCollection);
when(mockedOkapiHttpClient.delete(anyString())).thenReturn(CompletableFuture.completedFuture(new Response(204, null, null, null)));
when(mockedOkapiHttpClient.get(anyString())).thenReturn(CompletableFuture.completedFuture(getOkResponse(new JsonObject().encode())));
doAnswer(invocationOnMock -> {
Consumer<Success<Instance>> successHandler = invocationOnMock.getArgument(1);
successHandler.accept(new Success<>(existingInstance));
return null;
}).when(mockedInstanceCollection).findById(anyString(), any(Consumer.class), any(Consumer.class));
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(Consumer.class), any(Consumer.class));
Mockito.when(mappingMetadataCache.get(anyString(), any(Context.class))).thenReturn(Future.succeededFuture(Optional.of(new MappingMetadataDto().withMappingRules(mappingRules.encode()).withMappingParams(Json.encode(new MappingParameters())))));
PrecedingSucceedingTitlesHelper precedingSucceedingTitlesHelper = new PrecedingSucceedingTitlesHelper(ctxt -> mockedOkapiHttpClient);
marcBibModifiedEventHandler = new MarcBibModifiedPostProcessingEventHandler(new InstanceUpdateDelegate(mockedStorage), precedingSucceedingTitlesHelper, mappingMetadataCache);
}
Aggregations