Search in sources :

Example 1 with Examples

use of gherkin.ast.Examples 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 2 with Examples

use of gherkin.ast.Examples in project cucable-plugin by trivago.

the class GherkinDocumentParser method getSingleScenariosFromOutline.

/**
 * Returns a list of Cucable single scenarios from a Gherkin scenario outline.
 *
 * @param scenarioOutline     A Gherkin {@link ScenarioOutline}.
 * @param featureName         The name of the feature this scenario outline belongs to.
 * @param featureFilePath     The source path of the feature file.
 * @param featureLanguage     The feature language this scenario outline belongs to.
 * @param featureTags         The feature tags of the parent feature.
 * @param backgroundSteps     Return a Cucable {@link SingleScenario} list.
 * @param includeScenarioTags Optional scenario tags to include in scenario generation.
 * @throws CucablePluginException Thrown when the scenario outline does not contain an example table.
 */
private List<SingleScenario> getSingleScenariosFromOutline(final ScenarioOutline scenarioOutline, final String featureName, final String featureFilePath, final String featureLanguage, final String featureDescription, final List<String> featureTags, final List<Step> backgroundSteps, final List<String> includeScenarioTags, final List<String> excludeScenarioTags) throws CucablePluginException {
    // Retrieve the translation of "Scenario" in the target language and add it to the scenario
    String translatedScenarioKeyword = gherkinTranslations.getScenarioKeyword(featureLanguage);
    String scenarioName = translatedScenarioKeyword + ": " + scenarioOutline.getName();
    String scenarioDescription = scenarioOutline.getDescription();
    List<String> scenarioTags = gherkinToCucableConverter.convertGherkinTagsToCucableTags(scenarioOutline.getTags());
    if (!scenarioShouldBeIncluded(featureTags, scenarioTags, includeScenarioTags, excludeScenarioTags)) {
        return Collections.emptyList();
    }
    List<SingleScenario> outlineScenarios = new ArrayList<>();
    List<Step> steps = gherkinToCucableConverter.convertGherkinStepsToCucableSteps(scenarioOutline.getSteps());
    if (scenarioOutline.getExamples().isEmpty()) {
        throw new CucablePluginException("Scenario outline without examples table!");
    }
    Examples exampleTable = scenarioOutline.getExamples().get(0);
    Map<String, List<String>> exampleMap = gherkinToCucableConverter.convertGherkinExampleTableToCucableExampleMap(exampleTable);
    String firstColumnHeader = (String) exampleMap.keySet().toArray()[0];
    int rowCount = exampleMap.get(firstColumnHeader).size();
    // For each example row, create a new single scenario
    for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
        SingleScenario singleScenario = new SingleScenario(featureName, featureFilePath, featureLanguage, featureDescription, substituteScenarioNameExamplePlaceholders(scenarioName, exampleMap, rowIndex), scenarioDescription, featureTags, backgroundSteps);
        List<Step> substitutedSteps = substituteStepExamplePlaceholders(steps, exampleMap, rowIndex);
        singleScenario.setSteps(substitutedSteps);
        singleScenario.setScenarioTags(scenarioTags);
        outlineScenarios.add(singleScenario);
    }
    return outlineScenarios;
}
Also used : SingleScenario(com.trivago.rta.vo.SingleScenario) CucablePluginException(com.trivago.rta.exceptions.CucablePluginException) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Step(com.trivago.rta.vo.Step) Examples(gherkin.ast.Examples)

Example 3 with Examples

use of gherkin.ast.Examples in project cucable-plugin by trivago.

the class GherkinDocumentParser method getSingleScenariosFromOutline.

/**
 * Returns a list of Cucable single scenarios from a Gherkin scenario outline.
 *
 * @param scenarioOutline A Gherkin {@link ScenarioOutline}.
 * @param featureName     The name of the feature this scenario outline belongs to.
 * @param featureFilePath The source path of the feature file.
 * @param featureLanguage The feature language this scenario outline belongs to.
 * @param featureTags     The feature tags of the parent feature.
 * @param backgroundSteps Return a Cucable {@link SingleScenario} list.
 */
private List<SingleScenario> getSingleScenariosFromOutline(final ScenarioOutline scenarioOutline, final String featureName, final String featureFilePath, final String featureLanguage, final String featureDescription, final List<String> featureTags, final List<Step> backgroundSteps) {
    // Retrieve the translation of "Scenario" in the target language and add it to the scenario
    String translatedScenarioKeyword = gherkinTranslations.getScenarioKeyword(featureLanguage);
    String scenarioName = translatedScenarioKeyword + ": " + scenarioOutline.getName();
    String scenarioDescription = scenarioOutline.getDescription();
    List<String> scenarioTags = gherkinToCucableConverter.convertGherkinTagsToCucableTags(scenarioOutline.getTags());
    List<SingleScenario> outlineScenarios = new ArrayList<>();
    List<Step> steps = gherkinToCucableConverter.convertGherkinStepsToCucableSteps(scenarioOutline.getSteps());
    if (scenarioOutline.getExamples().isEmpty()) {
        cucableLogger.warn("Scenario outline '" + scenarioOutline.getName() + "' without example table!");
        return outlineScenarios;
    }
    for (Examples exampleTable : scenarioOutline.getExamples()) {
        Map<String, List<String>> exampleMap = gherkinToCucableConverter.convertGherkinExampleTableToCucableExampleMap(exampleTable);
        String firstColumnHeader = (String) exampleMap.keySet().toArray()[0];
        int rowCount = exampleMap.get(firstColumnHeader).size();
        // For each example row, create a new single scenario
        for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
            SingleScenario singleScenario = new SingleScenario(featureName, featureFilePath, featureLanguage, featureDescription, replacePlaceholderInString(scenarioName, exampleMap, rowIndex), scenarioDescription, featureTags, backgroundSteps);
            List<Step> substitutedSteps = substituteStepExamplePlaceholders(steps, exampleMap, rowIndex);
            singleScenario.setSteps(substitutedSteps);
            singleScenario.setScenarioTags(scenarioTags);
            singleScenario.setExampleTags(gherkinToCucableConverter.convertGherkinTagsToCucableTags(exampleTable.getTags()));
            outlineScenarios.add(singleScenario);
        }
    }
    return outlineScenarios;
}
Also used : SingleScenario(com.trivago.vo.SingleScenario) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Step(com.trivago.vo.Step) Examples(gherkin.ast.Examples)

Aggregations

Examples (gherkin.ast.Examples)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 CucablePluginException (com.trivago.rta.exceptions.CucablePluginException)1 SingleScenario (com.trivago.rta.vo.SingleScenario)1 Step (com.trivago.rta.vo.Step)1 SingleScenario (com.trivago.vo.SingleScenario)1 Step (com.trivago.vo.Step)1 Location (gherkin.ast.Location)1 TableCell (gherkin.ast.TableCell)1 TableRow (gherkin.ast.TableRow)1 Tag (gherkin.ast.Tag)1 Test (org.junit.Test)1