Search in sources :

Example 1 with INSTANCE

use of org.folio.rest.jaxrs.model.EntityType.INSTANCE in project mod-inventory by folio-org.

the class MatchInstanceEventHandlerUnitTest method shouldPutMultipleMatchResultToPayloadOnHandleEventPayload.

@Test
public void shouldPutMultipleMatchResultToPayloadOnHandleEventPayload(TestContext testContext) throws UnsupportedEncodingException {
    Async async = testContext.async();
    List<Instance> matchedInstances = List.of(new Instance(UUID.randomUUID().toString(), "1", "in1", "MARC", "Wonderful", "12334"), new Instance(UUID.randomUUID().toString(), "1", "in2", "MARC", "Wonderful", "12334"));
    doAnswer(invocation -> {
        Consumer<Success<MultipleRecords<Instance>>> successHandler = invocation.getArgument(2);
        Success<MultipleRecords<Instance>> result = new Success<>(new MultipleRecords<>(matchedInstances, 2));
        successHandler.accept(result);
        return null;
    }).when(instanceCollection).findByCql(eq(format("hrid == \"%s\"", INSTANCE_HRID)), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
    MatchProfile subMatchProfile = new MatchProfile().withExistingRecordType(INSTANCE).withIncomingRecordType(MARC_BIBLIOGRAPHIC);
    EventHandler eventHandler = new MatchInstanceEventHandler(mappingMetadataCache);
    HashMap<String, String> context = new HashMap<>();
    context.put(MAPPING_PARAMS, LOCATIONS_PARAMS);
    context.put(RELATIONS, MATCHING_RELATIONS);
    DataImportEventPayload eventPayload = createEventPayload().withContext(context);
    eventPayload.getCurrentNode().setChildSnapshotWrappers(List.of(new ProfileSnapshotWrapper().withContent(subMatchProfile).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(DI_INVENTORY_INSTANCE_MATCHED.value(), processedPayload.getEventType());
        assertThat(new JsonArray(processedPayload.getContext().get(MULTI_MATCH_IDS)), hasItems(matchedInstances.get(0).getId(), matchedInstances.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) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Failure(org.folio.inventory.common.domain.Failure) DI_INVENTORY_INSTANCE_MATCHED(org.folio.DataImportEventTypes.DI_INVENTORY_INSTANCE_MATCHED) ACTION_PROFILE(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.ACTION_PROFILE) 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) INSTANCE(org.folio.rest.jaxrs.model.EntityType.INSTANCE) MatchInstanceEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchInstanceEventHandler) DataImportEventPayload(org.folio.DataImportEventPayload) UUID(java.util.UUID) 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) Instance(org.folio.inventory.domain.instances.Instance) PagingParameters(org.folio.inventory.common.api.request.PagingParameters) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Async(io.vertx.ext.unit.Async) Json(io.vertx.core.json.Json) Context(org.folio.inventory.common.Context) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) InstanceCollection(org.folio.inventory.domain.instances.InstanceCollection) EXACTLY_MATCHES(org.folio.MatchDetail.MatchCriterion.EXACTLY_MATCHES) MultipleRecords(org.folio.inventory.common.domain.MultipleRecords) ArrayList(java.util.ArrayList) DI_ERROR(org.folio.DataImportEventTypes.DI_ERROR) MARC_BIBLIOGRAPHIC(org.folio.rest.jaxrs.model.EntityType.MARC_BIBLIOGRAPHIC) EntityType(org.folio.rest.jaxrs.model.EntityType) MAPPING_PROFILE(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.MAPPING_PROFILE) MatchProfile(org.folio.MatchProfile) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) MatchValueReaderFactory(org.folio.processing.matching.reader.MatchValueReaderFactory) MatchDetail(org.folio.MatchDetail) 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) DI_SRS_MARC_BIB_RECORD_CREATED(org.folio.DataImportEventTypes.DI_SRS_MARC_BIB_RECORD_CREATED) 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) DI_INVENTORY_INSTANCE_NOT_MATCHED(org.folio.DataImportEventTypes.DI_INVENTORY_INSTANCE_NOT_MATCHED) 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) InstanceLoader(org.folio.inventory.dataimport.handlers.matching.loaders.InstanceLoader) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PagingParameters(org.folio.inventory.common.api.request.PagingParameters) Instance(org.folio.inventory.domain.instances.Instance) HashMap(java.util.HashMap) MatchInstanceEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchInstanceEventHandler) EventHandler(org.folio.processing.events.services.handler.EventHandler) MatchInstanceEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchInstanceEventHandler) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Success(org.folio.inventory.common.domain.Success) DataImportEventPayload(org.folio.DataImportEventPayload) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) JsonArray(io.vertx.core.json.JsonArray) MatchProfile(org.folio.MatchProfile) Consumer(java.util.function.Consumer) Async(io.vertx.ext.unit.Async) MultipleRecords(org.folio.inventory.common.domain.MultipleRecords) Test(org.junit.Test)

Example 2 with INSTANCE

use of org.folio.rest.jaxrs.model.EntityType.INSTANCE in project mod-inventory by folio-org.

the class MarcBibModifiedPostProcessingEventHandlerTest method shouldUpdateInstance.

@Test
public void shouldUpdateInstance() throws InterruptedException, ExecutionException, TimeoutException {
    // given
    HashMap<String, String> payloadContext = new HashMap<>();
    payloadContext.put(MARC_BIBLIOGRAPHIC.value(), Json.encode(record));
    DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_SRS_MARC_BIB_RECORD_MODIFIED_READY_FOR_POST_PROCESSING.value()).withJobExecutionId(UUID.randomUUID().toString()).withContext(payloadContext).withOkapiUrl(OKAPI_URL).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0));
    // when
    CompletableFuture<DataImportEventPayload> future = marcBibModifiedEventHandler.handle(dataImportEventPayload);
    DataImportEventPayload eventPayload = future.get(5, TimeUnit.SECONDS);
    JsonObject instanceJson = new JsonObject(eventPayload.getContext().get(INSTANCE.value()));
    Instance updatedInstance = Instance.fromJson(instanceJson);
    // then
    Assert.assertEquals(existingInstance.getId(), instanceJson.getString("id"));
    Assert.assertEquals("Victorian environmental nightmares and something else/", updatedInstance.getIndexTitle());
    Assert.assertNotNull(updatedInstance.getIdentifiers().stream().filter(i -> "(OCoLC)1060180367".equals(i.value)).findFirst().get());
    Assert.assertNotNull(updatedInstance.getContributors().stream().filter(c -> "Mazzeno, Laurence W., 1234566".equals(c.name)).findFirst().get());
    Assert.assertEquals("b5968c9e-cddc-4576-99e3-8e60aed8b0dd", updatedInstance.getStatisticalCodeIds().get(0));
    Assert.assertEquals("b5968c9e-cddc-4576-99e3-8e60aed8b0cf", updatedInstance.getNatureOfContentTermIds().get(0));
    Assert.assertNotNull(updatedInstance.getSubjects());
    Assert.assertEquals(1, updatedInstance.getSubjects().size());
    Assert.assertTrue(updatedInstance.getSubjects().get(0).contains("additional subfield"));
    Assert.assertFalse(updatedInstance.getSubjects().get(0).contains("Environmentalism in literature"));
    Assert.assertNotNull(updatedInstance.getNotes());
    Assert.assertEquals("Adding a note", updatedInstance.getNotes().get(0).note);
}
Also used : MappingMetadataDto(org.folio.MappingMetadataDto) TimeoutException(java.util.concurrent.TimeoutException) Failure(org.folio.inventory.common.domain.Failure) ACTION_PROFILE(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.ACTION_PROFILE) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) Mockito.doAnswer(org.mockito.Mockito.doAnswer) JsonObject(io.vertx.core.json.JsonObject) MappingProfile(org.folio.MappingProfile) INSTANCE(org.folio.rest.jaxrs.model.EntityType.INSTANCE) DataImportEventPayload(org.folio.DataImportEventPayload) OkapiHttpClient(org.folio.inventory.support.http.client.OkapiHttpClient) UUID(java.util.UUID) Future(io.vertx.core.Future) Storage(org.folio.inventory.storage.Storage) Optional(java.util.Optional) MODIFY(org.folio.ActionProfile.Action.MODIFY) Instance(org.folio.inventory.domain.instances.Instance) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) DI_SRS_MARC_BIB_RECORD_MODIFIED_READY_FOR_POST_PROCESSING(org.folio.DataImportEventTypes.DI_SRS_MARC_BIB_RECORD_MODIFIED_READY_FOR_POST_PROCESSING) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Json(io.vertx.core.json.Json) Context(org.folio.inventory.common.Context) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) Response(org.folio.inventory.support.http.client.Response) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) InstanceCollection(org.folio.inventory.domain.instances.InstanceCollection) TestUtil(org.folio.inventory.TestUtil) MappingDetail(org.folio.rest.jaxrs.model.MappingDetail) MARC_BIBLIOGRAPHIC(org.folio.rest.jaxrs.model.EntityType.MARC_BIBLIOGRAPHIC) 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) Record(org.folio.rest.jaxrs.model.Record) Test(org.junit.Test) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) DI_SRS_MARC_BIB_RECORD_CREATED(org.folio.DataImportEventTypes.DI_SRS_MARC_BIB_RECORD_CREATED) PrecedingSucceedingTitle(org.folio.inventory.domain.instances.titles.PrecedingSucceedingTitle) Mockito.verify(org.mockito.Mockito.verify) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) JsonArray(io.vertx.core.json.JsonArray) Mockito(org.mockito.Mockito) Success(org.folio.inventory.common.domain.Success) Assert(org.junit.Assert) Collections(java.util.Collections) MappingMetadataCache(org.folio.inventory.dataimport.cache.MappingMetadataCache) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) HashMap(java.util.HashMap) Instance(org.folio.inventory.domain.instances.Instance) JsonObject(io.vertx.core.json.JsonObject) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DataImportEventPayload(org.folio.DataImportEventPayload) Test(org.junit.Test)

Aggregations

Future (io.vertx.core.Future)2 Json (io.vertx.core.json.Json)2 JsonArray (io.vertx.core.json.JsonArray)2 JsonObject (io.vertx.core.json.JsonObject)2 HashMap (java.util.HashMap)2 Optional (java.util.Optional)2 UUID (java.util.UUID)2 Consumer (java.util.function.Consumer)2 DataImportEventPayload (org.folio.DataImportEventPayload)2 DI_SRS_MARC_BIB_RECORD_CREATED (org.folio.DataImportEventTypes.DI_SRS_MARC_BIB_RECORD_CREATED)2 MappingMetadataDto (org.folio.MappingMetadataDto)2 Context (org.folio.inventory.common.Context)2 Failure (org.folio.inventory.common.domain.Failure)2 Success (org.folio.inventory.common.domain.Success)2 MappingMetadataCache (org.folio.inventory.dataimport.cache.MappingMetadataCache)2 Instance (org.folio.inventory.domain.instances.Instance)2 InstanceCollection (org.folio.inventory.domain.instances.InstanceCollection)2 Storage (org.folio.inventory.storage.Storage)2 INSTANCE (org.folio.rest.jaxrs.model.EntityType.INSTANCE)2 MARC_BIBLIOGRAPHIC (org.folio.rest.jaxrs.model.EntityType.MARC_BIBLIOGRAPHIC)2