diff --git a/allure-cucumber7-jvm/build.gradle.kts b/allure-cucumber7-jvm/build.gradle.kts index b6104c0aa..eceb85428 100644 --- a/allure-cucumber7-jvm/build.gradle.kts +++ b/allure-cucumber7-jvm/build.gradle.kts @@ -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")) diff --git a/allure-cucumber7-jvm/src/main/java/io/qameta/allure/cucumber7jvm/AllureCucumber7Jvm.java b/allure-cucumber7-jvm/src/main/java/io/qameta/allure/cucumber7jvm/AllureCucumber7Jvm.java index acb431134..38f0e52f1 100644 --- a/allure-cucumber7-jvm/src/main/java/io/qameta/allure/cucumber7jvm/AllureCucumber7Jvm.java +++ b/allure-cucumber7-jvm/src/main/java/io/qameta/allure/cucumber7jvm/AllureCucumber7Jvm.java @@ -337,9 +337,9 @@ private List 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); }) diff --git a/allure-cucumber7-jvm/src/main/java/io/qameta/allure/cucumber7jvm/testsourcemodel/TestSourcesModel.java b/allure-cucumber7-jvm/src/main/java/io/qameta/allure/cucumber7jvm/testsourcemodel/TestSourcesModel.java index 7741c41dc..5ce13730f 100644 --- a/allure-cucumber7-jvm/src/main/java/io/qameta/allure/cucumber7jvm/testsourcemodel/TestSourcesModel.java +++ b/allure-cucumber7-jvm/src/main/java/io/qameta/allure/cucumber7jvm/testsourcemodel/TestSourcesModel.java @@ -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; @@ -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 pathToReadEventMap = new HashMap<>(); @@ -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; } @@ -72,26 +69,27 @@ private void parseGherkinSource(final URI path) { } final String source = pathToReadEventMap.get(path).getSource(); - final List sources = singletonList( - makeSourceEnvelope(source, path.toString())); + final GherkinParser parser = GherkinParser.builder() + .build(); - final List envelopes = Gherkin.fromSources( - sources, - true, - true, - true, - () -> String.valueOf(UUID.randomUUID())).collect(toList()); + final Stream 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 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); @@ -100,17 +98,13 @@ private void parseGherkinSource(final URI path) { private void processFeatureDefinition( final Map 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( @@ -137,11 +131,8 @@ private void processScenarioDefinition( private void processRuleDefinition( final Map 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( @@ -149,7 +140,8 @@ private void processScenarioOutlineExamples( ) { 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) {