Search in sources :

Example 1 with UpdateInstanceQuickMarcEventHandler

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));
}
Also used : Response(org.folio.inventory.support.http.client.Response) UpdateInstanceQuickMarcEventHandler(org.folio.inventory.dataimport.handlers.quickmarc.UpdateInstanceQuickMarcEventHandler) Instance(org.folio.inventory.domain.instances.Instance) PrecedingSucceedingTitlesHelper(org.folio.inventory.dataimport.handlers.actions.PrecedingSucceedingTitlesHelper) InstanceUpdateDelegate(org.folio.inventory.dataimport.handlers.actions.InstanceUpdateDelegate) JsonObject(io.vertx.core.json.JsonObject) Success(org.folio.inventory.common.domain.Success) Before(org.junit.Before)

Aggregations

JsonObject (io.vertx.core.json.JsonObject)1 Success (org.folio.inventory.common.domain.Success)1 InstanceUpdateDelegate (org.folio.inventory.dataimport.handlers.actions.InstanceUpdateDelegate)1 PrecedingSucceedingTitlesHelper (org.folio.inventory.dataimport.handlers.actions.PrecedingSucceedingTitlesHelper)1 UpdateInstanceQuickMarcEventHandler (org.folio.inventory.dataimport.handlers.quickmarc.UpdateInstanceQuickMarcEventHandler)1 Instance (org.folio.inventory.domain.instances.Instance)1 Response (org.folio.inventory.support.http.client.Response)1 Before (org.junit.Before)1