use of com.trivago.rta.vo.SingleScenario in project cucable-plugin by trivago.
the class RunnerFileContentRendererTest method getRenderedFeatureFileContentTest.
@Test
public void getRenderedFeatureFileContentTest() throws Exception {
String template = "package parallel;\n" + "\n" + "import cucumber.api.CucumberOptions;\n" + "\n" + "@CucumberOptions(\n" + " monochrome = false,\n" + " features = {\"classpath:parallel/features/[FEATURE_FILE_NAME].feature\"},\n" + " plugin = {\"json:target/cucumber-report/[FEATURE_FILE_NAME].json\"}\n" + ")\n" + "public class [FEATURE_FILE_NAME] {\n" + "}\n";
when(fileIO.readContentFromFile(anyString())).thenReturn(template);
String expectedOutput = "package parallel;\n" + "\n" + "import cucumber.api.CucumberOptions;\n" + "\n" + "@CucumberOptions(\n" + " monochrome = false,\n" + " features = {\"classpath:parallel/features/featureFileName.feature\"},\n" + " plugin = {\"json:target/cucumber-report/featureFileName.json\"}\n" + ")\n" + "public class featureFileName {\n" + "}\n" + "\n" + "\n" + "// Source Feature: \n" + "// Generated by Cucable\n";
SingleScenarioRunner singleScenarioRunner = new SingleScenarioRunner("pathToTemplate", "featureFileName");
SingleScenario singleScenario = new SingleScenario("", "", "", "", "", "", null, null);
String renderedRunnerFileContent = runnerFileContentRenderer.getRenderedRunnerFileContent(singleScenarioRunner, singleScenario);
assertThat(renderedRunnerFileContent, is(expectedOutput));
}
use of com.trivago.rta.vo.SingleScenario in project cucable-plugin by trivago.
the class FeatureFileContentRendererTest method formatDocStringTest.
@Test
public void formatDocStringTest() {
String expectedOutput = "Feature: featureName\n" + "\n" + "Scenario: scenarioName\n" + "\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);
assertThat(renderedFeatureFileContent, is(expectedOutput));
}
use of com.trivago.rta.vo.SingleScenario in project cucable-plugin by trivago.
the class GherkinDocumentParserTest method validFeatureWithScenarioOutlineTest.
@Test
public void validFeatureWithScenarioOutlineTest() throws Exception {
String featureContent = "Feature: test feature 3\n" + "\n" + " Scenario Outline: This is a scenario outline\n" + " When I search for key <key>\n" + " Then I see the value '<value>'\n" + "\n" + " Examples:\n" + " | key | value |\n" + " | 1 | one |\n" + " | 2 | two |";
List<SingleScenario> singleScenariosFromFeature = gherkinDocumentParser.getSingleScenariosFromFeature(featureContent, "", null, null, null);
assertThat(singleScenariosFromFeature.size(), is(2));
SingleScenario scenario = singleScenariosFromFeature.get(0);
assertThat(scenario.getScenarioName(), is("Scenario: This is a scenario outline"));
assertThat(scenario.getSteps().size(), is(2));
assertThat(scenario.getBackgroundSteps().size(), is(0));
assertThat(scenario.getSteps().get(0).getDataTable(), is(nullValue()));
assertThat(scenario.getSteps().get(0).getName(), is("When I search for key 1"));
assertThat(scenario.getSteps().get(1).getName(), is("Then I see the value 'one'"));
scenario = singleScenariosFromFeature.get(1);
assertThat(scenario.getScenarioName(), is("Scenario: This is a scenario outline"));
assertThat(scenario.getSteps().size(), is(2));
assertThat(scenario.getBackgroundSteps().size(), is(0));
assertThat(scenario.getSteps().get(0).getDataTable(), is(nullValue()));
assertThat(scenario.getSteps().get(0).getName(), is("When I search for key 2"));
assertThat(scenario.getSteps().get(1).getName(), is("Then I see the value 'two'"));
}
use of com.trivago.rta.vo.SingleScenario in project cucable-plugin by trivago.
the class FeatureFileConverter method convertToSingleScenariosAndRunners.
/**
* Converts all scenarios in the given feature file to single
* scenario feature files and their respective runners.
*
* @param featureFilePath feature file to process.
* @return Number of created scenarios.
* @throws CucablePluginException see {@link CucablePluginException}
*/
private int convertToSingleScenariosAndRunners(final Path featureFilePath) throws CucablePluginException {
String featureFilePathString = featureFilePath.toString();
if (featureFilePathString == null || featureFilePathString.equals("")) {
throw new MissingFileException(featureFilePathString);
}
List<Integer> lineNumbers = propertyManager.getScenarioLineNumbers();
List<String> includeScenarioTags = propertyManager.getIncludeScenarioTags();
List<String> excludeScenarioTags = propertyManager.getExcludeScenarioTags();
String featureFileContent = fileIO.readContentFromFile(featureFilePathString);
List<SingleScenario> singleScenarios;
try {
singleScenarios = gherkinDocumentParser.getSingleScenariosFromFeature(featureFileContent, featureFilePathString, lineNumbers, includeScenarioTags, excludeScenarioTags);
} catch (CucablePluginException e) {
throw new FeatureFileParseException(featureFilePathString);
}
// that means that the provided line number is wrong.
if (propertyManager.hasValidScenarioLineNumbers() && singleScenarios.size() == 0) {
throw new CucablePluginException("There is no parseable scenario or scenario outline at line " + lineNumbers);
}
for (SingleScenario singleScenario : singleScenarios) {
String renderedFeatureFileContent = featureFileContentRenderer.getRenderedFeatureFileContent(singleScenario);
String featureFileName = getFeatureFileNameFromPath(featureFilePath);
Integer featureCounter = singleFeatureCounters.getOrDefault(featureFileName, 0);
featureCounter++;
String scenarioCounterFilenamePart = String.format(SCENARIO_COUNTER_FORMAT, featureCounter);
for (int testRuns = 1; testRuns <= propertyManager.getNumberOfTestRuns(); testRuns++) {
String testRunsCounterFilenamePart = String.format(TEST_RUNS_COUNTER_FORMAT, testRuns);
// Append the scenario and test run counters to the filename.
// Also add the "_IT" postfix so Maven Failsafe considers it an integration test automatically.
String generatedFileName = featureFileName.concat(scenarioCounterFilenamePart).concat(testRunsCounterFilenamePart).concat(INTEGRATION_TEST_POSTFIX);
String generatedFeatureFilePath = propertyManager.getGeneratedFeatureDirectory().concat(PATH_SEPARATOR).concat(generatedFileName).concat(FEATURE_FILE_EXTENSION);
singleFeatureCounters.put(featureFileName, featureCounter);
// Save scenario information to new feature file
fileIO.writeContentToFile(renderedFeatureFileContent, generatedFeatureFilePath);
// Generate runner for the newly generated single scenario feature file
SingleScenarioRunner singleScenarioRunner = new SingleScenarioRunner(propertyManager.getSourceRunnerTemplateFile(), generatedFileName);
String renderedRunnerFileContent = runnerFileContentRenderer.getRenderedRunnerFileContent(singleScenarioRunner, singleScenario);
String generatedRunnerFilePath = propertyManager.getGeneratedRunnerDirectory().concat(PATH_SEPARATOR).concat(generatedFileName).concat(RUNNER_FILE_EXTENSION);
fileIO.writeContentToFile(renderedRunnerFileContent, generatedRunnerFilePath);
}
}
int createdScenarios = singleScenarios.size();
logProcessCompleteMessage(featureFilePathString, createdScenarios);
return createdScenarios;
}
use of com.trivago.rta.vo.SingleScenario 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;
}
Aggregations