Skip to content

Commit

Permalink
cleaned up
Browse files Browse the repository at this point in the history
  • Loading branch information
bischoffdev committed Jun 27, 2023
1 parent 6ed2b28 commit 6f47653
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 34 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
4 changes: 2 additions & 2 deletions example-project/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<!-- <sourceFeatures>@src/test/resources</sourceFeatures>-->

<!-- process a specific feature file and specific line numbers in the given directory -->
<sourceFeatures>src/test/resources/features/testfeature/MyTest1.feature</sourceFeatures>
<sourceFeatures>src/test/resources/features/testfeature/MyTest1.feature:8:19</sourceFeatures>

<generatedFeatureDirectory>${generated.feature.directory}</generatedFeatureDirectory>
<generatedRunnerDirectory>${generated.runner.directory}</generatedRunnerDirectory>
Expand All @@ -100,7 +100,7 @@

<!-- optional: number of test runs to create runners and features multiple times
if set to a number greater than 1 -->
<!-- <numberOfTestRuns>1</numberOfTestRuns> -->
<!-- <numberOfTestRuns>5</numberOfTestRuns> -->

<!-- optional: generate a fixed number of runners and distribute all features round-robin.
This can only be used if desiredNumberOfFeaturesPerRunner is NOT used! -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand Down Expand Up @@ -93,41 +92,22 @@ public FeatureFileConverter(
public void generateParallelizableFeatures(
final List<CucableFeature> cucableFeatures) throws CucablePluginException {

StringBuilder propertiesFileContent = new StringBuilder();

int featureFileCounter = 0;
List<String> allGeneratedFeaturePaths = new ArrayList<>();

for (CucableFeature cucableFeature : cucableFeatures) {
System.out.println("SOURCE " + cucableFeature.getOrigin());
System.out.println("SOURCE " + cucableFeature.getLineNumbers());

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) {
System.out.println("PATH " + path);
List<String> 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<String, Integer> entry : singleFeatureCounters.entrySet()) {
logFeatureFileConversionMessage(entry.getKey(), entry.getValue());
}
Expand Down Expand Up @@ -262,8 +242,15 @@ private List<String> generateFeatureFiles(
);
generatedFeaturePaths.add(generatedFileName);
singleFeatureCounters.put(sourceFeatureFilePath.toString(), featureCounter);

fileSystemManager.writeContentToFile(
generatedFileName + "=" +
singleScenario.getFeatureFilePath() + ":" + singleScenario.getLineNumber() + "\n",
propertyManager.getGeneratedFeatureDirectory() +
"/generated-features.properties");
}
}

return generatedFeaturePaths;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,6 @@ public List<SingleScenario> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6f47653

Please sign in to comment.