Search in sources :

Example 6 with RecordDaoImpl

use of org.folio.dao.RecordDaoImpl in project mod-source-record-storage by folio-org.

the class MarcBibUpdateModifyEventHandlerTest method setUp.

@Before
public void setUp(TestContext context) {
    WireMock.stubFor(get(new UrlPathPattern(new RegexPattern(MAPPING_METADATA__URL + "/.*"), true)).willReturn(WireMock.ok().withBody(Json.encode(new MappingMetadataDto().withMappingParams(Json.encode(new MappingParameters()))))));
    recordDao = new RecordDaoImpl(postgresClientFactory);
    recordService = new RecordServiceImpl(recordDao);
    modifyRecordEventHandler = new MarcBibUpdateModifyEventHandler(recordService, new MappingParametersSnapshotCache(vertx), vertx);
    Snapshot snapshot = new Snapshot().withJobExecutionId(UUID.randomUUID().toString()).withProcessingStartedDate(new Date()).withStatus(Snapshot.Status.COMMITTED);
    snapshotForRecordUpdate = new Snapshot().withJobExecutionId(UUID.randomUUID().toString()).withStatus(Snapshot.Status.PARSING_IN_PROGRESS);
    record = new Record().withId(recordId).withSnapshotId(snapshot.getJobExecutionId()).withGeneration(0).withMatchedId(recordId).withRecordType(MARC_BIB).withRawRecord(rawRecord).withParsedRecord(parsedRecord);
    ReactiveClassicGenericQueryExecutor queryExecutor = postgresClientFactory.getQueryExecutor(TENANT_ID);
    SnapshotDaoUtil.save(queryExecutor, snapshot).compose(v -> recordService.saveRecord(record, TENANT_ID)).compose(v -> SnapshotDaoUtil.save(queryExecutor, snapshotForRecordUpdate)).onComplete(context.asyncAssertSuccess());
}
Also used : TestContext(io.vertx.ext.unit.TestContext) RecordDaoImpl(org.folio.dao.RecordDaoImpl) JOB_PROFILE(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.JOB_PROFILE) Date(java.util.Date) TimeoutException(java.util.concurrent.TimeoutException) ACTION_PROFILE(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.ACTION_PROFILE) UPDATE(org.folio.rest.jaxrs.model.MappingDetail.MarcMappingOption.UPDATE) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) After(org.junit.After) JsonObject(io.vertx.core.json.JsonObject) MarcBibUpdateModifyEventHandler(org.folio.services.handlers.actions.MarcBibUpdateModifyEventHandler) MappingProfile(org.folio.MappingProfile) DI_SRS_MARC_BIB_RECORD_MODIFIED(org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_BIB_RECORD_MODIFIED) RecordDao(org.folio.dao.RecordDao) DataImportEventPayload(org.folio.DataImportEventPayload) JobProfile(org.folio.JobProfile) MarcField(org.folio.rest.jaxrs.model.MarcField) SnapshotDaoUtil(org.folio.dao.util.SnapshotDaoUtil) UUID(java.util.UUID) Data(org.folio.rest.jaxrs.model.Data) Slf4jNotifier(com.github.tomakehurst.wiremock.common.Slf4jNotifier) MODIFY(org.folio.ActionProfile.Action.MODIFY) RunTestOnContext(io.vertx.ext.unit.junit.RunTestOnContext) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Async(io.vertx.ext.unit.Async) Json(io.vertx.core.json.Json) BeforeClass(org.junit.BeforeClass) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) WireMockConfiguration(com.github.tomakehurst.wiremock.core.WireMockConfiguration) RawRecord(org.folio.rest.jaxrs.model.RawRecord) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) MarcMappingDetail(org.folio.rest.jaxrs.model.MarcMappingDetail) MappingDetail(org.folio.rest.jaxrs.model.MappingDetail) MappingMetadataDto(org.folio.rest.jaxrs.model.MappingMetadataDto) WireMock(com.github.tomakehurst.wiremock.client.WireMock) WireMockRule(com.github.tomakehurst.wiremock.junit.WireMockRule) MARC_BIBLIOGRAPHIC(org.folio.rest.jaxrs.model.EntityType.MARC_BIBLIOGRAPHIC) TestUtil(org.folio.TestUtil) MAPPING_PROFILE(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.MAPPING_PROFILE) ActionProfile(org.folio.ActionProfile) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) Before(org.junit.Before) WireMock.get(com.github.tomakehurst.wiremock.client.WireMock.get) MarcSubfield(org.folio.rest.jaxrs.model.MarcSubfield) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) MappingParametersSnapshotCache(org.folio.services.caches.MappingParametersSnapshotCache) Record(org.folio.rest.jaxrs.model.Record) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ReactiveClassicGenericQueryExecutor(io.github.jklingsporn.vertx.jooq.classic.reactivepg.ReactiveClassicGenericQueryExecutor) Test(org.junit.Test) IOException(java.io.IOException) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) DI_SRS_MARC_BIB_RECORD_CREATED(org.folio.DataImportEventTypes.DI_SRS_MARC_BIB_RECORD_CREATED) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) MARC_BIB(org.folio.rest.jaxrs.model.Record.RecordType.MARC_BIB) Rule(org.junit.Rule) Assert(org.junit.Assert) Snapshot(org.folio.rest.jaxrs.model.Snapshot) Collections(java.util.Collections) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) ReactiveClassicGenericQueryExecutor(io.github.jklingsporn.vertx.jooq.classic.reactivepg.ReactiveClassicGenericQueryExecutor) MarcBibUpdateModifyEventHandler(org.folio.services.handlers.actions.MarcBibUpdateModifyEventHandler) MappingMetadataDto(org.folio.rest.jaxrs.model.MappingMetadataDto) MappingParametersSnapshotCache(org.folio.services.caches.MappingParametersSnapshotCache) Date(java.util.Date) Snapshot(org.folio.rest.jaxrs.model.Snapshot) RecordDaoImpl(org.folio.dao.RecordDaoImpl) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) RawRecord(org.folio.rest.jaxrs.model.RawRecord) Record(org.folio.rest.jaxrs.model.Record) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) Before(org.junit.Before)

Example 7 with RecordDaoImpl

use of org.folio.dao.RecordDaoImpl in project mod-source-record-storage by folio-org.

the class QuickMarcKafkaHandlerTest method setUp.

@Before
public void setUp(TestContext context) {
    MockitoAnnotations.initMocks(this);
    recordDao = new RecordDaoImpl(postgresClientFactory);
    recordService = new RecordServiceImpl(recordDao);
    Async async = context.async();
    Snapshot snapshot = new Snapshot().withJobExecutionId(UUID.randomUUID().toString()).withProcessingStartedDate(new Date()).withStatus(Snapshot.Status.COMMITTED);
    record = new Record().withId(recordId).withSnapshotId(snapshot.getJobExecutionId()).withGeneration(0).withMatchedId(recordId).withRecordType(MARC_BIB).withRawRecord(rawRecord).withParsedRecord(parsedRecord);
    SnapshotDaoUtil.save(postgresClientFactory.getQueryExecutor(TENANT_ID), snapshot).compose(savedSnapshot -> recordService.saveRecord(record, TENANT_ID)).onSuccess(ar -> async.complete()).onFailure(context::fail);
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Json(io.vertx.core.json.Json) ObserveKeyValues(net.mguenther.kafka.junit.ObserveKeyValues) RecordDaoImpl(org.folio.dao.RecordDaoImpl) BeforeClass(org.junit.BeforeClass) Date(java.util.Date) QM_ERROR(org.folio.dao.util.QMEventTypes.QM_ERROR) KafkaTopicNameHelper.getDefaultNameSpace(org.folio.kafka.KafkaTopicNameHelper.getDefaultNameSpace) RawRecord(org.folio.rest.jaxrs.model.RawRecord) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) QM_SRS_MARC_RECORD_UPDATED(org.folio.dao.util.QMEventTypes.QM_SRS_MARC_RECORD_UPDATED) MockitoAnnotations(org.mockito.MockitoAnnotations) KeyValue(net.mguenther.kafka.junit.KeyValue) IdType(org.folio.dao.util.IdType) Charset(java.nio.charset.Charset) TestUtil(org.folio.TestUtil) After(org.junit.After) Tables(org.folio.rest.jooq.Tables) JsonObject(io.vertx.core.json.JsonObject) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Before(org.junit.Before) Event(org.folio.rest.jaxrs.model.Event) KafkaTopicNameHelper.formatTopicName(org.folio.kafka.KafkaTopicNameHelper.formatTopicName) RecordDao(org.folio.dao.RecordDao) Record(org.folio.rest.jaxrs.model.Record) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) QM_RECORD_UPDATED(org.folio.dao.util.QMEventTypes.QM_RECORD_UPDATED) Test(org.junit.Test) IOException(java.io.IOException) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) SnapshotDaoUtil(org.folio.dao.util.SnapshotDaoUtil) UUID(java.util.UUID) Future(io.vertx.core.Future) ParsedRecordDto(org.folio.rest.jaxrs.model.ParsedRecordDto) OkapiConnectionParams(org.folio.rest.util.OkapiConnectionParams) TimeUnit(java.util.concurrent.TimeUnit) MARC_BIB(org.folio.rest.jaxrs.model.Record.RecordType.MARC_BIB) SendKeyValues(net.mguenther.kafka.junit.SendKeyValues) State(org.folio.rest.jaxrs.model.Record.State) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Snapshot(org.folio.rest.jaxrs.model.Snapshot) Collections(java.util.Collections) Snapshot(org.folio.rest.jaxrs.model.Snapshot) RecordDaoImpl(org.folio.dao.RecordDaoImpl) Async(io.vertx.ext.unit.Async) RawRecord(org.folio.rest.jaxrs.model.RawRecord) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Record(org.folio.rest.jaxrs.model.Record) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Date(java.util.Date) Before(org.junit.Before)

Example 8 with RecordDaoImpl

use of org.folio.dao.RecordDaoImpl in project mod-source-record-storage by folio-org.

the class AbstractPostProcessingEventHandlerTest method setUp.

@Before
public void setUp(TestContext context) {
    MockitoAnnotations.initMocks(this);
    WireMock.stubFor(get(new UrlPathPattern(new RegexPattern(MAPPING_METADATA__URL + "/.*"), true)).willReturn(WireMock.ok().withBody(Json.encode(new MappingMetadataDto().withMappingParams(Json.encode(new MappingParameters()))))));
    mappingParametersCache = new MappingParametersSnapshotCache(vertx);
    recordDao = new RecordDaoImpl(postgresClientFactory);
    handler = createHandler(recordDao, kafkaConfig);
    Async async = context.async();
    Snapshot snapshot1 = new Snapshot().withJobExecutionId(snapshotId1).withProcessingStartedDate(new Date()).withStatus(Snapshot.Status.COMMITTED);
    Snapshot snapshot2 = new Snapshot().withJobExecutionId(snapshotId2).withProcessingStartedDate(new Date()).withStatus(Snapshot.Status.COMMITTED);
    List<Snapshot> snapshots = new ArrayList<>();
    snapshots.add(snapshot1);
    snapshots.add(snapshot2);
    this.record = new Record().withId(recordId).withMatchedId(recordId).withSnapshotId(snapshotId1).withGeneration(0).withRecordType(getMarcType()).withRawRecord(rawRecord).withParsedRecord(parsedRecord).withExternalIdsHolder(null);
    SnapshotDaoUtil.save(postgresClientFactory.getQueryExecutor(TENANT_ID), snapshots).onComplete(save -> {
        if (save.failed()) {
            context.fail(save.cause());
        }
        async.complete();
    });
}
Also used : Snapshot(org.folio.rest.jaxrs.model.Snapshot) RecordDaoImpl(org.folio.dao.RecordDaoImpl) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) Async(io.vertx.ext.unit.Async) ArrayList(java.util.ArrayList) MappingMetadataDto(org.folio.rest.jaxrs.model.MappingMetadataDto) RawRecord(org.folio.rest.jaxrs.model.RawRecord) Record(org.folio.rest.jaxrs.model.Record) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) MappingParametersSnapshotCache(org.folio.services.caches.MappingParametersSnapshotCache) Date(java.util.Date) Before(org.junit.Before)

Aggregations

RecordDaoImpl (org.folio.dao.RecordDaoImpl)8 Before (org.junit.Before)8 Async (io.vertx.ext.unit.Async)7 Date (java.util.Date)7 ParsedRecord (org.folio.rest.jaxrs.model.ParsedRecord)7 RawRecord (org.folio.rest.jaxrs.model.RawRecord)7 Record (org.folio.rest.jaxrs.model.Record)7 Snapshot (org.folio.rest.jaxrs.model.Snapshot)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 RegexPattern (com.github.tomakehurst.wiremock.matching.RegexPattern)4 UrlPathPattern (com.github.tomakehurst.wiremock.matching.UrlPathPattern)4 Json (io.vertx.core.json.Json)4 JsonObject (io.vertx.core.json.JsonObject)4 TestContext (io.vertx.ext.unit.TestContext)4 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)4 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 UUID (java.util.UUID)4 TimeUnit (java.util.concurrent.TimeUnit)4 TestUtil (org.folio.TestUtil)4