use of com.trivago.rta.vo.SingleScenario in project cucable-plugin by trivago.
the class GherkinDocumentParser method getSingleScenariosFromFeature.
/**
* Returns a {@link com.trivago.rta.vo.SingleScenario} list from a given feature file.
*
* @param featureContent A feature string.
* @param featureFilePath The path to the source feature file.
* @param scenarioLineNumbers An optional line number of a scenario inside a feature file.
* @param includeScenarioTags Optional scenario tags to include into scenario generation.
* @param excludeScenarioTags Optional scenario tags to exclude from scenario generation.
* @return A {@link com.trivago.rta.vo.SingleScenario} list.
* @throws CucablePluginException see {@link CucablePluginException}.
*/
public List<SingleScenario> getSingleScenariosFromFeature(final String featureContent, final String featureFilePath, final List<Integer> scenarioLineNumbers, final List<String> includeScenarioTags, final List<String> excludeScenarioTags) throws CucablePluginException {
GherkinDocument gherkinDocument = getGherkinDocumentFromFeatureFileContent(featureContent);
Feature feature = gherkinDocument.getFeature();
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.getScenarioTags(), singleScenario.getFeatureTags(), includeScenarioTags, excludeScenarioTags)) {
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, includeScenarioTags, excludeScenarioTags);
singleScenarioFeatures.addAll(outlineScenarios);
}
}
}
return singleScenarioFeatures;
}
use of com.trivago.rta.vo.SingleScenario in project cucable-plugin by trivago.
the class FeatureFileContentRendererTest method formatDataTableStringTest.
@Test
public void formatDataTableStringTest() {
String expectedOutput = "Feature: featureName\n" + "featureDescription\n" + "\n" + "Scenario: scenarioName\n" + "scenarioDescription\n" + "\n" + "Step 1\n" + "|cell11|cell12|cell13|\n" + "|cell21|cell22|cell23|\n" + "\n# Source feature: TESTPATH\n" + "# Generated by Cucable\n";
String featureName = "Feature: featureName";
String featureLanguage = "";
String featureDescription = "featureDescription";
String scenarioName = "Scenario: scenarioName";
String scenarioDescription = "scenarioDescription";
DataTable dataTable = new DataTable();
dataTable.addRow(Arrays.asList("cell11", "cell12", "cell13"));
dataTable.addRow(Arrays.asList("cell21", "cell22", "cell23"));
List<Step> steps = Collections.singletonList(new Step("Step 1", dataTable, null));
String featureFilePath = "TESTPATH";
SingleScenario singleScenario = new SingleScenario(featureName, featureFilePath, featureLanguage, featureDescription, scenarioName, scenarioDescription, 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 FeatureFileContentRendererTest method getRenderedFeatureFileContentTest.
@Test
public void getRenderedFeatureFileContentTest() {
String expectedOutput = "@featureTag1\n" + "@featureTag2\n" + "Feature: featureName\n" + "featureDescription\n" + "\n" + "@scenarioTag1\n" + "@scenarioTag2\n" + "Scenario: scenarioName\n" + "scenarioDescription\n" + "\n" + "Step 1\n" + "Step 2\n" + "\n# Source feature: TESTPATH\n" + "# Generated by Cucable\n";
String featureName = "Feature: featureName";
String featureDescription = "featureDescription";
String featureLanguage = "";
List<String> featureTags = Arrays.asList("@featureTag1", "@featureTag2");
String scenarioName = "Scenario: scenarioName";
String scenarioDescription = "scenarioDescription";
List<Step> backgroundSteps = Arrays.asList(new Step("Step 1", null, null), new Step("Step 2", null, null));
List<String> scenarioTags = Arrays.asList("@scenarioTag1", "@scenarioTag2");
String featureFilePath = "TESTPATH";
SingleScenario singleScenario = new SingleScenario(featureName, featureFilePath, featureLanguage, featureDescription, scenarioName, scenarioDescription, featureTags, backgroundSteps);
singleScenario.setScenarioTags(scenarioTags);
String renderedFeatureFileContent = featureFileContentRenderer.getRenderedFeatureFileContent(singleScenario);
assertThat(renderedFeatureFileContent, is(expectedOutput));
}
use of com.trivago.rta.vo.SingleScenario in project cucable-plugin by trivago.
the class FeatureFileConverterTest method testConvertToSingleScenariosAndRunners.
@Test
public void testConvertToSingleScenariosAndRunners() throws Exception {
String generatedFeatureDir = testFolder.getRoot().getPath().concat("/features/");
String generatedRunnerDir = testFolder.getRoot().getPath().concat("/runners/");
propertyManager.setNumberOfTestRuns(1);
propertyManager.setGeneratedFeatureDirectory(generatedFeatureDir);
propertyManager.setGeneratedRunnerDirectory(generatedRunnerDir);
when(fileIO.readContentFromFile("TEST_PATH")).thenReturn("TEST_CONTENT");
List<SingleScenario> scenarioList = new ArrayList<>();
SingleScenario singleScenario = new SingleScenario("feature", "", "", "featureDescription", "name", "scenarioDescription", new ArrayList<>(), new ArrayList<>());
scenarioList.add(singleScenario);
when(gherkinDocumentParser.getSingleScenariosFromFeature("TEST_CONTENT", "TEST_PATH", null, null, null)).thenReturn(scenarioList);
String featureFileContent = "test";
when(featureFileContentRenderer.getRenderedFeatureFileContent(singleScenario)).thenReturn(featureFileContent);
when(runnerFileContentRenderer.getRenderedRunnerFileContent(any(SingleScenarioRunner.class), any(SingleScenario.class))).thenReturn("RUNNER_CONTENT");
List<Path> pathList = new ArrayList<>();
Path mockPath = mock(Path.class);
Path mockFilePath = mock(Path.class);
when(mockFilePath.toString()).thenReturn("FEATURE_FILE.feature");
when(mockPath.getFileName()).thenReturn(mockFilePath);
when(mockPath.toString()).thenReturn("TEST_PATH");
pathList.add(mockPath);
featureFileConverter.convertToSingleScenariosAndRunners(pathList);
verify(fileIO, times(2)).writeContentToFile(anyString(), anyString());
}
use of com.trivago.rta.vo.SingleScenario in project cucable-plugin by trivago.
the class GherkinDocumentParserTest method validFeatureTest.
@Test
public void validFeatureTest() throws Exception {
String featureContent = "@featureTag\n" + "Feature: test feature\n" + "\n" + "@scenario1Tag1\n" + "@scenario1Tag2\n" + "Scenario: This is a scenario with two steps\n" + "Given this is step 1\n" + "Then this is step 2\n";
List<SingleScenario> singleScenariosFromFeature = gherkinDocumentParser.getSingleScenariosFromFeature(featureContent, "", null, null, null);
assertThat(singleScenariosFromFeature.size(), is(1));
SingleScenario scenario = singleScenariosFromFeature.get(0);
assertThat(scenario.getScenarioName(), is("Scenario: This is a scenario with two steps"));
assertThat(scenario.getSteps().size(), is(2));
assertThat(scenario.getBackgroundSteps().size(), is(0));
}
Aggregations