@Test public void should_generate_reports_when_line_not_found() throws Exception { when(defaultWorkerParameters.getObjectName()).thenReturn("test"); when(defaultWorkerParameters.getContainerName()).thenReturn(processId); File resourceFile = PropertiesUtils.getResourceFile("evidenceAudit/data.txt"); when(handlerIO.getFileFromWorkspace("zip/test")).thenReturn(resourceFile); File file2 = tempFolder.newFile(); File report = tempFolder.newFile(); JsonHandler.writeAsFile("aeaqaaaaaaebta56aaoc4alcdk4hlcqaaaaq", file2); when(handlerIO.getFileFromWorkspace("fileNames/test")).thenReturn(file2); when(handlerIO.getFileFromWorkspace("data/aeaqaaaaaaebta56aaoc4alcdk4hlcqaaaaq")) .thenReturn(PropertiesUtils.getResourceFile("evidenceAudit/test.json")); when(handlerIO.getNewLocalFile("aeaqaaaaaaebta56aaoc4alcdk4hlcqaaaaq")).thenReturn(report); given(handlerIO.getJsonFromWorkspace("evidenceOptions")) .willReturn(JsonHandler.createObjectNode().put("correctiveOption", false)); ItemStatus execute = evidenceAuditGenerateReports.execute(defaultWorkerParameters, handlerIO); assertThat(execute.getGlobalStatus()).isEqualTo(StatusCode.OK); EvidenceAuditReportLine evidenceAuditReportLine = JsonHandler.getFromFile(report, EvidenceAuditReportLine.class); assertThat(evidenceAuditReportLine.getIdentifier()).isEqualTo("aeaqaaaaaaebta56aaoc4alcdk4hlcqaaaaq"); assertThat(evidenceAuditReportLine.getEvidenceStatus()).isEqualTo(EvidenceStatus.KO); assertThat(evidenceAuditReportLine.getMessage()) .isEqualTo("Could not find matching traceability info in the file"); }
@Override public ItemStatus execute(WorkerParameters param, HandlerIO handlerIO) throws ProcessingException { ItemStatus itemStatus = new ItemStatus(EVIDENCE_AUDIT_PREPARE_GENERATE_REPORTS); try { JsonNode options = handlerIO.getJsonFromWorkspace("evidenceOptions"); boolean correctiveAudit = options.get("correctiveOption").booleanValue(); File securedDataFile = handlerIO.getFileFromWorkspace(ZIP + "/" + param.getObjectName()); File listOfObjectByFile = handlerIO.getFileFromWorkspace(FILE_NAMES + "/" + param.getObjectName()); List<String> securedLines = Files.readAllLines(securedDataFile.toPath(), Charset.defaultCharset()); ArrayList<String> listIds = JsonHandler.getFromFileAsTypeReference(listOfObjectByFile, new TypeReference<ArrayList<String>>() { }); EvidenceService evidenceService = new EvidenceService(); for (String objectToAuditId : listIds) { File infoFromDatabase = handlerIO.getFileFromWorkspace(DATA + "/" + objectToAuditId); EvidenceAuditParameters parameters = JsonHandler.getFromFile(infoFromDatabase, EvidenceAuditParameters.class); EvidenceAuditReportLine evidenceAuditReportLine; File file = handlerIO.getNewLocalFile(objectToAuditId); if (parameters.getEvidenceStatus().equals(EvidenceStatus.OK)) { evidenceAuditReportLine = evidenceService.auditAndGenerateReportIfKo(parameters, securedLines, objectToAuditId); } else { evidenceAuditReportLine = new EvidenceAuditReportLine(objectToAuditId); evidenceAuditReportLine.setEvidenceStatus(parameters.getEvidenceStatus()); evidenceAuditReportLine.setMessage(parameters.getAuditMessage()); } JsonHandler.writeAsFile(evidenceAuditReportLine, file); if(!correctiveAudit) addReportEntry(param.getContainerName(), createEvidenceReportEntry(evidenceAuditReportLine)); handlerIO.transferFileToWorkspace(REPORTS + "/" + objectToAuditId + ".report.json", file, !correctiveAudit, false); if (correctiveAudit) { handlerIO.transferFileToWorkspace(ALTER + "/" + objectToAuditId + ".json", file, true, false); } } itemStatus.increment(StatusCode.OK); } catch (IOException | ContentAddressableStorageNotFoundException | InvalidParseOperationException | ProcessingStatusException | ContentAddressableStorageServerException e) { LOGGER.error(e); return itemStatus.increment(StatusCode.FATAL); } return new ItemStatus(EVIDENCE_AUDIT_PREPARE_GENERATE_REPORTS) .setItemsStatus(EVIDENCE_AUDIT_PREPARE_GENERATE_REPORTS, itemStatus); }
EvidenceAuditGenerateReports extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handlerIO) throws ProcessingException { ItemStatus itemStatus = new ItemStatus(EVIDENCE_AUDIT_PREPARE_GENERATE_REPORTS); try { JsonNode options = handlerIO.getJsonFromWorkspace("evidenceOptions"); boolean correctiveAudit = options.get("correctiveOption").booleanValue(); File securedDataFile = handlerIO.getFileFromWorkspace(ZIP + "/" + param.getObjectName()); File listOfObjectByFile = handlerIO.getFileFromWorkspace(FILE_NAMES + "/" + param.getObjectName()); List<String> securedLines = Files.readAllLines(securedDataFile.toPath(), Charset.defaultCharset()); ArrayList<String> listIds = JsonHandler.getFromFileAsTypeReference(listOfObjectByFile, new TypeReference<ArrayList<String>>() { }); EvidenceService evidenceService = new EvidenceService(); for (String objectToAuditId : listIds) { File infoFromDatabase = handlerIO.getFileFromWorkspace(DATA + "/" + objectToAuditId); EvidenceAuditParameters parameters = JsonHandler.getFromFile(infoFromDatabase, EvidenceAuditParameters.class); EvidenceAuditReportLine evidenceAuditReportLine; File file = handlerIO.getNewLocalFile(objectToAuditId); if (parameters.getEvidenceStatus().equals(EvidenceStatus.OK)) { evidenceAuditReportLine = evidenceService.auditAndGenerateReportIfKo(parameters, securedLines, objectToAuditId); } else { evidenceAuditReportLine = new EvidenceAuditReportLine(objectToAuditId); evidenceAuditReportLine.setEvidenceStatus(parameters.getEvidenceStatus()); evidenceAuditReportLine.setMessage(parameters.getAuditMessage()); } JsonHandler.writeAsFile(evidenceAuditReportLine, file); if(!correctiveAudit) addReportEntry(param.getContainerName(), createEvidenceReportEntry(evidenceAuditReportLine)); handlerIO.transferFileToWorkspace(REPORTS + "/" + objectToAuditId + ".report.json", file, !correctiveAudit, false); if (correctiveAudit) { handlerIO.transferFileToWorkspace(ALTER + "/" + objectToAuditId + ".json", file, true, false); } } itemStatus.increment(StatusCode.OK); } catch (IOException | ContentAddressableStorageNotFoundException | InvalidParseOperationException | ProcessingStatusException | ContentAddressableStorageServerException e) { LOGGER.error(e); return itemStatus.increment(StatusCode.FATAL); } return new ItemStatus(EVIDENCE_AUDIT_PREPARE_GENERATE_REPORTS) .setItemsStatus(EVIDENCE_AUDIT_PREPARE_GENERATE_REPORTS, itemStatus); } }
EvidenceAuditGenerateReports extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handlerIO) throws ProcessingException { ItemStatus itemStatus = new ItemStatus(EVIDENCE_AUDIT_PREPARE_GENERATE_REPORTS); try { JsonNode options = handlerIO.getJsonFromWorkspace("evidenceOptions"); boolean correctiveAudit = options.get("correctiveOption").booleanValue(); File securedDataFile = handlerIO.getFileFromWorkspace(ZIP + "/" + param.getObjectName()); File listOfObjectByFile = handlerIO.getFileFromWorkspace(FILE_NAMES + "/" + param.getObjectName()); List<String> securedLines = Files.readAllLines(securedDataFile.toPath(), Charset.defaultCharset()); ArrayList<String> listIds = JsonHandler.getFromFileAsTypeReference(listOfObjectByFile, new TypeReference<ArrayList<String>>() { }); EvidenceService evidenceService = new EvidenceService(); for (String objectToAuditId : listIds) { File infoFromDatabase = handlerIO.getFileFromWorkspace(DATA + "/" + objectToAuditId); EvidenceAuditParameters parameters = JsonHandler.getFromFile(infoFromDatabase, EvidenceAuditParameters.class); EvidenceAuditReportLine evidenceAuditReportLine; File file = handlerIO.getNewLocalFile(objectToAuditId); if (parameters.getEvidenceStatus().equals(EvidenceStatus.OK)) { evidenceAuditReportLine = evidenceService.auditAndGenerateReportIfKo(parameters, securedLines, objectToAuditId); } else { evidenceAuditReportLine = new EvidenceAuditReportLine(objectToAuditId); evidenceAuditReportLine.setEvidenceStatus(parameters.getEvidenceStatus()); evidenceAuditReportLine.setMessage(parameters.getAuditMessage()); } JsonHandler.writeAsFile(evidenceAuditReportLine, file); if(!correctiveAudit) addReportEntry(param.getContainerName(), createEvidenceReportEntry(evidenceAuditReportLine)); handlerIO.transferFileToWorkspace(REPORTS + "/" + objectToAuditId + ".report.json", file, !correctiveAudit, false); if (correctiveAudit) { handlerIO.transferFileToWorkspace(ALTER + "/" + objectToAuditId + ".json", file, true, false); } } itemStatus.increment(StatusCode.OK); } catch (IOException | ContentAddressableStorageNotFoundException | InvalidParseOperationException | ProcessingStatusException | ContentAddressableStorageServerException e) { LOGGER.error(e); return itemStatus.increment(StatusCode.FATAL); } return new ItemStatus(EVIDENCE_AUDIT_PREPARE_GENERATE_REPORTS) .setItemsStatus(EVIDENCE_AUDIT_PREPARE_GENERATE_REPORTS, itemStatus); } @VisibleForTesting  EvidenceAuditGenerateReports(EvidenceAuditReportService evidenceAuditReportService);  EvidenceAuditGenerateReports(); }
EvidenceAuditGenerateReports extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handlerIO) throws ProcessingException { ItemStatus itemStatus = new ItemStatus(EVIDENCE_AUDIT_PREPARE_GENERATE_REPORTS); try { JsonNode options = handlerIO.getJsonFromWorkspace("evidenceOptions"); boolean correctiveAudit = options.get("correctiveOption").booleanValue(); File securedDataFile = handlerIO.getFileFromWorkspace(ZIP + "/" + param.getObjectName()); File listOfObjectByFile = handlerIO.getFileFromWorkspace(FILE_NAMES + "/" + param.getObjectName()); List<String> securedLines = Files.readAllLines(securedDataFile.toPath(), Charset.defaultCharset()); ArrayList<String> listIds = JsonHandler.getFromFileAsTypeReference(listOfObjectByFile, new TypeReference<ArrayList<String>>() { }); EvidenceService evidenceService = new EvidenceService(); for (String objectToAuditId : listIds) { File infoFromDatabase = handlerIO.getFileFromWorkspace(DATA + "/" + objectToAuditId); EvidenceAuditParameters parameters = JsonHandler.getFromFile(infoFromDatabase, EvidenceAuditParameters.class); EvidenceAuditReportLine evidenceAuditReportLine; File file = handlerIO.getNewLocalFile(objectToAuditId); if (parameters.getEvidenceStatus().equals(EvidenceStatus.OK)) { evidenceAuditReportLine = evidenceService.auditAndGenerateReportIfKo(parameters, securedLines, objectToAuditId); } else { evidenceAuditReportLine = new EvidenceAuditReportLine(objectToAuditId); evidenceAuditReportLine.setEvidenceStatus(parameters.getEvidenceStatus()); evidenceAuditReportLine.setMessage(parameters.getAuditMessage()); } JsonHandler.writeAsFile(evidenceAuditReportLine, file); if(!correctiveAudit) addReportEntry(param.getContainerName(), createEvidenceReportEntry(evidenceAuditReportLine)); handlerIO.transferFileToWorkspace(REPORTS + "/" + objectToAuditId + ".report.json", file, !correctiveAudit, false); if (correctiveAudit) { handlerIO.transferFileToWorkspace(ALTER + "/" + objectToAuditId + ".json", file, true, false); } } itemStatus.increment(StatusCode.OK); } catch (IOException | ContentAddressableStorageNotFoundException | InvalidParseOperationException | ProcessingStatusException | ContentAddressableStorageServerException e) { LOGGER.error(e); return itemStatus.increment(StatusCode.FATAL); } return new ItemStatus(EVIDENCE_AUDIT_PREPARE_GENERATE_REPORTS) .setItemsStatus(EVIDENCE_AUDIT_PREPARE_GENERATE_REPORTS, itemStatus); } @VisibleForTesting  EvidenceAuditGenerateReports(EvidenceAuditReportService evidenceAuditReportService);  EvidenceAuditGenerateReports(); @Override ItemStatus execute(WorkerParameters param, HandlerIO handlerIO); }
EvidenceAuditGenerateReports extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handlerIO) throws ProcessingException { ItemStatus itemStatus = new ItemStatus(EVIDENCE_AUDIT_PREPARE_GENERATE_REPORTS); try { JsonNode options = handlerIO.getJsonFromWorkspace("evidenceOptions"); boolean correctiveAudit = options.get("correctiveOption").booleanValue(); File securedDataFile = handlerIO.getFileFromWorkspace(ZIP + "/" + param.getObjectName()); File listOfObjectByFile = handlerIO.getFileFromWorkspace(FILE_NAMES + "/" + param.getObjectName()); List<String> securedLines = Files.readAllLines(securedDataFile.toPath(), Charset.defaultCharset()); ArrayList<String> listIds = JsonHandler.getFromFileAsTypeReference(listOfObjectByFile, new TypeReference<ArrayList<String>>() { }); EvidenceService evidenceService = new EvidenceService(); for (String objectToAuditId : listIds) { File infoFromDatabase = handlerIO.getFileFromWorkspace(DATA + "/" + objectToAuditId); EvidenceAuditParameters parameters = JsonHandler.getFromFile(infoFromDatabase, EvidenceAuditParameters.class); EvidenceAuditReportLine evidenceAuditReportLine; File file = handlerIO.getNewLocalFile(objectToAuditId); if (parameters.getEvidenceStatus().equals(EvidenceStatus.OK)) { evidenceAuditReportLine = evidenceService.auditAndGenerateReportIfKo(parameters, securedLines, objectToAuditId); } else { evidenceAuditReportLine = new EvidenceAuditReportLine(objectToAuditId); evidenceAuditReportLine.setEvidenceStatus(parameters.getEvidenceStatus()); evidenceAuditReportLine.setMessage(parameters.getAuditMessage()); } JsonHandler.writeAsFile(evidenceAuditReportLine, file); if(!correctiveAudit) addReportEntry(param.getContainerName(), createEvidenceReportEntry(evidenceAuditReportLine)); handlerIO.transferFileToWorkspace(REPORTS + "/" + objectToAuditId + ".report.json", file, !correctiveAudit, false); if (correctiveAudit) { handlerIO.transferFileToWorkspace(ALTER + "/" + objectToAuditId + ".json", file, true, false); } } itemStatus.increment(StatusCode.OK); } catch (IOException | ContentAddressableStorageNotFoundException | InvalidParseOperationException | ProcessingStatusException | ContentAddressableStorageServerException e) { LOGGER.error(e); return itemStatus.increment(StatusCode.FATAL); } return new ItemStatus(EVIDENCE_AUDIT_PREPARE_GENERATE_REPORTS) .setItemsStatus(EVIDENCE_AUDIT_PREPARE_GENERATE_REPORTS, itemStatus); } @VisibleForTesting  EvidenceAuditGenerateReports(EvidenceAuditReportService evidenceAuditReportService);  EvidenceAuditGenerateReports(); @Override ItemStatus execute(WorkerParameters param, HandlerIO handlerIO); static final String ZIP; }