You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by ok...@apache.org on 2015/04/09 21:03:06 UTC

incubator-tinkerpop git commit: added ReferenceEdgeTest... clean and consistent.

Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/master e09e229f3 -> 2e9d34644


added ReferenceEdgeTest... clean and consistent.


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

Branch: refs/heads/master
Commit: 2e9d3464409518560d7020d63acdc8cddc69ff32
Parents: e09e229
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Thu Apr 9 13:03:21 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Thu Apr 9 13:03:21 2015 -0600

----------------------------------------------------------------------
 .../structure/StructureStandardSuite.java       |   6 +-
 .../util/reference/ReferenceEdgeTest.java       | 136 +++++++++++++++++++
 .../util/reference/ReferenceVertexTest.java     |   3 +-
 .../structure/util/star/StarGraphTest.java      |  31 ++++-
 4 files changed, 171 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/2e9d3464/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/StructureStandardSuite.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/StructureStandardSuite.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/StructureStandardSuite.java
index 10645df..1b65447 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/StructureStandardSuite.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/StructureStandardSuite.java
@@ -25,6 +25,7 @@ import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedEdgeTest;
 import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedPropertyTest;
 import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertexPropertyTest;
 import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertexTest;
+import org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceEdgeTest;
 import org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceVertexTest;
 import org.apache.tinkerpop.gremlin.structure.util.star.StarGraphTest;
 import org.junit.runners.model.InitializationError;
@@ -46,6 +47,8 @@ import java.util.stream.Stream;
  * "Suite" implements {@link org.apache.tinkerpop.gremlin.GraphProvider} as a convenience only. It could be implemented in a
  * separate class file):
  * <code>
+ *
+ * @author Stephen Mallette (http://stephen.genoprime.com)
  * @RunWith(StructureStandardSuite.class)
  * @StructureStandardSuite.GraphProviderClass(TinkerGraphStructureStandardTest.class) public class TinkerGraphStructureStandardTest implements GraphProvider {
  * }
@@ -58,8 +61,6 @@ import java.util.stream.Stream;
  * Set the {@code gremlin.structure.tests} environment variable to a comma separated list of test classes to execute.
  * This setting can be helpful to restrict execution of tests to specific ones being focused on during development.
  * <br/>
- *
- * @author Stephen Mallette (http://stephen.genoprime.com)
  */
 public class StructureStandardSuite extends AbstractGremlinSuite {
 
@@ -79,6 +80,7 @@ public class StructureStandardSuite extends AbstractGremlinSuite {
             VertexPropertyTest.class,
             VariablesTest.class,
             PropertyTest.class,
+            ReferenceEdgeTest.class,
             ReferenceVertexTest.class,
             SerializationTest.class,
             StarGraphTest.class,

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/2e9d3464/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceEdgeTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceEdgeTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceEdgeTest.java
new file mode 100644
index 0000000..9857fa0
--- /dev/null
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceEdgeTest.java
@@ -0,0 +1,136 @@
+/*
+ *
+ *  * 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.util.reference;
+
+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.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.util.detached.DetachedFactory;
+import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class ReferenceEdgeTest extends AbstractGremlinTest {
+
+    @Test
+    @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
+    public void shouldNotConstructNewWithSomethingAlreadyReferenced() {
+        final Vertex v = graph.addVertex();
+        final Edge e = v.addEdge("test", v);
+        final ReferenceEdge re = ReferenceFactory.detach(e);
+        assertSame(re, ReferenceFactory.detach(re));
+    }
+
+    @Test
+    @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
+    @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
+    @FeatureRequirement(featureClass = Graph.Features.EdgePropertyFeatures.class, feature = Graph.Features.EdgePropertyFeatures.FEATURE_DOUBLE_VALUES)
+    public void shouldConstructReferenceEdge() {
+        g.E(convertToEdgeId("marko", "knows", "vadas")).next().property("year", 2002);
+        final ReferenceEdge referenceEdge = ReferenceFactory.detach(g.E(convertToEdgeId("marko", "knows", "vadas")).next());
+        assertEquals(convertToEdgeId("marko", "knows", "vadas"), referenceEdge.id());
+        assertEquals(0, IteratorUtils.count(referenceEdge.properties()));
+        assertEquals(0, IteratorUtils.count(referenceEdge.vertices(Direction.BOTH)));
+    }
+
+    @Test
+    @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
+    public void shouldEvaluateToEqual() {
+        assertTrue(ReferenceFactory.detach(g.E(convertToEdgeId("josh", "created", "lop")).next()).equals(ReferenceFactory.detach(g.E(convertToEdgeId("josh", "created", "lop")).next())));
+        assertTrue(ReferenceFactory.detach(g.E(convertToEdgeId("josh", "created", "lop")).next()).equals(g.E(convertToEdgeId("josh", "created", "lop")).next()));
+        assertTrue(ReferenceFactory.detach(g.E(convertToEdgeId("josh", "created", "lop")).next()).equals(DetachedFactory.detach(g.E(convertToEdgeId("josh", "created", "lop")).next(), true)));
+        //
+        assertTrue(ReferenceFactory.detach(g.E(convertToEdgeId("josh", "created", "lop")).next()).equals(ReferenceFactory.detach(g.E(convertToEdgeId("josh", "created", "lop")).next())));
+        assertTrue(g.E(convertToEdgeId("josh", "created", "lop")).next().equals(ReferenceFactory.detach(g.E(convertToEdgeId("josh", "created", "lop")).next())));
+        assertTrue(DetachedFactory.detach(g.E(convertToEdgeId("josh", "created", "lop")).next(), true).equals(ReferenceFactory.detach(g.E(convertToEdgeId("josh", "created", "lop")).next())));
+    }
+
+    @Test
+    @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
+    public void shouldHaveSameHashCode() {
+        assertEquals(ReferenceFactory.detach(g.E(convertToEdgeId("josh", "created", "lop")).next()).hashCode(), ReferenceFactory.detach(g.E(convertToEdgeId("josh", "created", "lop")).next()).hashCode());
+        assertEquals(ReferenceFactory.detach(g.E(convertToEdgeId("josh", "created", "lop")).next()).hashCode(), g.E(convertToEdgeId("josh", "created", "lop")).next().hashCode());
+        assertEquals(ReferenceFactory.detach(g.E(convertToEdgeId("josh", "created", "lop")).next()).hashCode(), DetachedFactory.detach(g.E(convertToEdgeId("josh", "created", "lop")).next(), false).hashCode());
+    }
+
+    @Test
+    @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
+    public void shouldAttachToGraph() {
+        final Edge toReference = g.E(convertToEdgeId("josh", "created", "lop")).next();
+        final ReferenceEdge referenceEdge = ReferenceFactory.detach(toReference);
+        final Edge referenced = referenceEdge.attach(graph);
+
+        assertEquals(toReference, referenced);
+        assertFalse(referenced instanceof ReferenceEdge);
+    }
+
+    @Test
+    @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
+    public void shouldAttachToVertex() {
+        final Edge toReference = g.E(convertToEdgeId("josh", "created", "lop")).next();
+        final Vertex outV = toReference.vertices(Direction.OUT).next();
+        final ReferenceEdge detachedEdge = ReferenceFactory.detach(toReference);
+        final Edge attached = detachedEdge.attach(outV);
+
+        assertEquals(toReference, attached);
+        assertFalse(attached instanceof ReferenceEdge);
+    }
+
+    @Test
+    @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
+    @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
+    @FeatureRequirement(featureClass = Graph.Features.EdgePropertyFeatures.class, feature = Graph.Features.EdgePropertyFeatures.FEATURE_DOUBLE_VALUES)
+    public void shouldNotEvaluateToEqualDifferentId() {
+        final Object joshCreatedLopEdgeId = convertToEdgeId("josh", "created", "lop");
+        final Vertex vOut = g.V(convertToVertexId("josh")).next();
+        final Vertex vIn = g.V(convertToVertexId("lop")).next();
+        final Edge e = vOut.addEdge("created", vIn, "weight", 0.4d);
+        assertFalse(ReferenceFactory.detach(g.E(joshCreatedLopEdgeId).next()).equals(ReferenceFactory.detach(e)));
+    }
+
+    @Test(expected = IllegalStateException.class)
+    @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
+    public void shouldNotAllowSetProperty() {
+        final Vertex v = graph.addVertex();
+        final Edge e = v.addEdge("test", v);
+        final ReferenceEdge re = ReferenceFactory.detach(e);
+        re.property("test", "test");
+    }
+
+    @Test(expected = IllegalStateException.class)
+    @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
+    public void shouldNotAllowRemove() {
+        final Vertex v = graph.addVertex();
+        final Edge e = v.addEdge("test", v);
+        final ReferenceEdge re = ReferenceFactory.detach(e);
+        re.remove();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/2e9d3464/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 5250c39..f621fa7 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
@@ -63,12 +63,13 @@ public class ReferenceVertexTest extends AbstractGremlinTest {
     public void shouldEvaluateToEqualForVerticesAndDetachments() {
         assertTrue(ReferenceFactory.detach(g.V(convertToVertexId("marko")).next()).equals(ReferenceFactory.detach(g.V(convertToVertexId("marko")).next())));
         assertTrue(ReferenceFactory.detach(g.V(convertToVertexId("marko")).next()).equals(g.V(convertToVertexId("marko")).next()));
+        assertTrue(ReferenceFactory.detach(g.V(convertToVertexId("marko")).next()).equals(DetachedFactory.detach(g.V(convertToVertexId("marko")).next(), true)));
         assertTrue(ReferenceFactory.detach(g.V(convertToVertexId("marko")).next()).equals(DetachedFactory.detach(g.V(convertToVertexId("marko")).next(), false)));
         // reverse
         assertTrue(ReferenceFactory.detach(g.V(convertToVertexId("marko")).next().equals(ReferenceFactory.detach(g.V(convertToVertexId("marko")).next()))));
         assertTrue(g.V(convertToVertexId("marko")).next().equals(ReferenceFactory.detach(g.V(convertToVertexId("marko")).next())));
+        assertTrue(DetachedFactory.detach(g.V(convertToVertexId("marko")).next(), true).equals(ReferenceFactory.detach(g.V(convertToVertexId("marko")).next())));
         assertTrue(DetachedFactory.detach(g.V(convertToVertexId("marko")).next(), false).equals(ReferenceFactory.detach(g.V(convertToVertexId("marko")).next())));
-
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/2e9d3464/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 d50d9ee..eedde68 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
@@ -101,7 +101,7 @@ public class StarGraphTest extends AbstractGremlinTest {
         final AtomicInteger originalPropertyCounter = new AtomicInteger(0);
         final AtomicInteger starCounter = new AtomicInteger(0);
         matthias.properties().forEachRemaining(vertexProperty -> {
-            starCounter.incrementAndGet();
+            originalCounter.incrementAndGet();
             matthiasStar.properties(vertexProperty.label()).forEachRemaining(starVertexProperty -> {
                 if (starVertexProperty.equals(vertexProperty)) {
                     assertEquals(starVertexProperty.id(), vertexProperty.id());
@@ -109,7 +109,7 @@ public class StarGraphTest extends AbstractGremlinTest {
                     assertEquals(starVertexProperty.value(), vertexProperty.value());
                     assertEquals(starVertexProperty.key(), vertexProperty.key());
                     assertEquals(starVertexProperty.element(), vertexProperty.element());
-                    originalCounter.incrementAndGet();
+                    starCounter.incrementAndGet();
                     vertexProperty.properties().forEachRemaining(p -> {
                         originalPropertyCounter.incrementAndGet();
                         assertEquals(p.value(), starVertexProperty.property(p.key()).value());
@@ -122,5 +122,32 @@ public class StarGraphTest extends AbstractGremlinTest {
         assertEquals(5, originalCounter.get());
         assertEquals(5, starCounter.get());
         assertEquals(7, originalPropertyCounter.get());
+
+        originalCounter.set(0);
+        starCounter.set(0);
+        originalPropertyCounter.set(0);
+
+        matthiasStar.properties().forEachRemaining(starVertexProperty -> {
+            starCounter.incrementAndGet();
+            matthias.properties(starVertexProperty.label()).forEachRemaining(vertexProperty -> {
+                if (starVertexProperty.equals(vertexProperty)) {
+                    assertEquals(vertexProperty.id(), starVertexProperty.id());
+                    assertEquals(vertexProperty.label(), starVertexProperty.label());
+                    assertEquals(vertexProperty.value(), starVertexProperty.value());
+                    assertEquals(vertexProperty.key(), starVertexProperty.key());
+                    assertEquals(vertexProperty.element(), starVertexProperty.element());
+                    originalCounter.incrementAndGet();
+                    starVertexProperty.properties().forEachRemaining(p -> {
+                        originalPropertyCounter.incrementAndGet();
+                        assertEquals(p.value(), vertexProperty.property(p.key()).value());
+                        assertEquals(p.key(), vertexProperty.property(p.key()).key());
+                        assertEquals(p.element(), vertexProperty.property(p.key()).element());
+                    });
+                }
+            });
+        });
+        assertEquals(5, originalCounter.get());
+        assertEquals(5, starCounter.get());
+        assertEquals(7, originalPropertyCounter.get());
     }
 }