Search in sources :

Example 1 with DataTable

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

Example 3 with DataTable

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

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

Example 5 with DataTable

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

Aggregations

DataTable (gherkin.ast.DataTable)7 ArrayList (java.util.ArrayList)5 DocString (gherkin.ast.DocString)4 Node (gherkin.ast.Node)3 Step (gherkin.ast.Step)3 TableCell (gherkin.ast.TableCell)3 TableRow (gherkin.ast.TableRow)3 Map (java.util.Map)2 HashMap (java.util.HashMap)1