Search in sources :

Example 26 with DataImportEventPayload

use of org.folio.DataImportEventPayload in project mod-inventory by folio-org.

the class MatchItemEventHandlerUnitTest method shouldReturnFalseOnIsEligibleIfCurrentNodeTypeIsNotMatchProfile.

@Test
public void shouldReturnFalseOnIsEligibleIfCurrentNodeTypeIsNotMatchProfile() {
    EventHandler eventHandler = new MatchItemEventHandler(mappingMetadataCache);
    DataImportEventPayload eventPayload = new DataImportEventPayload().withCurrentNode(new ProfileSnapshotWrapper().withContentType(MAPPING_PROFILE));
    assertFalse(eventHandler.isEligible(eventPayload));
}
Also used : MatchItemEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchItemEventHandler) EventHandler(org.folio.processing.events.services.handler.EventHandler) MatchItemEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchItemEventHandler) DataImportEventPayload(org.folio.DataImportEventPayload) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) Test(org.junit.Test)

Example 27 with DataImportEventPayload

use of org.folio.DataImportEventPayload in project mod-inventory by folio-org.

the class MatchItemEventHandlerUnitTest method shouldPutMultipleMatchResultToPayloadOnHandleEventPayload.

@Test
public void shouldPutMultipleMatchResultToPayloadOnHandleEventPayload(TestContext testContext) throws UnsupportedEncodingException {
    Async async = testContext.async();
    List<Item> matchedItems = List.of(new Item(ITEM_ID, "1", HOLDING_ID, new Status(ItemStatusName.AVAILABLE), UUID.randomUUID().toString(), UUID.randomUUID().toString(), new JsonObject()), new Item(UUID.randomUUID().toString(), "1", HOLDING_ID, new Status(ItemStatusName.AVAILABLE), UUID.randomUUID().toString(), UUID.randomUUID().toString(), new JsonObject()));
    doAnswer(invocation -> {
        Consumer<Success<MultipleRecords<Item>>> callback = invocation.getArgument(2);
        Success<MultipleRecords<Item>> result = new Success<>(new MultipleRecords<>(matchedItems, 2));
        callback.accept(result);
        return null;
    }).when(itemCollection).findByCql(eq(format("hrid == \"%s\"", ITEM_HRID)), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
    EventHandler eventHandler = new MatchItemEventHandler(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(new MatchProfile().withExistingRecordType(ITEM).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(DI_INVENTORY_ITEM_MATCHED.value(), processedPayload.getEventType());
        assertThat(new JsonArray(processedPayload.getContext().get(MULTI_MATCH_IDS)), hasItems(matchedItems.get(0).getId(), matchedItems.get(1).getId()));
        async.complete();
    }));
}
Also used : Status(org.folio.inventory.domain.items.Status) 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) Item(org.folio.inventory.domain.items.Item) 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) ITEM(org.folio.rest.jaxrs.model.EntityType.ITEM) 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) ItemCollection(org.folio.inventory.domain.items.ItemCollection) MATCH(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ReactTo.MATCH) MatcherAssert.assertThat(org.hamcrest.junit.MatcherAssert.assertThat) MissingValue(org.folio.processing.value.MissingValue) DataImportEventPayload(org.folio.DataImportEventPayload) ItemLoader(org.folio.inventory.dataimport.handlers.matching.loaders.ItemLoader) DI_INVENTORY_ITEM_MATCHED(org.folio.DataImportEventTypes.DI_INVENTORY_ITEM_MATCHED) UUID(java.util.UUID) Future(io.vertx.core.Future) HoldingsRecord(org.folio.HoldingsRecord) 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) MatchItemEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchItemEventHandler) Optional(java.util.Optional) 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) 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) 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) ItemStatusName(org.folio.inventory.domain.items.ItemStatusName) 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) Status(org.folio.inventory.domain.items.Status) 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_ITEM_NOT_MATCHED(org.folio.DataImportEventTypes.DI_INVENTORY_ITEM_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) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PagingParameters(org.folio.inventory.common.api.request.PagingParameters) HashMap(java.util.HashMap) JsonObject(io.vertx.core.json.JsonObject) EventHandler(org.folio.processing.events.services.handler.EventHandler) MatchItemEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchItemEventHandler) 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) Item(org.folio.inventory.domain.items.Item) MatchProfile(org.folio.MatchProfile) Consumer(java.util.function.Consumer) MatchItemEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchItemEventHandler) Async(io.vertx.ext.unit.Async) MultipleRecords(org.folio.inventory.common.domain.MultipleRecords) Test(org.junit.Test)

Example 28 with DataImportEventPayload

use of org.folio.DataImportEventPayload in project mod-inventory by folio-org.

the class CreateInstanceEventHandlerTest method shouldNotProcessEventIfContextIsEmpty.

@Test(expected = ExecutionException.class)
public void shouldNotProcessEventIfContextIsEmpty() throws InterruptedException, ExecutionException, TimeoutException {
    Reader fakeReader = Mockito.mock(Reader.class);
    String instanceTypeId = UUID.randomUUID().toString();
    String title = "titleValue";
    when(fakeReader.read(any(MappingRule.class))).thenReturn(StringValue.of(instanceTypeId), StringValue.of(title));
    when(fakeReaderFactory.createReader()).thenReturn(fakeReader);
    when(storage.getInstanceCollection(any())).thenReturn(instanceRecordCollection);
    MappingManager.registerReaderFactory(fakeReaderFactory);
    MappingManager.registerWriterFactory(new InstanceWriterFactory());
    DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_INVENTORY_INSTANCE_CREATED.value()).withContext(new HashMap<>()).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0)).withTenant(TENANT_ID).withOkapiUrl(mockServer.baseUrl()).withToken(TOKEN).withJobExecutionId(UUID.randomUUID().toString());
    CompletableFuture<DataImportEventPayload> future = createInstanceEventHandler.handle(dataImportEventPayload);
    future.get(5, TimeUnit.MILLISECONDS);
}
Also used : InstanceWriterFactory(org.folio.inventory.dataimport.InstanceWriterFactory) HashMap(java.util.HashMap) Reader(org.folio.processing.mapping.mapper.reader.Reader) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MappingRule(org.folio.rest.jaxrs.model.MappingRule) DataImportEventPayload(org.folio.DataImportEventPayload) Test(org.junit.Test)

Example 29 with DataImportEventPayload

use of org.folio.DataImportEventPayload in project mod-inventory by folio-org.

the class CreateInstanceEventHandlerTest method shouldReturnFailedFutureIfCurrentActionProfileHasNoMappingProfile.

@Test
public void shouldReturnFailedFutureIfCurrentActionProfileHasNoMappingProfile() {
    HashMap<String, String> context = new HashMap<>();
    context.put(MARC_BIBLIOGRAPHIC.value(), Json.encode(new Record().withParsedRecord(new ParsedRecord().withContent(PARSED_CONTENT))));
    DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_SRS_MARC_BIB_RECORD_CREATED.value()).withContext(context).withCurrentNode(new ProfileSnapshotWrapper().withContentType(ACTION_PROFILE).withContent(actionProfile));
    CompletableFuture<DataImportEventPayload> future = createInstanceEventHandler.handle(dataImportEventPayload);
    ExecutionException exception = Assert.assertThrows(ExecutionException.class, future::get);
    Assert.assertEquals("Action profile to create an Instance requires a mapping profile by jobExecutionId: 'null' and recordId: 'null'", exception.getCause().getMessage());
}
Also used : HashMap(java.util.HashMap) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Record(org.folio.rest.jaxrs.model.Record) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) ExecutionException(java.util.concurrent.ExecutionException) DataImportEventPayload(org.folio.DataImportEventPayload) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) Test(org.junit.Test)

Example 30 with DataImportEventPayload

use of org.folio.DataImportEventPayload in project mod-inventory by folio-org.

the class CreateInstanceEventHandlerTest method shouldNotProcessEventIfMArcBibliographicIsNotExistsInContext.

@Test(expected = ExecutionException.class)
public void shouldNotProcessEventIfMArcBibliographicIsNotExistsInContext() throws InterruptedException, ExecutionException, TimeoutException {
    Reader fakeReader = Mockito.mock(Reader.class);
    String instanceTypeId = UUID.randomUUID().toString();
    String title = "titleValue";
    when(fakeReader.read(any(MappingRule.class))).thenReturn(StringValue.of(instanceTypeId), StringValue.of(title));
    when(fakeReaderFactory.createReader()).thenReturn(fakeReader);
    when(storage.getInstanceCollection(any())).thenReturn(instanceRecordCollection);
    MappingManager.registerReaderFactory(fakeReaderFactory);
    MappingManager.registerWriterFactory(new InstanceWriterFactory());
    HashMap<String, String> context = new HashMap<>();
    context.put("InvalidField", Json.encode(new Record()));
    DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_INVENTORY_INSTANCE_CREATED.value()).withContext(context).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0)).withTenant(TENANT_ID).withOkapiUrl(mockServer.baseUrl()).withToken(TOKEN).withJobExecutionId(UUID.randomUUID().toString());
    CompletableFuture<DataImportEventPayload> future = createInstanceEventHandler.handle(dataImportEventPayload);
    future.get(5, TimeUnit.MILLISECONDS);
}
Also used : InstanceWriterFactory(org.folio.inventory.dataimport.InstanceWriterFactory) HashMap(java.util.HashMap) Reader(org.folio.processing.mapping.mapper.reader.Reader) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Record(org.folio.rest.jaxrs.model.Record) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MappingRule(org.folio.rest.jaxrs.model.MappingRule) DataImportEventPayload(org.folio.DataImportEventPayload) Test(org.junit.Test)

Aggregations

DataImportEventPayload (org.folio.DataImportEventPayload)371 Test (org.junit.Test)319 HashMap (java.util.HashMap)230 JsonObject (io.vertx.core.json.JsonObject)135 Record (org.folio.rest.jaxrs.model.Record)118 ProfileSnapshotWrapper (org.folio.rest.jaxrs.model.ProfileSnapshotWrapper)115 Async (io.vertx.ext.unit.Async)107 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)107 ParsedRecord (org.folio.rest.jaxrs.model.ParsedRecord)102 EventHandler (org.folio.processing.events.services.handler.EventHandler)81 PagingParameters (org.folio.inventory.common.api.request.PagingParameters)55 Consumer (java.util.function.Consumer)53 HoldingsRecord (org.folio.HoldingsRecord)50 ActionProfile (org.folio.ActionProfile)47 Success (org.folio.inventory.common.domain.Success)45 MappingRule (org.folio.rest.jaxrs.model.MappingRule)44 MultipleRecords (org.folio.inventory.common.domain.MultipleRecords)43 Json (io.vertx.core.json.Json)40 CompletableFuture (java.util.concurrent.CompletableFuture)36 Reader (org.folio.processing.mapping.mapper.reader.Reader)36