use of com.trivago.vo.Step in project cucable-plugin by trivago.
the class GherkinDocumentParser method getSingleScenariosFromFeature.
/**
* Returns a {@link SingleScenario} list from a given feature file.
*
* @param featureContent A feature string.
* @param featureFilePath The path to the source feature file.
* @return A {@link SingleScenario} list.
* @throws CucablePluginException see {@link CucablePluginException}.
*/
public List<SingleScenario> getSingleScenariosFromFeature(final String featureContent, final String featureFilePath, final List<Integer> scenarioLineNumbers) throws CucablePluginException {
String escapedFeatureContent = featureContent.replace("\\n", "\\\\n");
GherkinDocument gherkinDocument;
try {
gherkinDocument = getGherkinDocumentFromFeatureFileContent(escapedFeatureContent);
} catch (CucablePluginException e) {
throw new FeatureFileParseException(featureFilePath, e.getMessage());
}
Feature feature = gherkinDocument.getFeature();
if (feature == null) {
return Collections.emptyList();
}
String featureName = feature.getKeyword() + ": " + feature.getName();
String featureLanguage = feature.getLanguage();
String featureDescription = feature.getDescription();
List<String> featureTags = gherkinToCucableConverter.convertGherkinTagsToCucableTags(feature.getTags());
ArrayList<SingleScenario> singleScenarioFeatures = new ArrayList<>();
List<Step> backgroundSteps = new ArrayList<>();
List<ScenarioDefinition> scenarioDefinitions = feature.getChildren();
for (ScenarioDefinition scenarioDefinition : scenarioDefinitions) {
String scenarioName = scenarioDefinition.getKeyword() + ": " + scenarioDefinition.getName();
String scenarioDescription = scenarioDefinition.getDescription();
if (scenarioDefinition instanceof Background) {
// Save background steps in order to add them to every scenario inside the same feature
Background background = (Background) scenarioDefinition;
backgroundSteps = gherkinToCucableConverter.convertGherkinStepsToCucableSteps(background.getSteps());
continue;
}
if (scenarioDefinition instanceof Scenario) {
Scenario scenario = (Scenario) scenarioDefinition;
if (scenarioLineNumbers == null || scenarioLineNumbers.isEmpty() || scenarioLineNumbers.contains(scenario.getLocation().getLine())) {
SingleScenario singleScenario = new SingleScenario(featureName, featureFilePath, featureLanguage, featureDescription, scenarioName, scenarioDescription, featureTags, backgroundSteps);
addGherkinScenarioInformationToSingleScenario(scenario, singleScenario);
if (scenarioShouldBeIncluded(singleScenario)) {
singleScenarioFeatures.add(singleScenario);
}
}
continue;
}
if (scenarioDefinition instanceof ScenarioOutline) {
ScenarioOutline scenarioOutline = (ScenarioOutline) scenarioDefinition;
if (scenarioLineNumbers == null || scenarioLineNumbers.isEmpty() || scenarioLineNumbers.contains(scenarioOutline.getLocation().getLine())) {
List<SingleScenario> outlineScenarios = getSingleScenariosFromOutline(scenarioOutline, featureName, featureFilePath, featureLanguage, featureDescription, featureTags, backgroundSteps);
for (SingleScenario singleScenario : outlineScenarios) {
if (scenarioShouldBeIncluded(singleScenario)) {
singleScenarioFeatures.add(singleScenario);
}
}
}
}
}
return singleScenarioFeatures;
}
use of com.trivago.vo.Step 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;
}
use of com.trivago.vo.Step in project cucable-plugin by trivago.
the class FeatureFileContentRendererTest method formatDocStringTest.
@Test
public void formatDocStringTest() {
String expectedOutput = "Feature: featureName\n" + "\n" + "Scenario: scenarioName\n" + "Step 1\n" + "\"\"\"\n" + "DOCSTRING LINE 1\n" + "DOCSTRING LINE 2\n" + "\"\"\"\n" + "\n# Source feature: TESTPATH\n" + "# Generated by Cucable\n";
String featureName = "Feature: featureName";
String scenarioName = "Scenario: scenarioName";
List<Step> steps = Collections.singletonList(new Step("Step 1", null, "DOCSTRING LINE 1\nDOCSTRING LINE 2"));
String featureFilePath = "TESTPATH";
SingleScenario singleScenario = new SingleScenario(featureName, featureFilePath, null, null, scenarioName, null, new ArrayList<>(), new ArrayList<>());
singleScenario.setSteps(steps);
String renderedFeatureFileContent = featureFileContentRenderer.getRenderedFeatureFileContent(singleScenario);
// In a windows system, replace line separator "\r\n" with "\n".
renderedFeatureFileContent = renderedFeatureFileContent.replaceAll("\\r\\n", "\n");
assertThat(renderedFeatureFileContent, is(expectedOutput));
}
use of com.trivago.vo.Step in project cucable-plugin by trivago.
the class FeatureFileContentRendererTest method getRenderedFeatureFileContentReplaceBackslashesInCommentsTest.
@Test
public void getRenderedFeatureFileContentReplaceBackslashesInCommentsTest() {
String expectedOutput = "# language: de\n\n" + "@featureTag1\n" + "@featureTag2\n" + "Feature: featureName\n" + "featureDescription\n" + "\n" + "@scenarioTag1\n" + "@scenarioTag2\n" + "Scenario: scenarioName\n" + "scenarioDescription\n" + "Step 1\n" + "Step 2\n" + "\n# Source feature: c:/unknown/path\n" + "# Generated by Cucable\n";
String featureName = "Feature: featureName";
String featureDescription = "featureDescription";
String featureLanguage = "de";
List<String> featureTags = Arrays.asList("@featureTag1", "@featureTag2");
String scenarioName = "Scenario: scenarioName";
String scenarioDescription = "scenarioDescription";
List<Step> steps = Arrays.asList(new Step("Step 1", null, null), new Step("Step 2", null, null));
List<String> scenarioTags = Arrays.asList("@scenarioTag1", "@scenarioTag2");
String featureFilePath = "c:\\unknown\\path";
SingleScenario singleScenario = new SingleScenario(featureName, featureFilePath, featureLanguage, featureDescription, scenarioName, scenarioDescription, featureTags, null);
singleScenario.setScenarioTags(scenarioTags);
singleScenario.setSteps(steps);
String renderedFeatureFileContent = featureFileContentRenderer.getRenderedFeatureFileContent(singleScenario);
// In a windows system, replace line separator "\r\n" with "\n".
renderedFeatureFileContent = renderedFeatureFileContent.replaceAll("\\r\\n", "\n");
assertThat(renderedFeatureFileContent, is(expectedOutput));
}
Aggregations