private List<String> createCellList(TableRow row) { List<String> cells = new ArrayList<String>(); for (TableCell cell : row.getCells()) { cells.add(cell.getValue()); } return cells; }
private void processScenarioOutlineExamples(Map<Integer, AstNode> nodeMap, ScenarioOutline scenarioOutline, AstNode childNode) { for (Examples examples : scenarioOutline.getExamples()) { AstNode examplesNode = new AstNode(examples, childNode); TableRow headerRow = examples.getTableHeader(); AstNode headerNode = new AstNode(headerRow, examplesNode); nodeMap.put(headerRow.getLocation().getLine(), headerNode); for (int i = 0; i < examples.getTableBody().size(); ++i) { TableRow examplesRow = examples.getTableBody().get(i); Node rowNode = new ExamplesRowWrapperNode(examplesRow, i); AstNode expandedScenarioNode = new AstNode(rowNode, examplesNode); nodeMap.put(examplesRow.getLocation().getLine(), expandedScenarioNode); } } }
private void ensureCellCount(List<TableRow> rows) { if (rows.isEmpty()) return; int cellCount = rows.get(0).getCells().size(); for (TableRow row : rows) { if (row.getCells().size() != cellCount) { throw new ParserException.AstBuilderException("inconsistent cell count within the table", row.getLocation()); } } }
private List<TableRow> replaceTableRows(List<TableRow> tableRows) throws DataException { List<TableRow> resultTableRows = new ArrayList<>(); for (TableRow row : tableRows) { List<TableCell> resultCells = new ArrayList<>(); for (TableCell cell : row.getCells()) { TableCell resultCell = new TableCell(cell.getLocation(), replaceDataPlaceholders(cell.getValue())); resultCells.add(resultCell); } resultTableRows.add(new TableRow(row.getLocation(), resultCells)); } return resultTableRows; } }
private List<TableRow> getTableRows(AstNode node) { List<TableRow> rows = new ArrayList<>(); for (Token token : node.getTokens(TokenType.TableRow)) { rows.add(new TableRow(getLocation(token, 0), getCells(token))); } ensureCellCount(rows); return rows; }
private void addRow(Map<Integer, Map<String, String>> exampleRows, List<String> headers, TableRow currentTableRow) { Map<String, String> row = new LinkedHashMap<>(); for (int j = 0; j < headers.size(); j++) { List<String> cells = currentTableRow.getCells().stream().map(TableCell::getValue).collect(Collectors.toList()); row.put(headers.get(j), cells.get(j)); } exampleRows().put(currentTableRow.getLocation().getLine(), row); }
private List<TableRow> replaceTableRows(List<TableRow> tableRows) throws DataException { List<TableRow> resultTableRows = new ArrayList<>(); for (TableRow row : tableRows) { List<TableCell> resultCells = new ArrayList<>(); for (TableCell cell : row.getCells()) { TableCell resultCell = new TableCell(cell.getLocation(), replaceDataPlaceholders(cell.getValue())); resultCells.add(resultCell); } resultTableRows.add(new TableRow(row.getLocation(), resultCells)); } return resultTableRows; } }
private void addRow(Map<Integer, Map<String, String>> exampleRows, List<String> headers, TableRow currentTableRow) { Map<String, String> row = new LinkedHashMap<>(); for (int j = 0; j < headers.size(); j++) { List<String> cells = currentTableRow.getCells().stream().map(TableCell::getValue).collect(Collectors.toList()); row.put(headers.get(j), cells.get(j)); } exampleRows().put(currentTableRow.getLocation().getLine(), row); }
private List<String> getHeadersFrom(TableRow headerRow) { return headerRow.getCells().stream().map(TableCell::getValue).collect(Collectors.toList()); }
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); } }
public DataTable(List<TableRow> rows) { super(rows.get(0).getLocation()); this.rows = Collections.unmodifiableList(rows); }
private Map<String, String> parametersMap(TableRow header, TableRow row) { List<TableCell> headerCells = header.getCells(); List<TableCell> rowCells = row.getCells(); if (headerCells.size() == rowCells.size()) { Map<String, String> parameters = new LinkedHashMap<>(); for (int i = 0; i < headerCells.size(); i++) { TableCell headerCell = headerCells.get(i); TableCell rowCell = rowCells.get(i); parameters.put(headerCell.getValue(), rowCell.getValue()); } return parameters; } else { throw new InvalidExampleException(header.getLocation().getLine(), header.getLocation().getColumn()); } }
private List<String> getHeadersFrom(TableRow headerRow) { return headerRow.getCells().stream().map(TableCell::getValue).collect(Collectors.toList()); }
private boolean tableRowIsNotExcludedByLinesFilter(TableRow tableRow) { if (lineFilters.isEmpty()) { return true; } if (!lineFilters.containsKey(currentFeaturePath())) { return false; } else { return lineFilters.get(currentFeaturePath()).contains((long) tableRow.getLocation().getLine()); } }
private List<Parameter> getExamplesAsParameters(final ScenarioOutline scenarioOutline) { final Examples examples = scenarioOutline.getExamples().get(0); final TableRow row = examples.getTableBody().stream() .filter(example -> example.getLocation().getLine() == currentTestCase.getLine()) .findFirst().get(); return IntStream.range(0, examples.getTableHeader().getCells().size()).mapToObj(index -> { final String name = examples.getTableHeader().getCells().get(index).getValue(); final String value = row.getCells().get(index).getValue(); return new Parameter().setName(name).setValue(value); }).collect(Collectors.toList()); }
private List<Map<String, String>> getValuesFrom(List<TableRow> examplesTableRows, List<String> headers) { List<Map<String, String>> rows = new ArrayList<>(); for (int row = 0; row < examplesTableRows.size(); row++) { Map<String, String> rowValues = new HashMap<>(); int column = 0; List<String> cells = examplesTableRows.get(row).getCells().stream().map(TableCell::getValue).collect(Collectors.toList()); for (String cellValue : cells) { String columnName = headers.get(column++); rowValues.put(columnName, cellValue); } rows.add(rowValues); } return rows; }
private boolean tableRowIsNotExcludedByLinesFilter(TableRow tableRow) { if (lineFilters.isEmpty()) { return true; } if (!lineFilters.containsKey(currentFeaturePath())) { return false; } else { return lineFilters.get(currentFeaturePath()).contains((long) tableRow.getLocation().getLine()); } }
private List<Parameter> getExamplesAsParameters(final ScenarioOutline scenarioOutline) { final Optional<Examples> examplesBlock = scenarioOutline.getExamples().stream() .filter(example -> example.getTableBody().stream() .anyMatch(row -> row.getLocation().getLine() == currentTestCase.getLine()) ).findFirst(); if (examplesBlock.isPresent()) { final TableRow row = examplesBlock.get().getTableBody().stream() .filter(example -> example.getLocation().getLine() == currentTestCase.getLine()) .findFirst().get(); return IntStream.range(0, examplesBlock.get().getTableHeader().getCells().size()).mapToObj(index -> { final String name = examplesBlock.get().getTableHeader().getCells().get(index).getValue(); final String value = row.getCells().get(index).getValue(); return new Parameter().setName(name).setValue(value); }).collect(Collectors.toList()); } else { return Collections.emptyList(); } }
private List<Map<String, String>> getValuesFrom(List<TableRow> examplesTableRows, List<String> headers) { List<Map<String, String>> rows = new ArrayList<>(); for (int row = 0; row < examplesTableRows.size(); row++) { Map<String, String> rowValues = new HashMap<>(); int column = 0; List<String> cells = examplesTableRows.get(row).getCells().stream().map(TableCell::getValue).collect(Collectors.toList()); for (String cellValue : cells) { String columnName = headers.get(column++); rowValues.put(columnName, cellValue); } rows.add(rowValues); } return rows; }
private boolean examplesAreNotExcludedByLinesFilter(Examples examples) { if (lineFilters.isEmpty()) { return true; } if (!lineFilters.containsKey(currentFeaturePath())) { return false; } else { return examples.getTableBody().stream().anyMatch( row -> lineFilters.get(currentFeaturePath()).contains((long) row.getLocation().getLine())); } }