tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spmalle...@apache.org
Subject tinkerpop git commit: TINKERPOP-1860 Added tests for valueMap(true) variations
Date Fri, 29 Dec 2017 13:48:35 GMT
Repository: tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-1860 [created] 0b94b5072


TINKERPOP-1860 Added tests for valueMap(true) variations

Note that with GraphSON 2.0 we get back string representations of T.id and T.label. That may
change for GraphSON 3.0 on the 3.3.x line of code.


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

Branch: refs/heads/TINKERPOP-1860
Commit: 0b94b5072a297ab883d66804c48d8a224012a90f
Parents: 9511dac
Author: Stephen Mallette <spmva@genoprime.com>
Authored: Fri Dec 29 08:02:55 2017 -0500
Committer: Stephen Mallette <spmva@genoprime.com>
Committed: Fri Dec 29 08:02:55 2017 -0500

----------------------------------------------------------------------
 .../step/map/GroovyValueMapTest.groovy          | 10 +++
 .../src/main/jython/radish/feature_steps.py     |  8 +-
 gremlin-test/features/map/ValueMap.feature      | 32 +++++++
 .../traversal/step/map/ValueMapTest.java        | 95 ++++++++++++++++++++
 4 files changed, 144 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0b94b507/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroovyValueMapTest.groovy
----------------------------------------------------------------------
diff --git a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroovyValueMapTest.groovy
b/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroovyValueMapTest.groovy
index c3c20fa..046f4ef 100644
--- a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroovyValueMapTest.groovy
+++ b/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroovyValueMapTest.groovy
@@ -34,11 +34,21 @@ public abstract class GroovyValueMapTest {
         }
 
         @Override
+        public Traversal<Vertex, Map<String, Object>> get_g_V_valueMapXtrueX()
{
+            new ScriptTraversal<>(g, "gremlin-groovy", "g.V.valueMap(true)")
+        }
+
+        @Override
         public Traversal<Vertex, Map<String, List>> get_g_V_valueMapXname_ageX()
{
             new ScriptTraversal<>(g, "gremlin-groovy", "g.V.valueMap('name', 'age')")
         }
 
         @Override
+        public Traversal<Vertex, Map<String, Object>> get_g_V_valueMapXtrue_name_ageX()
{
+            new ScriptTraversal<>(g, "gremlin-groovy", "g.V.valueMap(true, 'name',
'age')")
+        }
+
+        @Override
         public Traversal<Vertex, Map<String, List<String>>> get_g_VX1X_outXcreatedX_valueMap(final
Object v1Id) {
             new ScriptTraversal<>(g, "gremlin-groovy", "g.V(v1Id).out('created').valueMap",
"v1Id", v1Id)
         }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0b94b507/gremlin-python/src/main/jython/radish/feature_steps.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/radish/feature_steps.py b/gremlin-python/src/main/jython/radish/feature_steps.py
index 5cb4b9a..58bc199 100644
--- a/gremlin-python/src/main/jython/radish/feature_steps.py
+++ b/gremlin-python/src/main/jython/radish/feature_steps.py
@@ -33,6 +33,8 @@ regex_in = re.compile(r"([(.,\s])in\(")
 regex_is = re.compile(r"([(.,\s])is\(")
 regex_not = re.compile(r"([(.,\s])not\(")
 regex_or = re.compile(r"([(.,\s])or\(")
+regex_true = re.compile(r"(true)")
+regex_false = re.compile(r"(false)")
 
 
 ignores = [
@@ -157,6 +159,8 @@ def _convert(val, ctx):
         return Path([set([])], path_objects)
     elif isinstance(val, str) and re.match("^c\[.*\]$", val):         # parse lambda/closure
         return lambda: (val[2:-1], "gremlin-groovy")
+    elif isinstance(val, str) and re.match("^t\[.*\]$", val):         # parse instance of
T enum
+        return T[val[2:-1]]
     else:
         return val
 
@@ -209,7 +213,9 @@ def _translate(traversal):
     replaced = regex_is.sub(r"\1is_(", replaced)
     replaced = regex_not.sub(r"\1not_(", replaced)
     replaced = regex_or.sub(r"\1or_(", replaced)
-    return regex_in.sub(r"\1in_(", replaced)
+    replaced = regex_in.sub(r"\1in_(", replaced)
+    replaced = regex_true.sub(r"True", replaced)
+    return regex_false.sub(r"False", replaced)
 
 
 def _make_traversal(g, traversal_string, params):

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0b94b507/gremlin-test/features/map/ValueMap.feature
----------------------------------------------------------------------
diff --git a/gremlin-test/features/map/ValueMap.feature b/gremlin-test/features/map/ValueMap.feature
index 2390512..0860b15 100644
--- a/gremlin-test/features/map/ValueMap.feature
+++ b/gremlin-test/features/map/ValueMap.feature
@@ -33,6 +33,22 @@ Feature: Step - valueMap()
       | m[{"name": ["lop"], "lang": ["java"]}] |
       | m[{"name": ["ripple"], "lang": ["java"]}] |
 
+  Scenario: g_V_valueMapXtrueX
+    Given the modern graph
+    And the traversal of
+      """
+      g.V().valueMap(true)
+      """
+    When iterated to list
+    Then the result should be unordered
+      | result |
+      | m[{"id": "v[marko].id", "label": "person", "name": ["marko"], "age": [29]}] |
+      | m[{"id": "v[josh].id", "label": "person", "name": ["josh"], "age": [32]}] |
+      | m[{"id": "v[peter].id", "label": "person", "name": ["peter"], "age": [35]}] |
+      | m[{"id": "v[vadas].id", "label": "person", "name": ["vadas"], "age": [27]}] |
+      | m[{"id": "v[lop].id", "label": "software", "name": ["lop"], "lang": ["java"]}] |
+      | m[{"id": "v[ripple].id", "label": "software", "name": ["ripple"], "lang": ["java"]}]
|
+
   Scenario: g_V_valueMapXname_ageX
     Given the modern graph
     And the traversal of
@@ -49,6 +65,22 @@ Feature: Step - valueMap()
       | m[{"name": ["lop"]}] |
       | m[{"name": ["ripple"]}] |
 
+  Scenario: g_V_valueMapXtrue_name_ageX
+    Given the modern graph
+    And the traversal of
+      """
+      g.V().valueMap(true, "name", "age")
+      """
+    When iterated to list
+    Then the result should be unordered
+      | result |
+      | m[{"id": "v[marko].id", "label": "person", "name": ["marko"], "age": [29]}] |
+      | m[{"id": "v[josh].id", "label": "person", "name": ["josh"], "age": [32]}] |
+      | m[{"id": "v[peter].id", "label": "person", "name": ["peter"], "age": [35]}] |
+      | m[{"id": "v[vadas].id", "label": "person", "name": ["vadas"], "age": [27]}] |
+      | m[{"id": "v[lop].id", "label": "software", "name": ["lop"]}] |
+      | m[{"id": "v[ripple].id", "label": "software", "name": ["ripple"]}] |
+
   Scenario: g_VX1X_outXcreatedX_valueMap
     Given the modern graph
     And using the parameter v1Id defined as "v[marko].id"

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0b94b507/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/ValueMapTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/ValueMapTest.java
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/ValueMapTest.java
index 0935945..d1f08ce 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/ValueMapTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/ValueMapTest.java
@@ -23,6 +23,7 @@ import org.apache.tinkerpop.gremlin.process.AbstractGremlinProcessTest;
 import org.apache.tinkerpop.gremlin.process.GremlinProcessRunner;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalEngine;
+import org.apache.tinkerpop.gremlin.structure.T;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -31,6 +32,7 @@ import java.util.List;
 import java.util.Map;
 
 import static org.apache.tinkerpop.gremlin.LoadGraphWith.GraphData.MODERN;
+import static org.hamcrest.core.Is.is;
 import static org.junit.Assert.*;
 
 /**
@@ -42,8 +44,12 @@ public abstract class ValueMapTest extends AbstractGremlinProcessTest {
 
     public abstract Traversal<Vertex, Map<String, List>> get_g_V_valueMap();
 
+    public abstract Traversal<Vertex, Map<String, Object>> get_g_V_valueMapXtrueX();
+
     public abstract Traversal<Vertex, Map<String, List>> get_g_V_valueMapXname_ageX();
 
+    public abstract Traversal<Vertex, Map<String, Object>> get_g_V_valueMapXtrue_name_ageX();
+
     public abstract Traversal<Vertex, Map<String, List<String>>> get_g_VX1X_outXcreatedX_valueMap(final
Object v1Id);
 
     @Test
@@ -78,6 +84,43 @@ public abstract class ValueMapTest extends AbstractGremlinProcessTest {
 
     @Test
     @LoadGraphWith(MODERN)
+    public void g_V_valueMapXtrueX() {
+        final Traversal<Vertex, Map<String, Object>> traversal = get_g_V_valueMapXtrueX();
+        printTraversalForm(traversal);
+        int counter = 0;
+        while (traversal.hasNext()) {
+            counter++;
+            final Map<String, Object> values = traversal.next();
+            final String name = (String) ((List) values.get("name")).get(0);
+            assertEquals(4, values.size());
+            assertThat(values.containsKey(T.id), is(true));
+            if (name.equals("marko")) {
+                assertEquals(29, ((List) values.get("age")).get(0));
+                assertEquals("person", values.get(T.label));
+            } else if (name.equals("josh")) {
+                assertEquals(32, ((List) values.get("age")).get(0));
+                assertEquals("person", values.get(T.label));
+            } else if (name.equals("peter")) {
+                assertEquals(35, ((List) values.get("age")).get(0));
+                assertEquals("person", values.get(T.label));
+            } else if (name.equals("vadas")) {
+                assertEquals(27, ((List) values.get("age")).get(0));
+                assertEquals("person", values.get(T.label));
+            } else if (name.equals("lop")) {
+                assertEquals("java", ((List) values.get("lang")).get(0));
+                assertEquals("software", values.get(T.label));
+            } else if (name.equals("ripple")) {
+                assertEquals("java", ((List) values.get("lang")).get(0));
+                assertEquals("software", values.get(T.label));
+            } else {
+                throw new IllegalStateException("It is not possible to reach here: " + values);
+            }
+        }
+        assertEquals(6, counter);
+    }
+
+    @Test
+    @LoadGraphWith(MODERN)
     public void g_V_valueMapXname_ageX() {
         final Traversal<Vertex, Map<String, List>> traversal = get_g_V_valueMapXname_ageX();
         printTraversalForm(traversal);
@@ -113,6 +156,48 @@ public abstract class ValueMapTest extends AbstractGremlinProcessTest
{
 
     @Test
     @LoadGraphWith(MODERN)
+    public void g_V_valueMapXtrue_name_ageX() {
+        final Traversal<Vertex, Map<String, Object>> traversal = get_g_V_valueMapXtrue_name_ageX();
+        printTraversalForm(traversal);
+        int counter = 0;
+        while (traversal.hasNext()) {
+            counter++;
+            final Map<String, Object> values = traversal.next();
+            final String name = (String) ((List) values.get("name")).get(0);
+            assertThat(values.containsKey(T.id), is(true));
+            if (name.equals("marko")) {
+                assertEquals(4, values.size());
+                assertEquals(29, ((List) values.get("age")).get(0));
+                assertEquals("person", values.get(T.label));
+            } else if (name.equals("josh")) {
+                assertEquals(4, values.size());
+                assertEquals(32, ((List) values.get("age")).get(0));
+                assertEquals("person", values.get(T.label));
+            } else if (name.equals("peter")) {
+                assertEquals(4, values.size());
+                assertEquals(35, ((List) values.get("age")).get(0));
+                assertEquals("person", values.get(T.label));
+            } else if (name.equals("vadas")) {
+                assertEquals(4, values.size());
+                assertEquals(27, ((List) values.get("age")).get(0));
+                assertEquals("person", values.get(T.label));
+            } else if (name.equals("lop")) {
+                assertEquals(3, values.size());
+                assertNull(values.get("lang"));
+                assertEquals("software", values.get(T.label));
+            } else if (name.equals("ripple")) {
+                assertEquals(3, values.size());
+                assertNull(values.get("lang"));
+                assertEquals("software", values.get(T.label));
+            } else {
+                throw new IllegalStateException("It is not possible to reach here: " + values);
+            }
+        }
+        assertEquals(6, counter);
+    }
+
+    @Test
+    @LoadGraphWith(MODERN)
     public void g_VX1X_outXcreatedX_valueMap() {
         final Traversal<Vertex, Map<String, List<String>>> traversal =
get_g_VX1X_outXcreatedX_valueMap(convertToVertexId("marko"));
         printTraversalForm(traversal);
@@ -132,11 +217,21 @@ public abstract class ValueMapTest extends AbstractGremlinProcessTest
{
         }
 
         @Override
+        public Traversal<Vertex, Map<String, Object>> get_g_V_valueMapXtrueX()
{
+            return g.V().valueMap(true);
+        }
+
+        @Override
         public Traversal<Vertex, Map<String, List>> get_g_V_valueMapXname_ageX()
{
             return g.V().valueMap("name", "age");
         }
 
         @Override
+        public Traversal<Vertex, Map<String, Object>> get_g_V_valueMapXtrue_name_ageX()
{
+            return g.V().valueMap(true, "name", "age");
+        }
+
+        @Override
         public Traversal<Vertex, Map<String, List<String>>> get_g_VX1X_outXcreatedX_valueMap(final
Object v1Id) {
             return g.V(v1Id).out("created").valueMap();
         }


Mime
View raw message