use of com.trivago.vo.CucableFeature in project cucable-plugin by trivago.
the class FeatureFileConverter method generateParallelizableFeatures.
/**
* Converts a list of Cucable features
*
* @param cucableFeatures feature files to process
* @throws CucablePluginException see {@link CucablePluginException}
*/
public void generateParallelizableFeatures(final List<CucableFeature> cucableFeatures) throws CucablePluginException {
int featureFileCounter = 0;
List<String> allGeneratedFeaturePaths = new ArrayList<>();
for (CucableFeature cucableFeature : cucableFeatures) {
List<Path> paths = fileSystemManager.getPathsFromCucableFeature(cucableFeature);
if (paths.size() == 0) {
logger.warn("No features and runners could be created. Please check your properties!");
}
for (Path path : paths) {
List<String> generatedFeatureFilePaths = generateParallelizableFeatures(path, cucableFeature.getLineNumbers());
allGeneratedFeaturePaths.addAll(generatedFeatureFilePaths);
featureFileCounter += generatedFeatureFilePaths.size();
}
}
int runnerFileCounter;
if (propertyManager.getDesiredNumberOfFeaturesPerRunner() > 0) {
runnerFileCounter = generateRunnerClassesWithDesiredNumberOfFeatures(allGeneratedFeaturePaths, propertyManager.getDesiredNumberOfFeaturesPerRunner());
} else {
runnerFileCounter = generateRunnerClassesWithDesiredNumberOfRunners(allGeneratedFeaturePaths, propertyManager.getDesiredNumberOfRunners());
}
logger.logInfoSeparator(DEFAULT);
logger.info(String.format("Cucable created %d separate %s and %d %s.", featureFileCounter, Language.singularPlural(featureFileCounter, "feature file", "feature files"), runnerFileCounter, Language.singularPlural(runnerFileCounter, "runner", "runners")), DEFAULT, COMPACT, MINIMAL);
}
use of com.trivago.vo.CucableFeature in project cucable-plugin by trivago.
the class PropertyManager method sourceFeaturePathsToCucableFeatureList.
private List<CucableFeature> sourceFeaturePathsToCucableFeatureList(final String[] sourceFeatures) {
List<CucableFeature> cucableFeatures = new ArrayList<>();
Pattern lineNumberPattern = Pattern.compile(":(\\d*)");
for (String sourceFeature : sourceFeatures) {
String trimmedFeature = sourceFeature.trim();
StringBuffer resultBuffer = new StringBuffer();
Matcher matcher = lineNumberPattern.matcher(trimmedFeature);
List<Integer> scenarioLineNumbers = new ArrayList<>();
while (matcher.find()) {
try {
scenarioLineNumbers.add(Integer.parseInt(matcher.group(1)));
matcher.appendReplacement(resultBuffer, "");
} catch (NumberFormatException ignored) {
// Ignore unparsable line numbers
}
}
matcher.appendTail(resultBuffer);
cucableFeatures.add(new CucableFeature(resultBuffer.toString(), scenarioLineNumbers));
}
return cucableFeatures;
}
use of com.trivago.vo.CucableFeature in project cucable-plugin by trivago.
the class PropertyManager method logProperties.
/**
* Logs all passed property values.
*/
public void logProperties() {
CucableLogLevel[] logLevels = new CucableLogLevel[] { DEFAULT, COMPACT };
if (!isCucumberFeatureListFileSource()) {
logger.info("- sourceFeatures:", logLevels);
} else {
logger.info(String.format("- sourceFeatures from file %s:", cucumberFeatureListFile), logLevels);
}
if (sourceFeatures != null) {
for (CucableFeature sourceFeature : sourceFeatures) {
String logLine = " - " + sourceFeature.getName();
if (sourceFeature.hasValidScenarioLineNumbers()) {
List<Integer> lineNumbers = sourceFeature.getLineNumbers();
logLine += String.format(" (%s %s)", Language.singularPlural(lineNumbers.size(), "line", "lines"), lineNumbers.stream().map(String::valueOf).collect(Collectors.joining(",")));
}
logger.info(logLine, logLevels);
}
}
logger.info(String.format("- sourceRunnerTemplateFile : %s", sourceRunnerTemplateFile), logLevels);
logger.logInfoSeparator(DEFAULT);
logger.info(String.format("- generatedRunnerDirectory : %s", generatedRunnerDirectory), logLevels);
logger.info(String.format("- generatedFeatureDirectory : %s", generatedFeatureDirectory), logLevels);
logger.logInfoSeparator(DEFAULT);
if (includeScenarioTags != null && !includeScenarioTags.isEmpty()) {
logger.info(String.format("- includeScenarioTags : %s", String.join(", ", includeScenarioTags)), logLevels);
}
if (customPlaceholders != null && !customPlaceholders.isEmpty()) {
logger.info("- customPlaceholders :", logLevels);
for (Map.Entry<String, String> customPlaceholder : customPlaceholders.entrySet()) {
logger.info(String.format(" %s => %s", customPlaceholder.getKey(), customPlaceholder.getValue()), logLevels);
}
}
logger.info(String.format("- parallelizationMode : %s", parallelizationMode.name().toLowerCase()), logLevels);
logger.info(String.format("- numberOfTestRuns : %d", numberOfTestRuns), logLevels);
if (desiredNumberOfRunners > 0) {
logger.info(String.format("- desiredNumberOfRunners : %d", desiredNumberOfRunners), logLevels);
}
logger.logInfoSeparator(logLevels);
}
use of com.trivago.vo.CucableFeature in project cucable-plugin by trivago.
the class FeatureFileConverterTest method convertToSingleScenariosAndMultiRunnersTest.
@Test
public void convertToSingleScenariosAndMultiRunnersTest() throws Exception {
String generatedFeatureDir = testFolder.getRoot().getPath().concat("/features/");
String generatedRunnerDir = testFolder.getRoot().getPath().concat("/runners/");
final String FEATURE_FILE_NAME = "FEATURE_FILE.feature";
propertyManager.setNumberOfTestRuns(1);
propertyManager.setDesiredNumberOfRunners(1);
propertyManager.setGeneratedFeatureDirectory(generatedFeatureDir);
propertyManager.setGeneratedRunnerDirectory(generatedRunnerDir);
propertyManager.setParallelizationMode("scenarios");
when(fileIO.readContentFromFile(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);
String featureFileContent = "test";
when(featureFileContentRenderer.getRenderedFeatureFileContent(singleScenario)).thenReturn(featureFileContent);
when(runnerFileContentRenderer.getRenderedRunnerFileContent(any(FeatureRunner.class))).thenReturn("RUNNER_CONTENT");
featureFileConverter.generateParallelizableFeatures(cucableFeatures);
verify(fileIO, times(3)).writeContentToFile(anyString(), anyString());
}
use of com.trivago.vo.CucableFeature in project cucable-plugin by trivago.
the class FeatureFileConverterTest method convertToSingleScenariosAndRunnersTest.
@Test
public void convertToSingleScenariosAndRunnersTest() throws Exception {
String generatedFeatureDir = testFolder.getRoot().getPath().concat("/features/");
String generatedRunnerDir = testFolder.getRoot().getPath().concat("/runners/");
final String FEATURE_FILE_NAME = "FEATURE_FILE.feature";
propertyManager.setNumberOfTestRuns(1);
propertyManager.setGeneratedFeatureDirectory(generatedFeatureDir);
propertyManager.setGeneratedRunnerDirectory(generatedRunnerDir);
when(fileIO.readContentFromFile(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);
when(gherkinDocumentParser.getSingleScenariosFromFeature("TEST_CONTENT", FEATURE_FILE_NAME, null)).thenReturn(scenarioList);
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());
}
Aggregations