Search in sources :

Example 6 with FeatureRunner

use of com.trivago.vo.FeatureRunner in project cucable-plugin by trivago.

the class RunnerFileContentRendererTest method multipleFeatureRunnerTest.

@Test
public void multipleFeatureRunnerTest() throws Exception {
    String template = "package parallel;\n" + "\n" + "package some.package;\n" + "import cucumber.api.CucumberOptions;\n" + "\n" + "@CucumberOptions(\n" + "    monochrome = false,\n" + "    features = {\"classpath:parallel/features/[CUCABLE:FEATURE].feature\"},\n" + "    plugin = {\"json:target/cucumber-report/[CUCABLE:RUNNER].json\"}\n" + ")\n" + "public class MyClass {\n" + "}\n";
    when(fileIO.readContentFromFile(anyString())).thenReturn(template);
    String expectedOutput = "\n" + "\n" + "\n" + "import cucumber.api.CucumberOptions;\n" + "\n" + "@CucumberOptions(\n" + "    monochrome = false,\n" + "    features = {\"classpath:parallel/features/featureFileName.feature\",\n" + "\"classpath:parallel/features/featureFileName2.feature\"},\n" + "    plugin = {\"json:target/cucumber-report/RunnerClass.json\"}\n" + ")\n" + "public class RunnerClass {\n" + "}\n" + "\n" + "\n" + "// Generated by Cucable from MyClass.java\n";
    ArrayList<String> featureFileNames = new ArrayList<>();
    featureFileNames.add("featureFileName");
    featureFileNames.add("featureFileName2");
    FeatureRunner featureRunner = new FeatureRunner("MyClass.java", "RunnerClass", featureFileNames);
    String renderedRunnerFileContent = runnerFileContentRenderer.getRenderedRunnerFileContent(featureRunner);
    // In a windows system, replace line separator "\r\n" with "\n".
    renderedRunnerFileContent = renderedRunnerFileContent.replaceAll("\\r\\n", "\n");
    assertThat(renderedRunnerFileContent, is(expectedOutput));
}
Also used : ArrayList(java.util.ArrayList) FeatureRunner(com.trivago.vo.FeatureRunner) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 7 with FeatureRunner

use of com.trivago.vo.FeatureRunner in project cucable-plugin by trivago.

the class RunnerFileContentRendererTest method missingRequiredPlaceholderTest.

@Test(expected = CucablePluginException.class)
public void missingRequiredPlaceholderTest() throws Exception {
    String template = "No Placeholder included";
    when(fileIO.readContentFromFile(anyString())).thenReturn(template);
    ArrayList<String> featureFileNames = new ArrayList<>();
    featureFileNames.add("featureFileName");
    FeatureRunner featureRunner = new FeatureRunner("MyClass.java", "RunnerClass", featureFileNames);
    runnerFileContentRenderer.getRenderedRunnerFileContent(featureRunner);
}
Also used : ArrayList(java.util.ArrayList) FeatureRunner(com.trivago.vo.FeatureRunner) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 8 with FeatureRunner

use of com.trivago.vo.FeatureRunner in project cucable-plugin by trivago.

the class FeatureFileConverter method generateRunnerClass.

/**
 * Generate a single runner class from a list of feature files.
 *
 * @param generatedFeatureFileNames The list of generated generated feature file names.
 * @throws CucablePluginException see {@link CucablePluginException}.
 */
private void generateRunnerClass(final List<String> generatedFeatureFileNames) throws CucablePluginException {
    // The runner class name will be equal to the feature name if there is only one feature to run.
    // Otherwise, a generated runner class name is used.
    String runnerClassName;
    if (generatedFeatureFileNames.size() == 1) {
        runnerClassName = "Runner_" + generatedFeatureFileNames.get(0);
    } else {
        runnerClassName = "CucableMultiRunner_".concat(UUID.randomUUID().toString().replace("-", "_")).concat(INTEGRATION_TEST_POSTFIX);
    }
    // Generate runner for the newly generated single scenario feature file
    FeatureRunner featureRunner = new FeatureRunner(propertyManager.getSourceRunnerTemplateFile(), runnerClassName, generatedFeatureFileNames);
    String renderedRunnerClassContent = runnerFileContentRenderer.getRenderedRunnerFileContent(featureRunner);
    String generatedRunnerClassFilePath = propertyManager.getGeneratedRunnerDirectory().concat(PATH_SEPARATOR).concat(runnerClassName).concat(RUNNER_FILE_EXTENSION);
    fileIO.writeContentToFile(renderedRunnerClassContent, generatedRunnerClassFilePath);
}
Also used : FeatureRunner(com.trivago.vo.FeatureRunner)

Aggregations

FeatureRunner (com.trivago.vo.FeatureRunner)8 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 HashMap (java.util.HashMap)1