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); } } }
public DataTable(List<TableRow> rows) { super(rows.get(0).getLocation()); this.rows = Collections.unmodifiableList(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 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 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 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 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 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())); } }
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())); } }
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<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<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<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 processScenarioOutlineExamples( final Map<Integer, AstNode> nodeMap, final ScenarioOutline scenarioOutline, final AstNode childNode ) { scenarioOutline.getExamples().forEach(examples -> { final AstNode examplesNode = new AstNode(examples, childNode); final TableRow headerRow = examples.getTableHeader(); final AstNode headerNode = new AstNode(headerRow, examplesNode); nodeMap.put(headerRow.getLocation().getLine(), headerNode); IntStream.range(0, examples.getTableBody().size()).forEach(i -> { final TableRow examplesRow = examples.getTableBody().get(i); final Node rowNode = new CucumberSourceUtils.ExamplesRowWrapperNode(examplesRow, i); final AstNode expandedScenarioNode = new AstNode(rowNode, examplesNode); nodeMap.put(examplesRow.getLocation().getLine(), expandedScenarioNode); }); }); }
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 processScenarioOutlineExamples( final Map<Integer, AstNode> nodeMap, final ScenarioOutline scenarioOutline, final AstNode childNode ) { scenarioOutline.getExamples().forEach(examples -> { final AstNode examplesNode = new AstNode(examples, childNode); final TableRow headerRow = examples.getTableHeader(); final AstNode headerNode = new AstNode(headerRow, examplesNode); nodeMap.put(headerRow.getLocation().getLine(), headerNode); IntStream.range(0, examples.getTableBody().size()).forEach(i -> { final TableRow examplesRow = examples.getTableBody().get(i); final Node rowNode = new CucumberSourceUtils.ExamplesRowWrapperNode(examplesRow, i); final AstNode expandedScenarioNode = new AstNode(rowNode, examplesNode); nodeMap.put(examplesRow.getLocation().getLine(), expandedScenarioNode); }); }); }
tr -> lines.add(tr.getLocation().getLine()) )); } else {
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); } }
private void examples(Feature currentFeature, List<Tag> scenarioOutlineTags, String id, List<Examples> examplesList) { String featureName = currentFeature.getName(); List<Tag> currentFeatureTags = currentFeature.getTags(); addingScenarioOutlineSteps = false; initializeExamples(); for (Examples examples : examplesList) { if (examplesAreNotExcludedByTags(examples, scenarioOutlineTags, currentFeatureTags) && examplesAreNotExcludedByLinesFilter(examples)) { List<TableRow> examplesTableRows = examples.getTableBody().stream().filter( tableRow -> tableRowIsNotExcludedByLinesFilter(tableRow)).collect(Collectors.toList()); List<String> headers = getHeadersFrom(examples.getTableHeader()); List<Map<String, String>> rows = getValuesFrom(examplesTableRows, headers); for (int i = 0; i < examplesTableRows.size(); i++) { addRow(exampleRows(), headers, examplesTableRows.get(i)); if (examples.getTags() != null) { exampleTags().put(examplesTableRows.get(i).getLocation().getLine(), examples.getTags()); } } String scenarioId = scenarioIdFrom(featureName, id); boolean newScenario = !scenarioId.equals(currentScenarioId); table = (newScenario) ? thucydidesTableFrom(SCENARIO_OUTLINE_NOT_KNOWN_YET, headers, rows, trim(examples.getName()), trim(examples.getDescription())) : addTableRowsTo(table, headers, rows, trim(examples.getName()), trim(examples.getDescription())); table.addTagsToLatestDataSet(examples.getTags().stream().map(tag -> TestTag.withValue(tag.getName().substring(1))).collect(Collectors.toList())); exampleCount = table.getSize(); currentScenarioId = scenarioId; } } }
private void examples(Feature currentFeature, List<Tag> scenarioOutlineTags, String id, List<Examples> examplesList) { String featureName = currentFeature.getName(); List<Tag> currentFeatureTags = currentFeature.getTags(); addingScenarioOutlineSteps = false; initializeExamples(); for (Examples examples : examplesList) { if (examplesAreNotExcludedByTags(examples, scenarioOutlineTags, currentFeatureTags) && examplesAreNotExcludedByLinesFilter(examples)) { List<TableRow> examplesTableRows = examples.getTableBody().stream().filter( tableRow -> tableRowIsNotExcludedByLinesFilter(tableRow)).collect(Collectors.toList()); List<String> headers = getHeadersFrom(examples.getTableHeader()); List<Map<String, String>> rows = getValuesFrom(examplesTableRows, headers); for (int i = 0; i < examplesTableRows.size(); i++) { addRow(exampleRows(), headers, examplesTableRows.get(i)); if (examples.getTags() != null) { exampleTags().put(examplesTableRows.get(i).getLocation().getLine(), examples.getTags()); } } String scenarioId = scenarioIdFrom(featureName, id); boolean newScenario = !scenarioId.equals(currentScenarioId); table = (newScenario) ? thucydidesTableFrom(SCENARIO_OUTLINE_NOT_KNOWN_YET, headers, rows, trim(examples.getName()), trim(examples.getDescription())) : addTableRowsTo(table, headers, rows, trim(examples.getName()), trim(examples.getDescription())); table.addTagsToLatestDataSet(examples.getTags().stream().map(tag -> TestTag.withValue(tag.getName().substring(1))).collect(Collectors.toList())); exampleCount = table.getSize(); currentScenarioId = scenarioId; } } }