use of gherkin.ast.TableRow 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.TableRow in project cucable-plugin by trivago.
the class GherkinToCucableConverter method convertGherkinExampleTableToCucableExampleMap.
/**
* Converts a Gherkin example table to a map of columns (keys) and rows (values)
*
* @param exampleTable a Gherkin {@link Examples} instance.
* @return a map where the keys are the column headers and the values are lists of strings.
*/
Map<String, List<String>> convertGherkinExampleTableToCucableExampleMap(Examples exampleTable) {
Map<String, List<String>> exampleMap = new LinkedHashMap<>();
List<TableCell> headerCells = exampleTable.getTableHeader().getCells();
for (TableCell headerCell : headerCells) {
exampleMap.put("<" + headerCell.getValue() + ">", new ArrayList<>());
}
Object[] columnKeys = exampleMap.keySet().toArray();
List<TableRow> tableBody = exampleTable.getTableBody();
for (TableRow tableRow : tableBody) {
List<TableCell> cells = tableRow.getCells();
for (int i = 0; i < cells.size(); i++) {
String columnKey = (String) columnKeys[i];
List<String> values = exampleMap.get(columnKey);
values.add(cells.get(i).getValue());
}
}
return exampleMap;
}
use of gherkin.ast.TableRow 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.TableRow in project cucable-plugin by trivago.
the class GherkinToCucableConverterTest method convertGherkinExampleTableToCucableExampleMapTest.
@Test
public void convertGherkinExampleTableToCucableExampleMapTest() {
Location location = new Location(1, 2);
List<Tag> tags = new ArrayList<>();
Tag tag = new Tag(location, "@tag");
tags.add(tag);
String keyword = "keyword";
String name = "name";
String description = "description";
List<TableCell> headerCells = new ArrayList<>();
headerCells.add(new TableCell(location, "headerCell1"));
headerCells.add(new TableCell(location, "headerCell2"));
headerCells.add(new TableCell(location, "headerCell3"));
TableRow tableHeader = new TableRow(location, headerCells);
List<TableRow> tableBody = new ArrayList<>();
List<TableCell> bodyCells = new ArrayList<>();
bodyCells.add(new TableCell(location, "bodyCell1"));
bodyCells.add(new TableCell(location, "bodyCell2"));
bodyCells.add(new TableCell(location, "bodyCell3"));
tableBody.add(new TableRow(location, bodyCells));
bodyCells = new ArrayList<>();
bodyCells.add(new TableCell(location, "bodyCell4"));
bodyCells.add(new TableCell(location, "bodyCell5"));
bodyCells.add(new TableCell(location, "bodyCell6"));
tableBody.add(new TableRow(location, bodyCells));
Examples examples = new Examples(location, tags, keyword, name, description, tableHeader, tableBody);
List<String> includeTags = new ArrayList<>();
List<String> excludeTags = new ArrayList<>();
Map<String, List<String>> table = gherkinToCucableConverter.convertGherkinExampleTableToCucableExampleMap(examples);
assertThat(table.size(), is(3));
}
use of gherkin.ast.TableRow 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);
}
Aggregations