Search in sources :

Example 16 with MappingMetadataDto

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);
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Context(org.folio.inventory.common.Context) Instance(org.folio.inventory.domain.instances.Instance) InstanceUpdateDelegate(org.folio.inventory.dataimport.handlers.actions.InstanceUpdateDelegate) JsonObject(io.vertx.core.json.JsonObject) Record(org.folio.rest.jaxrs.model.Record) KafkaConsumerRecord(io.vertx.kafka.client.consumer.KafkaConsumerRecord) MappingMetadataDto(org.folio.MappingMetadataDto) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) Success(org.folio.inventory.common.domain.Success) Before(org.junit.Before)

Example 17 with MappingMetadataDto

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()));
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Context(org.folio.inventory.common.Context) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject) MappingMetadataDto(org.folio.MappingMetadataDto) HoldingsUpdateDelegate(org.folio.inventory.dataimport.handlers.actions.HoldingsUpdateDelegate) Success(org.folio.inventory.common.domain.Success) HoldingsRecord(org.folio.HoldingsRecord) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) HoldingsType(org.folio.HoldingsType) MappingMetadataCache(org.folio.inventory.dataimport.cache.MappingMetadataCache) HoldingsRecord(org.folio.HoldingsRecord) KafkaConsumerRecord(io.vertx.kafka.client.consumer.KafkaConsumerRecord) Record(org.folio.rest.jaxrs.model.Record) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) Before(org.junit.Before)

Example 18 with MappingMetadataDto

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()))));
}
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 19 with MappingMetadataDto

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();
    });
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Context(org.folio.inventory.common.Context) MatchHoldingEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchHoldingEventHandler) PagingParameters(org.folio.inventory.common.api.request.PagingParameters) JsonObject(io.vertx.core.json.JsonObject) EventHandler(org.folio.processing.events.services.handler.EventHandler) MatchItemEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchItemEventHandler) MatchHoldingEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchHoldingEventHandler) MappingMetadataDto(org.folio.MappingMetadataDto) Success(org.folio.inventory.common.domain.Success) DataImportEventPayload(org.folio.DataImportEventPayload) HoldingsRecord(org.folio.HoldingsRecord) Consumer(java.util.function.Consumer) Async(io.vertx.ext.unit.Async) MultipleRecords(org.folio.inventory.common.domain.MultipleRecords) Test(org.junit.Test)

Example 20 with MappingMetadataDto

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());
}
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)

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