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;
}
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;
}
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));
}