Search in sources :

Example 1 with Snapshot

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

the class DataImportConsumersVerticleTest method setUp.

@Before
public void setUp(TestContext context) throws IOException {
    WireMock.stubFor(get(new UrlPathPattern(new RegexPattern(MAPPING_METADATA_URL + "/.*"), true)).willReturn(WireMock.ok().withBody(Json.encode(new MappingMetadataDto().withMappingParams(Json.encode(new MappingParameters()))))));
    RawRecord rawRecord = new RawRecord().withId(recordId).withContent(new ObjectMapper().readValue(TestUtil.readFileFromPath(RAW_MARC_RECORD_CONTENT_SAMPLE_PATH), String.class));
    ParsedRecord parsedRecord = new ParsedRecord().withId(recordId).withContent(PARSED_CONTENT);
    Snapshot snapshot = new Snapshot().withJobExecutionId(snapshotId).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).withExternalIdsHolder(new ExternalIdsHolder().withAuthorityId(UUID.randomUUID().toString()));
    ReactiveClassicGenericQueryExecutor queryExecutor = postgresClientFactory.getQueryExecutor(TENANT_ID);
    RecordDaoImpl recordDao = new RecordDaoImpl(postgresClientFactory);
    SnapshotDaoUtil.save(queryExecutor, snapshot).compose(v -> recordDao.saveRecord(record, TENANT_ID)).onComplete(context.asyncAssertSuccess());
}
Also used : TestContext(io.vertx.ext.unit.TestContext) ObserveKeyValues(net.mguenther.kafka.junit.ObserveKeyValues) JOB_PROFILE(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.JOB_PROFILE) RecordDaoImpl(org.folio.dao.RecordDaoImpl) Date(java.util.Date) ACTION_PROFILE(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.ACTION_PROFILE) Collections.singletonList(java.util.Collections.singletonList) KeyValue(net.mguenther.kafka.junit.KeyValue) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) DI_SRS_MARC_BIB_RECORD_CREATED(org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_BIB_RECORD_CREATED) JOB_EXECUTION_ID_HEADER(org.folio.consumers.ParsedRecordChunksKafkaHandler.JOB_EXECUTION_ID_HEADER) JsonObject(io.vertx.core.json.JsonObject) MappingProfile(org.folio.MappingProfile) JobProfile(org.folio.JobProfile) MarcField(org.folio.rest.jaxrs.model.MarcField) UUID(java.util.UUID) SnapshotDaoUtil(org.folio.dao.util.SnapshotDaoUtil) Data(org.folio.rest.jaxrs.model.Data) StandardCharsets(java.nio.charset.StandardCharsets) DI_SRS_MARC_AUTHORITY_RECORD_DELETED(org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_AUTHORITY_RECORD_DELETED) List(java.util.List) SendKeyValues(net.mguenther.kafka.junit.SendKeyValues) DELETE(org.folio.ActionProfile.Action.DELETE) MODIFY(org.folio.ActionProfile.Action.MODIFY) Slf4jNotifier(com.github.tomakehurst.wiremock.common.Slf4jNotifier) RestUtil(org.folio.dataimport.util.RestUtil) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Json(io.vertx.core.json.Json) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) KafkaTopicNameHelper.getDefaultNameSpace(org.folio.kafka.KafkaTopicNameHelper.getDefaultNameSpace) DataImportEventPayload(org.folio.rest.jaxrs.model.DataImportEventPayload) WireMockConfiguration(com.github.tomakehurst.wiremock.core.WireMockConfiguration) RunWith(org.junit.runner.RunWith) RawRecord(org.folio.rest.jaxrs.model.RawRecord) HashMap(java.util.HashMap) 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) DI_MARC_FOR_DELETE_RECEIVED(org.folio.rest.jaxrs.model.DataImportEventTypes.DI_MARC_FOR_DELETE_RECEIVED) MARC_BIBLIOGRAPHIC(org.folio.rest.jaxrs.model.EntityType.MARC_BIBLIOGRAPHIC) WireMockRule(com.github.tomakehurst.wiremock.junit.WireMockRule) ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) DI_SRS_MARC_BIB_RECORD_MODIFIED_READY_FOR_POST_PROCESSING(org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_BIB_RECORD_MODIFIED_READY_FOR_POST_PROCESSING) TestUtil(org.folio.TestUtil) MAPPING_PROFILE(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.MAPPING_PROFILE) KafkaTopicNameHelper(org.folio.kafka.KafkaTopicNameHelper) 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) Event(org.folio.rest.jaxrs.model.Event) MarcSubfield(org.folio.rest.jaxrs.model.MarcSubfield) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Assert.assertNotNull(org.junit.Assert.assertNotNull) Record(org.folio.rest.jaxrs.model.Record) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) ReactiveClassicGenericQueryExecutor(io.github.jklingsporn.vertx.jooq.classic.reactivepg.ReactiveClassicGenericQueryExecutor) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) AbstractLBServiceTest(org.folio.services.AbstractLBServiceTest) TimeUnit(java.util.concurrent.TimeUnit) MARC_BIB(org.folio.rest.jaxrs.model.Record.RecordType.MARC_BIB) Rule(org.junit.Rule) PROFILE_SNAPSHOT_ID_KEY(org.folio.consumers.DataImportKafkaHandler.PROFILE_SNAPSHOT_ID_KEY) Snapshot(org.folio.rest.jaxrs.model.Snapshot) Assert.assertEquals(org.junit.Assert.assertEquals) ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) ReactiveClassicGenericQueryExecutor(io.github.jklingsporn.vertx.jooq.classic.reactivepg.ReactiveClassicGenericQueryExecutor) MappingMetadataDto(org.folio.rest.jaxrs.model.MappingMetadataDto) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Date(java.util.Date) Snapshot(org.folio.rest.jaxrs.model.Snapshot) RecordDaoImpl(org.folio.dao.RecordDaoImpl) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) RawRecord(org.folio.rest.jaxrs.model.RawRecord) 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) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 2 with Snapshot

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

the class ParsedRecordChunkConsumersVerticleTest method setUp.

@Before
public void setUp(TestContext context) {
    MockitoAnnotations.initMocks(this);
    Async async = context.async();
    Snapshot snapshot = new Snapshot().withJobExecutionId(snapshotId).withProcessingStartedDate(new Date()).withStatus(Snapshot.Status.COMMITTED);
    SnapshotDaoUtil.save(postgresClientFactory.getQueryExecutor(TENANT_ID), snapshot).onComplete(save -> {
        if (save.failed()) {
            context.fail(save.cause());
        }
        async.complete();
    });
}
Also used : Snapshot(org.folio.rest.jaxrs.model.Snapshot) Async(io.vertx.ext.unit.Async) Date(java.util.Date) Before(org.junit.Before)

Example 3 with Snapshot

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

the class SnapshotServiceTest method shouldNotDeleteSnapshot.

@Test
public void shouldNotDeleteSnapshot(TestContext context) {
    Async async = context.async();
    Snapshot snapshot = TestMocks.getSnapshot(0);
    snapshotService.deleteSnapshot(snapshot.getJobExecutionId(), TENANT_ID).onComplete(delete -> {
        if (delete.failed()) {
            context.fail(delete.cause());
        }
        context.assertFalse(delete.result());
        async.complete();
    });
}
Also used : Snapshot(org.folio.rest.jaxrs.model.Snapshot) Async(io.vertx.ext.unit.Async) Test(org.junit.Test)

Example 4 with Snapshot

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

the class SnapshotServiceTest method shouldFailToUpdateSnapshot.

@Test
public void shouldFailToUpdateSnapshot(TestContext context) {
    Async async = context.async();
    Snapshot snapshot = TestMocks.getSnapshot(0);
    snapshotDao.getSnapshotById(snapshot.getJobExecutionId(), TENANT_ID).onComplete(get -> {
        if (get.failed()) {
            context.fail(get.cause());
        }
        context.assertFalse(get.result().isPresent());
        snapshotService.updateSnapshot(snapshot, TENANT_ID).onComplete(update -> {
            context.assertTrue(update.failed());
            String expected = String.format("Snapshot with id '%s' was not found", snapshot.getJobExecutionId());
            context.assertEquals(expected, update.cause().getMessage());
            async.complete();
        });
    });
}
Also used : Snapshot(org.folio.rest.jaxrs.model.Snapshot) Async(io.vertx.ext.unit.Async) Test(org.junit.Test)

Example 5 with Snapshot

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

the class SnapshotServiceTest method shouldSaveSnapshot.

@Test
public void shouldSaveSnapshot(TestContext context) {
    Async async = context.async();
    Snapshot expected = TestMocks.getSnapshot(0);
    snapshotService.saveSnapshot(expected, TENANT_ID).onComplete(save -> {
        if (save.failed()) {
            context.fail(save.cause());
        }
        snapshotDao.getSnapshotById(expected.getJobExecutionId(), TENANT_ID).onComplete(get -> {
            if (get.failed()) {
                context.fail(get.cause());
            }
            context.assertTrue(get.result().isPresent());
            compareSnapshots(context, expected, get.result().get());
            async.complete();
        });
    });
}
Also used : Snapshot(org.folio.rest.jaxrs.model.Snapshot) Async(io.vertx.ext.unit.Async) 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