Search in sources :

Example 1 with SingleScenario

use of com.trivago.vo.SingleScenario in project cucable-plugin by trivago.

the class GherkinDocumentParserTest method validFeatureWithDataTableTest.

@Test
public void validFeatureWithDataTableTest() throws Exception {
    String featureContent = "@featureTag\n" + "Feature: test feature\n" + "\n" + "@scenario1Tag1\n" + "@scenario1Tag2\n" + "Scenario: This is a scenario with two steps\n" + "Given this is step 1\n" + "|value1|value2|\n" + "Then this is step 2\n";
    List<SingleScenario> singleScenariosFromFeature = gherkinDocumentParser.getSingleScenariosFromFeature(featureContent, "", null);
    assertThat(singleScenariosFromFeature.size(), is(1));
    SingleScenario scenario = singleScenariosFromFeature.get(0);
    assertThat(scenario.getScenarioName(), is("Scenario: This is a scenario with two steps"));
    assertThat(scenario.getSteps().size(), is(2));
    assertThat(scenario.getBackgroundSteps().size(), is(0));
    assertThat(scenario.getSteps().get(0).getDataTable(), is(notNullValue()));
    assertThat(scenario.getSteps().get(0).getDataTable().getRows().size(), is(1));
    assertThat(scenario.getSteps().get(0).getDataTable().getRows().get(0).size(), is(2));
}
Also used : SingleScenario(com.trivago.vo.SingleScenario) Test(org.junit.Test)

Example 2 with SingleScenario

use of com.trivago.vo.SingleScenario in project cucable-plugin by trivago.

the class FeatureFileConverterTest method convertToSingleScenariosAndRunnersWithFeaturesModeTest.

@Test
public void convertToSingleScenariosAndRunnersWithFeaturesModeTest() throws Exception {
    String generatedFeatureDir = testFolder.getRoot().getPath().concat("/features/");
    String generatedRunnerDir = testFolder.getRoot().getPath().concat("/runners/");
    final String FEATURE_FILE_NAME = "FEATURE_FILE.feature";
    propertyManager.setNumberOfTestRuns(1);
    propertyManager.setGeneratedFeatureDirectory(generatedFeatureDir);
    propertyManager.setGeneratedRunnerDirectory(generatedRunnerDir);
    propertyManager.setParallelizationMode("features");
    when(fileIO.readContentFromFile(FEATURE_FILE_NAME)).thenReturn("TEST_CONTENT");
    List<CucableFeature> cucableFeatures = new ArrayList<>();
    CucableFeature cucableFeature = new CucableFeature(FEATURE_FILE_NAME, null);
    cucableFeatures.add(cucableFeature);
    when(fileSystemManager.getPathsFromCucableFeature(cucableFeature)).thenReturn(Collections.singletonList(Paths.get(cucableFeature.getName())));
    List<SingleScenario> scenarioList = new ArrayList<>();
    SingleScenario singleScenario = getSingleScenario();
    scenarioList.add(singleScenario);
    when(gherkinDocumentParser.getSingleScenariosFromFeature("TEST_CONTENT", FEATURE_FILE_NAME, null)).thenReturn(scenarioList);
    String featureFileContent = "test";
    when(featureFileContentRenderer.getRenderedFeatureFileContent(singleScenario)).thenReturn(featureFileContent);
    when(runnerFileContentRenderer.getRenderedRunnerFileContent(any(FeatureRunner.class))).thenReturn("RUNNER_CONTENT");
    featureFileConverter.generateParallelizableFeatures(cucableFeatures);
    verify(fileIO, times(2)).writeContentToFile(anyString(), anyString());
}
Also used : SingleScenario(com.trivago.vo.SingleScenario) ArrayList(java.util.ArrayList) FeatureRunner(com.trivago.vo.FeatureRunner) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CucableFeature(com.trivago.vo.CucableFeature) Test(org.junit.Test)

Example 3 with SingleScenario

use of com.trivago.vo.SingleScenario in project cucable-plugin by trivago.

the class FeatureFileConverterTest method noScenariosMatchingScenarioNamesTest.

@Test(expected = CucablePluginException.class)
public void noScenariosMatchingScenarioNamesTest() throws Exception {
    String generatedFeatureDir = testFolder.getRoot().getPath().concat("/features/");
    String generatedRunnerDir = testFolder.getRoot().getPath().concat("/runners/");
    final String FEATURE_FILE_NAME = "FEATURE_FILE.feature";
    final String GENERATED_FEATURE_FILE_NAME = "FEATURE_FILE_scenario001_run001_IT.feature";
    final String scenarioNoMatchText = "Feature: feature1\n Scenario: noMatch";
    propertyManager.setNumberOfTestRuns(1);
    propertyManager.setGeneratedFeatureDirectory(generatedFeatureDir);
    propertyManager.setGeneratedRunnerDirectory(generatedRunnerDir);
    propertyManager.setScenarioNames("scenarioName1");
    when(fileIO.readContentFromFile(FEATURE_FILE_NAME)).thenReturn("TEST_CONTENT");
    when(fileIO.readContentFromFile(generatedFeatureDir + "/" + GENERATED_FEATURE_FILE_NAME)).thenReturn(scenarioNoMatchText);
    List<CucableFeature> cucableFeatures = new ArrayList<>();
    CucableFeature cucableFeature = new CucableFeature(FEATURE_FILE_NAME, null);
    cucableFeatures.add(cucableFeature);
    when(fileSystemManager.getPathsFromCucableFeature(cucableFeature)).thenReturn(Collections.singletonList(Paths.get(cucableFeature.getName())));
    List<SingleScenario> scenarioList = new ArrayList<>();
    SingleScenario singleScenario = getSingleScenario();
    scenarioList.add(singleScenario);
    when(gherkinDocumentParser.getSingleScenariosFromFeature("TEST_CONTENT", FEATURE_FILE_NAME, null)).thenReturn(scenarioList);
    when(gherkinDocumentParser.matchScenarioWithScenarioNames("en", scenarioNoMatchText)).thenReturn(-1);
    String featureFileContent = "test";
    when(featureFileContentRenderer.getRenderedFeatureFileContent(singleScenario)).thenReturn(featureFileContent);
    when(runnerFileContentRenderer.getRenderedRunnerFileContent(any(FeatureRunner.class))).thenReturn("RUNNER_CONTENT");
    featureFileConverter.generateParallelizableFeatures(cucableFeatures);
}
Also used : SingleScenario(com.trivago.vo.SingleScenario) ArrayList(java.util.ArrayList) FeatureRunner(com.trivago.vo.FeatureRunner) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CucableFeature(com.trivago.vo.CucableFeature) Test(org.junit.Test)

Example 4 with SingleScenario

use of com.trivago.vo.SingleScenario in project cucable-plugin by trivago.

the class FeatureFileConverterTest method convertToSingleScenariosAndMultiRunnersWithScenarioNamesTest.

@Test
public void convertToSingleScenariosAndMultiRunnersWithScenarioNamesTest() throws Exception {
    String generatedFeatureDir = testFolder.getRoot().getPath().concat("/features/");
    String generatedRunnerDir = testFolder.getRoot().getPath().concat("/runners/");
    final String scenarioMatch1Text = "Feature: feature1\n Scenario: scenarioName1";
    final String scenarioMatch2Text = "Feature: feature2\n Scenario: scenarioName2";
    final String FEATURE_FILE_NAME = "FEATURE_FILE.feature";
    final String GENERATED_FEATURE_FILE_NAME1 = "FEATURE_FILE_scenario001_run001_IT.feature";
    final String GENERATED_FEATURE_FILE_NAME2 = "FEATURE_FILE_scenario002_run001_IT.feature";
    propertyManager.setNumberOfTestRuns(1);
    propertyManager.setGeneratedFeatureDirectory(generatedFeatureDir);
    propertyManager.setGeneratedRunnerDirectory(generatedRunnerDir);
    propertyManager.setParallelizationMode("scenarios");
    propertyManager.setScenarioNames("scenarioName1, scenarioName2");
    when(fileIO.readContentFromFile(FEATURE_FILE_NAME)).thenReturn("TEST_CONTENT");
    when(fileIO.readContentFromFile(generatedFeatureDir + "/" + GENERATED_FEATURE_FILE_NAME1)).thenReturn(scenarioMatch1Text);
    when(fileIO.readContentFromFile(generatedFeatureDir + "/" + GENERATED_FEATURE_FILE_NAME2)).thenReturn(scenarioMatch2Text);
    when(fileIO.readContentFromFile(generatedFeatureDir + "/" + FEATURE_FILE_NAME)).thenReturn("TEST_CONTENT");
    List<CucableFeature> cucableFeatures = new ArrayList<>();
    CucableFeature cucableFeature = new CucableFeature(FEATURE_FILE_NAME, null);
    cucableFeatures.add(cucableFeature);
    when(fileSystemManager.getPathsFromCucableFeature(cucableFeature)).thenReturn(Collections.singletonList(Paths.get(cucableFeature.getName())));
    List<SingleScenario> scenarioList = new ArrayList<>();
    SingleScenario singleScenario = getSingleScenario();
    scenarioList.add(singleScenario);
    scenarioList.add(singleScenario);
    when(gherkinDocumentParser.getSingleScenariosFromFeature("TEST_CONTENT", FEATURE_FILE_NAME, null)).thenReturn(scenarioList);
    when(gherkinDocumentParser.matchScenarioWithScenarioNames("en", scenarioMatch1Text)).thenReturn(0);
    when(gherkinDocumentParser.matchScenarioWithScenarioNames("en", scenarioMatch2Text)).thenReturn(1);
    String featureFileContent = "test";
    when(featureFileContentRenderer.getRenderedFeatureFileContent(singleScenario)).thenReturn(featureFileContent);
    when(runnerFileContentRenderer.getRenderedRunnerFileContent(any(FeatureRunner.class))).thenReturn("RUNNER_CONTENT");
    featureFileConverter.generateParallelizableFeatures(cucableFeatures);
    ArgumentCaptor<String> logCaptor = ArgumentCaptor.forClass(String.class);
    verify(logger, times(1)).info(logCaptor.capture(), any(CucableLogger.CucableLogLevel.class), any(CucableLogger.CucableLogLevel.class), any(CucableLogger.CucableLogLevel.class));
    assertThat(logCaptor.getAllValues().get(0), is("Cucable created 2 separate feature files and 2 runners."));
    verify(fileIO, times(4)).writeContentToFile(anyString(), anyString());
}
Also used : SingleScenario(com.trivago.vo.SingleScenario) ArrayList(java.util.ArrayList) FeatureRunner(com.trivago.vo.FeatureRunner) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CucableFeature(com.trivago.vo.CucableFeature) Test(org.junit.Test)

Example 5 with SingleScenario

use of com.trivago.vo.SingleScenario in project cucable-plugin by trivago.

the class FeatureFileConverter method generateFeatureFiles.

/**
 * Write a single scenario feature to new files and return a list of generated file paths for later runner creation.
 *
 * @param sourceFeatureFilePath The complete path to the source feature.
 * @param singleScenarios       a list of single scenarios.
 * @return A list of generated feature file paths.
 * @throws FileCreationException Thrown if the feature file cannot be created.
 */
private List<String> generateFeatureFiles(final Path sourceFeatureFilePath, final List<SingleScenario> singleScenarios) throws FileCreationException {
    // Stores all generated feature file names and associated source feature paths for later runner creation
    List<String> generatedFeaturePaths = new ArrayList<>();
    // Default parallelization mode
    for (SingleScenario singleScenario : singleScenarios) {
        String featureFileName = getFeatureFileNameFromPath(sourceFeatureFilePath);
        Integer featureCounter = singleFeatureCounters.getOrDefault(featureFileName, 0);
        featureCounter++;
        String scenarioCounterFilenamePart = String.format(SCENARIO_COUNTER_FORMAT, featureCounter);
        for (int testRuns = 1; testRuns <= propertyManager.getNumberOfTestRuns(); testRuns++) {
            String generatedFileName = featureFileName.concat(scenarioCounterFilenamePart);
            String testRunsCounterFilenamePart = String.format(TEST_RUNS_COUNTER_FORMAT, testRuns);
            generatedFileName = generatedFileName.concat(testRunsCounterFilenamePart);
            if (propertyManager.isCucumberFeatureListFileSource()) {
                generatedFileName = generatedFileName.concat(TEST_RERUNS_FORMAT);
            }
            generatedFileName = generatedFileName.concat(INTEGRATION_TEST_POSTFIX);
            saveFeature(generatedFileName, featureFileContentRenderer.getRenderedFeatureFileContent(singleScenario));
            generatedFeaturePaths.add(generatedFileName);
            singleFeatureCounters.put(featureFileName, featureCounter);
        }
    }
    logFeatureFileConversionMessage(sourceFeatureFilePath.toString(), singleScenarios.size());
    return generatedFeaturePaths;
}
Also used : SingleScenario(com.trivago.vo.SingleScenario) ArrayList(java.util.ArrayList)

Aggregations

SingleScenario (com.trivago.vo.SingleScenario)23 Test (org.junit.Test)19 ArrayList (java.util.ArrayList)10 CucableFeature (com.trivago.vo.CucableFeature)7 FeatureRunner (com.trivago.vo.FeatureRunner)7 Step (com.trivago.vo.Step)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 DataTable (com.trivago.vo.DataTable)2 CucablePluginException (com.trivago.exceptions.CucablePluginException)1 FeatureFileParseException (com.trivago.exceptions.filesystem.FeatureFileParseException)1 Background (gherkin.ast.Background)1 Examples (gherkin.ast.Examples)1 Feature (gherkin.ast.Feature)1 GherkinDocument (gherkin.ast.GherkinDocument)1 Scenario (gherkin.ast.Scenario)1 ScenarioDefinition (gherkin.ast.ScenarioDefinition)1 ScenarioOutline (gherkin.ast.ScenarioOutline)1 List (java.util.List)1