Search in sources :

Example 21 with Snapshot

use of org.folio.rest.jaxrs.model.Snapshot in project mod-source-record-storage by folio-org.

the class MarcAuthorityMatchEventHandlerTest method setUp.

@Before
public void setUp(TestContext context) {
    MockitoAnnotations.initMocks(this);
    recordDao = new RecordDaoImpl(postgresClientFactory);
    handler = new MarcAuthorityMatchEventHandler(recordDao);
    Async async = context.async();
    Snapshot existingRecordSnapshot = new Snapshot().withJobExecutionId(UUID.randomUUID().toString()).withProcessingStartedDate(new Date()).withStatus(Snapshot.Status.COMMITTED);
    Snapshot incomingRecordSnapshot = new Snapshot().withJobExecutionId(UUID.randomUUID().toString()).withProcessingStartedDate(new Date()).withStatus(Snapshot.Status.COMMITTED);
    List<Snapshot> snapshots = new ArrayList<>();
    snapshots.add(existingRecordSnapshot);
    snapshots.add(incomingRecordSnapshot);
    this.existingRecord = new Record().withId(existingRecordId).withMatchedId(existingRecordId).withSnapshotId(existingRecordSnapshot.getJobExecutionId()).withGeneration(0).withRecordType(MARC_AUTHORITY).withRawRecord(new RawRecord().withId(existingRecordId).withContent(rawRecordContent)).withParsedRecord(new ParsedRecord().withId(existingRecordId).withContent(PARSED_CONTENT)).withExternalIdsHolder(new ExternalIdsHolder().withAuthorityHrid("1000649")).withState(Record.State.ACTUAL);
    String incomingRecordId = UUID.randomUUID().toString();
    this.incomingRecord = new Record().withId(incomingRecordId).withMatchedId(existingRecord.getId()).withSnapshotId(incomingRecordSnapshot.getJobExecutionId()).withGeneration(1).withRecordType(MARC_AUTHORITY).withRawRecord(new RawRecord().withId(incomingRecordId).withContent(rawRecordContent)).withParsedRecord(new ParsedRecord().withId(incomingRecordId).withContent(PARSED_CONTENT)).withExternalIdsHolder(new ExternalIdsHolder());
    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) ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) RecordDaoImpl(org.folio.dao.RecordDaoImpl) MarcAuthorityMatchEventHandler(org.folio.services.handlers.match.MarcAuthorityMatchEventHandler) Async(io.vertx.ext.unit.Async) RawRecord(org.folio.rest.jaxrs.model.RawRecord) ArrayList(java.util.ArrayList) RawRecord(org.folio.rest.jaxrs.model.RawRecord) Record(org.folio.rest.jaxrs.model.Record) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Date(java.util.Date) Before(org.junit.Before)

Example 22 with Snapshot

use of org.folio.rest.jaxrs.model.Snapshot 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 23 with Snapshot

use of org.folio.rest.jaxrs.model.Snapshot 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 24 with Snapshot

use of org.folio.rest.jaxrs.model.Snapshot in project mod-source-record-storage by folio-org.

the class RecordCleanupServiceTest method before.

@Before
public void before(TestContext testContext) throws InterruptedException {
    Async async = testContext.async();
    ReactiveClassicGenericQueryExecutor queryExecutor = postgresClientFactory.getQueryExecutor(TENANT_ID);
    SnapshotDaoUtil.save(queryExecutor, snapshot).compose(ar -> recordService.saveRecord(deletedRecord, TENANT_ID)).compose(ar -> recordService.saveRecord(oldRecordForDeletedRecord, TENANT_ID)).compose(ar -> recordService.saveRecord(actualRecord, TENANT_ID)).compose(ar -> recordService.saveRecord(oldRecordForActualRecord, TENANT_ID)).onComplete(ar -> async.complete());
}
Also used : TestContext(io.vertx.ext.unit.TestContext) ErrorRecordDaoUtil(org.folio.dao.util.ErrorRecordDaoUtil) Async(io.vertx.ext.unit.Async) RecordDaoImpl(org.folio.dao.RecordDaoImpl) RunWith(org.junit.runner.RunWith) RawRecordDaoUtil(org.folio.dao.util.RawRecordDaoUtil) CompositeFuture(io.vertx.core.CompositeFuture) RecordType(org.folio.dao.util.RecordType) ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) After(org.junit.After) TestMocks(org.folio.TestMocks) Before(org.junit.Before) RecordDao(org.folio.dao.RecordDao) Record(org.folio.rest.jaxrs.model.Record) Promise(io.vertx.core.Promise) RecordDaoUtil(org.folio.dao.util.RecordDaoUtil) ReactiveClassicGenericQueryExecutor(io.github.jklingsporn.vertx.jooq.classic.reactivepg.ReactiveClassicGenericQueryExecutor) ParsedRecordDaoUtil(org.folio.dao.util.ParsedRecordDaoUtil) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) SnapshotDaoUtil(org.folio.dao.util.SnapshotDaoUtil) UUID(java.util.UUID) Future(io.vertx.core.Future) DELETED(org.folio.rest.jaxrs.model.Record.State.DELETED) ACTUAL(org.folio.rest.jaxrs.model.Record.State.ACTUAL) OLD(org.folio.rest.jaxrs.model.Record.State.OLD) Snapshot(org.folio.rest.jaxrs.model.Snapshot) ReactiveClassicGenericQueryExecutor(io.github.jklingsporn.vertx.jooq.classic.reactivepg.ReactiveClassicGenericQueryExecutor) Async(io.vertx.ext.unit.Async) Before(org.junit.Before)

Example 25 with Snapshot

use of org.folio.rest.jaxrs.model.Snapshot in project mod-source-record-storage by folio-org.

the class SourceStorageBatchApiTest method shouldFailWithInvalidSnapshotStatusBadRequest.

@Test
public void shouldFailWithInvalidSnapshotStatusBadRequest(TestContext testContext) {
    Async async = testContext.async();
    Snapshot snapshot = new Snapshot().withJobExecutionId(UUID.randomUUID().toString()).withStatus(Snapshot.Status.NEW);
    RestAssured.given().spec(spec).body(snapshot).when().post(SOURCE_STORAGE_SNAPSHOTS_PATH).then().statusCode(HttpStatus.SC_CREATED).body("jobExecutionId", is(snapshot.getJobExecutionId())).body("status", is(snapshot.getStatus().name()));
    async.complete();
    async = testContext.async();
    List<Record> expected = TestMocks.getRecords().stream().filter(record -> record.getRecordType().equals(RecordType.MARC_BIB)).map(record -> record.withSnapshotId(snapshot.getJobExecutionId())).collect(Collectors.toList());
    RecordCollection recordCollection = new RecordCollection().withRecords(expected).withTotalRecords(expected.size());
    RestAssured.given().spec(spec).body(recordCollection).when().post(SOURCE_STORAGE_BATCH_RECORDS_PATH).then().statusCode(HttpStatus.SC_BAD_REQUEST).body(is(format(SNAPSHOT_NOT_STARTED_MESSAGE_TEMPLATE, snapshot.getStatus())));
    async.complete();
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Arrays(java.util.Arrays) SNAPSHOT_NOT_FOUND_TEMPLATE(org.folio.dao.util.SnapshotDaoUtil.SNAPSHOT_NOT_FOUND_TEMPLATE) RawRecord(org.folio.rest.jaxrs.model.RawRecord) RunWith(org.junit.runner.RunWith) HttpStatus(org.apache.http.HttpStatus) ArrayList(java.util.ArrayList) RecordsBatchResponse(org.folio.rest.jaxrs.model.RecordsBatchResponse) RecordType(org.folio.rest.jaxrs.model.Record.RecordType) Matchers.everyItem(org.hamcrest.Matchers.everyItem) ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) TestUtil(org.folio.TestUtil) SNAPSHOT_NOT_STARTED_MESSAGE_TEMPLATE(org.folio.dao.util.SnapshotDaoUtil.SNAPSHOT_NOT_STARTED_MESSAGE_TEMPLATE) JsonObject(io.vertx.core.json.JsonObject) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) AdditionalInfo(org.folio.rest.jaxrs.model.AdditionalInfo) ParsedRecordsBatchResponse(org.folio.rest.jaxrs.model.ParsedRecordsBatchResponse) TestMocks(org.folio.TestMocks) Before(org.junit.Before) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Record(org.folio.rest.jaxrs.model.Record) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Matchers(org.hamcrest.Matchers) IOException(java.io.IOException) Test(org.junit.Test) UUID(java.util.UUID) SnapshotDaoUtil(org.folio.dao.util.SnapshotDaoUtil) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) RecordCollection(org.folio.rest.jaxrs.model.RecordCollection) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Objects(java.util.Objects) JsonArray(io.vertx.core.json.JsonArray) List(java.util.List) Matchers.contains(org.hamcrest.Matchers.contains) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord) Response(io.restassured.response.Response) PostgresClientFactory(org.folio.dao.PostgresClientFactory) Matcher(org.hamcrest.Matcher) Matchers.is(org.hamcrest.Matchers.is) RestAssured(io.restassured.RestAssured) Matchers.containsString(org.hamcrest.Matchers.containsString) Collections(java.util.Collections) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Snapshot(org.folio.rest.jaxrs.model.Snapshot) Snapshot(org.folio.rest.jaxrs.model.Snapshot) Async(io.vertx.ext.unit.Async) RecordCollection(org.folio.rest.jaxrs.model.RecordCollection) RawRecord(org.folio.rest.jaxrs.model.RawRecord) Record(org.folio.rest.jaxrs.model.Record) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Test(org.junit.Test)

Aggregations

Snapshot (org.folio.rest.jaxrs.model.Snapshot)31 Async (io.vertx.ext.unit.Async)25 Test (org.junit.Test)21 Record (org.folio.rest.jaxrs.model.Record)15 ParsedRecord (org.folio.rest.jaxrs.model.ParsedRecord)14 RawRecord (org.folio.rest.jaxrs.model.RawRecord)14 Before (org.junit.Before)13 ArrayList (java.util.ArrayList)10 Date (java.util.Date)10 JsonObject (io.vertx.core.json.JsonObject)9 UUID (java.util.UUID)9 TestContext (io.vertx.ext.unit.TestContext)8 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)8 RecordDaoImpl (org.folio.dao.RecordDaoImpl)8 SnapshotDaoUtil (org.folio.dao.util.SnapshotDaoUtil)8 ExternalIdsHolder (org.folio.rest.jaxrs.model.ExternalIdsHolder)8 RunWith (org.junit.runner.RunWith)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 IOException (java.io.IOException)7 Collections (java.util.Collections)7