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 23:40:17 UTC

incubator-tinkerpop git commit: added ReferenceVertexPropertyTest.

Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/master 5575ab6e9 -> 302f01294


added ReferenceVertexPropertyTest.


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

Branch: refs/heads/master
Commit: 302f0129442583ac5a663f3ad898d9b39e457eec
Parents: 5575ab6
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Thu Apr 9 15:40:32 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Thu Apr 9 15:40:32 2015 -0600

----------------------------------------------------------------------
 .../util/reference/ReferenceVertexProperty.java |   9 +-
 .../structure/StructureStandardSuite.java       |   2 +
 .../reference/ReferenceVertexPropertyTest.java  | 101 +++++++++++++++++++
 3 files changed, 110 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/302f0129/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceVertexProperty.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceVertexProperty.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceVertexProperty.java
index 4ef4913..073529c 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceVertexProperty.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceVertexProperty.java
@@ -38,16 +38,21 @@ import java.util.NoSuchElementException;
  */
 public class ReferenceVertexProperty<V> extends ReferenceElement<VertexProperty> implements VertexProperty<V> {
 
+    private ReferenceVertex vertex;
+
     private ReferenceVertexProperty() {
 
     }
 
     public ReferenceVertexProperty(final VertexProperty vertexProperty) {
         super(vertexProperty);
+        this.vertex = ReferenceFactory.detach(vertexProperty.element());
     }
 
     @Override
     public VertexProperty<V> attach(final Vertex hostVertex) {
+        if (!hostVertex.equals(this.vertex))
+            throw Attachable.Exceptions.canNotAttachVertexPropertyToHostVertex(this, hostVertex);
         final Iterator<VertexProperty<V>> vertexPropertyIterator = IteratorUtils.filter(hostVertex.<V>properties(), vp -> vp.id().equals(this.id));
         if (!vertexPropertyIterator.hasNext())
             throw Attachable.Exceptions.canNotAttachVertexPropertyToHostVertex(this, hostVertex);
@@ -56,7 +61,7 @@ public class ReferenceVertexProperty<V> extends ReferenceElement<VertexProperty>
 
     @Override
     public VertexProperty<V> attach(final Graph hostGraph) {
-        throw new UnsupportedOperationException();
+        return this.attach(this.vertex.attach(hostGraph));
     }
 
     @Override
@@ -81,7 +86,7 @@ public class ReferenceVertexProperty<V> extends ReferenceElement<VertexProperty>
 
     @Override
     public Vertex element() {
-        return null;
+        return this.vertex;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/302f0129/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 1b65447..3211f6b 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
@@ -26,6 +26,7 @@ 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.ReferenceVertexPropertyTest;
 import org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceVertexTest;
 import org.apache.tinkerpop.gremlin.structure.util.star.StarGraphTest;
 import org.junit.runners.model.InitializationError;
@@ -81,6 +82,7 @@ public class StructureStandardSuite extends AbstractGremlinSuite {
             VariablesTest.class,
             PropertyTest.class,
             ReferenceEdgeTest.class,
+            ReferenceVertexPropertyTest.class,
             ReferenceVertexTest.class,
             SerializationTest.class,
             StarGraphTest.class,

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/302f0129/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceVertexPropertyTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceVertexPropertyTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceVertexPropertyTest.java
new file mode 100644
index 0000000..500a3ba
--- /dev/null
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceVertexPropertyTest.java
@@ -0,0 +1,101 @@
+/*
+ *
+ *  * 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.FeatureRequirementSet;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class ReferenceVertexPropertyTest extends AbstractGremlinTest {
+
+    @Test
+    @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
+    public void shouldNotConstructNewWithSomethingAlreadyReferenced() {
+        final Vertex v = graph.addVertex();
+        final VertexProperty vp = v.property("test", "this");
+        final ReferenceVertexProperty dvp = ReferenceFactory.detach(vp);
+        assertSame(dvp, ReferenceFactory.detach(dvp));
+    }
+
+    @Test(expected = IllegalStateException.class)
+    @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
+    public void shouldNotSupportRemove() {
+        final Vertex v = graph.addVertex();
+        final VertexProperty vp = v.property("test", "this");
+        ReferenceFactory.detach(vp).remove();
+    }
+
+    @Test
+    @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
+    public void shouldBeEqualsPropertiesAsIdIsTheSame() {
+        final Vertex v = graph.addVertex();
+        final VertexProperty vp = v.property("test", "this");
+        final ReferenceVertexProperty vp1 = ReferenceFactory.detach(vp);
+        final ReferenceVertexProperty vp2 = ReferenceFactory.detach(vp);
+        assertTrue(vp1.equals(vp2));
+        assertTrue(vp1.equals(vp));
+        assertTrue(vp.equals(vp2));
+    }
+
+    @Test
+    @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
+    public void shouldNotBeEqualsPropertiesAsIdIsDifferent() {
+        final Vertex v = graph.addVertex();
+        final VertexProperty vp1 = v.property("test", "this");
+        final ReferenceVertexProperty mp1 = ReferenceFactory.detach(vp1);
+        final VertexProperty vp2 = v.property("testing", "this");
+        final ReferenceVertexProperty mp2 = ReferenceFactory.detach(vp2);
+        assertFalse(mp1.equals(mp2));
+    }
+
+    @Test
+    @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
+    public void shouldAttachToGraph() {
+        final Vertex v = graph.addVertex();
+        final VertexProperty toReference = v.property("test", "this");
+        final ReferenceVertexProperty rvp = ReferenceFactory.detach(toReference);
+        final VertexProperty referenced = rvp.attach(graph);
+
+        assertEquals(toReference, referenced);
+        assertFalse(referenced instanceof ReferenceVertexProperty);
+    }
+
+    @Test
+    @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
+    public void shouldAttachToVertex() {
+        final Vertex v = graph.addVertex();
+        final VertexProperty toReference = v.property("test", "this");
+        final ReferenceVertexProperty rvp = ReferenceFactory.detach(toReference);
+        final VertexProperty referenced = rvp.attach(v);
+
+        assertEquals(toReference, referenced);
+        assertEquals(toReference.getClass(), referenced.getClass());
+        assertFalse(referenced instanceof ReferenceVertexProperty);
+    }
+}