Search in sources :

Example 1 with Step

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

the class FeatureFileContentRendererTest method getRenderedFeatureFileContentTest.

@Test
public void getRenderedFeatureFileContentTest() {
    String expectedOutput = "@featureTag1\n" + "@featureTag2\n" + "Feature: featureName\n" + "featureDescription\n" + "\n" + "Background:\n" + "Background Step 1\n" + "Background Step 2\n" + "\n" + "@scenarioTag1\n" + "@scenarioTag2\n" + "Scenario: scenarioName\n" + "scenarioDescription\n" + "Step 1\n" + "Step 2\n" + "\n# Source feature: TESTPATH\n" + "# Generated by Cucable\n";
    String featureName = "Feature: featureName";
    String featureDescription = "featureDescription";
    String featureLanguage = "";
    List<String> featureTags = Arrays.asList("@featureTag1", "@featureTag2");
    String scenarioName = "Scenario: scenarioName";
    String scenarioDescription = "scenarioDescription";
    List<Step> backgroundSteps = Arrays.asList(new Step("Background Step 1", null, null), new Step("Background Step 2", null, null));
    List<Step> steps = Arrays.asList(new Step("Step 1", null, null), new Step("Step 2", null, null));
    List<String> scenarioTags = Arrays.asList("@scenarioTag1", "@scenarioTag2");
    String featureFilePath = "TESTPATH";
    SingleScenario singleScenario = new SingleScenario(featureName, featureFilePath, featureLanguage, featureDescription, scenarioName, scenarioDescription, featureTags, backgroundSteps);
    singleScenario.setScenarioTags(scenarioTags);
    singleScenario.setSteps(steps);
    String renderedFeatureFileContent = featureFileContentRenderer.getRenderedFeatureFileContent(singleScenario);
    // In a windows system, replace line separator "\r\n" with "\n".
    renderedFeatureFileContent = renderedFeatureFileContent.replaceAll("\\r\\n", "\n");
    assertThat(renderedFeatureFileContent, is(expectedOutput));
}
Also used : SingleScenario(com.trivago.vo.SingleScenario) Step(com.trivago.vo.Step) Test(org.junit.Test)

Example 2 with Step

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

the class FeatureFileContentRendererTest method getRenderedFeatureFileContentNonEnglishTest.

@Test
public void getRenderedFeatureFileContentNonEnglishTest() {
    String expectedOutput = "# language: de\n\n" + "@featureTag1\n" + "@featureTag2\n" + "Feature: featureName\n" + "featureDescription\n" + "\n" + "Background:\n" + "Background Step 1\n" + "Background Step 2\n" + "\n" + "@scenarioTag1\n" + "@scenarioTag2\n" + "Scenario: scenarioName\n" + "scenarioDescription\n" + "Step 1\n" + "Step 2\n" + "\n# Source feature: TESTPATH\n" + "# Generated by Cucable\n";
    String featureName = "Feature: featureName";
    String featureDescription = "featureDescription";
    String featureLanguage = "de";
    List<String> featureTags = Arrays.asList("@featureTag1", "@featureTag2");
    String scenarioName = "Scenario: scenarioName";
    String scenarioDescription = "scenarioDescription";
    List<Step> backgroundSteps = Arrays.asList(new Step("Background Step 1", null, null), new Step("Background Step 2", null, null));
    List<Step> steps = Arrays.asList(new Step("Step 1", null, null), new Step("Step 2", null, null));
    List<String> scenarioTags = Arrays.asList("@scenarioTag1", "@scenarioTag2");
    String featureFilePath = "TESTPATH";
    SingleScenario singleScenario = new SingleScenario(featureName, featureFilePath, featureLanguage, featureDescription, scenarioName, scenarioDescription, featureTags, backgroundSteps);
    singleScenario.setScenarioTags(scenarioTags);
    singleScenario.setSteps(steps);
    String renderedFeatureFileContent = featureFileContentRenderer.getRenderedFeatureFileContent(singleScenario);
    // In a windows system, replace line separator "\r\n" with "\n".
    renderedFeatureFileContent = renderedFeatureFileContent.replaceAll("\\r\\n", "\n");
    assertThat(renderedFeatureFileContent, is(expectedOutput));
}
Also used : SingleScenario(com.trivago.vo.SingleScenario) Step(com.trivago.vo.Step) Test(org.junit.Test)

Example 3 with Step

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

the class FeatureFileContentRendererTest method formatDataTableStringTest.

@Test
public void formatDataTableStringTest() {
    String expectedOutput = "Feature: featureName\n" + "featureDescription\n" + "\n" + "Scenario: scenarioName\n" + "scenarioDescription\n" + "Step 1\n" + "|cell11|cell12|cell13|\n" + "|cell21|cell22|cell23|\n" + "\n# Source feature: TESTPATH\n" + "# Generated by Cucable\n";
    String featureName = "Feature: featureName";
    String featureLanguage = "";
    String featureDescription = "featureDescription";
    String scenarioName = "Scenario: scenarioName";
    String scenarioDescription = "scenarioDescription";
    DataTable dataTable = new DataTable();
    dataTable.addRow(Arrays.asList("cell11", "cell12", "cell13"));
    dataTable.addRow(Arrays.asList("cell21", "cell22", "cell23"));
    List<Step> steps = Collections.singletonList(new Step("Step 1", dataTable, null));
    String featureFilePath = "TESTPATH";
    SingleScenario singleScenario = new SingleScenario(featureName, featureFilePath, featureLanguage, featureDescription, scenarioName, scenarioDescription, new ArrayList<>(), new ArrayList<>());
    singleScenario.setSteps(steps);
    String renderedFeatureFileContent = featureFileContentRenderer.getRenderedFeatureFileContent(singleScenario);
    // In a windows system, replace line separator "\r\n" with "\n".
    renderedFeatureFileContent = renderedFeatureFileContent.replaceAll("\\r\\n", "\n");
    assertThat(renderedFeatureFileContent, is(expectedOutput));
}
Also used : DataTable(com.trivago.vo.DataTable) SingleScenario(com.trivago.vo.SingleScenario) Step(com.trivago.vo.Step) Test(org.junit.Test)

Example 4 with Step

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

the class GherkinDocumentParser method substituteStepExamplePlaceholders.

/**
 * Replaces the example value placeholders in steps by the actual example table values.
 *
 * @param steps      The Cucable {@link Step} list.
 * @param exampleMap The generated example map from an example table.
 * @param rowIndex   The row index of the example table to consider.
 * @return A {@link Step} list with substituted names.
 */
private List<Step> substituteStepExamplePlaceholders(final List<Step> steps, final Map<String, List<String>> exampleMap, final int rowIndex) {
    List<Step> substitutedSteps = new ArrayList<>();
    for (Step step : steps) {
        String stepName = step.getName();
        // substitute values in the step
        DataTable dataTable = step.getDataTable();
        String substitutedStepName = replacePlaceholderInString(stepName, exampleMap, rowIndex);
        DataTable substitutedDataTable = replaceDataTableExamplePlaceholder(dataTable, exampleMap, rowIndex);
        substitutedSteps.add(new Step(substitutedStepName, substitutedDataTable, step.getDocString()));
    }
    return substitutedSteps;
}
Also used : DataTable(com.trivago.vo.DataTable) ArrayList(java.util.ArrayList) Step(com.trivago.vo.Step)

Example 5 with Step

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

the class FeatureFileContentRenderer method addSteps.

/**
 * Adds the rendered steps to the generated feature file content.
 *
 * @param stringBuilder The current feature {@link StringBuilder} instance.
 * @param steps         The {@link Step} list.
 */
private void addSteps(final StringBuilder stringBuilder, final List<Step> steps) {
    if (steps == null) {
        return;
    }
    for (Step step : steps) {
        stringBuilder.append(step.getName()).append(LINE_SEPARATOR);
        stringBuilder.append(formatDocString(step.getDocString()));
        stringBuilder.append(formatDataTableString(step.getDataTable()));
    }
}
Also used : Step(com.trivago.vo.Step)

Aggregations

Step (com.trivago.vo.Step)9 SingleScenario (com.trivago.vo.SingleScenario)7 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)3 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