Search in sources :

Example 1 with DataTable

use of com.trivago.vo.DataTable 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 2 with DataTable

use of com.trivago.vo.DataTable 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 3 with DataTable

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

the class GherkinDocumentParser method replaceDataTableExamplePlaceholder.

/**
 * Replaces the example value placeholders in step data tables by the actual example table values.
 *
 * @param dataTable  The source {@link DataTable}.
 * @param exampleMap The generated example map from an example table.
 * @param rowIndex   The row index of the example table to consider.
 * @return The resulting {@link DataTable}.
 */
private DataTable replaceDataTableExamplePlaceholder(final DataTable dataTable, final Map<String, List<String>> exampleMap, final int rowIndex) {
    if (dataTable == null) {
        return null;
    }
    List<List<String>> dataTableRows = dataTable.getRows();
    DataTable replacedDataTable = new DataTable();
    for (List<String> dataTableRow : dataTableRows) {
        List<String> replacedDataTableRow = new ArrayList<>();
        for (String dataTableCell : dataTableRow) {
            replacedDataTableRow.add(replacePlaceholderInString(dataTableCell, exampleMap, rowIndex));
        }
        replacedDataTable.addRow(replacedDataTableRow);
    }
    return replacedDataTable;
}
Also used : DataTable(com.trivago.vo.DataTable) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with DataTable

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

the class GherkinDocumentParserTest method replaceDataTableExamplePlaceholderTest.

@Test
public void replaceDataTableExamplePlaceholderTest() throws Exception {
    String featureContent = "Feature: test feature 3\n" + "\n" + "  Scenario Outline: This is a scenario outline\n" + "    When I search for key <key>\n" + "    | test | <key> | <value> |" + "\n" + "    Examples:\n" + "      | key | value |\n" + "      | 1   | one   |\n";
    List<SingleScenario> singleScenariosFromFeature = gherkinDocumentParser.getSingleScenariosFromFeature(featureContent, "", null);
    assertThat(singleScenariosFromFeature.size(), is(1));
    assertThat(singleScenariosFromFeature.get(0).getSteps().size(), is(1));
    DataTable dataTable = singleScenariosFromFeature.get(0).getSteps().get(0).getDataTable();
    assertThat(dataTable.getRows().size(), is(1));
    List<String> firstRow = dataTable.getRows().get(0);
    assertThat(firstRow.get(0), is("test"));
    assertThat(firstRow.get(1), is("1"));
    assertThat(firstRow.get(2), is("one"));
}
Also used : DataTable(com.trivago.vo.DataTable) SingleScenario(com.trivago.vo.SingleScenario) Test(org.junit.Test)

Aggregations

DataTable (com.trivago.vo.DataTable)4 SingleScenario (com.trivago.vo.SingleScenario)2 Step (com.trivago.vo.Step)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 List (java.util.List)1