use of gherkin.ast.DataTable in project cucable-plugin by trivago.
the class GherkinToCucableConverter method convertGherkinDataTableToCucumberDataTable.
/**
* Converts a Gherkin data table to a Cucable data table.
*
* @param gherkinDataTable a {@link DataTable}.
* @return a {@link com.trivago.rta.vo.DataTable}.
*/
private com.trivago.rta.vo.DataTable convertGherkinDataTableToCucumberDataTable(final DataTable gherkinDataTable) {
com.trivago.rta.vo.DataTable dataTable = new com.trivago.rta.vo.DataTable();
for (TableRow row : gherkinDataTable.getRows()) {
List<TableCell> cells = row.getCells();
List<String> rowValues = new ArrayList<>();
for (TableCell cell : cells) {
rowValues.add(cell.getValue());
}
dataTable.addRow(rowValues);
}
return dataTable;
}
use of gherkin.ast.DataTable in project page-factory-2 by sbtqa.
the class StepReplacer method replaceWith.
List<Step> replaceWith(List<Step> replacementSteps) {
List<Map<String, String>> dataTable = FragmentDataTableUtils.getDataTable(step);
if (dataTable.isEmpty()) {
addSteps(replacementSteps);
return replacedSteps;
}
for (Map<String, String> dataTableRow : dataTable) {
for (Step replacementStep : replacementSteps) {
String text = FragmentDataTableUtils.applyToText(dataTableRow, replacementStep.getText());
DataTable argument = null;
if (replacementStep.getArgument() != null) {
argument = FragmentDataTableUtils.applyToArgument(dataTableRow, replacementStep);
}
addStep(step.getLocation(), replacementStep.getKeyword(), text, argument);
}
}
return replacedSteps;
}
use of gherkin.ast.DataTable in project page-factory-2 by sbtqa.
the class FragmentDataTableUtils method getDataTable.
static List<Map<String, String>> getDataTable(Step step) {
List<Map<String, String>> dataTableAsListOfMaps = new ArrayList<>();
Node argument = step.getArgument();
if (!(argument instanceof DataTable)) {
return dataTableAsListOfMaps;
}
DataTable dataTable = (DataTable) step.getArgument();
for (int i = FIRST_ROW_INDEX; i < dataTable.getRows().size(); i++) {
Map<String, String> dataTableRow = new HashMap<>();
List<TableRow> rows = dataTable.getRows();
for (int j = 0; j < rows.get(HEADER_INDEX).getCells().size(); j++) {
String key = rows.get(HEADER_INDEX).getCells().get(j).getValue();
List<TableCell> cells = dataTable.getRows().get(i).getCells();
String value = cells.get(j).getValue();
dataTableRow.put(key, value);
}
dataTableAsListOfMaps.add(dataTableRow);
}
return dataTableAsListOfMaps;
}
use of gherkin.ast.DataTable in project cucable-plugin by trivago.
the class GherkinToCucableConverter method convertGherkinStepsToCucableSteps.
/**
* Converts a list of Gherkin steps to Cucable steps including data tables.
*
* @param gherkinSteps a {@link Step} list.
* @return a {@link com.trivago.rta.vo.Step} list.
*/
List<com.trivago.rta.vo.Step> convertGherkinStepsToCucableSteps(final List<Step> gherkinSteps) {
List<com.trivago.rta.vo.Step> steps = new ArrayList<>();
for (Step gherkinStep : gherkinSteps) {
com.trivago.rta.vo.Step step;
com.trivago.rta.vo.DataTable dataTable = null;
String docString = null;
Node argument = gherkinStep.getArgument();
if (argument instanceof DataTable) {
dataTable = convertGherkinDataTableToCucumberDataTable((DataTable) argument);
} else if (argument instanceof DocString) {
docString = ((DocString) argument).getContent();
}
String keywordAndName = gherkinStep.getKeyword().concat(gherkinStep.getText());
step = new com.trivago.rta.vo.Step(keywordAndName, dataTable, docString);
steps.add(step);
}
return steps;
}
use of gherkin.ast.DataTable in project page-factory-2 by sbtqa.
the class FragmentDataTableUtils method applyToArgument.
static DataTable applyToArgument(Map<String, String> dataTableAsMap, Step fragmentStep) {
DataTable dataTable = (DataTable) fragmentStep.getArgument();
List<TableRow> resultTableRows = new ArrayList<>();
for (TableRow row : dataTable.getRows()) {
List<TableCell> resultCells = new ArrayList<>();
for (TableCell cell : row.getCells()) {
TableCell resultCell = new TableCell(cell.getLocation(), applyToText(dataTableAsMap, cell.getValue()));
resultCells.add(resultCell);
}
resultTableRows.add(new TableRow(row.getLocation(), resultCells));
}
return new DataTable(resultTableRows);
}