Skip to content

Commit

Permalink
fix allure-cucumber7-jvm 7.3.0 compatibility issues (fixes #722, via #…
Browse files Browse the repository at this point in the history
  • Loading branch information
unixshaman committed May 16, 2022
1 parent e869349 commit a79c669
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 42 deletions.
4 changes: 2 additions & 2 deletions allure-cucumber7-jvm/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
description = "Allure CucumberJVM 7.0"

val cucumberVersion = "7.0.0"
val cucumberGherkinVersion = "22.0.0"
val cucumberVersion = "7.3.2"
val cucumberGherkinVersion = "23.0.1"

dependencies {
api(project(":allure-java-commons"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,9 @@ private List<Parameter> getExamplesAsParameters(

final TableRow row = maybeRow.get();

return IntStream.range(0, examples.getTableHeader().getCells().size())
return IntStream.range(0, examples.getTableHeader().get().getCells().size())
.mapToObj(index -> {
final String name = examples.getTableHeader().getCells().get(index).getValue();
final String name = examples.getTableHeader().get().getCells().get(index).getValue();
final String value = row.getCells().get(index).getValue();
return createParameter(name, value);
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package io.qameta.allure.cucumber7jvm.testsourcemodel;

import io.cucumber.gherkin.Gherkin;
import io.cucumber.gherkin.GherkinParser;
import io.cucumber.messages.types.Background;
import io.cucumber.messages.types.Envelope;
import io.cucumber.messages.types.Examples;
Expand All @@ -24,20 +24,17 @@
import io.cucumber.messages.types.GherkinDocument;
import io.cucumber.messages.types.RuleChild;
import io.cucumber.messages.types.Scenario;
import io.cucumber.messages.types.Source;
import io.cucumber.messages.types.SourceMediaType;
import io.cucumber.messages.types.Step;
import io.cucumber.messages.types.TableRow;
import io.cucumber.plugin.event.TestSourceRead;

import java.net.URI;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;

import static io.cucumber.gherkin.Gherkin.makeSourceEnvelope;
import static java.util.Collections.singletonList;
import static java.util.stream.Collectors.toList;
import java.util.Optional;
import java.util.stream.Stream;

final class TestSourcesModel {
private final Map<URI, TestSourceRead> pathToReadEventMap = new HashMap<>();
Expand All @@ -61,7 +58,7 @@ public Feature getFeature(final URI path) {
parseGherkinSource(path);
}
if (pathToAstMap.containsKey(path)) {
return pathToAstMap.get(path).getFeature();
return pathToAstMap.get(path).getFeature().orElse(null);
}
return null;
}
Expand All @@ -72,26 +69,27 @@ private void parseGherkinSource(final URI path) {
}
final String source = pathToReadEventMap.get(path).getSource();

final List<Envelope> sources = singletonList(
makeSourceEnvelope(source, path.toString()));
final GherkinParser parser = GherkinParser.builder()
.build();

final List<Envelope> envelopes = Gherkin.fromSources(
sources,
true,
true,
true,
() -> String.valueOf(UUID.randomUUID())).collect(toList());
final Stream<Envelope> envelopes = parser.parse(
Envelope.of(new Source(path.toString(), source, SourceMediaType.TEXT_X_CUCUMBER_GHERKIN_PLAIN)));

final GherkinDocument gherkinDocument = envelopes.stream()
// TODO: What about empty gherkin docs?
final GherkinDocument gherkinDocument = envelopes
.map(Envelope::getGherkinDocument)
.filter(Objects::nonNull)
.filter(Optional::isPresent)
.map(Optional::get)
.findFirst()
.orElse(null);

pathToAstMap.put(path, gherkinDocument);
final Map<Long, AstNode> nodeMap = new HashMap<>();
final AstNode currentParent = createAstNode(Objects.requireNonNull(gherkinDocument).getFeature(), null);
for (FeatureChild child : gherkinDocument.getFeature().getChildren()) {

// TODO: What about gherkin docs with no features?
final Feature feature = gherkinDocument.getFeature().get();
final AstNode currentParent = new AstNode(feature, null);
for (FeatureChild child : feature.getChildren()) {
processFeatureDefinition(nodeMap, child, currentParent);
}
pathToNodeMap.put(path, nodeMap);
Expand All @@ -100,17 +98,13 @@ private void parseGherkinSource(final URI path) {

private void processFeatureDefinition(
final Map<Long, AstNode> nodeMap, final FeatureChild child, final AstNode currentParent) {
if (child.getBackground() != null) {
processBackgroundDefinition(nodeMap, child.getBackground(), currentParent);
} else if (child.getScenario() != null) {
processScenarioDefinition(nodeMap, child.getScenario(), currentParent);
} else if (child.getRule() != null) {
final AstNode childNode = createAstNode(child.getRule(), currentParent);
nodeMap.put(child.getRule().getLocation().getLine(), childNode);
for (RuleChild ruleChild : child.getRule().getChildren()) {
processRuleDefinition(nodeMap, ruleChild, childNode);
}
}
child.getBackground().ifPresent(background -> processBackgroundDefinition(nodeMap, background, currentParent));
child.getScenario().ifPresent(scenario -> processScenarioDefinition(nodeMap, scenario, currentParent));
child.getRule().ifPresent(rule -> {
final AstNode childNode = new AstNode(rule, currentParent);
nodeMap.put(rule.getLocation().getLine(), childNode);
rule.getChildren().forEach(ruleChild -> processRuleDefinition(nodeMap, ruleChild, childNode));
});
}

private void processBackgroundDefinition(
Expand All @@ -137,19 +131,17 @@ private void processScenarioDefinition(

private void processRuleDefinition(
final Map<Long, AstNode> nodeMap, final RuleChild child, final AstNode currentParent) {
if (child.getBackground() != null) {
processBackgroundDefinition(nodeMap, child.getBackground(), currentParent);
} else if (child.getScenario() != null) {
processScenarioDefinition(nodeMap, child.getScenario(), currentParent);
}
child.getBackground().ifPresent(background -> processBackgroundDefinition(nodeMap, background, currentParent));
child.getScenario().ifPresent(scenario -> processScenarioDefinition(nodeMap, scenario, currentParent));
}

private void processScenarioOutlineExamples(
final Map<Long, AstNode> nodeMap, final Scenario scenarioOutline, final AstNode parent
) {
for (Examples examples : scenarioOutline.getExamples()) {
final AstNode examplesNode = createAstNode(examples, parent);
final TableRow headerRow = examples.getTableHeader();
// TODO: Can tables without headers even exist?
final TableRow headerRow = examples.getTableHeader().get();
final AstNode headerNode = createAstNode(headerRow, examplesNode);
nodeMap.put(headerRow.getLocation().getLine(), headerNode);
for (int i = 0; i < examples.getTableBody().size(); ++i) {
Expand Down

0 comments on commit a79c669

Please sign in to comment.