Search in sources :

Example 1 with RawRecord

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

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

the class QuickMarcKafkaHandlerTest method setUpClass.

@BeforeClass
public static void setUpClass() throws IOException {
    rawRecord = new RawRecord().withId(recordId).withContent(new ObjectMapper().readValue(TestUtil.readFileFromPath(RAW_MARC_RECORD_CONTENT_SAMPLE_PATH), String.class));
    parsedRecord = new ParsedRecord().withId(recordId).withContent(new ObjectMapper().readValue(TestUtil.readFileFromPath(PARSED_MARC_RECORD_CONTENT_SAMPLE_PATH), JsonObject.class).encode());
}
Also used : RawRecord(org.folio.rest.jaxrs.model.RawRecord) JsonObject(io.vertx.core.json.JsonObject) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BeforeClass(org.junit.BeforeClass)

Example 3 with RawRecord

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

the class HoldingsPostProcessingEventHandlerTest method shouldUpdateField005WhenThisFiledIsNotProtected.

@Test
public void shouldUpdateField005WhenThisFiledIsNotProtected(TestContext context) throws IOException {
    Async async = context.async();
    String expectedDate = AdditionalFieldsUtil.dateTime005Formatter.format(ZonedDateTime.ofInstant(Instant.now(), ZoneId.systemDefault()));
    String recordId = UUID.randomUUID().toString();
    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(new ObjectMapper().readValue(TestUtil.readFileFromPath(PARSED_MARC_RECORD_CONTENT_SAMPLE_PATH), JsonObject.class).encode());
    Record defaultRecord = new Record().withId(recordId).withMatchedId(recordId).withSnapshotId(snapshotId1).withGeneration(0).withRecordType(MARC_HOLDING).withRawRecord(rawRecord).withParsedRecord(parsedRecord);
    String expectedHoldingsId = UUID.randomUUID().toString();
    String expectedHrId = UUID.randomUUID().toString();
    JsonObject holdings = createExternalEntity(expectedHoldingsId, expectedHrId);
    HashMap<String, String> payloadContext = new HashMap<>();
    payloadContext.put(HOLDINGS.value(), holdings.encode());
    payloadContext.put(MARC_HOLDINGS.value(), Json.encode(defaultRecord));
    DataImportEventPayload dataImportEventPayload = createDataImportEventPayload(payloadContext, DI_INVENTORY_HOLDINGS_CREATED_READY_FOR_POST_PROCESSING);
    CompletableFuture<DataImportEventPayload> future = handler.handle(dataImportEventPayload);
    future.whenComplete((payload, throwable) -> {
        if (throwable != null) {
            context.fail(throwable);
        }
        recordDao.getRecordByMatchedId(defaultRecord.getMatchedId(), TENANT_ID).onComplete(getAr -> {
            if (getAr.failed()) {
                context.fail(getAr.cause());
            }
            context.assertTrue(getAr.result().isPresent());
            Record updatedRecord = getAr.result().get();
            String actualDate = AdditionalFieldsUtil.getValueFromControlledField(updatedRecord, TAG_005);
            Assert.assertEquals(expectedDate.substring(0, 10), actualDate.substring(0, 10));
            async.complete();
        });
    });
}
Also used : HashMap(java.util.HashMap) Async(io.vertx.ext.unit.Async) RawRecord(org.folio.rest.jaxrs.model.RawRecord) JsonObject(io.vertx.core.json.JsonObject) 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) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DataImportEventPayload(org.folio.DataImportEventPayload) Test(org.junit.Test)

Example 4 with RawRecord

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

the class HoldingsPostProcessingEventHandlerTest method shouldSaveRecordWhenRecordDoesntExist.

@Test
public void shouldSaveRecordWhenRecordDoesntExist(TestContext context) throws IOException {
    Async async = context.async();
    String recordId = UUID.randomUUID().toString();
    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(new ObjectMapper().readValue(TestUtil.readFileFromPath(PARSED_MARC_RECORD_CONTENT_SAMPLE_PATH), JsonObject.class).encode());
    Record defaultRecord = new Record().withId(recordId).withMatchedId(recordId).withSnapshotId(snapshotId1).withGeneration(0).withRecordType(MARC_HOLDING).withRawRecord(rawRecord).withParsedRecord(parsedRecord);
    String expectedHoldingsId = UUID.randomUUID().toString();
    String expectedHrId = UUID.randomUUID().toString();
    JsonObject holdings = createExternalEntity(expectedHoldingsId, expectedHrId);
    HashMap<String, String> payloadContext = new HashMap<>();
    payloadContext.put(HOLDINGS.value(), holdings.encode());
    payloadContext.put(MARC_HOLDINGS.value(), Json.encode(defaultRecord));
    DataImportEventPayload dataImportEventPayload = createDataImportEventPayload(payloadContext, DI_INVENTORY_HOLDINGS_CREATED_READY_FOR_POST_PROCESSING);
    CompletableFuture<DataImportEventPayload> future = handler.handle(dataImportEventPayload);
    future.whenComplete((payload, e) -> {
        if (e != null) {
            context.fail(e);
        }
        recordDao.getRecordByMatchedId(defaultRecord.getMatchedId(), TENANT_ID).onComplete(getAr -> {
            if (getAr.failed()) {
                context.fail(getAr.cause());
            }
            context.assertTrue(getAr.result().isPresent());
            Record savedRecord = getAr.result().get();
            context.assertNotNull(savedRecord.getExternalIdsHolder());
            context.assertEquals(expectedHoldingsId, savedRecord.getExternalIdsHolder().getHoldingsId());
            context.assertNotNull(savedRecord.getParsedRecord());
            context.assertNotNull(savedRecord.getParsedRecord().getContent());
            JsonObject parsedContent = JsonObject.mapFrom(savedRecord.getParsedRecord().getContent());
            JsonArray fields = parsedContent.getJsonArray("fields");
            context.assertTrue(!fields.isEmpty());
            String actualHoldingsId = getInventoryId(fields);
            context.assertEquals(expectedHoldingsId, actualHoldingsId);
            async.complete();
        });
    });
}
Also used : JsonArray(io.vertx.core.json.JsonArray) HashMap(java.util.HashMap) Async(io.vertx.ext.unit.Async) RawRecord(org.folio.rest.jaxrs.model.RawRecord) JsonObject(io.vertx.core.json.JsonObject) 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) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DataImportEventPayload(org.folio.DataImportEventPayload) Test(org.junit.Test)

Example 5 with RawRecord

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

the class InstancePostProcessingEventHandlerTest method shouldSaveRecordWhenRecordDoesntExist.

@Test
public void shouldSaveRecordWhenRecordDoesntExist(TestContext context) throws IOException {
    Async async = context.async();
    String recordId = UUID.randomUUID().toString();
    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(new ObjectMapper().readValue(TestUtil.readFileFromPath(PARSED_MARC_RECORD_CONTENT_SAMPLE_PATH), JsonObject.class).encode());
    Record defaultRecord = new Record().withId(recordId).withMatchedId(recordId).withSnapshotId(snapshotId1).withGeneration(0).withRecordType(MARC_BIB).withRawRecord(rawRecord).withParsedRecord(parsedRecord);
    String expectedInstanceId = UUID.randomUUID().toString();
    String expectedHrId = UUID.randomUUID().toString();
    JsonObject instance = createExternalEntity(expectedInstanceId, expectedHrId);
    HashMap<String, String> payloadContext = new HashMap<>();
    payloadContext.put(INSTANCE.value(), instance.encode());
    payloadContext.put(MARC_BIBLIOGRAPHIC.value(), Json.encode(defaultRecord));
    DataImportEventPayload dataImportEventPayload = createDataImportEventPayload(payloadContext, DI_INVENTORY_INSTANCE_CREATED_READY_FOR_POST_PROCESSING);
    CompletableFuture<DataImportEventPayload> future = handler.handle(dataImportEventPayload);
    future.whenComplete((payload, e) -> {
        if (e != null) {
            context.fail(e);
        }
        recordDao.getRecordByMatchedId(defaultRecord.getMatchedId(), TENANT_ID).onComplete(getAr -> {
            if (getAr.failed()) {
                context.fail(getAr.cause());
            }
            context.assertTrue(getAr.result().isPresent());
            Record savedRecord = getAr.result().get();
            context.assertNotNull(savedRecord.getExternalIdsHolder());
            context.assertEquals(expectedInstanceId, savedRecord.getExternalIdsHolder().getInstanceId());
            context.assertNotNull(savedRecord.getParsedRecord());
            context.assertNotNull(savedRecord.getParsedRecord().getContent());
            JsonObject parsedContent = JsonObject.mapFrom(savedRecord.getParsedRecord().getContent());
            JsonArray fields = parsedContent.getJsonArray("fields");
            context.assertTrue(!fields.isEmpty());
            String actualInstanceId = getInventoryId(fields);
            context.assertEquals(expectedInstanceId, actualInstanceId);
            async.complete();
        });
    });
}
Also used : JsonArray(io.vertx.core.json.JsonArray) HashMap(java.util.HashMap) Async(io.vertx.ext.unit.Async) RawRecord(org.folio.rest.jaxrs.model.RawRecord) JsonObject(io.vertx.core.json.JsonObject) 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) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DataImportEventPayload(org.folio.DataImportEventPayload) Test(org.junit.Test)

Aggregations

RawRecord (org.folio.rest.jaxrs.model.RawRecord)64 ParsedRecord (org.folio.rest.jaxrs.model.ParsedRecord)61 Record (org.folio.rest.jaxrs.model.Record)57 Async (io.vertx.ext.unit.Async)53 Test (org.junit.Test)47 JsonObject (io.vertx.core.json.JsonObject)31 ErrorRecord (org.folio.rest.jaxrs.model.ErrorRecord)30 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)27 SourceRecord (org.folio.rest.jaxrs.model.SourceRecord)22 Snapshot (org.folio.rest.jaxrs.model.Snapshot)20 ExternalIdsHolder (org.folio.rest.jaxrs.model.ExternalIdsHolder)19 Before (org.junit.Before)17 Date (java.util.Date)16 Response (io.restassured.response.Response)15 UUID (java.util.UUID)14 TestContext (io.vertx.ext.unit.TestContext)13 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)13 IOException (java.io.IOException)13 ArrayList (java.util.ArrayList)13 TestUtil (org.folio.TestUtil)13