Search in sources :

Example 41 with HoldingsRecord

use of org.folio.HoldingsRecord 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 42 with HoldingsRecord

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

the class UpdateHoldingsQuickMarcEventHandlerTest method shouldProcessEvent.

@Test
public void shouldProcessEvent() {
    List<HoldingsType> holdings = new ArrayList<>();
    holdings.add(new HoldingsType().withName("testingnote$a").withId("fe19bae4-da28-472b-be90-d442e2428eadx"));
    MappingParameters mappingParameters = new MappingParameters();
    mappingParameters.withHoldingsTypes(holdings);
    HashMap<String, String> eventPayload = new HashMap<>();
    eventPayload.put("RECORD_TYPE", "MARC_HOLDING");
    eventPayload.put("MARC_HOLDING", record.encode());
    eventPayload.put("MAPPING_RULES", mappingRules.encode());
    eventPayload.put("MAPPING_PARAMS", Json.encode(mappingParameters));
    eventPayload.put("RELATED_RECORD_VERSION", HOLDINGS_VERSION.toString());
    Future<HoldingsRecord> future = updateHoldingsQuickMarcEventHandler.handle(eventPayload);
    HoldingsRecord updatedHoldings = future.result();
    Assert.assertNotNull(updatedHoldings);
    Assert.assertEquals(HOLDINGS_ID, updatedHoldings.getId());
    Assert.assertEquals(HOLDINGS_VERSION, updatedHoldings.getVersion());
    Assert.assertNull(updatedHoldings.getHoldingsTypeId());
    Assert.assertNotNull(updatedHoldings.getHoldingsStatements());
    Assert.assertEquals(21, updatedHoldings.getHoldingsStatements().size());
    Assert.assertNotNull(updatedHoldings.getNotes());
    Assert.assertEquals("testingnote$a ; testingnote$u ; testingnote$3 ; testingnote$5 ; testingnote$6 ; testingnote$8", updatedHoldings.getNotes().get(0).getNote());
    ArgumentCaptor<Context> argument = ArgumentCaptor.forClass(Context.class);
    verify(holdingsUpdateDelegate).handle(any(), any(), argument.capture());
    Assert.assertEquals("token", argument.getValue().getToken());
    Assert.assertEquals("dummy", argument.getValue().getTenantId());
    Assert.assertEquals("http://localhost", argument.getValue().getOkapiLocation());
}
Also used : Context(org.folio.inventory.common.Context) HoldingsRecord(org.folio.HoldingsRecord) HoldingsType(org.folio.HoldingsType) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 43 with HoldingsRecord

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

the class UpdateHoldingsQuickMarcEventHandlerTest method shouldSendError.

@Test
public void shouldSendError() {
    doAnswer(invocationOnMock -> {
        Consumer<Failure> failureHandler = invocationOnMock.getArgument(2);
        failureHandler.accept(new Failure("Internal Server Error", 500));
        return null;
    }).when(holdingsRecordCollection).update(any(), any(), any());
    List<HoldingsType> holdings = new ArrayList<>();
    holdings.add(new HoldingsType().withName("testingnote$a").withId("fe19bae4-da28-472b-be90-d442e2428eadx"));
    MappingParameters mappingParameters = new MappingParameters();
    mappingParameters.withHoldingsTypes(holdings);
    HashMap<String, String> eventPayload = new HashMap<>();
    eventPayload.put("RECORD_TYPE", "MARC_HOLDING");
    eventPayload.put("MARC_HOLDING", record.encode());
    eventPayload.put("MAPPING_RULES", mappingRules.encode());
    eventPayload.put("MAPPING_PARAMS", Json.encode(mappingParameters));
    Future<HoldingsRecord> future = updateHoldingsQuickMarcEventHandler.handle(eventPayload);
    Assert.assertTrue(future.failed());
}
Also used : HoldingsRecord(org.folio.HoldingsRecord) HoldingsType(org.folio.HoldingsType) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Failure(org.folio.inventory.common.domain.Failure) Test(org.junit.Test)

Example 44 with HoldingsRecord

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

the class ExternalStorageModuleHoldingsRecordCollectionExamples method shouldRetrieveId.

@Test
public void shouldRetrieveId() {
    String holdingId = UUID.randomUUID().toString();
    HoldingsRecord holdingsrecord = new HoldingsRecord().withId(holdingId);
    assertEquals(holdingId, storage.getId(holdingsrecord));
}
Also used : HoldingsRecord(org.folio.HoldingsRecord) Test(org.junit.Test)

Aggregations

HoldingsRecord (org.folio.HoldingsRecord)44 JsonObject (io.vertx.core.json.JsonObject)27 Test (org.junit.Test)26 DataImportEventPayload (org.folio.DataImportEventPayload)24 HashMap (java.util.HashMap)23 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)22 Record (org.folio.rest.jaxrs.model.Record)18 Success (org.folio.inventory.common.domain.Success)17 Consumer (java.util.function.Consumer)14 ParsedRecord (org.folio.rest.jaxrs.model.ParsedRecord)14 PagingParameters (org.folio.inventory.common.api.request.PagingParameters)13 Context (org.folio.inventory.common.Context)12 MultipleRecords (org.folio.inventory.common.domain.MultipleRecords)12 EventHandler (org.folio.processing.events.services.handler.EventHandler)11 MappingParameters (org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters)11 Async (io.vertx.ext.unit.Async)8 MappingMetadataDto (org.folio.MappingMetadataDto)8 MatchItemEventHandler (org.folio.inventory.dataimport.handlers.matching.MatchItemEventHandler)8 HoldingsRecordCollection (org.folio.inventory.domain.HoldingsRecordCollection)8 Before (org.junit.Before)8