You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2017/10/16 15:20:48 UTC

[35/47] tinkerpop git commit: TINKERPOP-1784 Added test to enforce implementation of process tests as features

TINKERPOP-1784 Added test to enforce implementation of process tests as features


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/672faea3
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/672faea3
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/672faea3

Branch: refs/heads/TINKERPOP-1784
Commit: 672faea3d636b2fb8f7afbd64715a921c9fbe240
Parents: 8325d46
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Sep 27 13:26:17 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Mon Oct 16 11:19:30 2017 -0400

----------------------------------------------------------------------
 gremlin-test/features/filter/Coin.feature       |  4 +-
 gremlin-test/features/map/Count.feature         | 18 +++-
 .../gremlin/structure/FeatureCoverageTest.java  | 92 ++++++++++++++++++++
 3 files changed, 108 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/672faea3/gremlin-test/features/filter/Coin.feature
----------------------------------------------------------------------
diff --git a/gremlin-test/features/filter/Coin.feature b/gremlin-test/features/filter/Coin.feature
index 1b88f58..802ebdc 100644
--- a/gremlin-test/features/filter/Coin.feature
+++ b/gremlin-test/features/filter/Coin.feature
@@ -17,7 +17,7 @@
 
 Feature: Step - coin()
 
-  Scenario: Use coin at 1.0
+  Scenario: g_V_coinX1X
     Given the modern graph
     And the traversal of
       """
@@ -33,7 +33,7 @@ Feature: Step - coin()
       | vertex | peter  |
 
 
-  Scenario: Use coin at 0.0
+  Scenario: g_V_coinX0X
     Given the modern graph
     And the traversal of
       """

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/672faea3/gremlin-test/features/map/Count.feature
----------------------------------------------------------------------
diff --git a/gremlin-test/features/map/Count.feature b/gremlin-test/features/map/Count.feature
index 316976e..1233ed3 100644
--- a/gremlin-test/features/map/Count.feature
+++ b/gremlin-test/features/map/Count.feature
@@ -17,7 +17,7 @@
 
 Feature: Step - count()
 
-  Scenario: Count all vertices
+  Scenario: g_V_count
     Given the modern graph
     And the traversal of
       """
@@ -27,7 +27,17 @@ Feature: Step - count()
     Then the result should be ordered
       | numeric | 6 |
 
-  Scenario: Count vertices after traversing both() twice
+  Scenario: g_V_out_count
+    Given the modern graph
+    And the traversal of
+      """
+      g.V().out().count()
+      """
+    When iterated to list
+    Then the result should be ordered
+      | numeric | 6 |
+
+  Scenario: g_V_both_both_count
     Given the modern graph
     And the traversal of
       """
@@ -37,7 +47,7 @@ Feature: Step - count()
     Then the result should be ordered
       | numeric | 30 |
 
-  Scenario: Count local
+  Scenario: g_V_fold_countXlocalX
     Given the modern graph
     And the traversal of
       """
@@ -47,7 +57,7 @@ Feature: Step - count()
     Then the result should be ordered
       | numeric | 6 |
 
-  Scenario: Count no vertices
+  Scenario: g_V_hasXnoX_count
     Given the modern graph
     And the traversal of
       """

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/672faea3/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/structure/FeatureCoverageTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/structure/FeatureCoverageTest.java b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/structure/FeatureCoverageTest.java
new file mode 100644
index 0000000..791d44e
--- /dev/null
+++ b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/structure/FeatureCoverageTest.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.structure;
+
+import org.apache.tinkerpop.gremlin.process.ProcessStandardSuite;
+import org.apache.tinkerpop.gremlin.process.traversal.step.filter.CoinTest;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.CountTest;
+import org.junit.Test;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class FeatureCoverageTest {
+
+    private static Pattern scenarioName = Pattern.compile("^\\s*Scenario:\\s*(.*)$");
+
+    @Test
+    public void shouldImplementAllProcessTestsAsFeatures() throws Exception {
+
+        // TEMPORARY while test framework is under development - all tests should ultimately be included
+        final List<Class<?>> temp = Arrays.asList(CoinTest.class);
+
+        final Field field = ProcessStandardSuite.class.getDeclaredField("testsToEnforce");
+        field.setAccessible(true);
+        final Class<?>[] testsToEnforce = (Class<?>[]) field.get(null);
+
+        final List<Class<?>> testClassesToEnforce = Stream.of(testsToEnforce).filter(temp::contains).collect(Collectors.toList());
+        for (Class<?> t : testClassesToEnforce) {
+            final String packge = t.getPackage().getName();
+            final String group = packge.substring(packge.lastIndexOf(".") + 1, packge.length());
+            final String featureFileName = "features" + File.separator +
+                                           group + File.separator +
+                                           t.getSimpleName().replace("Test", "") + ".feature";
+            final Set<String> testMethods = Stream.of(t.getDeclaredMethods())
+                    .filter(m -> m.isAnnotationPresent(Test.class))
+                    .map(Method::getName).collect(Collectors.toSet());
+
+            final File featureFile = new File(featureFileName);
+            assertThat(featureFile.exists(), is(true));
+            assertThat(featureFile.isFile(), is(true));
+
+            final Set<String> testsInFeatureFile = new HashSet<>();
+            final InputStream is = new FileInputStream(featureFile);
+            final BufferedReader buf = new BufferedReader(new InputStreamReader(is));
+            String line = buf.readLine();
+            while(line != null){
+                final Matcher matcher = scenarioName.matcher(line);
+                if (matcher.matches())
+                    testsInFeatureFile.add(matcher.group(1));
+                line = buf.readLine();
+            }
+
+            assertEquals("All test methods are not implemented in the " + featureFileName, testMethods, testsInFeatureFile);
+        }
+    }
+}