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 2015/04/24 17:45:57 UTC

[11/31] incubator-tinkerpop git commit: validateEquality() methods moved to TestHelper.

validateEquality() methods moved to TestHelper.


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

Branch: refs/heads/master
Commit: ff3fa143e0a9eec00b1276e5e46ee611262890fb
Parents: ea5a489
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Thu Apr 23 16:18:19 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Thu Apr 23 16:18:19 2015 -0600

----------------------------------------------------------------------
 .../apache/tinkerpop/gremlin/TestHelper.java    | 97 ++++++++++++++++++++
 .../structure/util/star/StarGraphTest.java      | 95 +++----------------
 2 files changed, 112 insertions(+), 80 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/ff3fa143/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/TestHelper.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/TestHelper.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/TestHelper.java
index 8c08fc4..9ebc62c 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/TestHelper.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/TestHelper.java
@@ -18,11 +18,23 @@
  */
 package org.apache.tinkerpop.gremlin;
 
+import org.apache.tinkerpop.gremlin.structure.Direction;
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Property;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
+
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
+import java.util.Iterator;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 
 /**
  * @author Stephen Mallette (http://stephen.genoprime.com)
@@ -89,4 +101,89 @@ public final class TestHelper {
             throw new IllegalStateException("Path segment " + toClean + " has not valid characters and is thus empty");
         return cleaned;
     }
+
+
+    ///////////////
+
+    public static void validateVertexEquality(final Vertex originalVertex, final Vertex otherVertex) {
+        assertEquals(originalVertex, otherVertex);
+        assertEquals(otherVertex, originalVertex);
+        assertEquals(originalVertex.id(), otherVertex.id());
+        assertEquals(originalVertex.label(), otherVertex.label());
+        assertEquals(originalVertex.keys().size(), otherVertex.keys().size());
+        for (final String key : originalVertex.keys()) {
+            final List<VertexProperty<Object>> originalVertexProperties = IteratorUtils.list(originalVertex.properties(key));
+            final List<VertexProperty<Object>> otherVertexProperties = IteratorUtils.list(otherVertex.properties(key));
+            assertEquals(originalVertexProperties.size(), otherVertexProperties.size());
+            for (VertexProperty<Object> originalVertexProperty : originalVertexProperties) {
+                final VertexProperty<Object> otherVertexProperty = otherVertexProperties.parallelStream().filter(vp -> vp.equals(originalVertexProperty)).findAny().get();
+                validateVertexPropertyEquality(originalVertexProperty, otherVertexProperty);
+            }
+        }
+
+        Iterator<Edge> originalEdges = IteratorUtils.set(originalVertex.edges(Direction.OUT)).iterator();
+        Iterator<Edge> otherEdges = IteratorUtils.set(otherVertex.edges(Direction.OUT)).iterator();
+        while (originalEdges.hasNext()) {
+            validateEdgeEquality(originalEdges.next(), otherEdges.next());
+        }
+        assertFalse(otherEdges.hasNext());
+
+        originalEdges = IteratorUtils.set(originalVertex.edges(Direction.IN)).iterator();
+        otherEdges = IteratorUtils.set(otherVertex.edges(Direction.IN)).iterator();
+        while (originalEdges.hasNext()) {
+            validateEdgeEquality(originalEdges.next(), otherEdges.next());
+        }
+        assertFalse(otherEdges.hasNext());
+
+    }
+
+    public static void validateVertexPropertyEquality(final VertexProperty originalVertexProperty, final VertexProperty otherVertexProperty) {
+        assertEquals(originalVertexProperty, otherVertexProperty);
+        assertEquals(otherVertexProperty, originalVertexProperty);
+        if (originalVertexProperty.isPresent()) {
+            assertEquals(originalVertexProperty.key(), otherVertexProperty.key());
+            assertEquals(originalVertexProperty.value(), otherVertexProperty.value());
+            assertEquals(originalVertexProperty.element(), otherVertexProperty.element());
+            assertEquals(originalVertexProperty.keys().size(), otherVertexProperty.keys().size());
+            for (final String key : originalVertexProperty.keys()) {
+                validatePropertyEquality(originalVertexProperty.property(key), otherVertexProperty.property(key));
+            }
+        }
+    }
+
+    public static void validatePropertyEquality(final Property originalProperty, final Property otherProperty) {
+        assertEquals(originalProperty, otherProperty);
+        assertEquals(otherProperty, originalProperty);
+        if (originalProperty.isPresent()) {
+            assertEquals(originalProperty.key(), otherProperty.key());
+            assertEquals(originalProperty.value(), otherProperty.value());
+            assertEquals(originalProperty.element(), otherProperty.element());
+        }
+    }
+
+    public static void validateEdgeEquality(final Edge originalEdge, final Edge otherEdge) {
+        assertEquals(originalEdge, otherEdge);
+        assertEquals(otherEdge, originalEdge);
+        assertEquals(originalEdge.id(), otherEdge.id());
+        assertEquals(originalEdge.label(), otherEdge.label());
+        assertEquals(originalEdge.inVertex(), otherEdge.inVertex());
+        assertEquals(originalEdge.outVertex(), otherEdge.outVertex());
+        assertEquals(originalEdge.keys().size(), otherEdge.keys().size());
+        for (final String key : originalEdge.keys()) {
+            validatePropertyEquality(originalEdge.property(key), otherEdge.property(key));
+        }
+    }
+
+    public static void validateEquality(final Object original, final Object other) {
+        if (original instanceof Vertex)
+            validateVertexEquality((Vertex) original, (Vertex) other);
+        else if (original instanceof VertexProperty)
+            validateVertexPropertyEquality((VertexProperty) original, (VertexProperty) other);
+        else if (original instanceof Edge)
+            validateEdgeEquality((Edge) original, (Edge) other);
+        else if (original instanceof Property)
+            validatePropertyEquality((Property) original, (Property) other);
+        else
+            throw new IllegalArgumentException("The provided object must be a graph object: " + original.getClass().getCanonicalName());
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/ff3fa143/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphTest.java
index abc388b..4aa769d 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphTest.java
@@ -24,6 +24,7 @@ package org.apache.tinkerpop.gremlin.structure.util.star;
 import org.apache.tinkerpop.gremlin.AbstractGremlinTest;
 import org.apache.tinkerpop.gremlin.FeatureRequirement;
 import org.apache.tinkerpop.gremlin.LoadGraphWith;
+import org.apache.tinkerpop.gremlin.TestHelper;
 import org.apache.tinkerpop.gremlin.structure.Direction;
 import org.apache.tinkerpop.gremlin.structure.Edge;
 import org.apache.tinkerpop.gremlin.structure.Graph;
@@ -33,7 +34,6 @@ import org.apache.tinkerpop.gremlin.structure.VertexProperty;
 import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoReader;
 import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoWriter;
 import org.apache.tinkerpop.gremlin.structure.util.Attachable;
-import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
 import org.javatuples.Pair;
 import org.junit.Test;
 
@@ -41,8 +41,6 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
 import java.util.Random;
 import java.util.Set;
 import java.util.UUID;
@@ -81,30 +79,30 @@ public class StarGraphTest extends AbstractGremlinTest {
     @Test
     @LoadGraphWith(LoadGraphWith.GraphData.CREW)
     public void originalAndStarVerticesShouldHaveTheSameTopology() {
-        g.V().forEachRemaining(vertex -> validateVertex(vertex, StarGraph.of(vertex).getStarVertex()));
+        g.V().forEachRemaining(vertex -> TestHelper.validateEquality(vertex, StarGraph.of(vertex).getStarVertex()));
     }
 
     @Test
     @LoadGraphWith(LoadGraphWith.GraphData.CREW)
     public void shouldSerializeCorrectlyUsingGryo() {
-        g.V().forEachRemaining(vertex -> validateVertex(vertex, serializeDeserialize(StarGraph.of(vertex)).getValue0().getStarVertex()));
+        g.V().forEachRemaining(vertex -> TestHelper.validateEquality(vertex, serializeDeserialize(StarGraph.of(vertex)).getValue0().getStarVertex()));
     }
 
     @Test
     @LoadGraphWith(LoadGraphWith.GraphData.CREW)
     public void testAttachableGetMethod() {
         // vertex host
-        g.V().forEachRemaining(vertex -> StarGraph.of(vertex).getStarVertex().properties().forEachRemaining(vertexProperty -> validateVertexProperty(vertexProperty, ((Attachable<VertexProperty>) vertexProperty).attach(vertex, Attachable.Method.GET))));
-        g.V().forEachRemaining(vertex -> StarGraph.of(vertex).getStarVertex().properties().forEachRemaining(vertexProperty -> vertexProperty.properties().forEachRemaining(property -> validateProperty(property, ((Attachable<Property>) property).attach(vertex, Attachable.Method.GET)))));
-        g.V().forEachRemaining(vertex -> StarGraph.of(vertex).getStarVertex().edges(Direction.OUT).forEachRemaining(edge -> validateEdge(edge, ((Attachable<Edge>) edge).attach(vertex, Attachable.Method.GET))));
-        g.V().forEachRemaining(vertex -> StarGraph.of(vertex).getStarVertex().edges(Direction.OUT).forEachRemaining(edge -> edge.properties().forEachRemaining(property -> validateProperty(property, ((Attachable<Property>) property).attach(vertex, Attachable.Method.GET)))));
+        g.V().forEachRemaining(vertex -> StarGraph.of(vertex).getStarVertex().properties().forEachRemaining(vertexProperty -> TestHelper.validateEquality(vertexProperty, ((Attachable<VertexProperty>) vertexProperty).attach(vertex, Attachable.Method.GET))));
+        g.V().forEachRemaining(vertex -> StarGraph.of(vertex).getStarVertex().properties().forEachRemaining(vertexProperty -> vertexProperty.properties().forEachRemaining(property -> TestHelper.validateEquality(property, ((Attachable<Property>) property).attach(vertex, Attachable.Method.GET)))));
+        g.V().forEachRemaining(vertex -> StarGraph.of(vertex).getStarVertex().edges(Direction.OUT).forEachRemaining(edge -> TestHelper.validateEquality(edge, ((Attachable<Edge>) edge).attach(vertex, Attachable.Method.GET))));
+        g.V().forEachRemaining(vertex -> StarGraph.of(vertex).getStarVertex().edges(Direction.OUT).forEachRemaining(edge -> edge.properties().forEachRemaining(property -> TestHelper.validateEquality(property, ((Attachable<Property>) property).attach(vertex, Attachable.Method.GET)))));
 
         // graph host
-        g.V().forEachRemaining(vertex -> validateVertex(vertex, StarGraph.of(vertex).getStarVertex().attach(graph, Attachable.Method.GET)));
-        g.V().forEachRemaining(vertex -> StarGraph.of(vertex).getStarVertex().properties().forEachRemaining(vertexProperty -> validateVertexProperty(vertexProperty, ((Attachable<VertexProperty>) vertexProperty).attach(graph, Attachable.Method.GET))));
-        g.V().forEachRemaining(vertex -> StarGraph.of(vertex).getStarVertex().properties().forEachRemaining(vertexProperty -> vertexProperty.properties().forEachRemaining(property -> validateProperty(property, ((Attachable<Property>) property).attach(graph, Attachable.Method.GET)))));
-        g.V().forEachRemaining(vertex -> StarGraph.of(vertex).getStarVertex().edges(Direction.OUT).forEachRemaining(edge -> validateEdge(edge, ((Attachable<Edge>) edge).attach(graph, Attachable.Method.GET))));
-        g.V().forEachRemaining(vertex -> StarGraph.of(vertex).getStarVertex().edges(Direction.OUT).forEachRemaining(edge -> edge.properties().forEachRemaining(property -> validateProperty(property, ((Attachable<Property>) property).attach(graph, Attachable.Method.GET)))));
+        g.V().forEachRemaining(vertex -> TestHelper.validateVertexEquality(vertex, StarGraph.of(vertex).getStarVertex().attach(graph, Attachable.Method.GET)));
+        g.V().forEachRemaining(vertex -> StarGraph.of(vertex).getStarVertex().properties().forEachRemaining(vertexProperty -> TestHelper.validateEquality(vertexProperty, ((Attachable<VertexProperty>) vertexProperty).attach(graph, Attachable.Method.GET))));
+        g.V().forEachRemaining(vertex -> StarGraph.of(vertex).getStarVertex().properties().forEachRemaining(vertexProperty -> vertexProperty.properties().forEachRemaining(property -> TestHelper.validateEquality(property, ((Attachable<Property>) property).attach(graph, Attachable.Method.GET)))));
+        g.V().forEachRemaining(vertex -> StarGraph.of(vertex).getStarVertex().edges(Direction.OUT).forEachRemaining(edge -> TestHelper.validateEquality(edge, ((Attachable<Edge>) edge).attach(graph, Attachable.Method.GET))));
+        g.V().forEachRemaining(vertex -> StarGraph.of(vertex).getStarVertex().edges(Direction.OUT).forEachRemaining(edge -> edge.properties().forEachRemaining(property -> TestHelper.validateEquality(property, ((Attachable<Property>) property).attach(graph, Attachable.Method.GET)))));
     }
 
     @Test
@@ -130,17 +128,17 @@ public class StarGraphTest extends AbstractGremlinTest {
         ///////////////
         Pair<StarGraph, Integer> pair = serializeDeserialize(StarGraph.of(vertex));
         int starGraphSize = pair.getValue1();
-        validateVertex(vertex, pair.getValue0().getStarVertex());
+        TestHelper.validateEquality(vertex, pair.getValue0().getStarVertex());
         ///
         pair = serializeDeserialize(pair.getValue0());
         assertEquals(starGraphSize, pair.getValue1().intValue());
         starGraphSize = pair.getValue1();
-        validateVertex(vertex, pair.getValue0().getStarVertex());
+        TestHelper.validateEquality(vertex, pair.getValue0().getStarVertex());
         ///
         pair = serializeDeserialize(pair.getValue0());
         assertEquals(starGraphSize, pair.getValue1().intValue());
         starGraphSize = pair.getValue1();
-        validateVertex(vertex, pair.getValue0().getStarVertex());
+        TestHelper.validateEquality(vertex, pair.getValue0().getStarVertex());
         ///
         final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
         GryoWriter.build().create().writeVertex(outputStream, vertex, Direction.BOTH);
@@ -152,69 +150,6 @@ public class StarGraphTest extends AbstractGremlinTest {
         System.out.println("Size reduction:            " + (float) detachedVertexSize / (float) starGraphSize);
     }
 
-    private void validateVertex(final Vertex originalVertex, final Vertex otherVertex) {
-        assertEquals(originalVertex, otherVertex);
-        assertEquals(otherVertex, originalVertex);
-        assertEquals(originalVertex.id(), otherVertex.id());
-        assertEquals(originalVertex.label(), otherVertex.label());
-        assertEquals(originalVertex.keys().size(), otherVertex.keys().size());
-        for (final String key : originalVertex.keys()) {
-            final List<VertexProperty<Object>> originalVertexProperties = IteratorUtils.list(originalVertex.properties(key));
-            final List<VertexProperty<Object>> otherVertexProperties = IteratorUtils.list(otherVertex.properties(key));
-            assertEquals(originalVertexProperties.size(), otherVertexProperties.size());
-            for (VertexProperty<Object> originalVertexProperty : originalVertexProperties) {
-                final VertexProperty<Object> otherVertexProperty = otherVertexProperties.parallelStream().filter(vp -> vp.equals(originalVertexProperty)).findAny().get();
-                validateVertexProperty(originalVertexProperty, otherVertexProperty);
-            }
-        }
-
-        Iterator<Edge> originalEdges = IteratorUtils.set(originalVertex.edges(Direction.OUT)).iterator();
-        Iterator<Edge> otherEdges = IteratorUtils.set(otherVertex.edges(Direction.OUT)).iterator();
-        while (originalEdges.hasNext()) {
-            validateEdge(originalEdges.next(), otherEdges.next());
-        }
-        assertFalse(otherEdges.hasNext());
-
-        originalEdges = IteratorUtils.set(originalVertex.edges(Direction.IN)).iterator();
-        otherEdges = IteratorUtils.set(otherVertex.edges(Direction.IN)).iterator();
-        while (originalEdges.hasNext()) {
-            validateEdge(originalEdges.next(), otherEdges.next());
-        }
-        assertFalse(otherEdges.hasNext());
-
-    }
 
-    private static void validateVertexProperty(final VertexProperty originalVertexProperty, final VertexProperty otherVertexProperty) {
-        assertEquals(originalVertexProperty.isPresent(), otherVertexProperty.isPresent());
-        if (originalVertexProperty.isPresent()) {
-            assertEquals(originalVertexProperty.key(), otherVertexProperty.key());
-            assertEquals(originalVertexProperty.value(), otherVertexProperty.value());
-            assertEquals(originalVertexProperty.element(), otherVertexProperty.element());
-            assertEquals(originalVertexProperty.keys().size(), otherVertexProperty.keys().size());
-            for (final String key : originalVertexProperty.keys()) {
-                validateProperty(originalVertexProperty.property(key), otherVertexProperty.property(key));
-            }
-        }
-    }
-
-    private static void validateProperty(final Property originalProperty, final Property otherProperty) {
-        assertEquals(originalProperty.isPresent(), otherProperty.isPresent());
-        if (originalProperty.isPresent()) {
-            assertEquals(originalProperty.key(), otherProperty.key());
-            assertEquals(originalProperty.value(), otherProperty.value());
-            assertEquals(originalProperty.element(), otherProperty.element());
-        }
-    }
-
-    private static void validateEdge(final Edge originalEdge, final Edge otherEdge) {
-        assertEquals(originalEdge.id(), otherEdge.id());
-        assertEquals(originalEdge.label(), otherEdge.label());
-        assertEquals(originalEdge.inVertex(), otherEdge.inVertex());
-        assertEquals(originalEdge.outVertex(), otherEdge.outVertex());
-        assertEquals(originalEdge.keys().size(), otherEdge.keys().size());
-        for (final String key : originalEdge.keys()) {
-            validateProperty(originalEdge.property(key), otherEdge.property(key));
-        }
-    }
 
 }