@Test public void getExecutedScenarios_returnExecutedScenarios_whenAStepDefinitionsFileIsMissing(){ File parentFolder = mock(File.class); Run run = mock(Run.class); Long projectId = 1L; String cucumberFolderPath = "/cucumberFolder"; File cucumberFolder = mock(File.class); String cucumberSuffix = "cucumber-suffix"; File cucumberReportFile1 = mock(File.class); String cucumberReportFileName1 = "report1.cucumber-suffix.json"; File cucumberReportFile2 = mock(File.class); String cucumberReportFileName2 = "report2.cucumber-suffix.json"; String stepDefinitionsFolderPath = "/stepDefinitionsFolder"; File stepDefinitionFolder = mock(File.class); String stepDefinitionsSuffix = "step-definitions-suffix"; File stepDefinitionsFile1 = mock(File.class); String stepDefinitionsFileName1 = "report1.step-definitions-suffix.json"; Feature feature11 = mock(Feature.class); Feature feature12 = mock(Feature.class); Feature feature13 = mock(Feature.class); List<Feature> features1 = Arrays.asList(feature11, feature12, feature13); String step11 = "step11"; String step12 = "step12"; String step13 = "step13"; String step14 = "step14"; String step15 = "step15"; List<String> steps1 = Arrays.asList(step11, step12, step13, step14, step15); Feature feature21 = mock(Feature.class); Feature feature22 = mock(Feature.class); List<Feature> features2 = Arrays.asList(feature21, feature22); List<String> steps2 = Arrays.asList(); String runJobUrl = "run-job-url"; ExecutedScenario executedScenario11 = mock(ExecutedScenario.class); ExecutedScenario executedScenario12 = mock(ExecutedScenario.class); ExecutedScenario executedScenario21 = mock(ExecutedScenario.class); ExecutedScenario executedScenario22 = mock(ExecutedScenario.class); ExecutedScenario executedScenario23 = mock(ExecutedScenario.class); when(technologySettingService.getSettingValue(projectId, CypressSettings.CUCUMBER_REPORTS_FOLDER_PATHS)).thenReturn(Optional.of(cucumberFolderPath)); when(fileProcessorService.getMatchingDirectory(parentFolder, cucumberFolderPath)).thenReturn(Optional.of(cucumberFolder)); when(technologySettingService.getSettingValue(projectId, CypressSettings.CUCUMBER_FILE_NAME_SUFFIX_VALUE)).thenReturn(Optional.of(cucumberSuffix)); when(cucumberFolder.listFiles()).thenReturn(new File[] {cucumberReportFile1, cucumberReportFile2}); when(cucumberReportFile1.isFile()).thenReturn(true); when(cucumberReportFile1.getName()).thenReturn(cucumberReportFileName1); when(cucumberReportFile2.isFile()).thenReturn(true); when(cucumberReportFile2.getName()).thenReturn(cucumberReportFileName2); when(technologySettingService.getSettingValue(projectId, CypressSettings.STEP_DEFINITIONS_FOLDER_PATH)).thenReturn(Optional.of(stepDefinitionsFolderPath)); when(fileProcessorService.getMatchingDirectory(parentFolder, stepDefinitionsFolderPath)).thenReturn(Optional.of(stepDefinitionFolder)); when(technologySettingService.getSettingValue(projectId, CypressSettings.STEP_DEFINITIONS_FILE_NAME_SUFFIX_VALUE)).thenReturn(Optional.of(stepDefinitionsSuffix)); when(stepDefinitionFolder.listFiles()).thenReturn(new File[]{stepDefinitionsFile1}); when(stepDefinitionsFile1.isFile()).thenReturn(true); when(stepDefinitionsFile1.getName()).thenReturn(stepDefinitionsFileName1); when(cucumberScenariosIndexer.getCucumberFeaturesFromReport(cucumberReportFile1)).thenReturn(features1); when(cucumberScenariosIndexer.getCucumberStepDefinitions(stepDefinitionsFile1)).thenReturn(steps1); when(cucumberScenariosIndexer.getCucumberFeaturesFromReport(cucumberReportFile2)).thenReturn(features2); when(run.getJobUrl()).thenReturn(runJobUrl); when(executedScenarioExtractorService.extractExecutedScenarios(features1, steps1, runJobUrl)).thenReturn(Arrays.asList(executedScenario11, executedScenario12)); when(executedScenarioExtractorService.extractExecutedScenarios(features2, steps2, runJobUrl)).thenReturn(Arrays.asList(executedScenario21, executedScenario22, executedScenario23)); List<ExecutedScenario> executedScenarios = cypressScenariosIndexer.getExecutedScenarios(parentFolder, run, projectId); assertThat(executedScenarios) .hasSize(5) .containsOnly( executedScenario11, executedScenario12, executedScenario21, executedScenario22, executedScenario23 ); verify(technologySettingService).getSettingValue(projectId, CypressSettings.CUCUMBER_FILE_NAME_SUFFIX_VALUE); verify(technologySettingService).getSettingValue(projectId, CypressSettings.STEP_DEFINITIONS_FOLDER_PATH); verify(technologySettingService).getSettingValue(projectId, CypressSettings.STEP_DEFINITIONS_FILE_NAME_SUFFIX_VALUE); verify(fileProcessorService, times(2)).getMatchingDirectory(any(File.class), anyString()); verify(fileProcessorService).getMatchingDirectory(parentFolder, cucumberFolderPath); verify(fileProcessorService).getMatchingDirectory(parentFolder, stepDefinitionsFolderPath); verify(cucumberScenariosIndexer).getCucumberFeaturesFromReport(cucumberReportFile1); verify(cucumberScenariosIndexer).getCucumberStepDefinitions(stepDefinitionsFile1); verify(cucumberScenariosIndexer, times(1)).getCucumberStepDefinitions(any(File.class)); verify(cucumberScenariosIndexer).getCucumberFeaturesFromReport(cucumberReportFile2); verify(executedScenarioExtractorService).extractExecutedScenarios(features1, steps1, runJobUrl); verify(executedScenarioExtractorService).extractExecutedScenarios(features2, steps2, runJobUrl); }
@Override public List<ExecutedScenario> getExecutedScenarios(File parentFolder, Run run, Long projectId) { List<ExecutedScenario> executedScenarios = new ArrayList<>(); String cucumberReportsFolderPath = technologySettingService.getSettingValue(projectId, CypressSettings.CUCUMBER_REPORTS_FOLDER_PATHS).orElse(""); Optional<File> cucumberFolder = fileProcessorService.getMatchingDirectory(parentFolder, cucumberReportsFolderPath); if (!cucumberFolder.isPresent()) { return executedScenarios; } String cucumberSuffixValue = technologySettingService.getSettingValue(projectId, CypressSettings.CUCUMBER_FILE_NAME_SUFFIX_VALUE).orElse(""); String cucumberReportFileNameSuffix = String.format(".%s.json", cucumberSuffixValue); File[] cucumberFolderContent = cucumberFolder.get().listFiles(); List<File> cucumberReportFiles = Arrays.stream(cucumberFolderContent) .filter(File::isFile) .filter(file -> file.getName().endsWith(cucumberReportFileNameSuffix)) .collect(Collectors.toList()); if (cucumberReportFiles.isEmpty()) { return executedScenarios; } String stepDefinitionsFolderPath = technologySettingService.getSettingValue(projectId, CypressSettings.STEP_DEFINITIONS_FOLDER_PATH).orElse(""); Optional<File> stepDefinitionFolder = fileProcessorService.getMatchingDirectory(parentFolder, stepDefinitionsFolderPath); final List<File> stepDefinitionFiles = stepDefinitionFolder .map(File::listFiles) .map(files -> { String stepDefinitionsSuffixValue = technologySettingService.getSettingValue(projectId, CypressSettings.STEP_DEFINITIONS_FILE_NAME_SUFFIX_VALUE).orElse(""); String stepDefinitionFileNameSuffix = String.format(".%s.json", stepDefinitionsSuffixValue); return Arrays.stream(files) .filter(File::isFile) .filter(file -> file.getName().endsWith(stepDefinitionFileNameSuffix)) .collect(Collectors.toList()); }) .orElse(new ArrayList<>()); executedScenarios = cucumberReportFiles.stream() .map(file -> Pair.of(file, getStepDefinitionsFile(file, stepDefinitionFiles))) .map(pair -> Pair.of( cucumberScenariosIndexer.getCucumberFeaturesFromReport(pair.getFirst()), pair.getSecond().isPresent() ? cucumberScenariosIndexer.getCucumberStepDefinitions(pair.getSecond().get()) : new ArrayList<String>() ) ) .map(pair -> executedScenarioExtractorService.extractExecutedScenarios(pair.getFirst(), pair.getSecond(), run.getJobUrl())) .flatMap(Collection::stream) .collect(Collectors.toList()); String mediaPath = technologySettingService.getSettingValue(projectId, CypressSettings.MEDIA_FILE_PATH).orElse(""); List<CypressMedia> medias = fileProcessorService.getMappedObjectListFromFile(parentFolder, mediaPath, CypressMedia.class); executedScenarios = executedScenarios.stream() .map(scenario -> { Optional<Pair<Optional<String>, String>> mediaUrls = getSnapshotAndVideoUrls(scenario, medias); mediaUrls.ifPresent(pair -> { pair.getFirst().ifPresent(scenario::setScreenshotUrl); scenario.setVideoUrl(pair.getSecond()); }); return scenario; }) .collect(Collectors.toList()); return executedScenarios; }
CypressScenariosIndexer implements ScenariosIndexer { @Override public List<ExecutedScenario> getExecutedScenarios(File parentFolder, Run run, Long projectId) { List<ExecutedScenario> executedScenarios = new ArrayList<>(); String cucumberReportsFolderPath = technologySettingService.getSettingValue(projectId, CypressSettings.CUCUMBER_REPORTS_FOLDER_PATHS).orElse(""); Optional<File> cucumberFolder = fileProcessorService.getMatchingDirectory(parentFolder, cucumberReportsFolderPath); if (!cucumberFolder.isPresent()) { return executedScenarios; } String cucumberSuffixValue = technologySettingService.getSettingValue(projectId, CypressSettings.CUCUMBER_FILE_NAME_SUFFIX_VALUE).orElse(""); String cucumberReportFileNameSuffix = String.format(".%s.json", cucumberSuffixValue); File[] cucumberFolderContent = cucumberFolder.get().listFiles(); List<File> cucumberReportFiles = Arrays.stream(cucumberFolderContent) .filter(File::isFile) .filter(file -> file.getName().endsWith(cucumberReportFileNameSuffix)) .collect(Collectors.toList()); if (cucumberReportFiles.isEmpty()) { return executedScenarios; } String stepDefinitionsFolderPath = technologySettingService.getSettingValue(projectId, CypressSettings.STEP_DEFINITIONS_FOLDER_PATH).orElse(""); Optional<File> stepDefinitionFolder = fileProcessorService.getMatchingDirectory(parentFolder, stepDefinitionsFolderPath); final List<File> stepDefinitionFiles = stepDefinitionFolder .map(File::listFiles) .map(files -> { String stepDefinitionsSuffixValue = technologySettingService.getSettingValue(projectId, CypressSettings.STEP_DEFINITIONS_FILE_NAME_SUFFIX_VALUE).orElse(""); String stepDefinitionFileNameSuffix = String.format(".%s.json", stepDefinitionsSuffixValue); return Arrays.stream(files) .filter(File::isFile) .filter(file -> file.getName().endsWith(stepDefinitionFileNameSuffix)) .collect(Collectors.toList()); }) .orElse(new ArrayList<>()); executedScenarios = cucumberReportFiles.stream() .map(file -> Pair.of(file, getStepDefinitionsFile(file, stepDefinitionFiles))) .map(pair -> Pair.of( cucumberScenariosIndexer.getCucumberFeaturesFromReport(pair.getFirst()), pair.getSecond().isPresent() ? cucumberScenariosIndexer.getCucumberStepDefinitions(pair.getSecond().get()) : new ArrayList<String>() ) ) .map(pair -> executedScenarioExtractorService.extractExecutedScenarios(pair.getFirst(), pair.getSecond(), run.getJobUrl())) .flatMap(Collection::stream) .collect(Collectors.toList()); String mediaPath = technologySettingService.getSettingValue(projectId, CypressSettings.MEDIA_FILE_PATH).orElse(""); List<CypressMedia> medias = fileProcessorService.getMappedObjectListFromFile(parentFolder, mediaPath, CypressMedia.class); executedScenarios = executedScenarios.stream() .map(scenario -> { Optional<Pair<Optional<String>, String>> mediaUrls = getSnapshotAndVideoUrls(scenario, medias); mediaUrls.ifPresent(pair -> { pair.getFirst().ifPresent(scenario::setScreenshotUrl); scenario.setVideoUrl(pair.getSecond()); }); return scenario; }) .collect(Collectors.toList()); return executedScenarios; } }
CypressScenariosIndexer implements ScenariosIndexer { @Override public List<ExecutedScenario> getExecutedScenarios(File parentFolder, Run run, Long projectId) { List<ExecutedScenario> executedScenarios = new ArrayList<>(); String cucumberReportsFolderPath = technologySettingService.getSettingValue(projectId, CypressSettings.CUCUMBER_REPORTS_FOLDER_PATHS).orElse(""); Optional<File> cucumberFolder = fileProcessorService.getMatchingDirectory(parentFolder, cucumberReportsFolderPath); if (!cucumberFolder.isPresent()) { return executedScenarios; } String cucumberSuffixValue = technologySettingService.getSettingValue(projectId, CypressSettings.CUCUMBER_FILE_NAME_SUFFIX_VALUE).orElse(""); String cucumberReportFileNameSuffix = String.format(".%s.json", cucumberSuffixValue); File[] cucumberFolderContent = cucumberFolder.get().listFiles(); List<File> cucumberReportFiles = Arrays.stream(cucumberFolderContent) .filter(File::isFile) .filter(file -> file.getName().endsWith(cucumberReportFileNameSuffix)) .collect(Collectors.toList()); if (cucumberReportFiles.isEmpty()) { return executedScenarios; } String stepDefinitionsFolderPath = technologySettingService.getSettingValue(projectId, CypressSettings.STEP_DEFINITIONS_FOLDER_PATH).orElse(""); Optional<File> stepDefinitionFolder = fileProcessorService.getMatchingDirectory(parentFolder, stepDefinitionsFolderPath); final List<File> stepDefinitionFiles = stepDefinitionFolder .map(File::listFiles) .map(files -> { String stepDefinitionsSuffixValue = technologySettingService.getSettingValue(projectId, CypressSettings.STEP_DEFINITIONS_FILE_NAME_SUFFIX_VALUE).orElse(""); String stepDefinitionFileNameSuffix = String.format(".%s.json", stepDefinitionsSuffixValue); return Arrays.stream(files) .filter(File::isFile) .filter(file -> file.getName().endsWith(stepDefinitionFileNameSuffix)) .collect(Collectors.toList()); }) .orElse(new ArrayList<>()); executedScenarios = cucumberReportFiles.stream() .map(file -> Pair.of(file, getStepDefinitionsFile(file, stepDefinitionFiles))) .map(pair -> Pair.of( cucumberScenariosIndexer.getCucumberFeaturesFromReport(pair.getFirst()), pair.getSecond().isPresent() ? cucumberScenariosIndexer.getCucumberStepDefinitions(pair.getSecond().get()) : new ArrayList<String>() ) ) .map(pair -> executedScenarioExtractorService.extractExecutedScenarios(pair.getFirst(), pair.getSecond(), run.getJobUrl())) .flatMap(Collection::stream) .collect(Collectors.toList()); String mediaPath = technologySettingService.getSettingValue(projectId, CypressSettings.MEDIA_FILE_PATH).orElse(""); List<CypressMedia> medias = fileProcessorService.getMappedObjectListFromFile(parentFolder, mediaPath, CypressMedia.class); executedScenarios = executedScenarios.stream() .map(scenario -> { Optional<Pair<Optional<String>, String>> mediaUrls = getSnapshotAndVideoUrls(scenario, medias); mediaUrls.ifPresent(pair -> { pair.getFirst().ifPresent(scenario::setScreenshotUrl); scenario.setVideoUrl(pair.getSecond()); }); return scenario; }) .collect(Collectors.toList()); return executedScenarios; }  }
CypressScenariosIndexer implements ScenariosIndexer { @Override public List<ExecutedScenario> getExecutedScenarios(File parentFolder, Run run, Long projectId) { List<ExecutedScenario> executedScenarios = new ArrayList<>(); String cucumberReportsFolderPath = technologySettingService.getSettingValue(projectId, CypressSettings.CUCUMBER_REPORTS_FOLDER_PATHS).orElse(""); Optional<File> cucumberFolder = fileProcessorService.getMatchingDirectory(parentFolder, cucumberReportsFolderPath); if (!cucumberFolder.isPresent()) { return executedScenarios; } String cucumberSuffixValue = technologySettingService.getSettingValue(projectId, CypressSettings.CUCUMBER_FILE_NAME_SUFFIX_VALUE).orElse(""); String cucumberReportFileNameSuffix = String.format(".%s.json", cucumberSuffixValue); File[] cucumberFolderContent = cucumberFolder.get().listFiles(); List<File> cucumberReportFiles = Arrays.stream(cucumberFolderContent) .filter(File::isFile) .filter(file -> file.getName().endsWith(cucumberReportFileNameSuffix)) .collect(Collectors.toList()); if (cucumberReportFiles.isEmpty()) { return executedScenarios; } String stepDefinitionsFolderPath = technologySettingService.getSettingValue(projectId, CypressSettings.STEP_DEFINITIONS_FOLDER_PATH).orElse(""); Optional<File> stepDefinitionFolder = fileProcessorService.getMatchingDirectory(parentFolder, stepDefinitionsFolderPath); final List<File> stepDefinitionFiles = stepDefinitionFolder .map(File::listFiles) .map(files -> { String stepDefinitionsSuffixValue = technologySettingService.getSettingValue(projectId, CypressSettings.STEP_DEFINITIONS_FILE_NAME_SUFFIX_VALUE).orElse(""); String stepDefinitionFileNameSuffix = String.format(".%s.json", stepDefinitionsSuffixValue); return Arrays.stream(files) .filter(File::isFile) .filter(file -> file.getName().endsWith(stepDefinitionFileNameSuffix)) .collect(Collectors.toList()); }) .orElse(new ArrayList<>()); executedScenarios = cucumberReportFiles.stream() .map(file -> Pair.of(file, getStepDefinitionsFile(file, stepDefinitionFiles))) .map(pair -> Pair.of( cucumberScenariosIndexer.getCucumberFeaturesFromReport(pair.getFirst()), pair.getSecond().isPresent() ? cucumberScenariosIndexer.getCucumberStepDefinitions(pair.getSecond().get()) : new ArrayList<String>() ) ) .map(pair -> executedScenarioExtractorService.extractExecutedScenarios(pair.getFirst(), pair.getSecond(), run.getJobUrl())) .flatMap(Collection::stream) .collect(Collectors.toList()); String mediaPath = technologySettingService.getSettingValue(projectId, CypressSettings.MEDIA_FILE_PATH).orElse(""); List<CypressMedia> medias = fileProcessorService.getMappedObjectListFromFile(parentFolder, mediaPath, CypressMedia.class); executedScenarios = executedScenarios.stream() .map(scenario -> { Optional<Pair<Optional<String>, String>> mediaUrls = getSnapshotAndVideoUrls(scenario, medias); mediaUrls.ifPresent(pair -> { pair.getFirst().ifPresent(scenario::setScreenshotUrl); scenario.setVideoUrl(pair.getSecond()); }); return scenario; }) .collect(Collectors.toList()); return executedScenarios; }  @Override List<ExecutedScenario> getExecutedScenarios(File parentFolder, Run run, Long projectId); }
CypressScenariosIndexer implements ScenariosIndexer { @Override public List<ExecutedScenario> getExecutedScenarios(File parentFolder, Run run, Long projectId) { List<ExecutedScenario> executedScenarios = new ArrayList<>(); String cucumberReportsFolderPath = technologySettingService.getSettingValue(projectId, CypressSettings.CUCUMBER_REPORTS_FOLDER_PATHS).orElse(""); Optional<File> cucumberFolder = fileProcessorService.getMatchingDirectory(parentFolder, cucumberReportsFolderPath); if (!cucumberFolder.isPresent()) { return executedScenarios; } String cucumberSuffixValue = technologySettingService.getSettingValue(projectId, CypressSettings.CUCUMBER_FILE_NAME_SUFFIX_VALUE).orElse(""); String cucumberReportFileNameSuffix = String.format(".%s.json", cucumberSuffixValue); File[] cucumberFolderContent = cucumberFolder.get().listFiles(); List<File> cucumberReportFiles = Arrays.stream(cucumberFolderContent) .filter(File::isFile) .filter(file -> file.getName().endsWith(cucumberReportFileNameSuffix)) .collect(Collectors.toList()); if (cucumberReportFiles.isEmpty()) { return executedScenarios; } String stepDefinitionsFolderPath = technologySettingService.getSettingValue(projectId, CypressSettings.STEP_DEFINITIONS_FOLDER_PATH).orElse(""); Optional<File> stepDefinitionFolder = fileProcessorService.getMatchingDirectory(parentFolder, stepDefinitionsFolderPath); final List<File> stepDefinitionFiles = stepDefinitionFolder .map(File::listFiles) .map(files -> { String stepDefinitionsSuffixValue = technologySettingService.getSettingValue(projectId, CypressSettings.STEP_DEFINITIONS_FILE_NAME_SUFFIX_VALUE).orElse(""); String stepDefinitionFileNameSuffix = String.format(".%s.json", stepDefinitionsSuffixValue); return Arrays.stream(files) .filter(File::isFile) .filter(file -> file.getName().endsWith(stepDefinitionFileNameSuffix)) .collect(Collectors.toList()); }) .orElse(new ArrayList<>()); executedScenarios = cucumberReportFiles.stream() .map(file -> Pair.of(file, getStepDefinitionsFile(file, stepDefinitionFiles))) .map(pair -> Pair.of( cucumberScenariosIndexer.getCucumberFeaturesFromReport(pair.getFirst()), pair.getSecond().isPresent() ? cucumberScenariosIndexer.getCucumberStepDefinitions(pair.getSecond().get()) : new ArrayList<String>() ) ) .map(pair -> executedScenarioExtractorService.extractExecutedScenarios(pair.getFirst(), pair.getSecond(), run.getJobUrl())) .flatMap(Collection::stream) .collect(Collectors.toList()); String mediaPath = technologySettingService.getSettingValue(projectId, CypressSettings.MEDIA_FILE_PATH).orElse(""); List<CypressMedia> medias = fileProcessorService.getMappedObjectListFromFile(parentFolder, mediaPath, CypressMedia.class); executedScenarios = executedScenarios.stream() .map(scenario -> { Optional<Pair<Optional<String>, String>> mediaUrls = getSnapshotAndVideoUrls(scenario, medias); mediaUrls.ifPresent(pair -> { pair.getFirst().ifPresent(scenario::setScreenshotUrl); scenario.setVideoUrl(pair.getSecond()); }); return scenario; }) .collect(Collectors.toList()); return executedScenarios; }  @Override List<ExecutedScenario> getExecutedScenarios(File parentFolder, Run run, Long projectId);  }