@RunWithCustomExecutor @Test public void givenRunningProcessWhenExecuteThenCheckAllPossibleStatusCode() throws Exception { reset(storeMetaDataUnitActionPlugin); VitamThreadUtils.getVitamSession().setTenantId(0); final File runningIngests = PropertiesUtils.getResourceFile(RUNNING_INGESTS); final JsonNode archiveUnitToBeUpdated = JsonHandler.getFromInputStream(PropertiesUtils.getResourceAsStream(AU_DETAIL)); final JsonNode archiveUnitUpdated = JsonHandler.getFromInputStream(PropertiesUtils.getResourceAsStream(UPDATED_AU)); params.setProcessId(GUIDFactory.newOperationLogbookGUID(0).toString()); when(handlerIO.getInputStreamFromWorkspace( eq(UpdateWorkflowConstants.PROCESSING_FOLDER + "/" + UpdateWorkflowConstants.UPDATED_RULES_JSON))) .then(o -> PropertiesUtils.getResourceAsStream(UPDATED_RULES_JSON)); when(handlerIO.getInput(0)).thenReturn(runningIngests); when(handlerIO.getLifecyclesClient()).thenReturn(mock(LogbookLifeCyclesClient.class)); when(processManagementClient.getOperationProcessStatus(any())) .thenReturn(new ItemStatus().setGlobalState(ProcessState.COMPLETED)); when(metaDataClient.selectUnits(any())).thenReturn(archiveUnitToBeUpdated); when(metaDataClient.updateUnitById(any(), any())).thenReturn(archiveUnitUpdated); doNothing() .when(storeMetaDataUnitActionPlugin).storeDocumentsWithLfc(any(), any(), anyList()); ItemStatus response = plugin.execute(params, handlerIO); assertEquals(StatusCode.OK, response.getGlobalStatus()); doThrow(VitamException.class) .when(storeMetaDataUnitActionPlugin).storeDocumentsWithLfc(any(), any(), anyList()); response = plugin.execute(params, handlerIO); assertEquals(StatusCode.FATAL, response.getGlobalStatus()); }
@Override public ItemStatus execute(WorkerParameters params, HandlerIO handler) { final ItemStatus itemStatus = new ItemStatus(RUNNING_INGESTS_UPDATE_TASK_ID); try { try { getRunningIngests(params, handler); } catch (VitamDBException e) { LOGGER.error(e); } itemStatus.increment(StatusCode.OK); } catch (ProcessingException e) { LOGGER.error("Processing exception", e); itemStatus.increment(StatusCode.FATAL); } catch (InvalidParseOperationException e) { LOGGER.error("Cannot parse json", e); itemStatus.increment(StatusCode.KO); } return new ItemStatus(RUNNING_INGESTS_UPDATE_TASK_ID).setItemsStatus(RUNNING_INGESTS_UPDATE_TASK_ID, itemStatus); }
RunningIngestsUpdateActionPlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters params, HandlerIO handler) { final ItemStatus itemStatus = new ItemStatus(RUNNING_INGESTS_UPDATE_TASK_ID); try { try { getRunningIngests(params, handler); } catch (VitamDBException e) { LOGGER.error(e); } itemStatus.increment(StatusCode.OK); } catch (ProcessingException e) { LOGGER.error("Processing exception", e); itemStatus.increment(StatusCode.FATAL); } catch (InvalidParseOperationException e) { LOGGER.error("Cannot parse json", e); itemStatus.increment(StatusCode.KO); } return new ItemStatus(RUNNING_INGESTS_UPDATE_TASK_ID).setItemsStatus(RUNNING_INGESTS_UPDATE_TASK_ID, itemStatus); } }
RunningIngestsUpdateActionPlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters params, HandlerIO handler) { final ItemStatus itemStatus = new ItemStatus(RUNNING_INGESTS_UPDATE_TASK_ID); try { try { getRunningIngests(params, handler); } catch (VitamDBException e) { LOGGER.error(e); } itemStatus.increment(StatusCode.OK); } catch (ProcessingException e) { LOGGER.error("Processing exception", e); itemStatus.increment(StatusCode.FATAL); } catch (InvalidParseOperationException e) { LOGGER.error("Cannot parse json", e); itemStatus.increment(StatusCode.KO); } return new ItemStatus(RUNNING_INGESTS_UPDATE_TASK_ID).setItemsStatus(RUNNING_INGESTS_UPDATE_TASK_ID, itemStatus); } RunningIngestsUpdateActionPlugin(); @VisibleForTesting  RunningIngestsUpdateActionPlugin(ProcessingManagementClientFactory processingManagementClientFactory,
        MetaDataClientFactory metaDataClientFactory, StoreMetaDataUnitActionPlugin storeMetaDataUnitActionPlugin); }
RunningIngestsUpdateActionPlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters params, HandlerIO handler) { final ItemStatus itemStatus = new ItemStatus(RUNNING_INGESTS_UPDATE_TASK_ID); try { try { getRunningIngests(params, handler); } catch (VitamDBException e) { LOGGER.error(e); } itemStatus.increment(StatusCode.OK); } catch (ProcessingException e) { LOGGER.error("Processing exception", e); itemStatus.increment(StatusCode.FATAL); } catch (InvalidParseOperationException e) { LOGGER.error("Cannot parse json", e); itemStatus.increment(StatusCode.KO); } return new ItemStatus(RUNNING_INGESTS_UPDATE_TASK_ID).setItemsStatus(RUNNING_INGESTS_UPDATE_TASK_ID, itemStatus); } RunningIngestsUpdateActionPlugin(); @VisibleForTesting  RunningIngestsUpdateActionPlugin(ProcessingManagementClientFactory processingManagementClientFactory,
        MetaDataClientFactory metaDataClientFactory, StoreMetaDataUnitActionPlugin storeMetaDataUnitActionPlugin); @Override ItemStatus execute(WorkerParameters params, HandlerIO handler); @Override void checkMandatoryIOParameter(HandlerIO handler); }
RunningIngestsUpdateActionPlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters params, HandlerIO handler) { final ItemStatus itemStatus = new ItemStatus(RUNNING_INGESTS_UPDATE_TASK_ID); try { try { getRunningIngests(params, handler); } catch (VitamDBException e) { LOGGER.error(e); } itemStatus.increment(StatusCode.OK); } catch (ProcessingException e) { LOGGER.error("Processing exception", e); itemStatus.increment(StatusCode.FATAL); } catch (InvalidParseOperationException e) { LOGGER.error("Cannot parse json", e); itemStatus.increment(StatusCode.KO); } return new ItemStatus(RUNNING_INGESTS_UPDATE_TASK_ID).setItemsStatus(RUNNING_INGESTS_UPDATE_TASK_ID, itemStatus); } RunningIngestsUpdateActionPlugin(); @VisibleForTesting  RunningIngestsUpdateActionPlugin(ProcessingManagementClientFactory processingManagementClientFactory,
        MetaDataClientFactory metaDataClientFactory, StoreMetaDataUnitActionPlugin storeMetaDataUnitActionPlugin); @Override ItemStatus execute(WorkerParameters params, HandlerIO handler); @Override void checkMandatoryIOParameter(HandlerIO handler);  }