Search in sources :

Example 6 with Success

use of org.folio.inventory.common.domain.Success in project mod-inventory by folio-org.

the class MatchInstanceEventHandlerUnitTest method shouldMatchWithSubConditionBasedOnMultiMatchResultOnHandleEventPayload.

@Test
public void shouldMatchWithSubConditionBasedOnMultiMatchResultOnHandleEventPayload(TestContext testContext) throws UnsupportedEncodingException {
    Async async = testContext.async();
    List<String> multiMatchResult = List.of(UUID.randomUUID().toString(), UUID.randomUUID().toString());
    Instance expectedInstance = createInstance();
    doAnswer(invocation -> {
        Consumer<Success<MultipleRecords<Instance>>> successHandler = invocation.getArgument(2);
        Success<MultipleRecords<Instance>> result = new Success<>(new MultipleRecords<>(singletonList(expectedInstance), 1));
        successHandler.accept(result);
        return null;
    }).when(instanceCollection).findByCql(eq(format("hrid == \"%s\" AND id == (%s OR %s)", INSTANCE_HRID, multiMatchResult.get(0), multiMatchResult.get(1))), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
    EventHandler eventHandler = new MatchInstanceEventHandler(mappingMetadataCache);
    HashMap<String, String> context = new HashMap<>();
    context.put(MULTI_MATCH_IDS, Json.encode(multiMatchResult));
    context.put(MAPPING_PARAMS, LOCATIONS_PARAMS);
    context.put(RELATIONS, MATCHING_RELATIONS);
    DataImportEventPayload eventPayload = createEventPayload().withContext(context);
    eventHandler.handle(eventPayload).whenComplete((processedPayload, throwable) -> {
        testContext.assertNull(throwable);
        testContext.assertEquals(1, processedPayload.getEventsChain().size());
        testContext.assertEquals(processedPayload.getEventsChain(), singletonList(DI_SRS_MARC_BIB_RECORD_CREATED.value()));
        testContext.assertEquals(DI_INVENTORY_INSTANCE_MATCHED.value(), processedPayload.getEventType());
        testContext.assertEquals(new JsonObject(processedPayload.getContext().get(INSTANCE.value())).getString("id"), expectedInstance.getId());
        async.complete();
    });
}
Also used : 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) JsonObject(io.vertx.core.json.JsonObject) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Success(org.folio.inventory.common.domain.Success) DataImportEventPayload(org.folio.DataImportEventPayload) Consumer(java.util.function.Consumer) Async(io.vertx.ext.unit.Async) MultipleRecords(org.folio.inventory.common.domain.MultipleRecords) Test(org.junit.Test)

Example 7 with Success

use of org.folio.inventory.common.domain.Success in project mod-inventory by folio-org.

the class MatchInstanceEventHandlerUnitTest method shouldFailOnHandleEventPayloadIfMatchedMultipleInstances.

@Test
public void shouldFailOnHandleEventPayloadIfMatchedMultipleInstances(TestContext testContext) throws UnsupportedEncodingException {
    Async async = testContext.async();
    doAnswer(ans -> {
        Consumer<Success<MultipleRecords<Instance>>> callback = ans.getArgument(2);
        Success<MultipleRecords<Instance>> result = new Success<>(new MultipleRecords<>(asList(createInstance(), createInstance()), 2));
        callback.accept(result);
        return null;
    }).when(instanceCollection).findByCql(anyString(), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
    EventHandler eventHandler = new MatchInstanceEventHandler(mappingMetadataCache);
    DataImportEventPayload eventPayload = createEventPayload();
    eventHandler.handle(eventPayload).whenComplete((updatedEventPayload, throwable) -> {
        testContext.assertNotNull(throwable);
        async.complete();
    });
}
Also used : PagingParameters(org.folio.inventory.common.api.request.PagingParameters) Consumer(java.util.function.Consumer) Instance(org.folio.inventory.domain.instances.Instance) Async(io.vertx.ext.unit.Async) MatchInstanceEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchInstanceEventHandler) MultipleRecords(org.folio.inventory.common.domain.MultipleRecords) EventHandler(org.folio.processing.events.services.handler.EventHandler) MatchInstanceEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchInstanceEventHandler) Success(org.folio.inventory.common.domain.Success) DataImportEventPayload(org.folio.DataImportEventPayload) Test(org.junit.Test)

Example 8 with Success

use of org.folio.inventory.common.domain.Success in project mod-inventory by folio-org.

the class MatchItemEventHandlerUnitTest method shouldNotMatchOnHandleEventPayload.

@Test
public void shouldNotMatchOnHandleEventPayload(TestContext testContext) throws UnsupportedEncodingException {
    Async async = testContext.async();
    doAnswer(ans -> {
        Consumer<Success<MultipleRecords<Item>>> callback = ans.getArgument(2);
        Success<MultipleRecords<Item>> result = new Success<>(new MultipleRecords<>(new ArrayList<>(), 0));
        callback.accept(result);
        return null;
    }).when(itemCollection).findByCql(anyString(), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
    EventHandler eventHandler = new MatchItemEventHandler(mappingMetadataCache);
    DataImportEventPayload eventPayload = createEventPayload();
    eventHandler.handle(eventPayload).whenComplete((updatedEventPayload, throwable) -> {
        testContext.assertNull(throwable);
        testContext.assertEquals(1, updatedEventPayload.getEventsChain().size());
        testContext.assertEquals(updatedEventPayload.getEventsChain(), singletonList(DI_SRS_MARC_BIB_RECORD_CREATED.value()));
        testContext.assertEquals(DI_INVENTORY_ITEM_NOT_MATCHED.value(), updatedEventPayload.getEventType());
        async.complete();
    });
}
Also used : PagingParameters(org.folio.inventory.common.api.request.PagingParameters) ArrayList(java.util.ArrayList) EventHandler(org.folio.processing.events.services.handler.EventHandler) MatchItemEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchItemEventHandler) Success(org.folio.inventory.common.domain.Success) DataImportEventPayload(org.folio.DataImportEventPayload) Item(org.folio.inventory.domain.items.Item) 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 9 with Success

use of org.folio.inventory.common.domain.Success in project mod-inventory by folio-org.

the class MatchItemEventHandlerUnitTest method shouldFailOnHandleEventPayloadIfMatchedMultipleItems.

@Test
public void shouldFailOnHandleEventPayloadIfMatchedMultipleItems(TestContext testContext) throws UnsupportedEncodingException {
    Async async = testContext.async();
    doAnswer(ans -> {
        Consumer<Success<MultipleRecords<Item>>> callback = ans.getArgument(2);
        Success<MultipleRecords<Item>> result = new Success<>(new MultipleRecords<>(asList(createItem(), createItem()), 2));
        callback.accept(result);
        return null;
    }).when(itemCollection).findByCql(anyString(), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
    EventHandler eventHandler = new MatchItemEventHandler(mappingMetadataCache);
    DataImportEventPayload eventPayload = createEventPayload();
    eventHandler.handle(eventPayload).whenComplete((updatedEventPayload, throwable) -> {
        testContext.assertNotNull(throwable);
        async.complete();
    });
}
Also used : Item(org.folio.inventory.domain.items.Item) PagingParameters(org.folio.inventory.common.api.request.PagingParameters) 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) EventHandler(org.folio.processing.events.services.handler.EventHandler) MatchItemEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchItemEventHandler) Success(org.folio.inventory.common.domain.Success) DataImportEventPayload(org.folio.DataImportEventPayload) Test(org.junit.Test)

Example 10 with Success

use of org.folio.inventory.common.domain.Success in project mod-inventory by folio-org.

the class MatchItemEventHandlerUnitTest method shouldMatchWithSubMatchByItemOnHandleEventPayload.

@Test
public void shouldMatchWithSubMatchByItemOnHandleEventPayload(TestContext testContext) throws UnsupportedEncodingException {
    Async async = testContext.async();
    doAnswer(ans -> {
        Consumer<Success<MultipleRecords<Item>>> callback = ans.getArgument(2);
        Success<MultipleRecords<Item>> result = new Success<>(new MultipleRecords<>(singletonList(createItem()), 1));
        callback.accept(result);
        return null;
    }).when(itemCollection).findByCql(eq(format("hrid == \"%s\" AND id == \"%s\"", ITEM_HRID, ITEM_ID)), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
    EventHandler eventHandler = new MatchItemEventHandler(mappingMetadataCache);
    HashMap<String, String> context = new HashMap<>();
    context.put(EntityType.ITEM.value(), JsonObject.mapFrom(createItem()).encode());
    context.put(MAPPING_PARAMS, LOCATIONS_PARAMS);
    context.put(RELATIONS, MATCHING_RELATIONS);
    DataImportEventPayload eventPayload = createEventPayload().withContext(context);
    eventHandler.handle(eventPayload).whenComplete((updatedEventPayload, throwable) -> {
        testContext.assertNull(throwable);
        testContext.assertEquals(1, updatedEventPayload.getEventsChain().size());
        testContext.assertEquals(updatedEventPayload.getEventsChain(), singletonList(DI_SRS_MARC_BIB_RECORD_CREATED.value()));
        testContext.assertEquals(DI_INVENTORY_ITEM_MATCHED.value(), updatedEventPayload.getEventType());
        async.complete();
    });
}
Also used : PagingParameters(org.folio.inventory.common.api.request.PagingParameters) HashMap(java.util.HashMap) 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) Item(org.folio.inventory.domain.items.Item) 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)

Aggregations

Success (org.folio.inventory.common.domain.Success)67 Consumer (java.util.function.Consumer)51 PagingParameters (org.folio.inventory.common.api.request.PagingParameters)49 MultipleRecords (org.folio.inventory.common.domain.MultipleRecords)48 Test (org.junit.Test)46 DataImportEventPayload (org.folio.DataImportEventPayload)44 JsonObject (io.vertx.core.json.JsonObject)42 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)34 HashMap (java.util.HashMap)33 Async (io.vertx.ext.unit.Async)31 EventHandler (org.folio.processing.events.services.handler.EventHandler)29 HoldingsRecord (org.folio.HoldingsRecord)24 Item (org.folio.inventory.domain.items.Item)23 Instance (org.folio.inventory.domain.instances.Instance)20 Before (org.junit.Before)19 Record (org.folio.rest.jaxrs.model.Record)18 MappingMetadataDto (org.folio.MappingMetadataDto)16 MatchItemEventHandler (org.folio.inventory.dataimport.handlers.matching.MatchItemEventHandler)14 Context (org.folio.inventory.common.Context)12 MappingParameters (org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters)12