Search in sources :

Example 6 with MappingMetadataDto

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))));
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Context(org.folio.inventory.common.Context) JsonObject(io.vertx.core.json.JsonObject) MappingMetadataDto(org.folio.MappingMetadataDto) MatchDetail(org.folio.MatchDetail) DataImportEventPayload(org.folio.DataImportEventPayload) Before(org.junit.Before)

Example 7 with MappingMetadataDto

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));
}
Also used : Authority(org.folio.Authority) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) JsonObject(io.vertx.core.json.JsonObject) MappingMetadataDto(org.folio.MappingMetadataDto) Success(org.folio.inventory.common.domain.Success) RecordToEntity(org.folio.inventory.domain.relationship.RecordToEntity) URL(java.net.URL) Response(org.folio.inventory.support.http.client.Response) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) MappingMetadataCache(org.folio.inventory.dataimport.cache.MappingMetadataCache) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) Before(org.junit.Before)

Example 8 with MappingMetadataDto

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())))));
}
Also used : Context(org.folio.inventory.common.Context) PagingParameters(org.folio.inventory.common.api.request.PagingParameters) JsonObject(io.vertx.core.json.JsonObject) MappingMetadataDto(org.folio.MappingMetadataDto) Success(org.folio.inventory.common.domain.Success) RecordToEntity(org.folio.inventory.domain.relationship.RecordToEntity) HoldingsRecord(org.folio.HoldingsRecord) Consumer(java.util.function.Consumer) MultipleRecords(org.folio.inventory.common.domain.MultipleRecords) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) Before(org.junit.Before)

Example 9 with MappingMetadataDto

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));
}
Also used : RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) Instance(org.folio.inventory.domain.instances.Instance) JsonObject(io.vertx.core.json.JsonObject) MappingMetadataDto(org.folio.MappingMetadataDto) Vertx(io.vertx.core.Vertx) HttpClientOptions(io.vertx.core.http.HttpClientOptions) Success(org.folio.inventory.common.domain.Success) URL(java.net.URL) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) Consumer(java.util.function.Consumer) MappingMetadataCache(org.folio.inventory.dataimport.cache.MappingMetadataCache) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) Before(org.junit.Before)

Example 10 with MappingMetadataDto

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);
}
Also used : Context(org.folio.inventory.common.Context) Instance(org.folio.inventory.domain.instances.Instance) JsonObject(io.vertx.core.json.JsonObject) MappingMetadataDto(org.folio.MappingMetadataDto) Success(org.folio.inventory.common.domain.Success) Response(org.folio.inventory.support.http.client.Response) Consumer(java.util.function.Consumer) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Record(org.folio.rest.jaxrs.model.Record) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) Before(org.junit.Before)

Aggregations

MappingMetadataDto (org.folio.MappingMetadataDto)23 JsonObject (io.vertx.core.json.JsonObject)21 Context (org.folio.inventory.common.Context)17 Before (org.junit.Before)16 MappingParameters (org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters)13 Success (org.folio.inventory.common.domain.Success)12 MappingMetadataCache (org.folio.inventory.dataimport.cache.MappingMetadataCache)11 Consumer (java.util.function.Consumer)8 DataImportEventPayload (org.folio.DataImportEventPayload)8 TestContext (io.vertx.ext.unit.TestContext)7 HoldingsRecord (org.folio.HoldingsRecord)7 Instance (org.folio.inventory.domain.instances.Instance)7 RegexPattern (com.github.tomakehurst.wiremock.matching.RegexPattern)6 UrlPathPattern (com.github.tomakehurst.wiremock.matching.UrlPathPattern)6 Record (org.folio.rest.jaxrs.model.Record)6 EventProcessingException (org.folio.processing.exceptions.EventProcessingException)5 Promise (io.vertx.core.Promise)4 Json (io.vertx.core.json.Json)4 KafkaConsumerRecord (io.vertx.kafka.client.consumer.KafkaConsumerRecord)4 String.format (java.lang.String.format)4