Search in sources :

Example 21 with MappingMetadataDto

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

the class UpdateHoldingEventHandlerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    MappingManager.clearReaderFactories();
    updateHoldingEventHandler = new UpdateHoldingEventHandler(storage, mappingMetadataCache);
    doAnswer(invocationOnMock -> {
        HoldingsRecord holdingsRecord = invocationOnMock.getArgument(0);
        Consumer<Success<HoldingsRecord>> successHandler = invocationOnMock.getArgument(1);
        successHandler.accept(new Success<>(holdingsRecord));
        return null;
    }).when(holdingsRecordsCollection).update(any(), any(Consumer.class), any(Consumer.class));
    when(mappingMetadataCache.get(anyString(), any(Context.class))).thenReturn(Future.succeededFuture(Optional.of(new MappingMetadataDto().withMappingRules(new JsonObject().encode()).withMappingParams(Json.encode(new MappingParameters())))));
}
Also used : Context(org.folio.inventory.common.Context) HoldingsRecord(org.folio.HoldingsRecord) Consumer(java.util.function.Consumer) JsonObject(io.vertx.core.json.JsonObject) MappingMetadataDto(org.folio.MappingMetadataDto) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) Success(org.folio.inventory.common.domain.Success) Before(org.junit.Before)

Example 22 with MappingMetadataDto

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

the class UpdateItemEventHandlerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    doAnswer(invocationOnMock -> {
        Item item = invocationOnMock.getArgument(0);
        return CompletableFuture.completedFuture(item);
    }).when(mockedItemCollection).update(any(Item.class));
    Item returnedItem = new Item(UUID.randomUUID().toString(), "2", UUID.randomUUID().toString(), "test", new Status(AVAILABLE), UUID.randomUUID().toString(), UUID.randomUUID().toString(), new JsonObject());
    doAnswer(invocationOnMock -> {
        Consumer<Success<Item>> successHandler = invocationOnMock.getArgument(1);
        successHandler.accept(new Success<>(returnedItem));
        return null;
    }).when(mockedItemCollection).update(any(), any(), any());
    when(fakeReaderFactory.createReader()).thenReturn(fakeReader);
    when(fakeReader.read(any(MappingRule.class))).thenReturn(StringValue.of(IN_PROCESS.value()));
    when(mockedStorage.getItemCollection(ArgumentMatchers.any(Context.class))).thenReturn(mockedItemCollection);
    when(mockedStorage.getHoldingsRecordCollection(ArgumentMatchers.any(Context.class))).thenReturn(mockedHoldingsCollection);
    String instanceId = String.valueOf(UUID.randomUUID());
    String holdingId = UUID.randomUUID().toString();
    String hrid = UUID.randomUUID().toString();
    String permanentLocationId = UUID.randomUUID().toString();
    doAnswer(invocationOnMock -> {
        HoldingsRecord returnedHoldings = new HoldingsRecord().withId(holdingId).withHrid(hrid).withInstanceId(instanceId).withPermanentLocationId(permanentLocationId).withVersion(1);
        Consumer<Success<HoldingsRecord>> successHandler = invocationOnMock.getArgument(1);
        successHandler.accept(new Success<>(returnedHoldings));
        return null;
    }).when(mockedHoldingsCollection).findById(anyString(), any(Consumer.class), any(Consumer.class));
    when(mappingMetadataCache.get(anyString(), any(Context.class))).thenReturn(Future.succeededFuture(Optional.of(new MappingMetadataDto().withMappingRules(new JsonObject().encode()).withMappingParams(Json.encode(new MappingParameters())))));
    MappingManager.clearReaderFactories();
    MappingManager.registerReaderFactory(fakeReaderFactory);
    MappingManager.registerWriterFactory(new ItemWriterFactory());
    updateItemHandler = new UpdateItemEventHandler(mockedStorage, mappingMetadataCache);
    existingItemJson = new JsonObject().put("id", UUID.randomUUID().toString()).put("status", new JsonObject().put("name", AVAILABLE.value())).put("materialType", new JsonObject().put("id", UUID.randomUUID().toString())).put("permanentLoanType", new JsonObject().put("id", UUID.randomUUID().toString())).put("holdingsRecordId", UUID.randomUUID().toString());
}
Also used : Status(org.folio.inventory.domain.items.Status) Context(org.folio.inventory.common.Context) JsonObject(io.vertx.core.json.JsonObject) MappingMetadataDto(org.folio.MappingMetadataDto) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MappingRule(org.folio.rest.jaxrs.model.MappingRule) ItemWriterFactory(org.folio.inventory.dataimport.ItemWriterFactory) Success(org.folio.inventory.common.domain.Success) Item(org.folio.inventory.domain.items.Item) HoldingsRecord(org.folio.HoldingsRecord) Consumer(java.util.function.Consumer) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) Before(org.junit.Before)

Example 23 with MappingMetadataDto

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

the class MatchItemEventHandlerUnitTest method setUp.

@Before
public void setUp() {
    MatchValueReaderFactory.clearReaderFactory();
    MatchValueLoaderFactory.clearLoaderFactory();
    MockitoAnnotations.initMocks(this);
    when(marcValueReader.isEligibleForEntityType(MARC_BIBLIOGRAPHIC)).thenReturn(true);
    when(storage.getItemCollection(any(Context.class))).thenReturn(itemCollection);
    when(marcValueReader.read(any(DataImportEventPayload.class), any(MatchDetail.class))).thenReturn(StringValue.of(ITEM_HRID));
    MatchValueReaderFactory.register(marcValueReader);
    MatchValueLoaderFactory.register(itemLoader);
    when(mappingMetadataCache.get(anyString(), any(Context.class))).thenReturn(Future.succeededFuture(Optional.of(new MappingMetadataDto().withMappingRules(new JsonObject().encode()).withMappingParams(LOCATIONS_PARAMS))));
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Context(org.folio.inventory.common.Context) JsonObject(io.vertx.core.json.JsonObject) MappingMetadataDto(org.folio.MappingMetadataDto) MatchDetail(org.folio.MatchDetail) DataImportEventPayload(org.folio.DataImportEventPayload) Before(org.junit.Before)

Aggregations

MappingMetadataDto (org.folio.MappingMetadataDto)23 JsonObject (io.vertx.core.json.JsonObject)21 Context (org.folio.inventory.common.Context)17 Before (org.junit.Before)16 MappingParameters (org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters)13 Success (org.folio.inventory.common.domain.Success)12 MappingMetadataCache (org.folio.inventory.dataimport.cache.MappingMetadataCache)11 Consumer (java.util.function.Consumer)8 DataImportEventPayload (org.folio.DataImportEventPayload)8 TestContext (io.vertx.ext.unit.TestContext)7 HoldingsRecord (org.folio.HoldingsRecord)7 Instance (org.folio.inventory.domain.instances.Instance)7 RegexPattern (com.github.tomakehurst.wiremock.matching.RegexPattern)6 UrlPathPattern (com.github.tomakehurst.wiremock.matching.UrlPathPattern)6 Record (org.folio.rest.jaxrs.model.Record)6 EventProcessingException (org.folio.processing.exceptions.EventProcessingException)5 Promise (io.vertx.core.Promise)4 Json (io.vertx.core.json.Json)4 KafkaConsumerRecord (io.vertx.kafka.client.consumer.KafkaConsumerRecord)4 String.format (java.lang.String.format)4