Skip to content

Commit a79c669

Browse files
authored
fix allure-cucumber7-jvm 7.3.0 compatibility issues (fixes #722, via #727)
1 parent e869349 commit a79c669

File tree

3 files changed

+34
-42
lines changed

3 files changed

+34
-42
lines changed

allure-cucumber7-jvm/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
description = "Allure CucumberJVM 7.0"
22

3-
val cucumberVersion = "7.0.0"
4-
val cucumberGherkinVersion = "22.0.0"
3+
val cucumberVersion = "7.3.2"
4+
val cucumberGherkinVersion = "23.0.1"
55

66
dependencies {
77
api(project(":allure-java-commons"))

allure-cucumber7-jvm/src/main/java/io/qameta/allure/cucumber7jvm/AllureCucumber7Jvm.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,9 @@ private List<Parameter> getExamplesAsParameters(
337337

338338
final TableRow row = maybeRow.get();
339339

340-
return IntStream.range(0, examples.getTableHeader().getCells().size())
340+
return IntStream.range(0, examples.getTableHeader().get().getCells().size())
341341
.mapToObj(index -> {
342-
final String name = examples.getTableHeader().getCells().get(index).getValue();
342+
final String name = examples.getTableHeader().get().getCells().get(index).getValue();
343343
final String value = row.getCells().get(index).getValue();
344344
return createParameter(name, value);
345345
})

allure-cucumber7-jvm/src/main/java/io/qameta/allure/cucumber7jvm/testsourcemodel/TestSourcesModel.java

Lines changed: 30 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package io.qameta.allure.cucumber7jvm.testsourcemodel;
1717

18-
import io.cucumber.gherkin.Gherkin;
18+
import io.cucumber.gherkin.GherkinParser;
1919
import io.cucumber.messages.types.Background;
2020
import io.cucumber.messages.types.Envelope;
2121
import io.cucumber.messages.types.Examples;
@@ -24,20 +24,17 @@
2424
import io.cucumber.messages.types.GherkinDocument;
2525
import io.cucumber.messages.types.RuleChild;
2626
import io.cucumber.messages.types.Scenario;
27+
import io.cucumber.messages.types.Source;
28+
import io.cucumber.messages.types.SourceMediaType;
2729
import io.cucumber.messages.types.Step;
2830
import io.cucumber.messages.types.TableRow;
2931
import io.cucumber.plugin.event.TestSourceRead;
3032

3133
import java.net.URI;
3234
import java.util.HashMap;
33-
import java.util.List;
3435
import java.util.Map;
35-
import java.util.Objects;
36-
import java.util.UUID;
37-
38-
import static io.cucumber.gherkin.Gherkin.makeSourceEnvelope;
39-
import static java.util.Collections.singletonList;
40-
import static java.util.stream.Collectors.toList;
36+
import java.util.Optional;
37+
import java.util.stream.Stream;
4138

4239
final class TestSourcesModel {
4340
private final Map<URI, TestSourceRead> pathToReadEventMap = new HashMap<>();
@@ -61,7 +58,7 @@ public Feature getFeature(final URI path) {
6158
parseGherkinSource(path);
6259
}
6360
if (pathToAstMap.containsKey(path)) {
64-
return pathToAstMap.get(path).getFeature();
61+
return pathToAstMap.get(path).getFeature().orElse(null);
6562
}
6663
return null;
6764
}
@@ -72,26 +69,27 @@ private void parseGherkinSource(final URI path) {
7269
}
7370
final String source = pathToReadEventMap.get(path).getSource();
7471

75-
final List<Envelope> sources = singletonList(
76-
makeSourceEnvelope(source, path.toString()));
72+
final GherkinParser parser = GherkinParser.builder()
73+
.build();
7774

78-
final List<Envelope> envelopes = Gherkin.fromSources(
79-
sources,
80-
true,
81-
true,
82-
true,
83-
() -> String.valueOf(UUID.randomUUID())).collect(toList());
75+
final Stream<Envelope> envelopes = parser.parse(
76+
Envelope.of(new Source(path.toString(), source, SourceMediaType.TEXT_X_CUCUMBER_GHERKIN_PLAIN)));
8477

85-
final GherkinDocument gherkinDocument = envelopes.stream()
78+
// TODO: What about empty gherkin docs?
79+
final GherkinDocument gherkinDocument = envelopes
8680
.map(Envelope::getGherkinDocument)
87-
.filter(Objects::nonNull)
81+
.filter(Optional::isPresent)
82+
.map(Optional::get)
8883
.findFirst()
8984
.orElse(null);
9085

9186
pathToAstMap.put(path, gherkinDocument);
9287
final Map<Long, AstNode> nodeMap = new HashMap<>();
93-
final AstNode currentParent = createAstNode(Objects.requireNonNull(gherkinDocument).getFeature(), null);
94-
for (FeatureChild child : gherkinDocument.getFeature().getChildren()) {
88+
89+
// TODO: What about gherkin docs with no features?
90+
final Feature feature = gherkinDocument.getFeature().get();
91+
final AstNode currentParent = new AstNode(feature, null);
92+
for (FeatureChild child : feature.getChildren()) {
9593
processFeatureDefinition(nodeMap, child, currentParent);
9694
}
9795
pathToNodeMap.put(path, nodeMap);
@@ -100,17 +98,13 @@ private void parseGherkinSource(final URI path) {
10098

10199
private void processFeatureDefinition(
102100
final Map<Long, AstNode> nodeMap, final FeatureChild child, final AstNode currentParent) {
103-
if (child.getBackground() != null) {
104-
processBackgroundDefinition(nodeMap, child.getBackground(), currentParent);
105-
} else if (child.getScenario() != null) {
106-
processScenarioDefinition(nodeMap, child.getScenario(), currentParent);
107-
} else if (child.getRule() != null) {
108-
final AstNode childNode = createAstNode(child.getRule(), currentParent);
109-
nodeMap.put(child.getRule().getLocation().getLine(), childNode);
110-
for (RuleChild ruleChild : child.getRule().getChildren()) {
111-
processRuleDefinition(nodeMap, ruleChild, childNode);
112-
}
113-
}
101+
child.getBackground().ifPresent(background -> processBackgroundDefinition(nodeMap, background, currentParent));
102+
child.getScenario().ifPresent(scenario -> processScenarioDefinition(nodeMap, scenario, currentParent));
103+
child.getRule().ifPresent(rule -> {
104+
final AstNode childNode = new AstNode(rule, currentParent);
105+
nodeMap.put(rule.getLocation().getLine(), childNode);
106+
rule.getChildren().forEach(ruleChild -> processRuleDefinition(nodeMap, ruleChild, childNode));
107+
});
114108
}
115109

116110
private void processBackgroundDefinition(
@@ -137,19 +131,17 @@ private void processScenarioDefinition(
137131

138132
private void processRuleDefinition(
139133
final Map<Long, AstNode> nodeMap, final RuleChild child, final AstNode currentParent) {
140-
if (child.getBackground() != null) {
141-
processBackgroundDefinition(nodeMap, child.getBackground(), currentParent);
142-
} else if (child.getScenario() != null) {
143-
processScenarioDefinition(nodeMap, child.getScenario(), currentParent);
144-
}
134+
child.getBackground().ifPresent(background -> processBackgroundDefinition(nodeMap, background, currentParent));
135+
child.getScenario().ifPresent(scenario -> processScenarioDefinition(nodeMap, scenario, currentParent));
145136
}
146137

147138
private void processScenarioOutlineExamples(
148139
final Map<Long, AstNode> nodeMap, final Scenario scenarioOutline, final AstNode parent
149140
) {
150141
for (Examples examples : scenarioOutline.getExamples()) {
151142
final AstNode examplesNode = createAstNode(examples, parent);
152-
final TableRow headerRow = examples.getTableHeader();
143+
// TODO: Can tables without headers even exist?
144+
final TableRow headerRow = examples.getTableHeader().get();
153145
final AstNode headerNode = createAstNode(headerRow, examplesNode);
154146
nodeMap.put(headerRow.getLocation().getLine(), headerNode);
155147
for (int i = 0; i < examples.getTableBody().size(); ++i) {

0 commit comments

Comments
 (0)