Search in sources :

Example 1 with DataTable

use of com.trivago.rta.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 columnName  The current placeholder to replace with a value.
 * @param columnValue The current value to replace.
 * @return The resulting {@link DataTable}.
 */
private DataTable replaceDataTableExamplePlaceholder(final DataTable dataTable, final String columnName, final String columnValue) {
    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(dataTableCell.replace(columnName, columnValue));
        }
        replacedDataTable.addRow(replacedDataTableRow);
    }
    return replacedDataTable;
}
Also used : DataTable(com.trivago.rta.vo.DataTable) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with DataTable

use of com.trivago.rta.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();
        for (String columnName : exampleMap.keySet()) {
            String columnValue = exampleMap.get(columnName).get(rowIndex);
            stepName = stepName.replace(columnName, columnValue);
            dataTable = replaceDataTableExamplePlaceholder(dataTable, columnName, columnValue);
        }
        substitutedSteps.add(new Step(stepName, dataTable, step.getDocString()));
    }
    return substitutedSteps;
}
Also used : DataTable(com.trivago.rta.vo.DataTable) ArrayList(java.util.ArrayList) Step(com.trivago.rta.vo.Step)

Example 3 with DataTable

use of com.trivago.rta.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" + "\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);
    assertThat(renderedFeatureFileContent, is(expectedOutput));
}
Also used : DataTable(com.trivago.rta.vo.DataTable) SingleScenario(com.trivago.rta.vo.SingleScenario) Step(com.trivago.rta.vo.Step) Test(org.junit.Test)

Aggregations

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