tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ok...@apache.org
Subject [02/11] tinkerpop git commit: added test cases that verify that nested collection detachment works for Lists, Sets, and Maps (and any arbitrary nest of those collections within themselves).
Date Fri, 30 Jun 2017 15:33:08 GMT
added test cases that verify that nested collection detachment works for Lists, Sets, and Maps
(and any arbitrary nest of those collections within themselves).


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

Branch: refs/heads/master
Commit: d16d0df5c64f6da04c6a11c9403273f30eb264d4
Parents: 6e2ebb5
Author: Marko A. Rodriguez <okrammarko@gmail.com>
Authored: Tue Jun 27 14:14:22 2017 -0600
Committer: Marko A. Rodriguez <okrammarko@gmail.com>
Committed: Tue Jun 27 14:14:22 2017 -0600

----------------------------------------------------------------------
 .../util/detached/DetachedVertexTest.java       | 49 ++++++++++++++++++
 .../util/reference/ReferenceVertexTest.java     | 53 ++++++++++++++++++++
 2 files changed, 102 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d16d0df5/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertexTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertexTest.java
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertexTest.java
index 582b9a5..93cb46f 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertexTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertexTest.java
@@ -22,6 +22,7 @@ import org.apache.tinkerpop.gremlin.AbstractGremlinTest;
 import org.apache.tinkerpop.gremlin.FeatureRequirement;
 import org.apache.tinkerpop.gremlin.FeatureRequirementSet;
 import org.apache.tinkerpop.gremlin.LoadGraphWith;
+import org.apache.tinkerpop.gremlin.structure.Edge;
 import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.apache.tinkerpop.gremlin.structure.VertexProperty;
@@ -39,6 +40,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.inE;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertSame;
@@ -325,4 +327,51 @@ public class DetachedVertexTest extends AbstractGremlinTest {
         });
         assertEquals(1, dogTimes.get());
     }
+
+    @Test
+    @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
+    @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
+    public void shouldDetachCollections() {
+        // single element
+        final Vertex vertex = DetachedFactory.detach(g.V().has("name", "marko").next(), true);
+        assertTrue(vertex instanceof DetachedVertex);
+        // list nest
+        final List<Vertex> vertices = DetachedFactory.detach(g.V().hasLabel("software").fold().next(),
true);
+        for (final Vertex v : vertices) {
+            assertTrue(v instanceof DetachedVertex);
+            assertEquals("java", v.value("lang"));
+        }
+        // double nested list
+        final List<List<Vertex>> lists = DetachedFactory.detach(g.V().hasLabel("software").fold().fold().next(),
true);
+        for (final Vertex v : lists.get(0)) {
+            assertTrue(v instanceof DetachedVertex);
+            assertEquals("java", v.value("lang"));
+        }
+        // double nested list to set
+        final Set<List<Vertex>> set = DetachedFactory.detach(g.V().hasLabel("software").fold().toSet(),
true);
+        for (final Vertex v : set.iterator().next()) {
+            assertTrue(v instanceof DetachedVertex);
+            assertEquals("java", v.value("lang"));
+        }
+        // map keys and values
+        Map<Vertex, List<Edge>> map = DetachedFactory.detach(g.V().hasLabel("software").group().by().by(inE().fold()).next(),
true);
+        for (final Map.Entry<Vertex, List<Edge>> entry : map.entrySet()) {
+            assertTrue(entry.getKey() instanceof DetachedVertex);
+            assertEquals("java", entry.getKey().value("lang"));
+            for (final Edge edge : entry.getValue()) {
+                assertTrue(edge instanceof DetachedEdge);
+                assertTrue(edge.property("weight").isPresent());
+            }
+        }
+        // map keys and values as sideEffect
+        map = DetachedFactory.detach(g.V().hasLabel("software").group("m").by().by(inE().fold()).identity().cap("m").next(),
true);
+        for (final Map.Entry<Vertex, List<Edge>> entry : map.entrySet()) {
+            assertTrue(entry.getKey() instanceof DetachedVertex);
+            assertEquals("java", entry.getKey().value("lang"));
+            for (final Edge edge : entry.getValue()) {
+                assertTrue(edge instanceof DetachedEdge);
+                assertTrue(edge.property("weight").isPresent());
+            }
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d16d0df5/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceVertexTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceVertexTest.java
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceVertexTest.java
index 76564a703..4f7f1da 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceVertexTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceVertexTest.java
@@ -23,17 +23,23 @@ import org.apache.tinkerpop.gremlin.FeatureRequirement;
 import org.apache.tinkerpop.gremlin.FeatureRequirementSet;
 import org.apache.tinkerpop.gremlin.LoadGraphWith;
 import org.apache.tinkerpop.gremlin.structure.Direction;
+import org.apache.tinkerpop.gremlin.structure.Edge;
 import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.apache.tinkerpop.gremlin.structure.VertexProperty;
 import org.apache.tinkerpop.gremlin.structure.util.Attachable;
+import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedEdge;
 import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedFactory;
+import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex;
 import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
 import org.junit.Test;
 
 import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.inE;
 import static org.junit.Assert.*;
 
 /**
@@ -171,4 +177,51 @@ public class ReferenceVertexTest extends AbstractGremlinTest {
         final ReferenceVertex rv = ReferenceFactory.detach(g.V(convertToVertexId("marko")).next());
         assertFalse(rv.vertices(Direction.BOTH).hasNext());
     }
+
+    @Test
+    @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
+    @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
+    public void shouldDetachCollections() {
+        // single element
+        final Vertex vertex = ReferenceFactory.detach(g.V().has("name", "marko").next());
+        assertTrue(vertex instanceof ReferenceVertex);
+        // list nest
+        final List<Vertex> vertices = ReferenceFactory.detach(g.V().hasLabel("software").fold().next());
+        for (final Vertex v : vertices) {
+            assertTrue(v instanceof ReferenceVertex);
+            assertEquals("java", v.value("lang"));
+        }
+        // double nested list
+        final List<List<Vertex>> lists = ReferenceFactory.detach(g.V().hasLabel("software").fold().fold().next());
+        for (final Vertex v : lists.get(0)) {
+            assertTrue(v instanceof ReferenceVertex);
+            assertEquals("java", v.value("lang"));
+        }
+        // double nested list to set
+        final Set<List<Vertex>> set = ReferenceFactory.detach(g.V().hasLabel("software").fold().toSet());
+        for (final Vertex v : set.iterator().next()) {
+            assertTrue(v instanceof ReferenceVertex);
+            assertEquals("java", v.value("lang"));
+        }
+        // map keys and values
+        Map<Vertex, List<Edge>> map = ReferenceFactory.detach(g.V().hasLabel("software").group().by().by(inE().fold()).next());
+        for (final Map.Entry<Vertex, List<Edge>> entry : map.entrySet()) {
+            assertTrue(entry.getKey() instanceof ReferenceVertex);
+            assertEquals("java", entry.getKey().value("lang"));
+            for (final Edge edge : entry.getValue()) {
+                assertTrue(edge instanceof ReferenceEdge);
+                assertTrue(edge.property("weight").isPresent());
+            }
+        }
+        // map keys and values as sideEffect
+        map = ReferenceFactory.detach(g.V().hasLabel("software").group("m").by().by(inE().fold()).identity().cap("m").next());
+        for (final Map.Entry<Vertex, List<Edge>> entry : map.entrySet()) {
+            assertTrue(entry.getKey() instanceof ReferenceVertex);
+            assertEquals("java", entry.getKey().value("lang"));
+            for (final Edge edge : entry.getValue()) {
+                assertTrue(edge instanceof ReferenceEdge);
+                assertTrue(edge.property("weight").isPresent());
+            }
+        }
+    }
 }


Mime
View raw message