Skip to content

Commit

Permalink
3.8.1 (#356)
Browse files Browse the repository at this point in the history
* tdd tests

* simplified unique scenario detection code

* more tdd

* multi run hash detection

* updated jobs
  • Loading branch information
bischoffdev authored Sep 12, 2024
1 parent 426f295 commit 8190086
Show file tree
Hide file tree
Showing 9 changed files with 350 additions and 41 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/example-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4.1.7
- name: Set up JDK
uses: actions/setup-java@v3
uses: actions/setup-java@v3.13.0
with:
java-version: '17'
distribution: 'temurin'
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up JDK 11
uses: actions/setup-java@v3
- uses: actions/checkout@v4.1.7
- name: Set up JDK
uses: actions/setup-java@v3.13.0
with:
distribution: 'temurin'
java-version: '11'
java-version: '17'
cache: maven

- name: Set up Apache Maven Central
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
- uses: actions/checkout@v4.1.7
- name: Set up JDK
uses: actions/setup-java@v3.13.0
with:
java-version: '11'
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Test with Maven
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

Back to [Readme](README.md).

## [3.8.1] - 2024-09-12

### Changed

* Much safer detection of multi-run scenarios when using `groupPreviousScenarioRuns`

## [3.8.0] - 2024-09-06

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@
*/
package com.trivago.cluecumber.engine.json.processors;

import com.trivago.cluecumber.engine.json.pojo.Argument;
import com.trivago.cluecumber.engine.json.pojo.Element;
import com.trivago.cluecumber.engine.json.pojo.Report;
import com.trivago.cluecumber.engine.json.pojo.Row;
import com.trivago.cluecumber.engine.json.pojo.Step;
import com.trivago.cluecumber.engine.json.pojo.Tag;

import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand All @@ -46,40 +51,71 @@ public ElementMultipleRunsPreProcessor() {
* @param reports The list of reports to cycle through.
*/
public void addMultipleRunsInformationToScenarios(final List<Report> reports) {
Map<String, List<Element>> elementsByUniqueId = new HashMap<>();

List<Element> elements = new ArrayList<>();
// Group elements by unique ID
for (Report report : reports) {
elements.addAll(report.getElements());
for (Element element : report.getElements()) {
String combinedId = generateCombinedId(element);
elementsByUniqueId.computeIfAbsent(combinedId, k -> new ArrayList<>()).add(element);
}
}

// Group elements by id (that should combine feature and scenario names) and line, to also ensure that scenario outlines are properly handled
Map<String, Map<Integer, List<Element>>> groupedElements = elements.stream()
.collect(Collectors.groupingBy(
Element::getId,
Collectors.groupingBy(Element::getLine)
));
// Process each group of elements
for (List<Element> group : elementsByUniqueId.values()) {
if (group.size() < 2) continue;

// set flags based on start time and add children element to last run element
groupedElements.values().forEach(idGroup -> idGroup.values().forEach(group -> {
if (group.size() < 2) {
return;
}
group.sort(Comparator.comparing(
Element::getStartDateTime, Comparator.nullsLast(Comparator.naturalOrder())).reversed());
Element lastRunElement = group.get(0);
lastRunElement.setMultiRunChildren(group);
lastRunElement.setMultiRunParent(true);
// remove first of line group as it is the last run element
group.remove(0);
for (Element element : group) {
element.isMultiRunChild(true);
}
lastRunElement.setMultiRunChildren(group);
}));
group.sort(Comparator.comparing(Element::getStartDateTime, Comparator.nullsLast(Comparator.naturalOrder())).reversed());
Element parentElement = group.remove(0);
parentElement.setMultiRunParent(true);
group.forEach(element -> element.isMultiRunChild(true));
parentElement.setMultiRunChildren(group);
}

// Remove elements marked as isMultiRunChild from each report
// Remove child elements from reports
for (Report report : reports) {
report.getElements().removeIf(Element::isMultiRunChild);
}
}

private String generateCombinedId(Element element) {
List<String> argumentValues = new ArrayList<>();
List<String> docStrings = new ArrayList<>();
List<List<String>> outputs = new ArrayList<>();
List<String> rows = new ArrayList<>();

for (Step step : element.getSteps()) {
step.getMatch().getArguments().stream()
.map(argument -> argument.getOffset() + ": " + argument.getVal())
.forEach(argumentValues::add);

if (step.getDocString() != null) {
docStrings.add(step.getDocString().getLine() + ": " + step.getDocString().getValue());
}

if (step.getOutput() != null) {
outputs.add(step.getOutput());
}

if (step.getRows() != null) {
step.getRows().forEach(row -> rows.add(String.join(", ", row.getCells())));
}
}

return String.valueOf((element.getFeatureIndex() +
element.getDescription() +
element.getLine() +
element.getFeatureName() +
element.getName() +
element.getId() +
element.getTags().stream().map(Tag::getName).collect(Collectors.joining(",")) +
element.getTotalNumberOfSteps() +
element.getSteps().stream().map(Step::getKeyword).collect(Collectors.joining(", ")) +
element.getSteps().stream().map(Step::getName).collect(Collectors.joining(", ")) +
String.join(", ", docStrings) +
String.join(", ", argumentValues) +
String.join(", ", rows) +
outputs.stream().map(output -> String.join(", ", output)).collect(Collectors.joining(", ")))
.hashCode());
}
}
Loading

0 comments on commit 8190086

Please sign in to comment.