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 2016/12/20 20:25:59 UTC
[41/47] tinkerpop git commit: TINKERPOP-1130 Improved asserts on
Graph elements.
TINKERPOP-1130 Improved asserts on Graph elements.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/4610295d
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/4610295d
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/4610295d
Branch: refs/heads/TINKERPOP-1130
Commit: 4610295da7c775effc653120a49fc2dcb7269892
Parents: 46b14b3
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Dec 15 14:40:00 2016 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Dec 20 15:24:52 2016 -0500
----------------------------------------------------------------------
.../structure/io/AbstractCompatibilityTest.java | 59 ++++++++++++++++++++
.../io/AbstractTypedCompatibilityTest.java | 36 +++---------
2 files changed, 68 insertions(+), 27 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/4610295d/gremlin-tools/gremlin-io-test/src/test/java/org/apache/tinkerpop/gremlin/structure/io/AbstractCompatibilityTest.java
----------------------------------------------------------------------
diff --git a/gremlin-tools/gremlin-io-test/src/test/java/org/apache/tinkerpop/gremlin/structure/io/AbstractCompatibilityTest.java b/gremlin-tools/gremlin-io-test/src/test/java/org/apache/tinkerpop/gremlin/structure/io/AbstractCompatibilityTest.java
index c2bb304..edd833e 100644
--- a/gremlin-tools/gremlin-io-test/src/test/java/org/apache/tinkerpop/gremlin/structure/io/AbstractCompatibilityTest.java
+++ b/gremlin-tools/gremlin-io-test/src/test/java/org/apache/tinkerpop/gremlin/structure/io/AbstractCompatibilityTest.java
@@ -18,7 +18,17 @@
*/
package org.apache.tinkerpop.gremlin.structure.io;
+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.util.Iterator;
+import java.util.List;
+
import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assume.assumeThat;
/**
@@ -37,4 +47,53 @@ public abstract class AbstractCompatibilityTest {
protected <T> T findModelEntryObject(final String resourceName) {
return model.find(resourceName).orElseThrow(() -> new IllegalStateException("Could not find requested model entry")).getObject();
}
+
+ protected void assertVertex(final Vertex expected, final Vertex actual) {
+ assertEquals(expected.id(), actual.id());
+ assertEquals(expected.label(), actual.label());
+ assertEquals(IteratorUtils.count(expected.properties()), IteratorUtils.count(actual.properties()));
+ for (String k : expected.keys()) {
+ final Iterator<VertexProperty<Object>> expectedVps = expected.properties(k);
+ final List<VertexProperty<Object>> actualVps = IteratorUtils.list(actual.properties(k));
+ while (expectedVps.hasNext()) {
+ final VertexProperty expectedVp = expectedVps.next();
+ final VertexProperty<Object> found = actualVps.stream()
+ .filter(vp -> vp.id().equals(expectedVp.id()))
+ .findFirst()
+ .orElseThrow(() -> new RuntimeException("Could not find VertexProperty for " + expectedVp.id()));
+ assertVertexProperty(expectedVp, found);
+ }
+ }
+ }
+
+ protected void assertEdge(final Edge expected, final Edge actual) {
+ assertEquals(expected.id(), actual.id());
+ assertEquals(expected.label(), actual.label());
+ assertEquals(IteratorUtils.count(expected.properties()), IteratorUtils.count(actual.properties()));
+ assertEquals(expected.inVertex().id(), actual.inVertex().id());
+ assertEquals(expected.outVertex().id(), actual.outVertex().id());
+ assertEquals(expected.inVertex().label(), actual.inVertex().label());
+ assertEquals(expected.outVertex().label(), actual.outVertex().label());
+ final Iterator<Property<Object>> itty = expected.properties();
+ while(itty.hasNext()) {
+ final Property p = itty.next();
+ assertProperty(p, actual.property(p.key()));
+ }
+ }
+
+ protected void assertVertexProperty(final VertexProperty expected, final VertexProperty actual) {
+ assertEquals(expected.id(), actual.id());
+ assertEquals(expected.label(), actual.label());
+ assertEquals(IteratorUtils.count(expected.properties()), IteratorUtils.count(actual.properties()));
+ final Iterator<Property> itty = expected.properties();
+ while(itty.hasNext()) {
+ final Property p = itty.next();
+ assertProperty(p, actual.property(p.key()));
+ }
+ }
+
+ protected void assertProperty(final Property expected, final Property actual) {
+ assertEquals(expected.key(), actual.key());
+ assertEquals(expected.value(), actual.value());
+ }
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/4610295d/gremlin-tools/gremlin-io-test/src/test/java/org/apache/tinkerpop/gremlin/structure/io/AbstractTypedCompatibilityTest.java
----------------------------------------------------------------------
diff --git a/gremlin-tools/gremlin-io-test/src/test/java/org/apache/tinkerpop/gremlin/structure/io/AbstractTypedCompatibilityTest.java b/gremlin-tools/gremlin-io-test/src/test/java/org/apache/tinkerpop/gremlin/structure/io/AbstractTypedCompatibilityTest.java
index 8db93f6..89275c0 100644
--- a/gremlin-tools/gremlin-io-test/src/test/java/org/apache/tinkerpop/gremlin/structure/io/AbstractTypedCompatibilityTest.java
+++ b/gremlin-tools/gremlin-io-test/src/test/java/org/apache/tinkerpop/gremlin/structure/io/AbstractTypedCompatibilityTest.java
@@ -339,22 +339,8 @@ public abstract class AbstractTypedCompatibilityTest extends AbstractCompatibili
assertEquals(fromStatic, recycled);
assertEquals(resource, fromStatic);
assertEquals(resource, recycled);
- assertEquals(resource.id(), recycled.id());
- assertEquals(resource.label(), recycled.label());
- assertEquals(resource.inVertex().id(), recycled.inVertex().id());
- assertEquals(resource.outVertex().id(), recycled.outVertex().id());
- assertEquals(resource.inVertex().label(), recycled.inVertex().label());
- assertEquals(resource.outVertex().label(), recycled.outVertex().label());
- assertEquals(IteratorUtils.count(resource.properties()), IteratorUtils.count(recycled.properties()));
- assertEquals((int) resource.value("since"), (int) recycled.value("since"));
- assertEquals(resource.id(), fromStatic.id());
- assertEquals(resource.label(), fromStatic.label());
- assertEquals(resource.inVertex().id(), fromStatic.inVertex().id());
- assertEquals(resource.outVertex().id(), fromStatic.outVertex().id());
- assertEquals(resource.inVertex().label(), fromStatic.inVertex().label());
- assertEquals(resource.outVertex().label(), fromStatic.outVertex().label());
- assertEquals(IteratorUtils.count(resource.properties()), IteratorUtils.count(fromStatic.properties()));
- assertEquals((int) resource.value("since"), (int) fromStatic.value("since"));
+ assertEdge(resource, fromStatic);
+ assertEdge(resource, recycled);
}
@Test
@@ -653,10 +639,8 @@ public abstract class AbstractTypedCompatibilityTest extends AbstractCompatibili
final Property fromStatic = read(getCompatibility().readFromResource(resourceName), Property.class);
final Property recycled = (Property) read(write(fromStatic, Property.class), getCompatibility().resolve(Property.class));
assertNotSame(fromStatic, recycled);
- assertEquals(resource.key(), recycled.key());
- assertEquals(resource.value(), recycled.value());
- assertEquals(resource.key(), fromStatic.key());
- assertEquals(resource.value(), fromStatic.value());
+ assertProperty(resource, fromStatic);
+ assertProperty(resource, recycled);
}
@Test
@@ -889,7 +873,7 @@ public abstract class AbstractTypedCompatibilityTest extends AbstractCompatibili
final TraversalMetrics recycled = (TraversalMetrics) read(write(fromStatic, TraversalMetrics.class), getCompatibility().resolve(TraversalMetrics.class));
assertNotSame(fromStatic, recycled);
- // need to assert against each other since the model version can change between test runs as it is dyncamically
+ // need to assert against each other since the model version can change between test runs as it is dynamically
// generated
assertEquals(recycled.getDuration(TimeUnit.MILLISECONDS), fromStatic.getDuration(TimeUnit.MILLISECONDS));
final Collection<? extends Metrics> resourceMetrics = resource.getMetrics();
@@ -956,9 +940,8 @@ public abstract class AbstractTypedCompatibilityTest extends AbstractCompatibili
assertEquals(fromStatic, recycled);
assertEquals(resource, fromStatic);
assertEquals(resource, recycled);
- assertEquals(resource.id(), recycled.id());
- assertEquals(resource.label(), recycled.label());
- // todo: more asserts
+ assertVertex(resource, fromStatic);
+ assertVertex(resource, recycled);
}
@Test
@@ -973,9 +956,8 @@ public abstract class AbstractTypedCompatibilityTest extends AbstractCompatibili
assertEquals(fromStatic, recycled);
assertEquals(resource, fromStatic);
assertEquals(resource, recycled);
- assertEquals(resource.id(), recycled.id());
- assertEquals(resource.label(), recycled.label());
- // todo: more asserts
+ assertVertexProperty(resource, recycled);
+ assertVertexProperty(resource, fromStatic);
}
@Test