Search in sources :

Example 1 with EXACTLY_MATCHES

use of org.folio.MatchDetail.MatchCriterion.EXACTLY_MATCHES in project mod-inventory by folio-org.

the class MatchAuthorityEventHandlerUnitTest method shouldPutMultipleMatchResultToPayloadOnHandleEventPayload.

@Test
public void shouldPutMultipleMatchResultToPayloadOnHandleEventPayload(TestContext testContext) throws UnsupportedEncodingException {
    Async async = testContext.async();
    List<Authority> matchedAuthorities = List.of(new Authority().withId(AUTHORITY_ID), new Authority().withId(UUID.randomUUID().toString()));
    MatchDetail personalNameMatchDetail = new MatchDetail().withMatchCriterion(EXACTLY_MATCHES).withExistingMatchExpression(new MatchExpression().withDataValueType(VALUE_FROM_RECORD).withFields(singletonList(new Field().withLabel("personalName").withValue("authority.personalName"))));
    doAnswer(invocation -> {
        Consumer<Success<MultipleRecords<Authority>>> successHandler = invocation.getArgument(2);
        Success<MultipleRecords<Authority>> result = new Success<>(new MultipleRecords<>(matchedAuthorities, 2));
        successHandler.accept(result);
        return null;
    }).when(collection).findByCql(eq(format("personalName == \"%s\"", PERSONAL_NAME)), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
    EventHandler eventHandler = new MatchAuthorityEventHandler(mappingMetadataCache);
    HashMap<String, String> context = new HashMap<>();
    context.put("MAPPING_PARAMS", new JsonObject().encode());
    DataImportEventPayload eventPayload = createEventPayload(personalNameMatchDetail).withContext(context);
    eventPayload.getCurrentNode().setChildSnapshotWrappers(List.of(new ProfileSnapshotWrapper().withContent(new MatchProfile().withExistingRecordType(AUTHORITY).withIncomingRecordType(MARC_BIBLIOGRAPHIC)).withContentType(MATCH_PROFILE).withReactTo(MATCH)));
    eventHandler.handle(eventPayload).whenComplete((processedPayload, throwable) -> testContext.verify(v -> {
        testContext.assertNull(throwable);
        testContext.assertEquals(1, processedPayload.getEventsChain().size());
        testContext.assertEquals(processedPayload.getEventsChain(), List.of(DI_SRS_MARC_AUTHORITY_RECORD_CREATED.value()));
        testContext.assertEquals(DI_INVENTORY_AUTHORITY_MATCHED.value(), processedPayload.getEventType());
        assertThat(new JsonArray(processedPayload.getContext().get(MULTI_MATCH_IDS)), hasItems(matchedAuthorities.get(0).getId(), matchedAuthorities.get(1).getId()));
        async.complete();
    }));
}
Also used : TestContext(io.vertx.ext.unit.TestContext) MappingMetadataDto(org.folio.MappingMetadataDto) EventHandler(org.folio.processing.events.services.handler.EventHandler) AuthorityRecordCollection(org.folio.inventory.domain.AuthorityRecordCollection) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Failure(org.folio.inventory.common.domain.Failure) AuthorityLoader(org.folio.inventory.dataimport.handlers.matching.loaders.AuthorityLoader) Matchers.hasItems(org.hamcrest.Matchers.hasItems) MarcValueReaderImpl(org.folio.processing.matching.reader.MarcValueReaderImpl) Collections.singletonList(java.util.Collections.singletonList) MockitoAnnotations(org.mockito.MockitoAnnotations) Mockito.doThrow(org.mockito.Mockito.doThrow) MULTI_MATCH_IDS(org.folio.inventory.dataimport.handlers.matching.loaders.AbstractLoader.MULTI_MATCH_IDS) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) Arrays.asList(java.util.Arrays.asList) Mockito.doAnswer(org.mockito.Mockito.doAnswer) JsonObject(io.vertx.core.json.JsonObject) MATCH(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ReactTo.MATCH) MatcherAssert.assertThat(org.hamcrest.junit.MatcherAssert.assertThat) MissingValue(org.folio.processing.value.MissingValue) AUTHORITY(org.folio.rest.jaxrs.model.EntityType.AUTHORITY) DataImportEventPayload(org.folio.DataImportEventPayload) UUID(java.util.UUID) DI_INVENTORY_AUTHORITY_MATCHED(org.folio.DataImportEventTypes.DI_INVENTORY_AUTHORITY_MATCHED) Future(io.vertx.core.Future) String.format(java.lang.String.format) Storage(org.folio.inventory.storage.Storage) List(java.util.List) StringValue(org.folio.processing.value.StringValue) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) PagingParameters(org.folio.inventory.common.api.request.PagingParameters) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DI_SRS_MARC_AUTHORITY_RECORD_CREATED(org.folio.DataImportEventTypes.DI_SRS_MARC_AUTHORITY_RECORD_CREATED) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Async(io.vertx.ext.unit.Async) Json(io.vertx.core.json.Json) Context(org.folio.inventory.common.Context) DI_INVENTORY_AUTHORITY_NOT_MATCHED(org.folio.DataImportEventTypes.DI_INVENTORY_AUTHORITY_NOT_MATCHED) MARC_AUTHORITY(org.folio.rest.jaxrs.model.EntityType.MARC_AUTHORITY) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) EXACTLY_MATCHES(org.folio.MatchDetail.MatchCriterion.EXACTLY_MATCHES) MultipleRecords(org.folio.inventory.common.domain.MultipleRecords) ArrayList(java.util.ArrayList) MARC_BIBLIOGRAPHIC(org.folio.rest.jaxrs.model.EntityType.MARC_BIBLIOGRAPHIC) MAPPING_PROFILE(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.MAPPING_PROFILE) MatchProfile(org.folio.MatchProfile) MatchAuthorityEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchAuthorityEventHandler) ListValue(org.folio.processing.value.ListValue) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) MatchValueReaderFactory(org.folio.processing.matching.reader.MatchValueReaderFactory) MatchDetail(org.folio.MatchDetail) Identifier___(org.folio.Identifier___) MatchExpression(org.folio.rest.jaxrs.model.MatchExpression) Vertx(io.vertx.core.Vertx) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) Mockito.when(org.mockito.Mockito.when) VALUE_FROM_RECORD(org.folio.rest.jaxrs.model.MatchExpression.DataValueType.VALUE_FROM_RECORD) MATCH_PROFILE(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.MATCH_PROFILE) Consumer(java.util.function.Consumer) JsonArray(io.vertx.core.json.JsonArray) Mockito(org.mockito.Mockito) Authority(org.folio.Authority) Field(org.folio.rest.jaxrs.model.Field) Success(org.folio.inventory.common.domain.Success) MatchValueLoaderFactory(org.folio.processing.matching.loader.MatchValueLoaderFactory) MappingMetadataCache(org.folio.inventory.dataimport.cache.MappingMetadataCache) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PagingParameters(org.folio.inventory.common.api.request.PagingParameters) Authority(org.folio.Authority) HashMap(java.util.HashMap) MatchAuthorityEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchAuthorityEventHandler) EventHandler(org.folio.processing.events.services.handler.EventHandler) MatchAuthorityEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchAuthorityEventHandler) JsonObject(io.vertx.core.json.JsonObject) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MatchExpression(org.folio.rest.jaxrs.model.MatchExpression) Success(org.folio.inventory.common.domain.Success) DataImportEventPayload(org.folio.DataImportEventPayload) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) JsonArray(io.vertx.core.json.JsonArray) Field(org.folio.rest.jaxrs.model.Field) MatchProfile(org.folio.MatchProfile) Consumer(java.util.function.Consumer) Async(io.vertx.ext.unit.Async) MultipleRecords(org.folio.inventory.common.domain.MultipleRecords) MatchDetail(org.folio.MatchDetail) Test(org.junit.Test)

Example 2 with EXACTLY_MATCHES

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

the class MarcBibliographicMatchEventHandlerTest method shouldMatchByMatchedIdField.

@Test
public void shouldMatchByMatchedIdField(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("a"))))))));
    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)

Example 3 with EXACTLY_MATCHES

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

the class MarcBibliographicMatchEventHandlerTest method shouldMatchByInstanceHridField.

@Test
public void shouldMatchByInstanceHridField(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("001"), new Field().withLabel("indicator1").withValue(""), new Field().withLabel("indicator2").withValue(""), new Field().withLabel("recordSubfield").withValue("")))).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("d"))))))));
    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)

Example 4 with EXACTLY_MATCHES

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

the class MarcAuthorityMatchEventHandlerTest method shouldNotMatchBy001Field.

@Test
public void shouldNotMatchBy001Field(TestContext context) {
    Async async = context.async();
    HashMap<String, String> payloadContext = new HashMap<>();
    payloadContext.put(EntityType.MARC_AUTHORITY.value(), Json.encode(existingRecord));
    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_AUTHORITY).withIncomingRecordType(EntityType.MARC_AUTHORITY).withMatchDetails(singletonList(new MatchDetail().withMatchCriterion(EXACTLY_MATCHES).withExistingMatchExpression(new MatchExpression().withDataValueType(VALUE_FROM_RECORD).withFields(Lists.newArrayList(new Field().withLabel("field").withValue("001")))).withExistingRecordType(EntityType.MARC_AUTHORITY).withIncomingRecordType(EntityType.MARC_AUTHORITY).withIncomingMatchExpression(new MatchExpression().withDataValueType(VALUE_FROM_RECORD).withFields(Lists.newArrayList(new Field().withLabel("field").withValue("035"), new Field().withLabel("indicator1").withValue(""), new Field().withLabel("indicator2").withValue(""), new Field().withLabel("recordSubfield").withValue("a"))))))));
    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_AUTHORITY_RECORD_NOT_MATCHED.value());
        context.assertNull(updatedEventPayload.getContext().get(MATCHED_MARC_KEY));
        async.complete();
    }));
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Json(io.vertx.core.json.Json) EventHandler(org.folio.processing.events.services.handler.EventHandler) RecordDaoImpl(org.folio.dao.RecordDaoImpl) BeforeClass(org.junit.BeforeClass) MarcAuthorityMatchEventHandler(org.folio.services.handlers.match.MarcAuthorityMatchEventHandler) Date(java.util.Date) RawRecord(org.folio.rest.jaxrs.model.RawRecord) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) EXACTLY_MATCHES(org.folio.MatchDetail.MatchCriterion.EXACTLY_MATCHES) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) MockitoAnnotations(org.mockito.MockitoAnnotations) MARC_AUTHORITY(org.folio.rest.jaxrs.model.Record.RecordType.MARC_AUTHORITY) 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) DI_SRS_MARC_AUTHORITY_RECORD_CREATED(org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_AUTHORITY_RECORD_CREATED) JsonObject(io.vertx.core.json.JsonObject) MatchProfile(org.folio.MatchProfile) MappingProfile(org.folio.MappingProfile) Before(org.junit.Before) MatchDetail(org.folio.MatchDetail) DI_SRS_MARC_AUTHORITY_RECORD_NOT_MATCHED(org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_AUTHORITY_RECORD_NOT_MATCHED) RecordDao(org.folio.dao.RecordDao) MatchExpression(org.folio.rest.jaxrs.model.MatchExpression) Record(org.folio.rest.jaxrs.model.Record) 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) DI_SRS_MARC_AUTHORITY_RECORD_MATCHED(org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_AUTHORITY_RECORD_MATCHED) 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) 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 5 with EXACTLY_MATCHES

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

the class MarcAuthorityMatchEventHandlerTest method shouldMatchBy010aField.

@Test
public void shouldMatchBy010aField(TestContext context) {
    Async async = context.async();
    HashMap<String, String> payloadContext = new HashMap<>();
    payloadContext.put(EntityType.MARC_AUTHORITY.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_AUTHORITY).withIncomingRecordType(EntityType.MARC_AUTHORITY).withMatchDetails(singletonList(new MatchDetail().withMatchCriterion(EXACTLY_MATCHES).withExistingRecordType(EntityType.MARC_AUTHORITY).withExistingMatchExpression(new MatchExpression().withDataValueType(VALUE_FROM_RECORD).withFields(Lists.newArrayList(new Field().withLabel("field").withValue("010"), new Field().withLabel("indicator1").withValue(""), new Field().withLabel("indicator2").withValue(""), new Field().withLabel("recordSubfield").withValue("a")))).withIncomingRecordType(EntityType.MARC_AUTHORITY).withIncomingMatchExpression(new MatchExpression().withDataValueType(VALUE_FROM_RECORD).withFields(Lists.newArrayList(new Field().withLabel("field").withValue("010"), new Field().withLabel("indicator1").withValue(""), new Field().withLabel("indicator2").withValue(""), new Field().withLabel("recordSubfield").withValue("a"))))))));
    recordDao.saveRecord(existingRecord, TENANT_ID).onComplete(context.asyncAssertSuccess()).onSuccess(existingSavedRecord -> handler.handle(dataImportEventPayload).whenComplete((updatedEventPayload, throwable) -> {
        context.assertNull(throwable);
        context.assertEquals(1, updatedEventPayload.getEventsChain().size());
        context.assertEquals(updatedEventPayload.getEventType(), DI_SRS_MARC_AUTHORITY_RECORD_MATCHED.value());
        context.assertEquals(new JsonObject(updatedEventPayload.getContext().get(MATCHED_MARC_KEY)).mapTo(Record.class), existingSavedRecord);
        async.complete();
    }));
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Json(io.vertx.core.json.Json) EventHandler(org.folio.processing.events.services.handler.EventHandler) RecordDaoImpl(org.folio.dao.RecordDaoImpl) BeforeClass(org.junit.BeforeClass) MarcAuthorityMatchEventHandler(org.folio.services.handlers.match.MarcAuthorityMatchEventHandler) Date(java.util.Date) RawRecord(org.folio.rest.jaxrs.model.RawRecord) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) EXACTLY_MATCHES(org.folio.MatchDetail.MatchCriterion.EXACTLY_MATCHES) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) MockitoAnnotations(org.mockito.MockitoAnnotations) MARC_AUTHORITY(org.folio.rest.jaxrs.model.Record.RecordType.MARC_AUTHORITY) 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) DI_SRS_MARC_AUTHORITY_RECORD_CREATED(org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_AUTHORITY_RECORD_CREATED) JsonObject(io.vertx.core.json.JsonObject) MatchProfile(org.folio.MatchProfile) MappingProfile(org.folio.MappingProfile) Before(org.junit.Before) MatchDetail(org.folio.MatchDetail) DI_SRS_MARC_AUTHORITY_RECORD_NOT_MATCHED(org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_AUTHORITY_RECORD_NOT_MATCHED) RecordDao(org.folio.dao.RecordDao) MatchExpression(org.folio.rest.jaxrs.model.MatchExpression) Record(org.folio.rest.jaxrs.model.Record) 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) DI_SRS_MARC_AUTHORITY_RECORD_MATCHED(org.folio.rest.jaxrs.model.DataImportEventTypes.DI_SRS_MARC_AUTHORITY_RECORD_MATCHED) 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) 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

Json (io.vertx.core.json.Json)11 JsonObject (io.vertx.core.json.JsonObject)11 Async (io.vertx.ext.unit.Async)11 TestContext (io.vertx.ext.unit.TestContext)11 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)11 ArrayList (java.util.ArrayList)11 Collections.singletonList (java.util.Collections.singletonList)11 HashMap (java.util.HashMap)11 List (java.util.List)11 UUID (java.util.UUID)11 DataImportEventPayload (org.folio.DataImportEventPayload)11 MatchDetail (org.folio.MatchDetail)11 EXACTLY_MATCHES (org.folio.MatchDetail.MatchCriterion.EXACTLY_MATCHES)11 MatchProfile (org.folio.MatchProfile)11 Field (org.folio.rest.jaxrs.model.Field)11 MatchExpression (org.folio.rest.jaxrs.model.MatchExpression)11 VALUE_FROM_RECORD (org.folio.rest.jaxrs.model.MatchExpression.DataValueType.VALUE_FROM_RECORD)11 ProfileSnapshotWrapper (org.folio.rest.jaxrs.model.ProfileSnapshotWrapper)11 MAPPING_PROFILE (org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.MAPPING_PROFILE)11 MATCH_PROFILE (org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.MATCH_PROFILE)11