Search in sources :

Example 21 with MatchDetail

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

the class MarcBibliographicMatchEventHandlerTest method shouldNotMatchByMatchedIdField.

@Test
public void shouldNotMatchByMatchedIdField(TestContext context) {
    Async async = context.async();
    HashMap<String, String> payloadContext = new HashMap<>();
    payloadContext.put(EntityType.MARC_BIBLIOGRAPHIC.value(), Json.encode(incomingRecord));
    DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withContext(payloadContext).withTenant(TENANT_ID).withCurrentNode(new ProfileSnapshotWrapper().withId(UUID.randomUUID().toString()).withContentType(MATCH_PROFILE).withContent(new MatchProfile().withExistingRecordType(EntityType.MARC_BIBLIOGRAPHIC).withIncomingRecordType(EntityType.MARC_BIBLIOGRAPHIC).withMatchDetails(singletonList(new MatchDetail().withMatchCriterion(EXACTLY_MATCHES).withExistingMatchExpression(new MatchExpression().withDataValueType(VALUE_FROM_RECORD).withFields(Lists.newArrayList(new Field().withLabel("field").withValue("999"), new Field().withLabel("indicator1").withValue("f"), new Field().withLabel("indicator2").withValue("f"), new Field().withLabel("recordSubfield").withValue("s")))).withExistingRecordType(EntityType.MARC_BIBLIOGRAPHIC).withIncomingRecordType(EntityType.MARC_BIBLIOGRAPHIC).withIncomingMatchExpression(new MatchExpression().withDataValueType(VALUE_FROM_RECORD).withFields(Lists.newArrayList(new Field().withLabel("field").withValue("948"), new Field().withLabel("indicator1").withValue(""), new Field().withLabel("indicator2").withValue(""), new Field().withLabel("recordSubfield").withValue("b"))))))));
    recordDao.saveRecord(existingRecord, TENANT_ID).onComplete(context.asyncAssertSuccess()).onSuccess(record -> handler.handle(dataImportEventPayload).whenComplete((updatedEventPayload, throwable) -> {
        context.assertNull(throwable);
        context.assertEquals(1, updatedEventPayload.getEventsChain().size());
        context.assertEquals(updatedEventPayload.getEventType(), DI_SRS_MARC_BIB_RECORD_NOT_MATCHED.value());
        async.complete();
    }));
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Json(io.vertx.core.json.Json) DI_SRS_MARC_BIB_RECORD_MATCHED(org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_BIB_RECORD_MATCHED) MarcBibliographicMatchEventHandler(org.folio.services.handlers.match.MarcBibliographicMatchEventHandler) RecordDaoImpl(org.folio.dao.RecordDaoImpl) BeforeClass(org.junit.BeforeClass) Date(java.util.Date) RawRecord(org.folio.rest.jaxrs.model.RawRecord) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) DI_SRS_MARC_BIB_RECORD_NOT_MATCHED(org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_BIB_RECORD_NOT_MATCHED) EXACTLY_MATCHES(org.folio.MatchDetail.MatchCriterion.EXACTLY_MATCHES) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) MockitoAnnotations(org.mockito.MockitoAnnotations) Lists(com.google.common.collect.Lists) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) TestUtil(org.folio.TestUtil) After(org.junit.After) EntityType(org.folio.rest.jaxrs.model.EntityType) MAPPING_PROFILE(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.MAPPING_PROFILE) JsonObject(io.vertx.core.json.JsonObject) MatchProfile(org.folio.MatchProfile) MappingProfile(org.folio.MappingProfile) Before(org.junit.Before) INSTANCE(org.folio.rest.jaxrs.model.EntityType.INSTANCE) MatchDetail(org.folio.MatchDetail) RecordDao(org.folio.dao.RecordDao) MatchExpression(org.folio.rest.jaxrs.model.MatchExpression) Record(org.folio.rest.jaxrs.model.Record) RecordDaoUtil(org.folio.dao.util.RecordDaoUtil) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DataImportEventPayload(org.folio.DataImportEventPayload) 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) VALUE_FROM_RECORD(org.folio.rest.jaxrs.model.MatchExpression.DataValueType.VALUE_FROM_RECORD) MATCH_PROFILE(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.MATCH_PROFILE) List(java.util.List) MARC_BIB(org.folio.rest.jaxrs.model.Record.RecordType.MARC_BIB) Field(org.folio.rest.jaxrs.model.Field) Assert(org.junit.Assert) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Snapshot(org.folio.rest.jaxrs.model.Snapshot) Field(org.folio.rest.jaxrs.model.Field) MatchProfile(org.folio.MatchProfile) HashMap(java.util.HashMap) Async(io.vertx.ext.unit.Async) MatchDetail(org.folio.MatchDetail) MatchExpression(org.folio.rest.jaxrs.model.MatchExpression) DataImportEventPayload(org.folio.DataImportEventPayload) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) Test(org.junit.Test)

Example 22 with MatchDetail

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

the class MarcBibliographicMatchEventHandlerTest method shouldMatchByInstanceIdField.

@Test
public void shouldMatchByInstanceIdField(TestContext context) {
    Async async = context.async();
    HashMap<String, String> payloadContext = new HashMap<>();
    payloadContext.put(EntityType.MARC_BIBLIOGRAPHIC.value(), Json.encode(incomingRecord));
    DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withContext(payloadContext).withTenant(TENANT_ID).withCurrentNode(new ProfileSnapshotWrapper().withId(UUID.randomUUID().toString()).withContentType(MATCH_PROFILE).withContent(new MatchProfile().withExistingRecordType(EntityType.MARC_BIBLIOGRAPHIC).withIncomingRecordType(EntityType.MARC_BIBLIOGRAPHIC).withMatchDetails(singletonList(new MatchDetail().withMatchCriterion(EXACTLY_MATCHES).withExistingMatchExpression(new MatchExpression().withDataValueType(VALUE_FROM_RECORD).withFields(Lists.newArrayList(new Field().withLabel("field").withValue("999"), new Field().withLabel("indicator1").withValue("f"), new Field().withLabel("indicator2").withValue("f"), new Field().withLabel("recordSubfield").withValue("i")))).withExistingRecordType(EntityType.MARC_BIBLIOGRAPHIC).withIncomingRecordType(EntityType.MARC_BIBLIOGRAPHIC).withIncomingMatchExpression(new MatchExpression().withDataValueType(VALUE_FROM_RECORD).withFields(Lists.newArrayList(new Field().withLabel("field").withValue("948"), new Field().withLabel("indicator1").withValue(""), new Field().withLabel("indicator2").withValue(""), new Field().withLabel("recordSubfield").withValue("b"))))))));
    recordDao.saveRecord(existingRecord, TENANT_ID).onComplete(context.asyncAssertSuccess()).onSuccess(record -> handler.handle(dataImportEventPayload).whenComplete((updatedEventPayload, throwable) -> {
        context.assertNull(throwable);
        context.assertEquals(1, updatedEventPayload.getEventsChain().size());
        context.assertEquals(updatedEventPayload.getEventType(), DI_SRS_MARC_BIB_RECORD_MATCHED.value());
        context.assertEquals(new JsonObject(updatedEventPayload.getContext().get(MATCHED_MARC_BIB_KEY)).mapTo(Record.class), record);
        async.complete();
    }));
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Json(io.vertx.core.json.Json) DI_SRS_MARC_BIB_RECORD_MATCHED(org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_BIB_RECORD_MATCHED) MarcBibliographicMatchEventHandler(org.folio.services.handlers.match.MarcBibliographicMatchEventHandler) RecordDaoImpl(org.folio.dao.RecordDaoImpl) BeforeClass(org.junit.BeforeClass) Date(java.util.Date) RawRecord(org.folio.rest.jaxrs.model.RawRecord) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) DI_SRS_MARC_BIB_RECORD_NOT_MATCHED(org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_BIB_RECORD_NOT_MATCHED) EXACTLY_MATCHES(org.folio.MatchDetail.MatchCriterion.EXACTLY_MATCHES) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) MockitoAnnotations(org.mockito.MockitoAnnotations) Lists(com.google.common.collect.Lists) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) TestUtil(org.folio.TestUtil) After(org.junit.After) EntityType(org.folio.rest.jaxrs.model.EntityType) MAPPING_PROFILE(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.MAPPING_PROFILE) JsonObject(io.vertx.core.json.JsonObject) MatchProfile(org.folio.MatchProfile) MappingProfile(org.folio.MappingProfile) Before(org.junit.Before) INSTANCE(org.folio.rest.jaxrs.model.EntityType.INSTANCE) MatchDetail(org.folio.MatchDetail) RecordDao(org.folio.dao.RecordDao) MatchExpression(org.folio.rest.jaxrs.model.MatchExpression) Record(org.folio.rest.jaxrs.model.Record) RecordDaoUtil(org.folio.dao.util.RecordDaoUtil) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DataImportEventPayload(org.folio.DataImportEventPayload) 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) VALUE_FROM_RECORD(org.folio.rest.jaxrs.model.MatchExpression.DataValueType.VALUE_FROM_RECORD) MATCH_PROFILE(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.MATCH_PROFILE) List(java.util.List) MARC_BIB(org.folio.rest.jaxrs.model.Record.RecordType.MARC_BIB) Field(org.folio.rest.jaxrs.model.Field) Assert(org.junit.Assert) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Snapshot(org.folio.rest.jaxrs.model.Snapshot) Field(org.folio.rest.jaxrs.model.Field) MatchProfile(org.folio.MatchProfile) HashMap(java.util.HashMap) Async(io.vertx.ext.unit.Async) JsonObject(io.vertx.core.json.JsonObject) MatchDetail(org.folio.MatchDetail) MatchExpression(org.folio.rest.jaxrs.model.MatchExpression) DataImportEventPayload(org.folio.DataImportEventPayload) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) Test(org.junit.Test)

Aggregations

DataImportEventPayload (org.folio.DataImportEventPayload)22 MatchDetail (org.folio.MatchDetail)22 Field (org.folio.rest.jaxrs.model.Field)22 MatchExpression (org.folio.rest.jaxrs.model.MatchExpression)22 Async (io.vertx.ext.unit.Async)21 Test (org.junit.Test)21 EventHandler (org.folio.processing.events.services.handler.EventHandler)17 JsonObject (io.vertx.core.json.JsonObject)14 HashMap (java.util.HashMap)14 ArrayList (java.util.ArrayList)13 Json (io.vertx.core.json.Json)12 List (java.util.List)12 MatchProfile (org.folio.MatchProfile)12 VALUE_FROM_RECORD (org.folio.rest.jaxrs.model.MatchExpression.DataValueType.VALUE_FROM_RECORD)12 ProfileSnapshotWrapper (org.folio.rest.jaxrs.model.ProfileSnapshotWrapper)12 MATCH_PROFILE (org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.MATCH_PROFILE)12 TestContext (io.vertx.ext.unit.TestContext)11 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)11 Collections.singletonList (java.util.Collections.singletonList)11 UUID (java.util.UUID)11