Search in sources :

Example 6 with Snapshot

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

the class MarcBibliographicMatchEventHandlerTest method setUp.

@Before
public void setUp(TestContext context) {
    MockitoAnnotations.initMocks(this);
    recordDao = new RecordDaoImpl(postgresClientFactory);
    handler = new MarcBibliographicMatchEventHandler(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);
    String existingRecordId = "acf4f6e2-115c-4509-9d4c-536c758ef917";
    this.existingRecord = new Record().withId(existingRecordId).withMatchedId(existingRecordId).withSnapshotId(existingRecordSnapshot.getJobExecutionId()).withGeneration(0).withRecordType(MARC_BIB).withRawRecord(new RawRecord().withId(existingRecordId).withContent(rawRecordContent)).withParsedRecord(new ParsedRecord().withId(existingRecordId).withContent(PARSED_CONTENT_WITH_ADDITIONAL_FIELDS)).withExternalIdsHolder(new ExternalIdsHolder().withInstanceId("681394b4-10d8-4cb1-a618-0f9bd6152119").withInstanceHrid("12345"));
    String incomingRecordId = UUID.randomUUID().toString();
    this.incomingRecord = new Record().withId(incomingRecordId).withMatchedId(existingRecordId).withSnapshotId(incomingRecordSnapshot.getJobExecutionId()).withGeneration(1).withRecordType(MARC_BIB).withRawRecord(new RawRecord().withId(incomingRecordId).withContent(rawRecordContent)).withParsedRecord(new ParsedRecord().withId(incomingRecordId).withContent(PARSED_CONTENT_WITH_ADDITIONAL_FIELDS)).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) MarcBibliographicMatchEventHandler(org.folio.services.handlers.match.MarcBibliographicMatchEventHandler) 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 7 with Snapshot

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

the class SnapshotServiceTest method shouldGetSnapshotById.

@Test
public void shouldGetSnapshotById(TestContext context) {
    Async async = context.async();
    Snapshot expected = TestMocks.getSnapshot(0);
    snapshotDao.saveSnapshot(expected, TENANT_ID).onComplete(save -> {
        if (save.failed()) {
            context.fail(save.cause());
        }
        snapshotService.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)

Example 8 with Snapshot

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

the class SnapshotServiceTest method shouldUpdateSnapshot.

@Test
public void shouldUpdateSnapshot(TestContext context) {
    Async async = context.async();
    Snapshot original = TestMocks.getSnapshot(0);
    snapshotDao.saveSnapshot(original, TENANT_ID).onComplete(save -> {
        if (save.failed()) {
            context.fail(save.cause());
        }
        Snapshot expected = new Snapshot().withJobExecutionId(original.getJobExecutionId()).withStatus(Status.COMMITTED).withProcessingStartedDate(original.getProcessingStartedDate()).withMetadata(original.getMetadata());
        snapshotService.updateSnapshot(expected, TENANT_ID).onComplete(update -> {
            if (update.failed()) {
                context.fail(update.cause());
            }
            context.assertTrue(update.result().getMetadata().getUpdatedDate().after(update.result().getMetadata().getCreatedDate()));
            compareSnapshots(context, expected, update.result());
            async.complete();
        });
    });
}
Also used : Snapshot(org.folio.rest.jaxrs.model.Snapshot) Async(io.vertx.ext.unit.Async) Test(org.junit.Test)

Example 9 with Snapshot

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

the class MarcAuthorityUpdateModifyEventHandlerTest 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 MarcAuthorityUpdateModifyEventHandler(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) JOB_PROFILE(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.JOB_PROFILE) RecordDaoImpl(org.folio.dao.RecordDaoImpl) 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) UUID(java.util.UUID) SnapshotDaoUtil(org.folio.dao.util.SnapshotDaoUtil) Data(org.folio.rest.jaxrs.model.Data) MODIFY(org.folio.ActionProfile.Action.MODIFY) Slf4jNotifier(com.github.tomakehurst.wiremock.common.Slf4jNotifier) RunTestOnContext(io.vertx.ext.unit.junit.RunTestOnContext) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) MarcAuthorityUpdateModifyEventHandler(org.folio.services.handlers.actions.MarcAuthorityUpdateModifyEventHandler) Async(io.vertx.ext.unit.Async) Json(io.vertx.core.json.Json) MARC_AUTHORITY(org.folio.rest.jaxrs.model.EntityType.MARC_AUTHORITY) BeforeClass(org.junit.BeforeClass) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) WireMockConfiguration(com.github.tomakehurst.wiremock.core.WireMockConfiguration) RunWith(org.junit.runner.RunWith) RawRecord(org.folio.rest.jaxrs.model.RawRecord) 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) MARC_BIBLIOGRAPHIC(org.folio.rest.jaxrs.model.EntityType.MARC_BIBLIOGRAPHIC) WireMockRule(com.github.tomakehurst.wiremock.junit.WireMockRule) 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) IOException(java.io.IOException) ReactiveClassicGenericQueryExecutor(io.github.jklingsporn.vertx.jooq.classic.reactivepg.ReactiveClassicGenericQueryExecutor) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) DI_SRS_MARC_BIB_RECORD_CREATED(org.folio.DataImportEventTypes.DI_SRS_MARC_BIB_RECORD_CREATED) DI_SRS_MARC_AUTHORITY_RECORD_UPDATED(org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_AUTHORITY_RECORD_UPDATED) 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) Collections(java.util.Collections) Snapshot(org.folio.rest.jaxrs.model.Snapshot) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) ReactiveClassicGenericQueryExecutor(io.github.jklingsporn.vertx.jooq.classic.reactivepg.ReactiveClassicGenericQueryExecutor) MarcAuthorityUpdateModifyEventHandler(org.folio.services.handlers.actions.MarcAuthorityUpdateModifyEventHandler) 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 10 with Snapshot

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

the class AbstractRestVerticleTest method postSnapshots.

protected void postSnapshots(TestContext testContext, Snapshot... snapshots) {
    Async async = testContext.async();
    for (Snapshot snapshot : snapshots) {
        RestAssured.given().spec(spec).body(snapshot).when().post(SOURCE_STORAGE_SNAPSHOTS_PATH).then().statusCode(HttpStatus.SC_CREATED);
    }
    async.complete();
}
Also used : Snapshot(org.folio.rest.jaxrs.model.Snapshot) Async(io.vertx.ext.unit.Async)

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