diff --git a/CHANGELOG.md b/CHANGELOG.md index a6d73c6..b9d3695 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,12 +11,13 @@ Back to [Readme](README.md). ### Added * Ability added to specify a folder containing rerun text files [183] +* Additional `generated-features.properties` file in the generated feature directory that stores all generated feature names and their reference to the respective source feature [184] * Feature source options can now be freely combined * Cucable version is now mentioned in the generated runners and features ### Changed -* Dependency updates +* Various dependency updates ## [1.9.0] - 2020-11-26 diff --git a/README.md b/README.md index d9647a9..83781c0 100644 --- a/README.md +++ b/README.md @@ -355,6 +355,8 @@ __Note:__ You need to be careful when selecting multiple sources as the same fea The path where the __generated__ [Cucumber](https://cucumber.io) .feature files should be located (e.g. _src/test/resources/parallel_). +Additionally, a file called `generated-features.properties` will be generated there that shows all generated features along with their reference to the respective source feature. + **Note:** This directory should be located under a valid resource folder to be included as a test source by Maven. If you want to use a directory inside Maven's target folder, [check this example](#generating-runners-and-features-inside-target-directory). diff --git a/example-project/pom.xml b/example-project/pom.xml index ecee7a7..a087e63 100644 --- a/example-project/pom.xml +++ b/example-project/pom.xml @@ -76,7 +76,7 @@ - src/test/resources/features/testfeature/MyTest1.feature + src/test/resources/features/testfeature/MyTest1.feature:8:19 ${generated.feature.directory} ${generated.runner.directory} @@ -100,7 +100,7 @@ - + diff --git a/plugin-code/src/main/java/com/trivago/features/FeatureFileConverter.java b/plugin-code/src/main/java/com/trivago/features/FeatureFileConverter.java index 2237fc0..e9c87d7 100644 --- a/plugin-code/src/main/java/com/trivago/features/FeatureFileConverter.java +++ b/plugin-code/src/main/java/com/trivago/features/FeatureFileConverter.java @@ -36,7 +36,6 @@ import javax.inject.Singleton; import java.nio.file.Path; import java.util.*; -import java.util.concurrent.LinkedTransferQueue; import static com.trivago.logging.CucableLogger.CucableLogLevel.*; @@ -93,41 +92,22 @@ public FeatureFileConverter( public void generateParallelizableFeatures( final List cucableFeatures) throws CucablePluginException { - StringBuilder propertiesFileContent = new StringBuilder(); - int featureFileCounter = 0; List allGeneratedFeaturePaths = new ArrayList<>(); for (CucableFeature cucableFeature : cucableFeatures) { - System.out.println("SOURCE " + cucableFeature.getOrigin()); - System.out.println("SOURCE " + cucableFeature.getLineNumbers()); - List 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) { - System.out.println("PATH " + path); List generatedFeatureFilePaths = generateParallelizableFeatures(path, cucableFeature.getLineNumbers()); - - for (String generatedFeatureFilePath : generatedFeatureFilePaths) { - propertiesFileContent - .append(generatedFeatureFilePath) - .append("=") - .append(path) - .append("\n"); - } - allGeneratedFeaturePaths.addAll(generatedFeatureFilePaths); featureFileCounter += generatedFeatureFilePaths.size(); } } - System.out.println("/////////////////////"); - System.out.println(propertiesFileContent); - System.out.println("/////////////////////"); - for (Map.Entry entry : singleFeatureCounters.entrySet()) { logFeatureFileConversionMessage(entry.getKey(), entry.getValue()); } @@ -262,8 +242,15 @@ private List generateFeatureFiles( ); generatedFeaturePaths.add(generatedFileName); singleFeatureCounters.put(sourceFeatureFilePath.toString(), featureCounter); + + fileSystemManager.writeContentToFile( + generatedFileName + "=" + + singleScenario.getFeatureFilePath() + ":" + singleScenario.getLineNumber() + "\n", + propertyManager.getGeneratedFeatureDirectory() + + "/generated-features.properties"); } } + return generatedFeaturePaths; } diff --git a/plugin-code/src/main/java/com/trivago/files/FileSystemManager.java b/plugin-code/src/main/java/com/trivago/files/FileSystemManager.java index 0bf9d8a..4c9b157 100644 --- a/plugin-code/src/main/java/com/trivago/files/FileSystemManager.java +++ b/plugin-code/src/main/java/com/trivago/files/FileSystemManager.java @@ -31,6 +31,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -153,7 +154,7 @@ private void removeFilesFromPath(final String path, final String fileExtension) */ public void writeContentToFile(String content, String filePath) throws FileCreationException { try { - FileUtils.fileWrite(filePath, "UTF-8", content); + FileUtils.fileAppend(filePath, "UTF-8", content); } catch (IOException e) { throw new FileCreationException(filePath); } diff --git a/plugin-code/src/main/java/com/trivago/gherkin/GherkinDocumentParser.java b/plugin-code/src/main/java/com/trivago/gherkin/GherkinDocumentParser.java index f6a4374..fae45ec 100644 --- a/plugin-code/src/main/java/com/trivago/gherkin/GherkinDocumentParser.java +++ b/plugin-code/src/main/java/com/trivago/gherkin/GherkinDocumentParser.java @@ -116,11 +116,6 @@ public List getSingleScenariosFromFeature( continue; } - System.out.println("....."); - System.out.println(featureFilePath); - System.out.println(scenarioDefinition.getLocation().getLine()); - System.out.println("....."); - if (scenarioDefinition instanceof Scenario) { Scenario scenario = (Scenario) scenarioDefinition; if (scenarioLineNumbers == null diff --git a/plugin-code/src/test/java/com/trivago/features/FeatureFileConverterTest.java b/plugin-code/src/test/java/com/trivago/features/FeatureFileConverterTest.java index 261918a..bcf172f 100644 --- a/plugin-code/src/test/java/com/trivago/features/FeatureFileConverterTest.java +++ b/plugin-code/src/test/java/com/trivago/features/FeatureFileConverterTest.java @@ -120,7 +120,7 @@ public void convertToSingleScenariosAndRunnersTest() throws Exception { any(CucableLogger.CucableLogLevel.class), any(CucableLogger.CucableLogLevel.class) ); assertThat(logCaptor.getAllValues().get(0), is("Cucable created 1 separate feature file and 1 runner.")); - verify(fileSystemManager, times(2)).writeContentToFile(anyString(), anyString()); + verify(fileSystemManager, times(3)).writeContentToFile(anyString(), anyString()); } @Test @@ -167,7 +167,7 @@ public void convertToSingleScenariosAndRunnersWithScenarioNameTest() throws Exce any(CucableLogger.CucableLogLevel.class), any(CucableLogger.CucableLogLevel.class) ); assertThat(logCaptor.getAllValues().get(0), is("Cucable created 1 separate feature file and 1 runner.")); - verify(fileSystemManager, times(2)).writeContentToFile(anyString(), anyString()); + verify(fileSystemManager, times(3)).writeContentToFile(anyString(), anyString()); } @Test @@ -246,7 +246,7 @@ public void convertToSingleScenariosAndMultiRunnersTest() throws Exception { featureFileConverter.generateParallelizableFeatures(cucableFeatures); - verify(fileSystemManager, times(3)).writeContentToFile(anyString(), anyString()); + verify(fileSystemManager, times(5)).writeContentToFile(anyString(), anyString()); } @Test @@ -303,7 +303,7 @@ public void convertToSingleScenariosAndMultiRunnersWithScenarioNamesTest() throw any(CucableLogger.CucableLogLevel.class), any(CucableLogger.CucableLogLevel.class) ); assertThat(logCaptor.getAllValues().get(0), is("Cucable created 2 separate feature files and 2 runners.")); - verify(fileSystemManager, times(4)).writeContentToFile(anyString(), anyString()); + verify(fileSystemManager, times(6)).writeContentToFile(anyString(), anyString()); } @Test @@ -360,7 +360,7 @@ public void convertToSingleScenariosAndMultiRunnersWithScenarioNamesAndExampleKe any(CucableLogger.CucableLogLevel.class), any(CucableLogger.CucableLogLevel.class) ); assertThat(logCaptor.getAllValues().get(0), is("Cucable created 2 separate feature files and 2 runners.")); - verify(fileSystemManager, times(4)).writeContentToFile(anyString(), anyString()); + verify(fileSystemManager, times(6)).writeContentToFile(anyString(), anyString()); } @Test