@RunWithCustomExecutor @Test public void should_ko_report_when_ko_logbook() throws Exception { HandlerIO handler = mock(HandlerIO.class); VitamThreadUtils.getVitamSession().setTenantId(0); VitamThreadUtils.getVitamSession().setRequestId(PROCESS_ID_KO); WorkerParameters workerParameters = WorkerParametersFactory.newWorkerParameters() .setWorkerGUID(GUIDFactory.newGUID().getId()) .setContainerName(VitamThreadUtils.getVitamSession().getRequestId()) .setRequestId(VitamThreadUtils.getVitamSession().getRequestId()) .setProcessId(VitamThreadUtils.getVitamSession().getRequestId()).setObjectId("0") .setCurrentStep("StepName"); workerParameters.putParameterValue(WorkerParameterName.auditActions, "AUDIT_FILE_EXISTING"); workerParameters.putParameterValue(WorkerParameterName.auditType, "tenant"); Mockito.doNothing().when(auditReportService).storeReportToWorkspace(reportInfosCaptor.capture()); when(logbookClient.selectOperationById(any())) .thenReturn(getFromInputStream(getClass().getResourceAsStream(JOP_RESULTS_KO))); when(auditReportService.isReportWrittenInWorkspace(anyString())).thenReturn(false); ItemStatus response = auditFinalizePlugin.execute(workerParameters, handler); assertEquals(StatusCode.OK, response.getGlobalStatus()); assertThat(reportInfosCaptor.getValue().getContext()).isNotNull(); assertThat(reportInfosCaptor.getValue().getContext().get("auditType").asText()).isEqualTo("tenant"); assertThat(reportInfosCaptor.getValue().getContext().get("objectId").asText()).isEqualTo("0"); assertThat(reportInfosCaptor.getValue().getContext().get("auditActions").asText()) .isEqualTo("AUDIT_FILE_EXISTING"); assertThat(reportInfosCaptor.getValue().getOperationSummary()).isNotNull(); assertThat(reportInfosCaptor.getValue().getOperationSummary().getRightsStatementIdentifier() .get("AccessContract").asText()).isEqualTo("ContratTNR"); assertThat(reportInfosCaptor.getValue().getOperationSummary().getEvDetData()).isEmpty(); assertThat(reportInfosCaptor.getValue().getOperationSummary().getEvId()).isEqualTo(PROCESS_ID_KO); assertThat(reportInfosCaptor.getValue().getOperationSummary().getEvType()).isEqualTo("PROCESS_AUDIT"); assertThat(reportInfosCaptor.getValue().getOperationSummary().getOutcome()).isEqualTo("KO"); assertThat(reportInfosCaptor.getValue().getOperationSummary().getOutDetail()) .isEqualTo("AUDIT_CHECK_OBJECT.AUDIT_CHECK_OBJECT.KO"); assertThat(reportInfosCaptor.getValue().getOperationSummary().getOutMsg()) .isEqualTo("Échec de l'audit de l'existence et de l'intégrité des objets Detail= OK:91 KO:1"); assertThat(reportInfosCaptor.getValue().getReportSummary()).isNotNull(); assertThat(reportInfosCaptor.getValue().getReportSummary().getExtendedInfo()).isEmpty(); assertThat(reportInfosCaptor.getValue().getReportSummary().getEvStartDateTime()) .isEqualTo("2019-04-02T08:29:27.567"); assertThat(reportInfosCaptor.getValue().getReportSummary().getReportType()).isEqualTo(ReportType.AUDIT); }
@Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { try { generateAuditReportToWorkspace(param, handler); storeReportToOffers(param.getContainerName()); cleanupReport(param); LOGGER.info("Audit object finalization succeeded"); return buildItemStatus(OBJECT_AUDIT_FINALIZE, StatusCode.OK, null); } catch (ProcessingStatusException e) { LOGGER.error(String.format("Audit object finalization failed with status [%s]", e.getStatusCode()), e); return buildItemStatus(OBJECT_AUDIT_FINALIZE, e.getStatusCode(), null); } }
AuditFinalizePlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { try { generateAuditReportToWorkspace(param, handler); storeReportToOffers(param.getContainerName()); cleanupReport(param); LOGGER.info("Audit object finalization succeeded"); return buildItemStatus(OBJECT_AUDIT_FINALIZE, StatusCode.OK, null); } catch (ProcessingStatusException e) { LOGGER.error(String.format("Audit object finalization failed with status [%s]", e.getStatusCode()), e); return buildItemStatus(OBJECT_AUDIT_FINALIZE, e.getStatusCode(), null); } } }
AuditFinalizePlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { try { generateAuditReportToWorkspace(param, handler); storeReportToOffers(param.getContainerName()); cleanupReport(param); LOGGER.info("Audit object finalization succeeded"); return buildItemStatus(OBJECT_AUDIT_FINALIZE, StatusCode.OK, null); } catch (ProcessingStatusException e) { LOGGER.error(String.format("Audit object finalization failed with status [%s]", e.getStatusCode()), e); return buildItemStatus(OBJECT_AUDIT_FINALIZE, e.getStatusCode(), null); } } AuditFinalizePlugin(); @VisibleForTesting  AuditFinalizePlugin(AuditReportService auditReportService,
        LogbookOperationsClientFactory logbookOperationsClientFactory); }
AuditFinalizePlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { try { generateAuditReportToWorkspace(param, handler); storeReportToOffers(param.getContainerName()); cleanupReport(param); LOGGER.info("Audit object finalization succeeded"); return buildItemStatus(OBJECT_AUDIT_FINALIZE, StatusCode.OK, null); } catch (ProcessingStatusException e) { LOGGER.error(String.format("Audit object finalization failed with status [%s]", e.getStatusCode()), e); return buildItemStatus(OBJECT_AUDIT_FINALIZE, e.getStatusCode(), null); } } AuditFinalizePlugin(); @VisibleForTesting  AuditFinalizePlugin(AuditReportService auditReportService,
        LogbookOperationsClientFactory logbookOperationsClientFactory); @Override ItemStatus execute(WorkerParameters param, HandlerIO handler); }
AuditFinalizePlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { try { generateAuditReportToWorkspace(param, handler); storeReportToOffers(param.getContainerName()); cleanupReport(param); LOGGER.info("Audit object finalization succeeded"); return buildItemStatus(OBJECT_AUDIT_FINALIZE, StatusCode.OK, null); } catch (ProcessingStatusException e) { LOGGER.error(String.format("Audit object finalization failed with status [%s]", e.getStatusCode()), e); return buildItemStatus(OBJECT_AUDIT_FINALIZE, e.getStatusCode(), null); } } AuditFinalizePlugin(); @VisibleForTesting  AuditFinalizePlugin(AuditReportService auditReportService,
        LogbookOperationsClientFactory logbookOperationsClientFactory); @Override ItemStatus execute(WorkerParameters param, HandlerIO handler);  }