@Test public void indexExecution_manageErrors_whenErrorsFound() { PlannedIndexation plannedIndexation = mock(PlannedIndexation.class); File executionFile = mock(File.class); CycleDefinition cycleDefinition = mock(CycleDefinition.class); Execution indexedExecution = mock(Execution.class); Execution savedExecution = mock(Execution.class); Run savedRun1 = mock(Run.class); ExecutedScenario savedScenario11 = mock(ExecutedScenario.class); Set<ExecutedScenario> savedScenarios1 = new TreeSet<>(); savedScenarios1.addAll(Arrays.asList(savedScenario11)); Error savedError111 = mock(Error.class); Error savedError112 = mock(Error.class); Error savedError113 = mock(Error.class); Set<Error> savedErrors11 = new TreeSet<>(); savedErrors11.addAll(Arrays.asList(savedError111, savedError112, savedError113)); Run savedRun2 = mock(Run.class); ExecutedScenario savedScenario21 = mock(ExecutedScenario.class); Error savedError211 = mock(Error.class); Error savedError212 = mock(Error.class); Set<Error> savedErrors21 = new TreeSet<>(); savedErrors21.addAll(Arrays.asList(savedError211, savedError212)); ExecutedScenario savedScenario22 = mock(ExecutedScenario.class); Error savedError221 = mock(Error.class); Error savedError222 = mock(Error.class); Set<Error> savedErrors22 = new TreeSet<>(); savedErrors22.addAll(Arrays.asList(savedError221, savedError222)); Set<ExecutedScenario> savedScenarios2 = new TreeSet<>(); savedScenarios2.addAll(Arrays.asList(savedScenario21, savedScenario22)); Set<Run> savedRuns = new TreeSet<>(); savedRuns.addAll(Arrays.asList(savedRun1, savedRun2)); Execution previousExecution = mock(Execution.class); Run previousRun = mock(Run.class); Set<Run> previousRuns = new TreeSet<>(); previousRuns.add(previousRun); ExecutedScenario previousScenario = mock(ExecutedScenario.class); Set<ExecutedScenario> previousExecutedScenarios = new TreeSet<>(); previousExecutedScenarios.add(previousScenario); Error previousError1 = mock(Error.class); Error previousError2 = mock(Error.class); Set<Error> previousErrors = new TreeSet<>(); previousErrors.addAll(Arrays.asList(previousError1, previousError2)); Problem problem1 = mock(Problem.class); Problem problem2 = mock(Problem.class); Problem problem3 = mock(Problem.class); Set<Problem> problems = new TreeSet<>(); problems.addAll(Arrays.asList(problem1, problem2, problem3)); when(plannedIndexation.getExecutionFolder()).thenReturn(executionFile); when(plannedIndexation.getCycleDefinition()).thenReturn(cycleDefinition); when(executionFile.getAbsolutePath()).thenReturn("/execution/folder/location/in/disk"); when(cycleDefinition.getProjectId()).thenReturn(1L); when(cycleDefinition.getBranch()).thenReturn("branch"); when(cycleDefinition.getName()).thenReturn("cycle"); when(executionFilesProcessorService.getExecution(plannedIndexation)).thenReturn(Optional.of(indexedExecution)); when(executionRepository.save(indexedExecution)).thenReturn(savedExecution); when(indexedExecution.getJobUrl()).thenReturn("http: when(savedExecution.getStatus()).thenReturn(JobStatus.UNAVAILABLE); when(executionRepository.findByCycleDefinitionProjectIdAndJobLinkAndJobLinkNotNull(1L, "/execution/folder/location/in/disk" + File.separator)).thenReturn(Optional.of(previousExecution)); when(previousExecution.getRuns()).thenReturn(previousRuns); when(previousRun.getExecutedScenarios()).thenReturn(previousExecutedScenarios); when(previousScenario.getErrors()).thenReturn(previousErrors); when(previousError1.getId()).thenReturn(112L); when(previousError2.getId()).thenReturn(212L); when(savedExecution.getRuns()).thenReturn(savedRuns); when(savedRun1.getExecutedScenarios()).thenReturn(savedScenarios1); when(savedScenario11.getErrors()).thenReturn(savedErrors11); when(savedError111.getId()).thenReturn(111L); when(savedError112.getId()).thenReturn(112L); when(savedError113.getId()).thenReturn(113L); when(savedRun2.getExecutedScenarios()).thenReturn(savedScenarios2); when(savedScenario21.getErrors()).thenReturn(savedErrors21); when(savedError211.getId()).thenReturn(211L); when(savedError212.getId()).thenReturn(212L); when(savedScenario22.getErrors()).thenReturn(savedErrors22); when(savedError221.getId()).thenReturn(221L); when(savedError222.getId()).thenReturn(222L); when(errorRepository.autoAssignProblemsToNewErrors(anyLong(), anyList())).thenReturn(problems); cut.indexExecution(plannedIndexation); verify(executionFilesProcessorService).getExecution(plannedIndexation); verify(executionRepository).save(indexedExecution); verify(executionRepository).findByCycleDefinitionProjectIdAndJobLinkAndJobLinkNotNull(1L, "/execution/folder/location/in/disk" + File.separator); verify(errorRepository).autoAssignProblemsToNewErrors(1L, Arrays.asList(111L, 113L, 211L, 221L, 222L)); verify(problemDenormalizationService).updateFirstAndLastSeenDateTimes(problems); verify(transactionService, never()).doAfterCommit(any(Runnable.class)); }
@Transactional public void indexExecution(PlannedIndexation plannedIndexation) { if (plannedIndexation == null) { log.info("No execution indexation found"); return; } File rawExecutionFolder = plannedIndexation.getExecutionFolder(); if (rawExecutionFolder == null) { log.info("No execution folder found"); return; } CycleDefinition cycleDefinition = plannedIndexation.getCycleDefinition(); if (cycleDefinition == null) { log.info("No cycle definition found"); return; } String branch = cycleDefinition.getBranch(); String cycle = cycleDefinition.getName(); final Long projectId = cycleDefinition.getProjectId(); String link = rawExecutionFolder.getAbsolutePath() + File.separator; log.info("Began execution indexing {}/{} for link {}", branch, cycle, link); Optional<Execution> previousExecution = executionRepository.findByCycleDefinitionProjectIdAndJobLinkAndJobLinkNotNull(projectId, link); List<Long> existingErrorIds = getErrorIds(previousExecution); Optional<Execution> processedExecution = executionFilesProcessorService.getExecution(plannedIndexation); if (!processedExecution.isPresent()) { log.info("Could not extract any execution from the directory {}", link); log.info("Some of the files may be incorrect, please check again"); return; } final Execution savedExecution = executionRepository.save(processedExecution.get()); List<Long> newErrorIds = getErrorIds(Optional.of(savedExecution)); newErrorIds.removeAll(existingErrorIds); if (!newErrorIds.isEmpty()) { final Set<Problem> updatedProblems = errorRepository.autoAssignProblemsToNewErrors(projectId, newErrorIds); problemDenormalizationService.updateFirstAndLastSeenDateTimes(updatedProblems); } if (JobStatus.DONE.equals(savedExecution.getStatus())) { transactionAppenderUtil.doAfterCommit(() -> safelySendQualityEmail(savedExecution)); } String url = processedExecution.get().getJobUrl(); log.info("Ended indexing execution {}/{} job URL {} and link {}", branch, cycle, url, link); }
ExecutionIndexerService { @Transactional public void indexExecution(PlannedIndexation plannedIndexation) { if (plannedIndexation == null) { log.info("No execution indexation found"); return; } File rawExecutionFolder = plannedIndexation.getExecutionFolder(); if (rawExecutionFolder == null) { log.info("No execution folder found"); return; } CycleDefinition cycleDefinition = plannedIndexation.getCycleDefinition(); if (cycleDefinition == null) { log.info("No cycle definition found"); return; } String branch = cycleDefinition.getBranch(); String cycle = cycleDefinition.getName(); final Long projectId = cycleDefinition.getProjectId(); String link = rawExecutionFolder.getAbsolutePath() + File.separator; log.info("Began execution indexing {}/{} for link {}", branch, cycle, link); Optional<Execution> previousExecution = executionRepository.findByCycleDefinitionProjectIdAndJobLinkAndJobLinkNotNull(projectId, link); List<Long> existingErrorIds = getErrorIds(previousExecution); Optional<Execution> processedExecution = executionFilesProcessorService.getExecution(plannedIndexation); if (!processedExecution.isPresent()) { log.info("Could not extract any execution from the directory {}", link); log.info("Some of the files may be incorrect, please check again"); return; } final Execution savedExecution = executionRepository.save(processedExecution.get()); List<Long> newErrorIds = getErrorIds(Optional.of(savedExecution)); newErrorIds.removeAll(existingErrorIds); if (!newErrorIds.isEmpty()) { final Set<Problem> updatedProblems = errorRepository.autoAssignProblemsToNewErrors(projectId, newErrorIds); problemDenormalizationService.updateFirstAndLastSeenDateTimes(updatedProblems); } if (JobStatus.DONE.equals(savedExecution.getStatus())) { transactionAppenderUtil.doAfterCommit(() -> safelySendQualityEmail(savedExecution)); } String url = processedExecution.get().getJobUrl(); log.info("Ended indexing execution {}/{} job URL {} and link {}", branch, cycle, url, link); } }
ExecutionIndexerService { @Transactional public void indexExecution(PlannedIndexation plannedIndexation) { if (plannedIndexation == null) { log.info("No execution indexation found"); return; } File rawExecutionFolder = plannedIndexation.getExecutionFolder(); if (rawExecutionFolder == null) { log.info("No execution folder found"); return; } CycleDefinition cycleDefinition = plannedIndexation.getCycleDefinition(); if (cycleDefinition == null) { log.info("No cycle definition found"); return; } String branch = cycleDefinition.getBranch(); String cycle = cycleDefinition.getName(); final Long projectId = cycleDefinition.getProjectId(); String link = rawExecutionFolder.getAbsolutePath() + File.separator; log.info("Began execution indexing {}/{} for link {}", branch, cycle, link); Optional<Execution> previousExecution = executionRepository.findByCycleDefinitionProjectIdAndJobLinkAndJobLinkNotNull(projectId, link); List<Long> existingErrorIds = getErrorIds(previousExecution); Optional<Execution> processedExecution = executionFilesProcessorService.getExecution(plannedIndexation); if (!processedExecution.isPresent()) { log.info("Could not extract any execution from the directory {}", link); log.info("Some of the files may be incorrect, please check again"); return; } final Execution savedExecution = executionRepository.save(processedExecution.get()); List<Long> newErrorIds = getErrorIds(Optional.of(savedExecution)); newErrorIds.removeAll(existingErrorIds); if (!newErrorIds.isEmpty()) { final Set<Problem> updatedProblems = errorRepository.autoAssignProblemsToNewErrors(projectId, newErrorIds); problemDenormalizationService.updateFirstAndLastSeenDateTimes(updatedProblems); } if (JobStatus.DONE.equals(savedExecution.getStatus())) { transactionAppenderUtil.doAfterCommit(() -> safelySendQualityEmail(savedExecution)); } String url = processedExecution.get().getJobUrl(); log.info("Ended indexing execution {}/{} job URL {} and link {}", branch, cycle, url, link); }  }
ExecutionIndexerService { @Transactional public void indexExecution(PlannedIndexation plannedIndexation) { if (plannedIndexation == null) { log.info("No execution indexation found"); return; } File rawExecutionFolder = plannedIndexation.getExecutionFolder(); if (rawExecutionFolder == null) { log.info("No execution folder found"); return; } CycleDefinition cycleDefinition = plannedIndexation.getCycleDefinition(); if (cycleDefinition == null) { log.info("No cycle definition found"); return; } String branch = cycleDefinition.getBranch(); String cycle = cycleDefinition.getName(); final Long projectId = cycleDefinition.getProjectId(); String link = rawExecutionFolder.getAbsolutePath() + File.separator; log.info("Began execution indexing {}/{} for link {}", branch, cycle, link); Optional<Execution> previousExecution = executionRepository.findByCycleDefinitionProjectIdAndJobLinkAndJobLinkNotNull(projectId, link); List<Long> existingErrorIds = getErrorIds(previousExecution); Optional<Execution> processedExecution = executionFilesProcessorService.getExecution(plannedIndexation); if (!processedExecution.isPresent()) { log.info("Could not extract any execution from the directory {}", link); log.info("Some of the files may be incorrect, please check again"); return; } final Execution savedExecution = executionRepository.save(processedExecution.get()); List<Long> newErrorIds = getErrorIds(Optional.of(savedExecution)); newErrorIds.removeAll(existingErrorIds); if (!newErrorIds.isEmpty()) { final Set<Problem> updatedProblems = errorRepository.autoAssignProblemsToNewErrors(projectId, newErrorIds); problemDenormalizationService.updateFirstAndLastSeenDateTimes(updatedProblems); } if (JobStatus.DONE.equals(savedExecution.getStatus())) { transactionAppenderUtil.doAfterCommit(() -> safelySendQualityEmail(savedExecution)); } String url = processedExecution.get().getJobUrl(); log.info("Ended indexing execution {}/{} job URL {} and link {}", branch, cycle, url, link); }  @Transactional void indexExecution(PlannedIndexation plannedIndexation); }
ExecutionIndexerService { @Transactional public void indexExecution(PlannedIndexation plannedIndexation) { if (plannedIndexation == null) { log.info("No execution indexation found"); return; } File rawExecutionFolder = plannedIndexation.getExecutionFolder(); if (rawExecutionFolder == null) { log.info("No execution folder found"); return; } CycleDefinition cycleDefinition = plannedIndexation.getCycleDefinition(); if (cycleDefinition == null) { log.info("No cycle definition found"); return; } String branch = cycleDefinition.getBranch(); String cycle = cycleDefinition.getName(); final Long projectId = cycleDefinition.getProjectId(); String link = rawExecutionFolder.getAbsolutePath() + File.separator; log.info("Began execution indexing {}/{} for link {}", branch, cycle, link); Optional<Execution> previousExecution = executionRepository.findByCycleDefinitionProjectIdAndJobLinkAndJobLinkNotNull(projectId, link); List<Long> existingErrorIds = getErrorIds(previousExecution); Optional<Execution> processedExecution = executionFilesProcessorService.getExecution(plannedIndexation); if (!processedExecution.isPresent()) { log.info("Could not extract any execution from the directory {}", link); log.info("Some of the files may be incorrect, please check again"); return; } final Execution savedExecution = executionRepository.save(processedExecution.get()); List<Long> newErrorIds = getErrorIds(Optional.of(savedExecution)); newErrorIds.removeAll(existingErrorIds); if (!newErrorIds.isEmpty()) { final Set<Problem> updatedProblems = errorRepository.autoAssignProblemsToNewErrors(projectId, newErrorIds); problemDenormalizationService.updateFirstAndLastSeenDateTimes(updatedProblems); } if (JobStatus.DONE.equals(savedExecution.getStatus())) { transactionAppenderUtil.doAfterCommit(() -> safelySendQualityEmail(savedExecution)); } String url = processedExecution.get().getJobUrl(); log.info("Ended indexing execution {}/{} job URL {} and link {}", branch, cycle, url, link); }  @Transactional void indexExecution(PlannedIndexation plannedIndexation);  }