Search in sources :

Example 1 with TableRow

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;
}
Also used : DataTable(gherkin.ast.DataTable) TableCell(gherkin.ast.TableCell) TableRow(gherkin.ast.TableRow) ArrayList(java.util.ArrayList) DocString(gherkin.ast.DocString)

Example 2 with TableRow

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;
}
Also used : DocString(gherkin.ast.DocString) LinkedHashMap(java.util.LinkedHashMap) TableCell(gherkin.ast.TableCell) TableRow(gherkin.ast.TableRow) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with TableRow

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;
}
Also used : DataTable(gherkin.ast.DataTable) HashMap(java.util.HashMap) Node(gherkin.ast.Node) ArrayList(java.util.ArrayList) TableCell(gherkin.ast.TableCell) TableRow(gherkin.ast.TableRow) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with TableRow

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));
}
Also used : ArrayList(java.util.ArrayList) TableCell(gherkin.ast.TableCell) TableRow(gherkin.ast.TableRow) ArrayList(java.util.ArrayList) List(java.util.List) Tag(gherkin.ast.Tag) Examples(gherkin.ast.Examples) Location(gherkin.ast.Location) Test(org.junit.Test)

Example 5 with TableRow

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);
}
Also used : DataTable(gherkin.ast.DataTable) TableCell(gherkin.ast.TableCell) TableRow(gherkin.ast.TableRow) ArrayList(java.util.ArrayList)

Aggregations

TableCell (gherkin.ast.TableCell)5 TableRow (gherkin.ast.TableRow)5 ArrayList (java.util.ArrayList)5 DataTable (gherkin.ast.DataTable)3 DocString (gherkin.ast.DocString)2 List (java.util.List)2 Examples (gherkin.ast.Examples)1 Location (gherkin.ast.Location)1 Node (gherkin.ast.Node)1 Tag (gherkin.ast.Tag)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1