use of org.folio.inventory.dataimport.handlers.quickmarc.UpdateInstanceQuickMarcEventHandler in project mod-inventory by folio-org.
the class UpdateInstanceQuickMarcEventHandlerTest method setUp.
@Before
public void setUp() throws IOException {
existingInstance = Instance.fromJson(new JsonObject(TestUtil.readFileFromPath(INSTANCE_PATH)));
instanceUpdateDelegate = Mockito.spy(new InstanceUpdateDelegate(storage));
precedingSucceedingTitlesHelper = Mockito.spy(new PrecedingSucceedingTitlesHelper(ctxt -> okapiHttpClient));
updateInstanceEventHandler = new UpdateInstanceQuickMarcEventHandler(instanceUpdateDelegate, context, precedingSucceedingTitlesHelper);
when(storage.getInstanceCollection(any())).thenReturn(instanceRecordCollection);
doAnswer(invocationOnMock -> {
Consumer<Success<Instance>> successHandler = invocationOnMock.getArgument(1);
successHandler.accept(new Success<>(existingInstance));
return null;
}).when(instanceRecordCollection).findById(anyString(), any(), any());
doAnswer(invocationOnMock -> {
Instance instanceRecord = invocationOnMock.getArgument(0);
Consumer<Success<Instance>> successHandler = invocationOnMock.getArgument(1);
successHandler.accept(new Success<>(instanceRecord));
return null;
}).when(instanceRecordCollection).update(any(), any(), any());
when(okapiHttpClient.put(anyString(), any(JsonObject.class))).thenReturn(CompletableFuture.completedFuture(new Response(204, null, null, null)));
when(context.getTenantId()).thenReturn("dummy");
when(context.getToken()).thenReturn("token");
when(context.getOkapiLocation()).thenReturn("http://localhost");
mappingRules = new JsonObject(TestUtil.readFileFromPath(MAPPING_RULES_PATH));
record = new JsonObject(TestUtil.readFileFromPath(RECORD_PATH));
}
Aggregations