This is an automated email from the ASF dual-hosted git repository. spmallette pushed a commit to branch TINKERPOP-2601 in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
commit 77dc7adcc961e0cc2658d5358defa2818cb8958b Author: Stephen Mallette <[email protected]> AuthorDate: Fri Aug 13 14:56:07 2021 -0400 TINKERPOP-2601 Add io() support for Gherkin tests on jvm --- .../tinkerpop/gremlin/features/StepDefinition.java | 22 +++++++++++++--------- .../apache/tinkerpop/gremlin/features/World.java | 12 ++++++++++++ .../tinkergraph/TinkerGraphFeatureTest.java | 8 ++++++++ 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/features/StepDefinition.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/features/StepDefinition.java index b769e21..e97c264 100644 --- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/features/StepDefinition.java +++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/features/StepDefinition.java @@ -75,12 +75,13 @@ public final class StepDefinition { private static final ObjectMapper mapper = new ObjectMapper(); - private final World world; + private World world; private GraphTraversalSource g; private final Map<String, String> stringParameters = new HashMap<>(); private Traversal traversal; private Object result; - private static Pattern edgeTriplet = Pattern.compile("(.+)-(.+)->(.+)"); + private static final Pattern edgeTripletPattern = Pattern.compile("(.+)-(.+)->(.+)"); + private static final Pattern ioPattern = Pattern.compile("g\\.io\\(\"(.*)\"\\).*"); private List<Pair<Pattern, Function<String,String>>> stringMatcherConverters = new ArrayList<Pair<Pattern, Function<String,String>>>() {{ // expects json so that should port to the Gremlin script form - replace curly json braces with square ones // for Gremlin sake. @@ -228,7 +229,8 @@ public final class StepDefinition { @Given("the traversal of") public void theTraversalOf(final String docString) { - traversal = parseGremlin(applyParameters(docString)); + final String gremlin = tryUpdateDataFilePath(docString); + traversal = parseGremlin(applyParameters(gremlin)); } @When("iterated to list") @@ -313,11 +315,6 @@ public final class StepDefinition { if (script.contains(".withComputer(")) throw new AssumptionViolatedException("withComputer() syntax is not supported by gremlin-language at this time"); - // TODO: fix io() data pathing stuff to bind it better to the graph - if (script.startsWith("g.io(\"")) { - throw new AssumptionViolatedException("io() syntax"); - } - final GremlinLexer lexer = new GremlinLexer(CharStreams.fromString(script)); final GremlinParser parser = new GremlinParser(new CommonTokenStream(lexer)); final GremlinParser.QueryContext ctx = parser.query(); @@ -403,7 +400,7 @@ public final class StepDefinition { } private static Triplet<String,String,String> getEdgeTriplet(final String e) { - final Matcher m = edgeTriplet.matcher(e); + final Matcher m = edgeTripletPattern.matcher(e); if (m.matches()) { return Triplet.with(m.group(1), m.group(2), m.group(3)); } @@ -431,4 +428,11 @@ public final class StepDefinition { } return replaced; } + + private String tryUpdateDataFilePath(final String docString) { + final Matcher matcher = ioPattern.matcher(docString); + final String gremlin = matcher.matches() ? + docString.replace(matcher.group(1), world.changePathToDataFile(matcher.group(1))) : docString; + return gremlin; + } } diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/features/World.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/features/World.java index 99fac71..971105b 100644 --- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/features/World.java +++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/features/World.java @@ -54,4 +54,16 @@ public interface World { public default void afterEachScenario() { // do nothing } + + /** + * Called when {@code g.io()} is encountered in the Gherkin tests and allows the path to the data file to + * referenced to be changed. The default path will look something like: {@code data/file.extension} and will + * match one of the standard TinkerPop data files associated with the test framework. If the files need to be + * located somewhere else for a particular provider, this method can alter the path as needed. + * + * @param pathToFileFromGremlin the path to a data file as taken from the Gherkin tests + */ + public default String changePathToDataFile(final String pathToFileFromGremlin) { + return pathToFileFromGremlin; + } } diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/TinkerGraphFeatureTest.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/TinkerGraphFeatureTest.java index 3cc834d..6c2d27f 100644 --- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/TinkerGraphFeatureTest.java +++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/TinkerGraphFeatureTest.java @@ -29,12 +29,15 @@ import io.cucumber.junit.Cucumber; import io.cucumber.junit.CucumberOptions; import org.apache.commons.configuration2.BaseConfiguration; import org.apache.commons.configuration2.Configuration; +import org.apache.tinkerpop.gremlin.TestHelper; import org.apache.tinkerpop.gremlin.features.World; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory; import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph; import org.junit.runner.RunWith; +import java.io.File; + import static org.apache.tinkerpop.gremlin.LoadGraphWith.GraphData; @RunWith(Cucumber.class) @@ -77,6 +80,11 @@ public class TinkerGraphFeatureTest { else throw new UnsupportedOperationException("GraphData not supported: " + graphData.name()); } + + @Override + public String changePathToDataFile(final String pathToFileFromGremlin) { + return ".." + File.separator + pathToFileFromGremlin; + } } public static final class WorldInjectorSource implements InjectorSource {
