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());
}
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());
}
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());
}
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));
}
Aggregations