use of com.trivago.vo.SingleScenario in project cucable-plugin by trivago.
the class FeatureFileConverterTest method convertToSingleScenariosAndRunnersWithScenarioNameTest.
@Test
public void convertToSingleScenariosAndRunnersWithScenarioNameTest() throws Exception {
String generatedFeatureDir = testFolder.getRoot().getPath().concat("/features/");
String generatedRunnerDir = testFolder.getRoot().getPath().concat("/runners/");
String scenarioMatchText = "Feature: feature1\n Scenario: scenarioName1";
final String FEATURE_FILE_NAME = "FEATURE_FILE.feature";
final String GENERATED_FEATURE_FILE_NAME = "FEATURE_FILE_scenario001_run001_IT.feature";
propertyManager.setNumberOfTestRuns(1);
propertyManager.setGeneratedFeatureDirectory(generatedFeatureDir);
propertyManager.setGeneratedRunnerDirectory(generatedRunnerDir);
propertyManager.setScenarioNames("scenarioName1");
when(fileIO.readContentFromFile(FEATURE_FILE_NAME)).thenReturn("TEST_CONTENT");
when(fileIO.readContentFromFile(generatedFeatureDir + "/" + GENERATED_FEATURE_FILE_NAME)).thenReturn(scenarioMatchText);
List<CucableFeature> cucableFeatures = new ArrayList<>();
CucableFeature cucableFeature = new CucableFeature(FEATURE_FILE_NAME, null);
cucableFeatures.add(cucableFeature);
when(fileSystemManager.getPathsFromCucableFeature(cucableFeature)).thenReturn(Collections.singletonList(Paths.get(cucableFeature.getName())));
List<SingleScenario> scenarioList = new ArrayList<>();
SingleScenario singleScenario = getSingleScenario();
scenarioList.add(singleScenario);
when(gherkinDocumentParser.getSingleScenariosFromFeature("TEST_CONTENT", FEATURE_FILE_NAME, null)).thenReturn(scenarioList);
when(gherkinDocumentParser.matchScenarioWithScenarioNames("en", scenarioMatchText)).thenReturn(0);
String featureFileContent = "test";
when(featureFileContentRenderer.getRenderedFeatureFileContent(singleScenario)).thenReturn(featureFileContent);
when(runnerFileContentRenderer.getRenderedRunnerFileContent(any(FeatureRunner.class))).thenReturn("RUNNER_CONTENT");
featureFileConverter.generateParallelizableFeatures(cucableFeatures);
ArgumentCaptor<String> logCaptor = ArgumentCaptor.forClass(String.class);
verify(logger, times(1)).info(logCaptor.capture(), any(CucableLogger.CucableLogLevel.class), any(CucableLogger.CucableLogLevel.class), any(CucableLogger.CucableLogLevel.class));
assertThat(logCaptor.getAllValues().get(0), is("Cucable created 1 separate feature file and 1 runner."));
verify(fileIO, times(2)).writeContentToFile(anyString(), anyString());
}
use of com.trivago.vo.SingleScenario in project cucable-plugin by trivago.
the class FeatureFileConverterTest method convertToSingleScenariosAndMultiRunnersWithScenarioNamesAndExampleKeywordTest.
@Test
public void convertToSingleScenariosAndMultiRunnersWithScenarioNamesAndExampleKeywordTest() throws Exception {
String generatedFeatureDir = testFolder.getRoot().getPath().concat("/features/");
String generatedRunnerDir = testFolder.getRoot().getPath().concat("/runners/");
final String scenarioMatch1Text = "Feature: feature1\n Scenario: scenarioName1";
final String scenarioMatch2Text = "Feature: feature2\n Example: scenarioName2";
final String FEATURE_FILE_NAME = "FEATURE_FILE.feature";
final String GENERATED_FEATURE_FILE_NAME1 = "FEATURE_FILE_scenario001_run001_IT.feature";
final String GENERATED_FEATURE_FILE_NAME2 = "FEATURE_FILE_scenario002_run001_IT.feature";
propertyManager.setNumberOfTestRuns(1);
propertyManager.setGeneratedFeatureDirectory(generatedFeatureDir);
propertyManager.setGeneratedRunnerDirectory(generatedRunnerDir);
propertyManager.setParallelizationMode("scenarios");
propertyManager.setScenarioNames("scenarioName1, scenarioName2");
when(fileIO.readContentFromFile(FEATURE_FILE_NAME)).thenReturn("TEST_CONTENT");
when(fileIO.readContentFromFile(generatedFeatureDir + "/" + GENERATED_FEATURE_FILE_NAME1)).thenReturn(scenarioMatch1Text);
when(fileIO.readContentFromFile(generatedFeatureDir + "/" + GENERATED_FEATURE_FILE_NAME2)).thenReturn(scenarioMatch2Text);
when(fileIO.readContentFromFile(generatedFeatureDir + "/" + FEATURE_FILE_NAME)).thenReturn("TEST_CONTENT");
List<CucableFeature> cucableFeatures = new ArrayList<>();
CucableFeature cucableFeature = new CucableFeature(FEATURE_FILE_NAME, null);
cucableFeatures.add(cucableFeature);
when(fileSystemManager.getPathsFromCucableFeature(cucableFeature)).thenReturn(Collections.singletonList(Paths.get(cucableFeature.getName())));
List<SingleScenario> scenarioList = new ArrayList<>();
SingleScenario singleScenario = getSingleScenario();
scenarioList.add(singleScenario);
scenarioList.add(singleScenario);
when(gherkinDocumentParser.getSingleScenariosFromFeature("TEST_CONTENT", FEATURE_FILE_NAME, null)).thenReturn(scenarioList);
when(gherkinDocumentParser.matchScenarioWithScenarioNames("en", scenarioMatch1Text)).thenReturn(0);
when(gherkinDocumentParser.matchScenarioWithScenarioNames("en", scenarioMatch2Text)).thenReturn(1);
String featureFileContent = "test";
when(featureFileContentRenderer.getRenderedFeatureFileContent(singleScenario)).thenReturn(featureFileContent);
when(runnerFileContentRenderer.getRenderedRunnerFileContent(any(FeatureRunner.class))).thenReturn("RUNNER_CONTENT");
featureFileConverter.generateParallelizableFeatures(cucableFeatures);
ArgumentCaptor<String> logCaptor = ArgumentCaptor.forClass(String.class);
verify(logger, times(1)).info(logCaptor.capture(), any(CucableLogger.CucableLogLevel.class), any(CucableLogger.CucableLogLevel.class), any(CucableLogger.CucableLogLevel.class));
assertThat(logCaptor.getAllValues().get(0), is("Cucable created 2 separate feature files and 2 runners."));
verify(fileIO, times(4)).writeContentToFile(anyString(), anyString());
}
use of com.trivago.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" + "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.SingleScenario 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));
}
use of com.trivago.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);
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