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/05/28 23:51:37 UTC
[1/2] incubator-tinkerpop git commit: added
ElementHelper.attachProperties() for vertices which checks Cardinality from
the graph.
Repository: incubator-tinkerpop
Updated Branches:
refs/heads/neo4j-gremlin-apache a19390010 -> c850d5e77
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/c850d5e7/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/structure/NativeNeo4jStructureTest.java
----------------------------------------------------------------------
diff --git a/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/structure/NativeNeo4jStructureTest.java b/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/structure/NativeNeo4jStructureTest.java
new file mode 100644
index 0000000..a761e66
--- /dev/null
+++ b/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/structure/NativeNeo4jStructureTest.java
@@ -0,0 +1,718 @@
+/*
+ *
+ * * 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.neo4j.structure;
+
+import org.apache.tinkerpop.gremlin.AbstractGremlinTest;
+import org.apache.tinkerpop.gremlin.FeatureRequirement;
+import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine;
+import org.apache.tinkerpop.gremlin.neo4j.AbstractNeo4jGremlinTest;
+import org.apache.tinkerpop.gremlin.neo4j.structure.full.FullNeo4jVertexProperty;
+import org.apache.tinkerpop.gremlin.process.traversal.P;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.T;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
+import org.junit.Test;
+import org.neo4j.tinkerpop.api.Neo4jDirection;
+import org.neo4j.tinkerpop.api.Neo4jGraphAPI;
+import org.neo4j.tinkerpop.api.Neo4jNode;
+import org.neo4j.tinkerpop.api.Neo4jRelationship;
+import org.neo4j.tinkerpop.api.Neo4jTx;
+
+import javax.script.Bindings;
+import javax.script.ScriptException;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import static org.junit.Assert.*;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class NativeNeo4jStructureTest extends AbstractNeo4jGremlinTest {
+
+ @Test
+ public void shouldOpenWithOverriddenConfig() throws Exception {
+ assertNotNull(this.graph);
+ }
+
+ @Test
+ public void shouldNotThrowConcurrentModificationException() {
+ this.graph.addVertex("name", "a");
+ this.graph.addVertex("name", "b");
+ this.graph.addVertex("name", "c");
+ this.graph.addVertex("name", "d");
+ this.graph.vertices().forEachRemaining(Vertex::remove);
+ this.graph.tx().commit();
+ assertEquals(0, IteratorUtils.count(this.graph.vertices()), 0);
+ }
+
+ @Test
+ public void shouldTraverseWithoutLabels() {
+ final Neo4jGraphAPI service = this.getGraph().getBaseGraph();
+
+ final Neo4jTx tx = service.tx();
+ final Neo4jNode n = service.createNode();
+ tx.success();
+ tx.close();
+
+ final Neo4jTx tx2 = service.tx();
+ assertEquals(0, IteratorUtils.count(n.labels().iterator()));
+ assertEquals(1, IteratorUtils.count(graph.vertices()));
+ graph.tx().close();
+ tx2.close();
+ }
+
+ @Test
+ public void shouldReturnResultsLabeledIndexOnVertexWithHasHas() {
+ this.graph.tx().readWrite();
+ this.getBaseGraph().execute("CREATE INDEX ON :Person(name)", null);
+ this.graph.tx().commit();
+ this.graph.addVertex(T.label, "Person", "name", "marko");
+ this.graph.addVertex(T.label, "Person", "name", "marko");
+ this.graph.tx().commit();
+ assertEquals(2, this.g.V().has(T.label, "Person").has("name", "marko").count().next(), 0);
+ assertEquals(2, this.g.V().has("name", "marko").count().next(), 0);
+ }
+
+ @Test
+ public void shouldEnsureColonedKeyIsTreatedAsNormalKey() {
+ this.graph.tx().readWrite();
+ this.getBaseGraph().execute("CREATE INDEX ON :Person(name)", null);
+ this.graph.tx().commit();
+ this.graph.addVertex(T.label, "Person", "name", "marko");
+ this.graph.addVertex(T.label, "Person", "name", "marko");
+ this.graph.tx().commit();
+ assertEquals(2, this.g.V().has(T.label, "Person").has("name", "marko").count().next(), 0);
+ assertEquals(0, this.g.V().has("Person:name", "marko").count().next(), 0);
+
+ }
+
+ @Test
+ public void shouldReturnResultsUsingLabeledIndexOnVertexWithHasHasHas() {
+ this.graph.tx().readWrite();
+ this.getBaseGraph().execute("CREATE INDEX ON :Person(name)", null);
+ this.graph.tx().commit();
+ this.graph.addVertex(T.label, "Person", "name", "marko", "color", "blue");
+ this.graph.addVertex(T.label, "Person", "name", "marko", "color", "green");
+ this.graph.tx().commit();
+ assertEquals(1, this.g.V().has(T.label, "Person").has("name", "marko").has("color", "blue").count().next(), 0);
+ assertEquals(2, this.g.V().has("name", "marko").count().next(), 0);
+ }
+
+ @Test
+ public void shouldReturnResultsOnVertexWithHasHasHasNoIndex() {
+ this.graph.tx().commit();
+ this.graph.addVertex(T.label, "Person", "name", "marko", "color", "blue");
+ this.graph.addVertex(T.label, "Person", "name", "marko", "color", "green");
+ this.graph.tx().commit();
+ assertEquals(1, this.g.V().has(T.label, "Person").has("name", "marko").has("color", "blue").count().next(), 0);
+ assertEquals(2, this.g.V().has("name", "marko").count().next(), 0);
+ }
+
+ @Test
+ public void shouldReturnResultsUsingLabeledIndexOnVertexWithColonFails() {
+ this.graph.tx().readWrite();
+ this.getBaseGraph().execute("CREATE INDEX ON :Person(name)", null);
+ this.graph.tx().commit();
+ this.graph.addVertex(T.label, "Person", "name", "marko");
+ this.graph.addVertex(T.label, "Person", "name", "marko");
+ this.graph.tx().commit();
+ assertNotEquals(2l, this.g.V().has("Person:name", "marko").count().next().longValue());
+ assertEquals(2, this.g.V().has("name", "marko").count().next(), 0);
+ }
+
+ @Test
+ public void shouldReturnResultsUsingLegacyIndexOnVertex() {
+ graph.tx().readWrite();
+ this.getBaseGraph().autoIndexProperties(true, "name");
+ this.graph.tx().commit();
+
+ this.graph.addVertex(T.label, "Person", "name", "marko");
+ this.graph.addVertex(T.label, "Person", "name", "marko");
+ this.graph.tx().commit();
+ assertEquals(2, this.g.V().has("Person", "name", "marko").count().next(), 0);
+ assertEquals(2, this.g.V().has("name", "marko").count().next(), 0);
+ }
+
+ @Test
+ public void shouldUseLegacyIndexOnEdge() {
+ graph.tx().readWrite();
+ this.getBaseGraph().autoIndexProperties(true, "weight");
+ this.graph.tx().commit();
+
+ Vertex marko = this.graph.addVertex(T.label, "Person", "name", "marko");
+ Vertex john = this.graph.addVertex(T.label, "Person", "name", "john");
+ Vertex pete = this.graph.addVertex(T.label, "Person", "name", "pete");
+ marko.addEdge("friend", john, "weight", "a");
+ marko.addEdge("friend", pete, "weight", "a");
+ this.graph.tx().commit();
+ assertEquals(2, this.g.E().has("weight", "a").count().next(), 0);
+ }
+
+ @Test
+ public void shouldEnforceUniqueConstraint() {
+ this.graph.tx().readWrite();
+ this.getBaseGraph().execute("CREATE CONSTRAINT ON (p:Person) assert p.name is unique", null);
+ this.graph.tx().commit();
+ this.graph.tx().commit();
+ this.graph.addVertex(T.label, "Person", "name", "marko");
+ this.graph.tx().commit();
+ assertEquals("marko", g.V().has(T.label, "Person").has("name", "marko").next().value("name"));
+ }
+
+ @Test
+ public void shouldEnforceMultipleUniqueConstraint() {
+ this.graph.tx().readWrite();
+ this.getGraph().execute("CREATE CONSTRAINT ON (p:Person) assert p.name is unique", null);
+ this.getGraph().execute("CREATE CONSTRAINT ON (p:Person) assert p.surname is unique", null);
+ this.graph.tx().commit();
+ this.graph.addVertex(T.label, "Person", "name", "marko");
+ this.graph.addVertex(T.label, "Person", "surname", "aaaa");
+ this.graph.tx().commit();
+ boolean failSurname = false;
+ try {
+ this.graph.addVertex(T.label, "Person", "surname", "aaaa");
+ } catch (RuntimeException e) {
+ if (isConstraintViolation(e)) failSurname = true;
+ }
+ assertTrue(failSurname);
+ boolean failName = false;
+ try {
+ this.graph.addVertex(T.label, "Person", "name", "marko");
+ } catch (RuntimeException e) {
+ if (isConstraintViolation(e)) failName = true;
+ }
+ assertTrue(failName);
+ this.graph.tx().commit();
+ }
+
+ private boolean isConstraintViolation(RuntimeException e) {
+ return e.getClass().getSimpleName().equals("ConstraintViolationException");
+ }
+
+ @Test
+ public void shouldDropMultipleUniqueConstraint() {
+ this.graph.tx().readWrite();
+ this.getGraph().execute("CREATE CONSTRAINT ON (p:Person) assert p.name is unique", null);
+ this.getGraph().execute("CREATE CONSTRAINT ON (p:Person) assert p.surname is unique", null);
+ this.graph.tx().commit();
+
+ this.graph.addVertex(T.label, "Person", "name", "marko");
+ this.graph.addVertex(T.label, "Person", "surname", "aaaa");
+ this.graph.tx().commit();
+ boolean failSurname = false;
+ try {
+ this.graph.addVertex(T.label, "Person", "surname", "aaaa");
+ } catch (RuntimeException e) {
+ if (isConstraintViolation(e)) failSurname = true;
+ }
+ assertTrue(failSurname);
+ boolean failName = false;
+ try {
+ this.graph.addVertex(T.label, "Person", "name", "marko");
+ } catch (RuntimeException e) {
+ if (isConstraintViolation(e)) failName = true;
+ }
+ assertTrue(failName);
+ this.graph.tx().commit();
+
+ this.graph.tx().readWrite();
+ this.getGraph().execute("DROP CONSTRAINT ON (p:Person) assert p.name is unique", null);
+ this.getGraph().execute("DROP CONSTRAINT ON (p:Person) assert p.surname is unique", null);
+
+ this.graph.tx().commit();
+ assertEquals(1, this.g.V().has(T.label, "Person").has("name", "marko").count().next(), 0);
+ assertEquals(1, this.g.V().has(T.label, "Person").has("surname", "aaaa").count().next(), 0);
+ this.graph.addVertex(T.label, "Person", "surname", "aaaa");
+ this.graph.addVertex(T.label, "Person", "name", "marko");
+ this.graph.tx().commit();
+ assertEquals(2, this.g.V().has(T.label, "Person").has("name", "marko").count().next(), 0);
+ assertEquals(2, this.g.V().has(T.label, "Person").has("surname", "aaaa").count().next(), 0);
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void shouldFailUniqueConstraint() {
+ this.graph.tx().readWrite();
+ this.getGraph().execute("CREATE CONSTRAINT ON (p:Person) assert p.name is unique", null);
+ this.graph.tx().commit();
+ this.graph.addVertex(T.label, "Person", "name", "marko");
+ this.graph.tx().commit();
+ assertEquals("marko", g.V().has(T.label, "Person").has("name", "marko").next().value("name"));
+ this.graph.addVertex(T.label, "Person", "name", "marko");
+ }
+
+ @Test
+ public void shouldEnsureTraverseRelationshipNeedsTx() throws ScriptException {
+ final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine();
+ final Bindings bindings = engine.createBindings();
+ bindings.put("g", graph.traversal(GraphTraversalSource.standard()));
+ bindings.put("#jsr223.groovy.engine.keep.globals", "phantom");
+
+ Vertex marko = this.graph.addVertex(T.label, "Person", "name", "marko");
+ Vertex john = this.graph.addVertex(T.label, "Person", "name", "john");
+ Vertex pete = this.graph.addVertex(T.label, "Person", "name", "pete");
+ marko.addEdge("friend", john);
+ marko.addEdge("friend", pete);
+ this.graph.tx().commit();
+
+ Object result = engine.eval("g.V(" + marko.id().toString() + ").outE('friend')", bindings);
+ assertTrue(result instanceof GraphTraversal);
+
+ this.graph.tx().commit();
+ assertEquals(2L, ((GraphTraversal) result).count().next());
+ }
+
+ @Test
+ public void shouldEnsureTraversalOfVerticesNeedsTx() throws ScriptException {
+ final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine();
+ final Bindings bindings = engine.createBindings();
+ bindings.put("g", graph.traversal(GraphTraversalSource.standard()));
+ bindings.put("#jsr223.groovy.engine.keep.globals", "phantom");
+
+ Vertex marko = this.graph.addVertex(T.label, "Person", "name", "marko");
+ Vertex john = this.graph.addVertex(T.label, "Person", "name", "john");
+ Vertex pete = this.graph.addVertex(T.label, "Person", "name", "pete");
+ marko.addEdge("friend", john);
+ marko.addEdge("friend", pete);
+ this.graph.tx().commit();
+
+ Object result = engine.eval("g.V(" + marko.id().toString() + ").out('friend')", bindings);
+ assertTrue(result instanceof GraphTraversal);
+
+ this.graph.tx().commit();
+ assertEquals(2L, ((GraphTraversal) result).count().next());
+ }
+
+ @Test
+ public void shouldDoLabelSearch() {
+ this.graph.addVertex(T.label, "Person", "name", "marko");
+ this.graph.addVertex(T.label, "Person", "name", "john");
+ Vertex pete = this.graph.addVertex(T.label, "Person", "name", "pete");
+ this.graph.addVertex(T.label, "Monkey", "name", "pete");
+ this.graph.tx().commit();
+ assertEquals(3, this.g.V().has(T.label, "Person").count().next(), 0);
+ pete.remove();
+ this.graph.tx().commit();
+ assertEquals(2, this.g.V().has(T.label, "Person").count().next(), 0);
+ }
+
+ @Test
+ public void shouldDoLabelAndIndexSearch() {
+ graph.tx().readWrite();
+ this.getBaseGraph().execute("CREATE INDEX ON :Person(name)", null);
+ this.graph.tx().commit();
+
+ this.graph.addVertex(T.label, "Person", "name", "marko");
+ this.graph.addVertex(T.label, "Person", "name", "john");
+ this.graph.addVertex(T.label, "Person", "name", "pete");
+ this.graph.tx().commit();
+ assertEquals(1, this.g.V().has("Person", "name", "marko").count().next(), 0);
+ assertEquals(3, this.g.V().has(T.label, "Person").count().next(), 0);
+ assertEquals(1, this.g.V().has(T.label, "Person").has("name", "marko").count().next(), 0);
+ }
+
+ @Test
+ public void shouldDoLabelAndLegacyIndexSearch() {
+ graph.tx().readWrite();
+
+ this.getBaseGraph().execute("CREATE INDEX ON :Person(name)", null);
+ this.getBaseGraph().autoIndexProperties(true, "name");
+
+ this.graph.tx().commit();
+ this.graph.addVertex(T.label, "Person", "name", "marko");
+ this.graph.addVertex(T.label, "Person", "name", "john");
+ this.graph.addVertex(T.label, "Person", "name", "pete");
+ this.graph.tx().commit();
+ assertEquals(1, this.g.V().has(T.label, "Person").has("name", "marko").count().next(), 0);
+ assertEquals(3, this.g.V().has(T.label, "Person").count().next(), 0);
+ assertEquals(1, this.g.V().has("name", "john").count().next(), 0);
+
+ }
+
+ @Test
+ @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_MULTI_PROPERTIES)
+ public void shouldSupportVertexPropertyToVertexMappingOnIndexCalls() {
+ graph.tx().readWrite();
+ this.getGraph().execute("CREATE INDEX ON :person(name)", null);
+// this.graph.getBaseGraph().execute("CREATE INDEX ON :name(" + T.value.getAccessor() + ")", null);
+ this.graph.tx().commit();
+
+ final Vertex a = graph.addVertex(T.label, "person", "name", "marko", "age", 34);
+ a.property(VertexProperty.Cardinality.list, "name", "okram");
+ a.property(VertexProperty.Cardinality.list, "name", "marko a. rodriguez");
+ final Vertex b = graph.addVertex(T.label, "person", "name", "stephen");
+ final Vertex c = graph.addVertex("name", "matthias", "name", "mbroecheler");
+
+ tryCommit(graph, graph -> {
+ assertEquals(a.id(), g.V().has("person", "name", "okram").id().next());
+ assertEquals(1, g.V().has("person", "name", "okram").count().next().intValue());
+ assertEquals(34, ((Neo4jVertex) g.V().has("person", "name", "okram").next()).getBaseVertex().getProperty("age"));
+ assertEquals(FullNeo4jVertexProperty.VERTEX_PROPERTY_TOKEN, ((Neo4jVertex) g.V().has("person", "name", "okram").next()).getBaseVertex().getProperty("name"));
+ ///
+ assertEquals(b.id(), g.V().has("person", "name", "stephen").id().next());
+ assertEquals(1, g.V().has("person", "name", "stephen").count().next().intValue());
+ assertEquals("stephen", ((Neo4jVertex) g.V().has("person", "name", "stephen").next()).getBaseVertex().getProperty("name"));
+ ///
+ assertEquals(c.id(), g.V().has("name", "matthias").id().next());
+ assertEquals(c.id(), g.V().has("name", "mbroecheler").id().next());
+ assertEquals(1, g.V().has("name", "matthias").count().next().intValue());
+ assertEquals(1, g.V().has("name", "mbroecheler").count().next().intValue());
+ assertEquals(0, g.V().has("person", "name", "matthias").count().next().intValue());
+ assertEquals(0, g.V().has("person", "name", "mbroecheler").count().next().intValue());
+ });
+
+ final Vertex d = graph.addVertex(T.label, "person", "name", "kuppitz");
+ tryCommit(graph, graph -> {
+ assertEquals(d.id(), g.V().has("person", "name", "kuppitz").id().next());
+ assertEquals("kuppitz", ((Neo4jVertex) g.V().has("person", "name", "kuppitz").next()).getBaseVertex().getProperty("name"));
+ });
+ d.property(VertexProperty.Cardinality.list, "name", "daniel", "acl", "private");
+ tryCommit(graph, graph -> {
+ assertEquals(d.id(), g.V().has("person", "name", P.within("daniel", "kuppitz")).id().next());
+ assertEquals(d.id(), g.V().has("person", "name", "kuppitz").id().next());
+ assertEquals(d.id(), g.V().has("person", "name", "daniel").id().next());
+ assertEquals(FullNeo4jVertexProperty.VERTEX_PROPERTY_TOKEN, ((Neo4jVertex) g.V().has("person", "name", "kuppitz").next()).getBaseVertex().getProperty("name"));
+ });
+ d.property(VertexProperty.Cardinality.list, "name", "marko", "acl", "private");
+ tryCommit(graph, graph -> {
+ assertEquals(2, g.V().has("person", "name", "marko").count().next().intValue());
+ assertEquals(1, g.V().has("person", "name", "marko").properties("name").has(T.value, "marko").has("acl", "private").count().next().intValue());
+ g.V().has("person", "name", "marko").forEachRemaining(v -> {
+ assertEquals(FullNeo4jVertexProperty.VERTEX_PROPERTY_TOKEN, ((Neo4jVertex) v).getBaseVertex().getProperty("name"));
+ });
+
+ });
+ }
+
+ @Test
+ public void shouldDoLabelsNamespaceBehavior() {
+ graph.tx().readWrite();
+
+ this.getGraph().execute("CREATE INDEX ON :Person(name)", null);
+ this.getGraph().execute("CREATE INDEX ON :Product(name)", null);
+ this.getGraph().execute("CREATE INDEX ON :Corporate(name)", null);
+
+ this.graph.tx().commit();
+ this.graph.addVertex(T.label, "Person", "name", "marko");
+ this.graph.addVertex(T.label, "Person", "name", "john");
+ this.graph.addVertex(T.label, "Person", "name", "pete");
+ this.graph.addVertex(T.label, "Product", "name", "marko");
+ this.graph.addVertex(T.label, "Product", "name", "john");
+ this.graph.addVertex(T.label, "Product", "name", "pete");
+ this.graph.addVertex(T.label, "Corporate", "name", "marko");
+ this.graph.addVertex(T.label, "Corporate", "name", "john");
+ this.graph.addVertex(T.label, "Corporate", "name", "pete");
+ this.graph.tx().commit();
+ assertEquals(1, this.g.V().has(T.label, "Person").has("name", "marko").has(T.label, "Person").count().next(), 0);
+ assertEquals(1, this.g.V().has(T.label, "Product").has("name", "marko").has(T.label, "Product").count().next(), 0);
+ assertEquals(1, this.g.V().has(T.label, "Corporate").has("name", "marko").has(T.label, "Corporate").count().next(), 0);
+ assertEquals(0, this.g.V().has(T.label, "Person").has("name", "marko").has(T.label, "Product").count().next(), 0);
+ assertEquals(0, this.g.V().has(T.label, "Product").has("name", "marko").has(T.label, "Person").count().next(), 0);
+ assertEquals(0, this.g.V().has(T.label, "Corporate").has("name", "marko").has(T.label, "Person").count().next(), 0);
+ }
+
+ @Test
+ public void shouldNotGenerateVerticesOrEdgesForGraphVariables() {
+ graph.tx().readWrite();
+ graph.variables().set("namespace", "rdf-xml");
+ tryCommit(graph, graph -> {
+ assertEquals("rdf-xml", graph.variables().get("namespace").get());
+ assertEquals(0, g.V().count().next().intValue());
+ assertEquals(0, g.E().count().next().intValue());
+ assertEquals(0, IteratorUtils.count(this.getBaseGraph().allNodes()));
+ assertEquals(0, IteratorUtils.count(this.getBaseGraph().allRelationships()));
+ });
+ }
+
+ @Test
+ @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_MULTI_PROPERTIES, supported = false)
+ @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES, supported = false)
+ public void shouldNotGenerateNodesAndRelationshipsForNoMultiPropertiesNoMetaProperties() {
+ graph.tx().readWrite();
+ tryCommit(graph, graph -> validateCounts(0, 0, 0, 0));
+ Vertex vertex = graph.addVertex(T.label, "person");
+ tryCommit(graph, graph -> validateCounts(1, 0, 1, 0));
+ vertex.property("name", "marko");
+ assertEquals("marko", vertex.value("name"));
+ tryCommit(graph, graph -> validateCounts(1, 0, 1, 0));
+ vertex.property("name", "okram");
+ tryCommit(graph, g -> {
+ validateCounts(1, 0, 1, 0);
+ assertEquals("okram", vertex.value("name"));
+ });
+ VertexProperty vertexProperty = vertex.property("name");
+ tryCommit(graph, graph -> {
+ assertTrue(vertexProperty.isPresent());
+ assertEquals("name", vertexProperty.key());
+ assertEquals("okram", vertexProperty.value());
+ validateCounts(1, 0, 1, 0);
+ });
+ try {
+ vertexProperty.property("acl", "private");
+ } catch (UnsupportedOperationException e) {
+ assertEquals(VertexProperty.Exceptions.metaPropertiesNotSupported().getMessage(), e.getMessage());
+ }
+ }
+
+ @Test
+ @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_MULTI_PROPERTIES)
+ public void shouldGenerateNodesAndRelationshipsCorrectlyForVertexProperties() {
+
+ graph.tx().readWrite();
+ Neo4jVertex a = (Neo4jVertex) graph.addVertex("name", "marko", "name", "okram");
+ Neo4jVertex b = (Neo4jVertex) graph.addVertex("name", "stephen", "location", "virginia");
+
+ tryCommit(graph, graph -> {
+ assertEquals(2, g.V().count().next().intValue());
+ // assertEquals(2, a.properties("name").count().next().intValue());
+ // assertEquals(1, b.properties("name").count().next().intValue());
+ // assertEquals(1, b.properties("location").count().next().intValue());
+ // assertEquals(0, g.E().count().next().intValue());
+
+ assertEquals(4l, this.getGraph().execute("MATCH n RETURN COUNT(n)", null).next().get("COUNT(n)"));
+ assertEquals(2l, this.getGraph().execute("MATCH (n)-[r]->(m) RETURN COUNT(r)", null).next().get("COUNT(r)"));
+ assertEquals(2l, this.getGraph().execute("MATCH (a)-[r]->() WHERE id(a) = " + a.id() + " RETURN COUNT(r)", null).next().get("COUNT(r)"));
+ final AtomicInteger counter = new AtomicInteger(0);
+ a.getBaseVertex().relationships(Neo4jDirection.OUTGOING).forEach(relationship -> {
+ assertEquals(FullNeo4jVertexProperty.VERTEX_PROPERTY_PREFIX.concat("name"), relationship.type());
+ counter.incrementAndGet();
+ });
+ assertEquals(2, counter.getAndSet(0));
+ this.getGraph().execute("MATCH (a)-[]->(m) WHERE id(a) = " + a.id() + " RETURN labels(m)", null).forEachRemaining(results -> {
+ assertEquals(VertexProperty.DEFAULT_LABEL, ((List<String>) results.get("labels(m)")).get(0));
+ counter.incrementAndGet();
+ });
+ assertEquals(2, counter.getAndSet(0));
+ IteratorUtils.stream(a.getBaseVertex().relationships(Neo4jDirection.OUTGOING)).map(Neo4jRelationship::end).forEach(node -> {
+ assertEquals(2, IteratorUtils.count(node.getKeys()));
+ assertEquals("name", node.getProperty(T.key.getAccessor()));
+ assertTrue("marko".equals(node.getProperty(T.value.getAccessor())) || "okram".equals(node.getProperty(T.value.getAccessor())));
+ assertEquals(0, node.degree(Neo4jDirection.OUTGOING, null));
+ assertEquals(1, node.degree(Neo4jDirection.INCOMING, null));
+ assertEquals(FullNeo4jVertexProperty.VERTEX_PROPERTY_PREFIX.concat("name"), node.relationships(Neo4jDirection.INCOMING).iterator().next().type());
+ counter.incrementAndGet();
+ });
+ assertEquals(2, counter.getAndSet(0));
+
+ assertEquals(2, IteratorUtils.count(b.getBaseVertex().getKeys()));
+ assertEquals("stephen", b.getBaseVertex().getProperty("name"));
+ assertEquals("virginia", b.getBaseVertex().getProperty("location"));
+ });
+
+ a.property("name", "the marko");
+ tryCommit(graph, g -> {
+ assertEquals(2, g.traversal().V().count().next().intValue());
+ //assertEquals(1, a.prope rties().count().next().intValue());
+ // assertEquals(1, b.properties("name").count().next().intValue());
+ // assertEquals(1, b.properties("location").count().next().intValue());
+ // assertEquals(0, g.E().count().next().intValue());
+
+ assertEquals(2l, this.getGraph().execute("MATCH n RETURN COUNT(n)", null).next().get("COUNT(n)"));
+ assertEquals(0l, this.getGraph().execute("MATCH (n)-[r]->(m) RETURN COUNT(r)", null).next().get("COUNT(r)"));
+
+ assertEquals(1, IteratorUtils.count(a.getBaseVertex().getKeys()));
+ assertEquals("the marko", a.getBaseVertex().getProperty("name"));
+ assertEquals(2, IteratorUtils.count(b.getBaseVertex().getKeys()));
+ assertEquals("stephen", b.getBaseVertex().getProperty("name"));
+ assertEquals("virginia", b.getBaseVertex().getProperty("location"));
+ });
+
+ a.property("name").remove();
+ tryCommit(graph, g -> {
+ assertEquals(2, g.traversal().V().count().next().intValue());
+ // assertEquals(0, a.properties().count().next().intValue());
+ // assertEquals(2, b.properties().count().next().intValue());
+ // assertEquals(0, g.E().count().next().intValue());
+ assertEquals(2l, this.getGraph().execute("MATCH n RETURN COUNT(n)", null).next().get("COUNT(n)"));
+ assertEquals(0l, this.getGraph().execute("MATCH (n)-[r]->(m) RETURN COUNT(r)", null).next().get("COUNT(r)"));
+ assertEquals(0, IteratorUtils.count(a.getBaseVertex().getKeys()));
+ assertEquals(2, IteratorUtils.count(b.getBaseVertex().getKeys()));
+ });
+
+ graph.tx().commit();
+ a.property("name", "the marko", "acl", "private");
+ tryCommit(graph, g -> {
+ assertEquals(2, g.traversal().V().count().next().intValue());
+ // assertEquals(1, a.properties("name").count().next().intValue());
+ // assertEquals(1, b.properties("name").count().next().intValue());
+ // assertEquals(1, b.properties("location").count().next().intValue());
+ // assertEquals(0, g.E().count().next().intValue());
+
+ assertEquals(3l, this.getGraph().execute("MATCH n RETURN COUNT(n)", null).next().get("COUNT(n)"));
+ assertEquals(1l, this.getGraph().execute("MATCH (n)-[r]->(m) RETURN COUNT(r)", null).next().get("COUNT(r)"));
+ assertEquals(1l, this.getGraph().execute("MATCH (a)-[r]->() WHERE id(a) = " + a.id() + " RETURN COUNT(r)", null).next().get("COUNT(r)"));
+ final AtomicInteger counter = new AtomicInteger(0);
+ a.getBaseVertex().relationships(Neo4jDirection.OUTGOING).forEach(relationship -> {
+ assertEquals(FullNeo4jVertexProperty.VERTEX_PROPERTY_PREFIX.concat("name"), relationship.type());
+ counter.incrementAndGet();
+ });
+ assertEquals(1, counter.getAndSet(0));
+ this.getGraph().execute("MATCH (a)-[]->(m) WHERE id(a) = " + a.id() + " RETURN labels(m)", null).forEachRemaining(results -> {
+ assertEquals(VertexProperty.DEFAULT_LABEL, ((List<String>) results.get("labels(m)")).get(0));
+ counter.incrementAndGet();
+ });
+ assertEquals(1, counter.getAndSet(0));
+ IteratorUtils.stream(a.getBaseVertex().relationships(Neo4jDirection.OUTGOING)).map(Neo4jRelationship::end).forEach(node -> {
+ assertEquals(3, IteratorUtils.count(node.getKeys()));
+ assertEquals("name", node.getProperty(T.key.getAccessor()));
+ assertEquals("the marko", node.getProperty(T.value.getAccessor()));
+ assertEquals("private", node.getProperty("acl"));
+ assertEquals(0, node.degree(Neo4jDirection.OUTGOING, null));
+ assertEquals(1, node.degree(Neo4jDirection.INCOMING, null));
+ assertEquals(FullNeo4jVertexProperty.VERTEX_PROPERTY_PREFIX.concat("name"), node.relationships(Neo4jDirection.INCOMING).iterator().next().type());
+ counter.incrementAndGet();
+ });
+ assertEquals(1, counter.getAndSet(0));
+
+ assertEquals(1, IteratorUtils.count(a.getBaseVertex().getKeys()));
+ assertTrue(a.getBaseVertex().hasProperty("name"));
+ assertEquals(FullNeo4jVertexProperty.VERTEX_PROPERTY_TOKEN, a.getBaseVertex().getProperty("name"));
+ assertEquals(2, IteratorUtils.count(b.getBaseVertex().getKeys()));
+ assertEquals("stephen", b.getBaseVertex().getProperty("name"));
+ assertEquals("virginia", b.getBaseVertex().getProperty("location"));
+ });
+
+ a.property(VertexProperty.Cardinality.list, "name", "marko", "acl", "private");
+ a.property(VertexProperty.Cardinality.list, "name", "okram", "acl", "public");
+ graph.tx().commit(); // TODO tx.commit() THIS IS REQUIRED: ?! Why does Neo4j not delete vertices correctly?
+ a.property(VertexProperty.Cardinality.single, "name", "the marko", "acl", "private");
+ tryCommit(graph, g -> {
+ assertEquals(2, g.traversal().V().count().next().intValue());
+ // assertEquals(1, a.properties("name").count().next().intValue());
+ // assertEquals(1, b.properties("name").count().next().intValue());
+ // assertEquals(1, b.properties("location").count().next().intValue());
+ // assertEquals(0, g.E().count().next().intValue());
+
+ assertEquals(3l, this.getGraph().execute("MATCH n RETURN COUNT(n)", null).next().get("COUNT(n)"));
+ assertEquals(1l, this.getGraph().execute("MATCH (n)-[r]->(m) RETURN COUNT(r)", null).next().get("COUNT(r)"));
+ assertEquals(1l, this.getGraph().execute("MATCH (a)-[r]->() WHERE id(a) = " + a.id() + " RETURN COUNT(r)", null).next().get("COUNT(r)"));
+ final AtomicInteger counter = new AtomicInteger(0);
+ a.getBaseVertex().relationships(Neo4jDirection.OUTGOING).forEach(relationship -> {
+ assertEquals(FullNeo4jVertexProperty.VERTEX_PROPERTY_PREFIX.concat("name"), relationship.type());
+ counter.incrementAndGet();
+ });
+ assertEquals(1, counter.getAndSet(0));
+ this.getGraph().execute("MATCH (a)-[]->(m) WHERE id(a) = " + a.id() + " RETURN labels(m)", null).forEachRemaining(results -> {
+ assertEquals(VertexProperty.DEFAULT_LABEL, ((List<String>) results.get("labels(m)")).get(0));
+ counter.incrementAndGet();
+ });
+ assertEquals(1, counter.getAndSet(0));
+ IteratorUtils.stream(a.getBaseVertex().relationships(Neo4jDirection.OUTGOING)).map(Neo4jRelationship::end).forEach(node -> {
+ assertEquals(3, IteratorUtils.count(node.getKeys()));
+ assertEquals("name", node.getProperty(T.key.getAccessor()));
+ assertEquals("the marko", node.getProperty(T.value.getAccessor()));
+ assertEquals("private", node.getProperty("acl"));
+ assertEquals(0, node.degree(Neo4jDirection.OUTGOING, null));
+ assertEquals(1, node.degree(Neo4jDirection.INCOMING, null));
+ assertEquals(FullNeo4jVertexProperty.VERTEX_PROPERTY_PREFIX.concat("name"), node.relationships(Neo4jDirection.INCOMING).iterator().next().type());
+ counter.incrementAndGet();
+ });
+ assertEquals(1, counter.getAndSet(0));
+
+ assertEquals(1, IteratorUtils.count(a.getBaseVertex().getKeys()));
+ assertTrue(a.getBaseVertex().hasProperty("name"));
+ assertEquals(FullNeo4jVertexProperty.VERTEX_PROPERTY_TOKEN, a.getBaseVertex().getProperty("name"));
+ assertEquals(2, IteratorUtils.count(b.getBaseVertex().getKeys()));
+ assertEquals("stephen", b.getBaseVertex().getProperty("name"));
+ assertEquals("virginia", b.getBaseVertex().getProperty("location"));
+ });
+ }
+
+ @Test
+ @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_MULTI_PROPERTIES)
+ @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES)
+ public void shouldNotGenerateNodesAndRelationshipsForMultiPropertiesWithSingle() {
+ graph.tx().readWrite();
+ tryCommit(graph, graph -> validateCounts(0, 0, 0, 0));
+ Vertex vertex = graph.addVertex(T.label, "person");
+ tryCommit(graph, graph -> validateCounts(1, 0, 1, 0));
+ vertex.property(VertexProperty.Cardinality.list, "name", "marko");
+ assertEquals("marko", vertex.value("name"));
+ tryCommit(graph, graph -> validateCounts(1, 0, 1, 0));
+ vertex.property(VertexProperty.Cardinality.single, "name", "okram");
+ tryCommit(graph, graph -> {
+ validateCounts(1, 0, 1, 0);
+ assertEquals("okram", vertex.value("name"));
+ });
+ VertexProperty vertexProperty = vertex.property("name");
+ tryCommit(graph, graph -> {
+ assertTrue(vertexProperty.isPresent());
+ assertEquals("name", vertexProperty.key());
+ assertEquals("okram", vertexProperty.value());
+ validateCounts(1, 0, 1, 0);
+ });
+
+ // now make it a meta property (and thus, force node/relationship creation)
+ vertexProperty.property("acl", "private");
+ tryCommit(graph, graph -> {
+ assertEquals("private", vertexProperty.value("acl"));
+ validateCounts(1, 0, 2, 1);
+ });
+
+ }
+
+ @Test
+ public void shouldSupportNeo4jMultiLabels() {
+ final Neo4jVertex vertex = (Neo4jVertex) graph.addVertex(T.label, "animal::person", "name", "marko");
+ tryCommit(graph, graph -> {
+ assertTrue(vertex.label().equals("animal::person"));
+ assertEquals(2, vertex.labels().size());
+ assertTrue(vertex.labels().contains("person"));
+ assertTrue(vertex.labels().contains("animal"));
+ assertEquals(2, IteratorUtils.count(vertex.getBaseVertex().labels().iterator()));
+ });
+
+ vertex.addLabel("organism");
+ tryCommit(graph, graph -> {
+ assertTrue(vertex.label().equals("animal::organism::person"));
+ assertEquals(3, vertex.labels().size());
+ assertTrue(vertex.labels().contains("person"));
+ assertTrue(vertex.labels().contains("animal"));
+ assertTrue(vertex.labels().contains("organism"));
+ assertEquals(3, IteratorUtils.count(vertex.getBaseVertex().labels().iterator()));
+ });
+
+ vertex.removeLabel("person");
+ tryCommit(graph, graph -> {
+ assertTrue(vertex.label().equals("animal::organism"));
+ assertEquals(2, vertex.labels().size());
+ assertTrue(vertex.labels().contains("animal"));
+ assertTrue(vertex.labels().contains("organism"));
+ });
+
+ vertex.addLabel("organism"); // repeat add
+ vertex.removeLabel("person"); // repeat remove
+ tryCommit(graph, graph -> {
+ assertTrue(vertex.label().equals("animal::organism"));
+ assertEquals(2, vertex.labels().size());
+ assertTrue(vertex.labels().contains("animal"));
+ assertTrue(vertex.labels().contains("organism"));
+ assertEquals(2, IteratorUtils.count(vertex.getBaseVertex().labels().iterator()));
+ });
+
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/c850d5e7/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/structure/SimpleNeo4jGraphNativeNeo4jTest.java
----------------------------------------------------------------------
diff --git a/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/structure/SimpleNeo4jGraphNativeNeo4jTest.java b/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/structure/SimpleNeo4jGraphNativeNeo4jTest.java
new file mode 100644
index 0000000..c0caa13
--- /dev/null
+++ b/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/structure/SimpleNeo4jGraphNativeNeo4jTest.java
@@ -0,0 +1,36 @@
+/*
+ *
+ * * 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.neo4j.structure;
+
+import org.apache.tinkerpop.gremlin.GraphProviderClass;
+import org.apache.tinkerpop.gremlin.neo4j.NativeNeo4jSuite;
+import org.apache.tinkerpop.gremlin.neo4j.SimpleNeo4jGraphProvider;
+import org.apache.tinkerpop.gremlin.neo4j.structure.simple.SimpleNeo4jGraph;
+import org.junit.runner.RunWith;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+@RunWith(NativeNeo4jSuite.class)
+@GraphProviderClass(provider = SimpleNeo4jGraphProvider.class, graph = SimpleNeo4jGraph.class)
+public class SimpleNeo4jGraphNativeNeo4jTest {
+}
[2/2] incubator-tinkerpop git commit: added
ElementHelper.attachProperties() for vertices which checks Cardinality from
the graph.
Posted by ok...@apache.org.
added ElementHelper.attachProperties() for vertices which checks Cardinality from the graph.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/c850d5e7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/c850d5e7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/c850d5e7
Branch: refs/heads/neo4j-gremlin-apache
Commit: c850d5e773543089ac1b69f3ea80413a09b6f81a
Parents: a193900
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Thu May 28 15:51:48 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Thu May 28 15:51:48 2015 -0600
----------------------------------------------------------------------
.../gremlin/structure/util/ElementHelper.java | 19 +
.../groovy/plugin/HadoopGremlinPluginTest.java | 5 +-
.../gremlin/neo4j/AbstractNeo4jGremlinTest.java | 50 ++
.../gremlin/neo4j/BaseNeo4jGraphTest.java | 92 ---
.../gremlin/neo4j/NativeNeo4jSuite.java | 46 ++
.../tinkerpop/gremlin/neo4j/Neo4jGraphTest.java | 721 -------------------
.../neo4j/process/NativeNeo4jCypherTest.java | 126 ++++
.../neo4j/process/Neo4jCypherStartTest.java | 117 ---
.../FullNeo4jGraphNativeNeo4jTest.java | 36 +
.../structure/NativeNeo4jStructureTest.java | 718 ++++++++++++++++++
.../SimpleNeo4jGraphNativeNeo4jTest.java | 36 +
11 files changed, 1034 insertions(+), 932 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/c850d5e7/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelper.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelper.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelper.java
index 931f1ae..c77b82d 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelper.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelper.java
@@ -266,6 +266,25 @@ public final class ElementHelper {
}
/**
+ * Assign key/value pairs as properties to an {@link org.apache.tinkerpop.gremlin.structure.Vertex}. If the value of {@link T#id} or
+ * {@link T#label} is in the set of pairs, then they are ignored. The {@link org.apache.tinkerpop.gremlin.structure.VertexProperty.Cardinality} of the key is determined from the {@link org.apache.tinkerpop.gremlin.structure.Graph.Features.VertexFeatures}.
+ *
+ * @param vertex the graph vertex to assign the {@code propertyKeyValues}
+ * @param propertyKeyValues the key/value pairs to assign to the {@code element}
+ * @throws ClassCastException if the value of the key is not a {@link String}
+ * @throws IllegalArgumentException if the value of {@code element} is null
+ */
+ public static void attachProperties(final Vertex vertex, final Object... propertyKeyValues) {
+ if (null == vertex)
+ throw Graph.Exceptions.argumentCanNotBeNull("vertex");
+
+ for (int i = 0; i < propertyKeyValues.length; i = i + 2) {
+ if (!propertyKeyValues[i].equals(T.id) && !propertyKeyValues[i].equals(T.label))
+ vertex.property(vertex.graph().features().vertex().getCardinality((String) propertyKeyValues[i]), (String) propertyKeyValues[i], propertyKeyValues[i + 1]);
+ }
+ }
+
+ /**
* Assign key/value pairs as properties to a {@link org.apache.tinkerpop.gremlin.structure.Vertex}. If the value of {@link T#id} or
* {@link T#label} is in the set of pairs, then they are ignored.
*
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/c850d5e7/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/groovy/plugin/HadoopGremlinPluginTest.java
----------------------------------------------------------------------
diff --git a/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/groovy/plugin/HadoopGremlinPluginTest.java b/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/groovy/plugin/HadoopGremlinPluginTest.java
index 8499840..404a375 100644
--- a/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/groovy/plugin/HadoopGremlinPluginTest.java
+++ b/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/groovy/plugin/HadoopGremlinPluginTest.java
@@ -23,6 +23,7 @@ package org.apache.tinkerpop.gremlin.hadoop.groovy.plugin;
import org.apache.tinkerpop.gremlin.AbstractGremlinTest;
import org.apache.tinkerpop.gremlin.LoadGraphWith;
+import org.apache.tinkerpop.gremlin.groovy.plugin.RemoteAcceptor;
import org.apache.tinkerpop.gremlin.groovy.util.TestableConsolePluginAcceptor;
import org.apache.tinkerpop.gremlin.hadoop.HadoopGraphProvider;
import org.apache.tinkerpop.gremlin.process.AbstractGremlinProcessTest;
@@ -65,7 +66,7 @@ public class HadoopGremlinPluginTest extends AbstractGremlinTest {
private HadoopRemoteAcceptor remote;
private TestableConsolePluginAcceptor console;
- /*@Test
+ @Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSupportRemoteTraversal() throws Exception {
this.console.addBinding("graph", this.graph);
@@ -91,7 +92,7 @@ public class HadoopGremlinPluginTest extends AbstractGremlinTest {
assertEquals(28.0d, traversal.next());
assertFalse(traversal.hasNext());
assertNotNull(this.console.getBindings().get(RemoteAcceptor.RESULT));
- }*/
+ }
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/c850d5e7/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/AbstractNeo4jGremlinTest.java
----------------------------------------------------------------------
diff --git a/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/AbstractNeo4jGremlinTest.java b/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/AbstractNeo4jGremlinTest.java
new file mode 100644
index 0000000..b67aee7
--- /dev/null
+++ b/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/AbstractNeo4jGremlinTest.java
@@ -0,0 +1,50 @@
+/*
+ *
+ * * 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.neo4j;
+
+import org.apache.tinkerpop.gremlin.AbstractGremlinTest;
+import org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jGraph;
+import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
+import org.neo4j.tinkerpop.api.Neo4jGraphAPI;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class AbstractNeo4jGremlinTest extends AbstractGremlinTest {
+
+ protected Neo4jGraph getGraph() {
+ return (Neo4jGraph) this.graph;
+ }
+
+ protected Neo4jGraphAPI getBaseGraph() {
+ return ((Neo4jGraph) this.graph).getBaseGraph();
+ }
+
+ protected void validateCounts(int gV, int gE, int gN, int gR) {
+ assertEquals(gV, IteratorUtils.count(graph.vertices()));
+ assertEquals(gE, IteratorUtils.count(graph.edges()));
+ assertEquals(gN, IteratorUtils.count(this.getBaseGraph().allNodes()));
+ assertEquals(gR, IteratorUtils.count(this.getBaseGraph().allRelationships()));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/c850d5e7/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/BaseNeo4jGraphTest.java
----------------------------------------------------------------------
diff --git a/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/BaseNeo4jGraphTest.java b/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/BaseNeo4jGraphTest.java
deleted file mode 100644
index d7f0454..0000000
--- a/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/BaseNeo4jGraphTest.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * 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.neo4j;
-
-import org.apache.commons.configuration.Configuration;
-import org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jGraph;
-import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
-import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.rules.TestName;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.function.Consumer;
-
-import static org.junit.Assert.assertEquals;
-
-/**
- * This should only be used for Neo4j-specific testing that is not related to the Gremlin test suite.
- *
- * @author Stephen Mallette (http://stephen.genoprime.com)
- */
-public class BaseNeo4jGraphTest {
- protected Configuration conf;
- protected final FullNeo4jGraphProvider graphProvider = new FullNeo4jGraphProvider();
- protected Neo4jGraph graph;
- protected GraphTraversalSource g;
-
- @Rule
- public TestName name = new TestName();
-
- @Before
- public void before() throws Exception {
- // tests that involve legacy indices need legacy indices turned on at startup of the graph.
- final Map<String, Object> neo4jSettings = new HashMap<>();
- if (name.getMethodName().contains("NoMultiProperties"))
- neo4jSettings.put(Neo4jGraph.CONFIG_MULTI_PROPERTIES, false);
- if (name.getMethodName().contains("NoMetaProperties"))
- neo4jSettings.put(Neo4jGraph.CONFIG_META_PROPERTIES, false);
- if (name.getMethodName().contains("Legacy")) {
- neo4jSettings.put("gremlin.neo4j.conf.node_auto_indexing", "true");
- neo4jSettings.put("gremlin.neo4j.conf.relationship_auto_indexing", "true");
- }
-
- this.conf = neo4jSettings.size() == 0 ?
- this.graphProvider.newGraphConfiguration("standard", this.getClass(), name.getMethodName(), null) :
- this.graphProvider.newGraphConfiguration("standard", this.getClass(), name.getMethodName(), null);
-
- this.graphProvider.clear(this.conf);
- this.graph = Neo4jGraph.open(this.conf);
- this.g = this.graph.traversal();
-
- }
-
- @After
- public void after() throws Exception {
- this.graphProvider.clear(this.graph, this.conf);
- }
-
- protected void tryCommit(final Neo4jGraph g, final Consumer<Neo4jGraph> assertFunction) {
- assertFunction.accept(g);
- if (g.features().graph().supportsTransactions()) {
- g.tx().commit();
- assertFunction.accept(g);
- }
- }
-
- protected static void validateCounts(final Neo4jGraph graph, int gV, int gE, int gN, int gR) {
- assertEquals(gV, IteratorUtils.count(graph.vertices()));
- assertEquals(gE, IteratorUtils.count(graph.edges()));
- assertEquals(gN, IteratorUtils.count(graph.getBaseGraph().allNodes()));
- assertEquals(gR, IteratorUtils.count(graph.getBaseGraph().allRelationships()));
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/c850d5e7/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/NativeNeo4jSuite.java
----------------------------------------------------------------------
diff --git a/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/NativeNeo4jSuite.java b/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/NativeNeo4jSuite.java
new file mode 100644
index 0000000..cf23fda
--- /dev/null
+++ b/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/NativeNeo4jSuite.java
@@ -0,0 +1,46 @@
+/*
+ *
+ * * 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.neo4j;
+
+import org.apache.tinkerpop.gremlin.AbstractGremlinSuite;
+import org.apache.tinkerpop.gremlin.neo4j.process.NativeNeo4jCypherTest;
+import org.apache.tinkerpop.gremlin.neo4j.structure.NativeNeo4jStructureTest;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalEngine;
+import org.junit.runners.model.InitializationError;
+import org.junit.runners.model.RunnerBuilder;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class NativeNeo4jSuite extends AbstractGremlinSuite {
+
+ public NativeNeo4jSuite(final Class<?> klass, final RunnerBuilder builder) throws InitializationError {
+ super(klass, builder,
+ new Class<?>[]{
+ NativeNeo4jStructureTest.class,
+ NativeNeo4jCypherTest.class,
+ }, new Class<?>[]{
+ NativeNeo4jStructureTest.class,
+ NativeNeo4jCypherTest.class}, true, TraversalEngine.Type.STANDARD);
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/c850d5e7/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/Neo4jGraphTest.java
----------------------------------------------------------------------
diff --git a/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/Neo4jGraphTest.java b/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/Neo4jGraphTest.java
deleted file mode 100644
index ba064a4..0000000
--- a/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/Neo4jGraphTest.java
+++ /dev/null
@@ -1,721 +0,0 @@
-/*
- *
- * * 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.neo4j;
-
-import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine;
-import org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jVertex;
-import org.apache.tinkerpop.gremlin.neo4j.structure.full.FullNeo4jVertexProperty;
-import org.apache.tinkerpop.gremlin.process.traversal.P;
-import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
-import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
-import org.apache.tinkerpop.gremlin.structure.T;
-import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.tinkerpop.gremlin.structure.VertexProperty;
-import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
-import org.junit.Test;
-import org.neo4j.tinkerpop.api.Neo4jDirection;
-import org.neo4j.tinkerpop.api.Neo4jGraphAPI;
-import org.neo4j.tinkerpop.api.Neo4jNode;
-import org.neo4j.tinkerpop.api.Neo4jRelationship;
-import org.neo4j.tinkerpop.api.Neo4jTx;
-
-import javax.script.Bindings;
-import javax.script.ScriptException;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import static org.junit.Assert.*;
-
-/**
- * These are tests specific to Neo4j.
- *
- * @author Stephen Mallette (http://stephen.genoprime.com)
- * @author Pieter Martin
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public class Neo4jGraphTest extends BaseNeo4jGraphTest {
-
- @Test
- public void shouldOpenWithOverriddenConfig() throws Exception {
- assertNotNull(this.graph);
- }
-
- @Test
- public void shouldNotThrowConcurrentModificationException() {
- this.graph.addVertex("name", "a");
- this.graph.addVertex("name", "b");
- this.graph.addVertex("name", "c");
- this.graph.addVertex("name", "d");
- this.graph.vertices().forEachRemaining(Vertex::remove);
- this.graph.tx().commit();
- assertEquals(0, IteratorUtils.count(this.graph.vertices()), 0);
- }
-
- /**
- * Neo4j upgrades from 1.x don't come with labels.
- */
- @Test
- public void shouldTraverseWithoutLabels() {
- final Neo4jGraphAPI service = graph.getBaseGraph();
-
- final Neo4jTx tx = service.tx();
- final Neo4jNode n = service.createNode();
- tx.success();
- tx.close();
-
- final Neo4jTx tx2 = service.tx();
- assertEquals(0, IteratorUtils.count(n.labels().iterator()));
- assertEquals(1, IteratorUtils.count(graph.vertices()));
- graph.tx().close();
- tx2.close();
- }
-
- @Test
- public void shouldReturnResultsLabeledIndexOnVertexWithHasHas() {
- this.graph.tx().readWrite();
- this.graph.getBaseGraph().execute("CREATE INDEX ON :Person(name)", null);
- this.graph.tx().commit();
- this.graph.addVertex(T.label, "Person", "name", "marko");
- this.graph.addVertex(T.label, "Person", "name", "marko");
- this.graph.tx().commit();
- assertEquals(2, this.g.V().has(T.label, "Person").has("name", "marko").count().next(), 0);
- assertEquals(2, this.g.V().has("name", "marko").count().next(), 0);
- }
-
- @Test
- public void shouldEnsureColonedKeyIsTreatedAsNormalKey() {
- this.graph.tx().readWrite();
- this.graph.getBaseGraph().execute("CREATE INDEX ON :Person(name)", null);
- this.graph.tx().commit();
- this.graph.addVertex(T.label, "Person", "name", "marko");
- this.graph.addVertex(T.label, "Person", "name", "marko");
- this.graph.tx().commit();
- assertEquals(2, this.g.V().has(T.label, "Person").has("name", "marko").count().next(), 0);
- assertEquals(0, this.g.V().has("Person:name", "marko").count().next(), 0);
-
- }
-
- @Test
- public void shouldReturnResultsUsingLabeledIndexOnVertexWithHasHasHas() {
- this.graph.tx().readWrite();
- this.graph.getBaseGraph().execute("CREATE INDEX ON :Person(name)", null);
- this.graph.tx().commit();
- this.graph.addVertex(T.label, "Person", "name", "marko", "color", "blue");
- this.graph.addVertex(T.label, "Person", "name", "marko", "color", "green");
- this.graph.tx().commit();
- assertEquals(1, this.g.V().has(T.label, "Person").has("name", "marko").has("color", "blue").count().next(), 0);
- assertEquals(2, this.g.V().has("name", "marko").count().next(), 0);
- }
-
- @Test
- public void shouldReturnResultsOnVertexWithHasHasHasNoIndex() {
- this.graph.tx().commit();
- this.graph.addVertex(T.label, "Person", "name", "marko", "color", "blue");
- this.graph.addVertex(T.label, "Person", "name", "marko", "color", "green");
- this.graph.tx().commit();
- assertEquals(1, this.g.V().has(T.label, "Person").has("name", "marko").has("color", "blue").count().next(), 0);
- assertEquals(2, this.g.V().has("name", "marko").count().next(), 0);
- }
-
- @Test
- public void shouldReturnResultsUsingLabeledIndexOnVertexWithColonFails() {
- this.graph.tx().readWrite();
- this.graph.getBaseGraph().execute("CREATE INDEX ON :Person(name)", null);
- this.graph.tx().commit();
- this.graph.addVertex(T.label, "Person", "name", "marko");
- this.graph.addVertex(T.label, "Person", "name", "marko");
- this.graph.tx().commit();
- assertNotEquals(2l, this.g.V().has("Person:name", "marko").count().next().longValue());
- assertEquals(2, this.g.V().has("name", "marko").count().next(), 0);
- }
-
- @Test
- public void shouldReturnResultsUsingLegacyIndexOnVertex() {
- graph.tx().readWrite();
- this.graph.getBaseGraph().autoIndexProperties(true, "name");
- this.graph.tx().commit();
-
- this.graph.addVertex(T.label, "Person", "name", "marko");
- this.graph.addVertex(T.label, "Person", "name", "marko");
- this.graph.tx().commit();
- assertEquals(2, this.g.V().has("Person", "name", "marko").count().next(), 0);
- assertEquals(2, this.g.V().has("name", "marko").count().next(), 0);
- }
-
- @Test
- public void shouldUseLegacyIndexOnEdge() {
- graph.tx().readWrite();
- this.graph.getBaseGraph().autoIndexProperties(true, "weight");
- this.graph.tx().commit();
-
- Vertex marko = this.graph.addVertex(T.label, "Person", "name", "marko");
- Vertex john = this.graph.addVertex(T.label, "Person", "name", "john");
- Vertex pete = this.graph.addVertex(T.label, "Person", "name", "pete");
- marko.addEdge("friend", john, "weight", "a");
- marko.addEdge("friend", pete, "weight", "a");
- this.graph.tx().commit();
- assertEquals(2, this.g.E().has("weight", "a").count().next(), 0);
- }
-
- @Test
- public void shouldEnforceUniqueConstraint() {
- this.graph.tx().readWrite();
- this.graph.getBaseGraph().execute("CREATE CONSTRAINT ON (p:Person) assert p.name is unique", null);
- this.graph.tx().commit();
- this.graph.tx().commit();
- this.graph.addVertex(T.label, "Person", "name", "marko");
- this.graph.tx().commit();
- assertEquals("marko", g.V().has(T.label, "Person").has("name", "marko").next().value("name"));
- }
-
- @Test
- public void shouldEnforceMultipleUniqueConstraint() {
- this.graph.tx().readWrite();
- this.graph.getBaseGraph().execute("CREATE CONSTRAINT ON (p:Person) assert p.name is unique", null);
- this.graph.getBaseGraph().execute("CREATE CONSTRAINT ON (p:Person) assert p.surname is unique", null);
- this.graph.tx().commit();
- this.graph.addVertex(T.label, "Person", "name", "marko");
- this.graph.addVertex(T.label, "Person", "surname", "aaaa");
- this.graph.tx().commit();
- boolean failSurname = false;
- try {
- this.graph.addVertex(T.label, "Person", "surname", "aaaa");
- } catch (RuntimeException e) {
- if (isConstraintViolation(e)) failSurname = true;
- }
- assertTrue(failSurname);
- boolean failName = false;
- try {
- this.graph.addVertex(T.label, "Person", "name", "marko");
- } catch (RuntimeException e) {
- if (isConstraintViolation(e)) failName = true;
- }
- assertTrue(failName);
- this.graph.tx().commit();
- }
-
- private boolean isConstraintViolation(RuntimeException e) {
- return e.getClass().getSimpleName().equals("ConstraintViolationException");
- }
-
- @Test
- public void shouldDropMultipleUniqueConstraint() {
- this.graph.tx().readWrite();
- this.graph.getBaseGraph().execute("CREATE CONSTRAINT ON (p:Person) assert p.name is unique", null);
- this.graph.getBaseGraph().execute("CREATE CONSTRAINT ON (p:Person) assert p.surname is unique", null);
- this.graph.tx().commit();
-
- this.graph.addVertex(T.label, "Person", "name", "marko");
- this.graph.addVertex(T.label, "Person", "surname", "aaaa");
- this.graph.tx().commit();
- boolean failSurname = false;
- try {
- this.graph.addVertex(T.label, "Person", "surname", "aaaa");
- } catch (RuntimeException e) {
- if (isConstraintViolation(e)) failSurname = true;
- }
- assertTrue(failSurname);
- boolean failName = false;
- try {
- this.graph.addVertex(T.label, "Person", "name", "marko");
- } catch (RuntimeException e) {
- if (isConstraintViolation(e)) failName = true;
- }
- assertTrue(failName);
- this.graph.tx().commit();
-
- this.graph.tx().readWrite();
- this.graph.getBaseGraph().execute("DROP CONSTRAINT ON (p:Person) assert p.name is unique", null);
- this.graph.getBaseGraph().execute("DROP CONSTRAINT ON (p:Person) assert p.surname is unique", null);
-
- this.graph.tx().commit();
- assertEquals(1, this.g.V().has(T.label, "Person").has("name", "marko").count().next(), 0);
- assertEquals(1, this.g.V().has(T.label, "Person").has("surname", "aaaa").count().next(), 0);
- this.graph.addVertex(T.label, "Person", "surname", "aaaa");
- this.graph.addVertex(T.label, "Person", "name", "marko");
- this.graph.tx().commit();
- assertEquals(2, this.g.V().has(T.label, "Person").has("name", "marko").count().next(), 0);
- assertEquals(2, this.g.V().has(T.label, "Person").has("surname", "aaaa").count().next(), 0);
- }
-
- @Test(expected = RuntimeException.class)
- public void shouldFailUniqueConstraint() {
- this.graph.tx().readWrite();
- this.graph.getBaseGraph().execute("CREATE CONSTRAINT ON (p:Person) assert p.name is unique", null);
- this.graph.tx().commit();
- this.graph.addVertex(T.label, "Person", "name", "marko");
- this.graph.tx().commit();
- assertEquals("marko", g.V().has(T.label, "Person").has("name", "marko").next().value("name"));
- this.graph.addVertex(T.label, "Person", "name", "marko");
- }
-
- @Test
- public void shouldEnsureTraverseRelationshipNeedsTx() throws ScriptException {
- final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine();
- final Bindings bindings = engine.createBindings();
- bindings.put("g", graph.traversal(GraphTraversalSource.standard()));
- bindings.put("#jsr223.groovy.engine.keep.globals", "phantom");
-
- Vertex marko = this.graph.addVertex(T.label, "Person", "name", "marko");
- Vertex john = this.graph.addVertex(T.label, "Person", "name", "john");
- Vertex pete = this.graph.addVertex(T.label, "Person", "name", "pete");
- marko.addEdge("friend", john);
- marko.addEdge("friend", pete);
- this.graph.tx().commit();
-
- Object result = engine.eval("g.V(" + marko.id().toString() + ").outE('friend')", bindings);
- assertTrue(result instanceof GraphTraversal);
-
- this.graph.tx().commit();
- assertEquals(2L, ((GraphTraversal) result).count().next());
- }
-
- @Test
- public void shouldEnsureTraversalOfVerticesNeedsTx() throws ScriptException {
- final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine();
- final Bindings bindings = engine.createBindings();
- bindings.put("g", graph.traversal(GraphTraversalSource.standard()));
- bindings.put("#jsr223.groovy.engine.keep.globals", "phantom");
-
- Vertex marko = this.graph.addVertex(T.label, "Person", "name", "marko");
- Vertex john = this.graph.addVertex(T.label, "Person", "name", "john");
- Vertex pete = this.graph.addVertex(T.label, "Person", "name", "pete");
- marko.addEdge("friend", john);
- marko.addEdge("friend", pete);
- this.graph.tx().commit();
-
- Object result = engine.eval("g.V(" + marko.id().toString() + ").out('friend')", bindings);
- assertTrue(result instanceof GraphTraversal);
-
- this.graph.tx().commit();
- assertEquals(2L, ((GraphTraversal) result).count().next());
- }
-
- @Test
- public void shouldDoLabelSearch() {
- this.graph.addVertex(T.label, "Person", "name", "marko");
- this.graph.addVertex(T.label, "Person", "name", "john");
- Vertex pete = this.graph.addVertex(T.label, "Person", "name", "pete");
- this.graph.addVertex(T.label, "Monkey", "name", "pete");
- this.graph.tx().commit();
- assertEquals(3, this.g.V().has(T.label, "Person").count().next(), 0);
- pete.remove();
- this.graph.tx().commit();
- assertEquals(2, this.g.V().has(T.label, "Person").count().next(), 0);
- }
-
- @Test
- public void shouldDoLabelAndIndexSearch() {
- graph.tx().readWrite();
- this.graph.getBaseGraph().execute("CREATE INDEX ON :Person(name)", null);
- this.graph.tx().commit();
-
- this.graph.addVertex(T.label, "Person", "name", "marko");
- this.graph.addVertex(T.label, "Person", "name", "john");
- this.graph.addVertex(T.label, "Person", "name", "pete");
- this.graph.tx().commit();
- assertEquals(1, this.g.V().has("Person", "name", "marko").count().next(), 0);
- assertEquals(3, this.g.V().has(T.label, "Person").count().next(), 0);
- assertEquals(1, this.g.V().has(T.label, "Person").has("name", "marko").count().next(), 0);
- }
-
- @Test
- public void shouldDoLabelAndLegacyIndexSearch() {
- graph.tx().readWrite();
-
- this.graph.getBaseGraph().execute("CREATE INDEX ON :Person(name)", null);
- this.graph.getBaseGraph().autoIndexProperties(true, "name");
-
- this.graph.tx().commit();
- this.graph.addVertex(T.label, "Person", "name", "marko");
- this.graph.addVertex(T.label, "Person", "name", "john");
- this.graph.addVertex(T.label, "Person", "name", "pete");
- this.graph.tx().commit();
- assertEquals(1, this.g.V().has(T.label, "Person").has("name", "marko").count().next(), 0);
- assertEquals(3, this.g.V().has(T.label, "Person").count().next(), 0);
- assertEquals(1, this.g.V().has("name", "john").count().next(), 0);
-
- }
-
- @Test
- public void shouldSupportVertexPropertyToVertexMappingOnIndexCalls() {
- // todo: review this feature check - this test does a lot of stuff - maybe losing some important assertions this way
- if (graph.features().vertex().supportsMultiProperties()) {
- graph.tx().readWrite();
- this.graph.getBaseGraph().execute("CREATE INDEX ON :person(name)", null);
-// this.graph.getBaseGraph().execute("CREATE INDEX ON :name(" + T.value.getAccessor() + ")", null);
- this.graph.tx().commit();
-
- final Vertex a = graph.addVertex(T.label, "person", "name", "marko", "age", 34);
- a.property(VertexProperty.Cardinality.list, "name", "okram");
- a.property(VertexProperty.Cardinality.list, "name", "marko a. rodriguez");
- final Vertex b = graph.addVertex(T.label, "person", "name", "stephen");
- final Vertex c = graph.addVertex("name", "matthias", "name", "mbroecheler");
-
- tryCommit(graph, graph -> {
- assertEquals(a.id(), graph.traversal().V().has("person", "name", "okram").id().next());
- assertEquals(1, graph.traversal().V().has("person", "name", "okram").count().next().intValue());
- assertEquals(34, ((Neo4jVertex) graph.traversal().V().has("person", "name", "okram").next()).getBaseVertex().getProperty("age"));
- assertEquals(FullNeo4jVertexProperty.VERTEX_PROPERTY_TOKEN, ((Neo4jVertex) graph.traversal().V().has("person", "name", "okram").next()).getBaseVertex().getProperty("name"));
- ///
- assertEquals(b.id(), graph.traversal().V().has("person", "name", "stephen").id().next());
- assertEquals(1, graph.traversal().V().has("person", "name", "stephen").count().next().intValue());
- assertEquals("stephen", ((Neo4jVertex) graph.traversal().V().has("person", "name", "stephen").next()).getBaseVertex().getProperty("name"));
- ///
- assertEquals(c.id(), graph.traversal().V().has("name", "matthias").id().next());
- assertEquals(c.id(), graph.traversal().V().has("name", "mbroecheler").id().next());
- assertEquals(1, graph.traversal().V().has("name", "matthias").count().next().intValue());
- assertEquals(1, graph.traversal().V().has("name", "mbroecheler").count().next().intValue());
- assertEquals(0, graph.traversal().V().has("person", "name", "matthias").count().next().intValue());
- assertEquals(0, graph.traversal().V().has("person", "name", "mbroecheler").count().next().intValue());
- });
-
- final Vertex d = graph.addVertex(T.label, "person", "name", "kuppitz");
- tryCommit(graph, graph -> {
- assertEquals(d.id(), graph.traversal().V().has("person", "name", "kuppitz").id().next());
- assertEquals("kuppitz", ((Neo4jVertex) graph.traversal().V().has("person", "name", "kuppitz").next()).getBaseVertex().getProperty("name"));
- });
- d.property(VertexProperty.Cardinality.list, "name", "daniel", "acl", "private");
- tryCommit(graph, graph -> {
- assertEquals(d.id(), graph.traversal().V().has("person", "name", P.within("daniel", "kuppitz")).id().next());
- assertEquals(d.id(), graph.traversal().V().has("person", "name", "kuppitz").id().next());
- assertEquals(d.id(), graph.traversal().V().has("person", "name", "daniel").id().next());
- assertEquals(FullNeo4jVertexProperty.VERTEX_PROPERTY_TOKEN, ((Neo4jVertex) graph.traversal().V().has("person", "name", "kuppitz").next()).getBaseVertex().getProperty("name"));
- });
- d.property(VertexProperty.Cardinality.list, "name", "marko", "acl", "private");
- tryCommit(graph, g -> {
- assertEquals(2, g.traversal().V().has("person", "name", "marko").count().next().intValue());
- assertEquals(1, g.traversal().V().has("person", "name", "marko").properties("name").has(T.value, "marko").has("acl", "private").count().next().intValue());
- g.traversal().V().has("person", "name", "marko").forEachRemaining(v -> {
- assertEquals(FullNeo4jVertexProperty.VERTEX_PROPERTY_TOKEN, ((Neo4jVertex) v).getBaseVertex().getProperty("name"));
- });
-
- });
- }
- }
-
- @Test
- public void shouldDoLabelsNamespaceBehavior() {
- graph.tx().readWrite();
-
- this.graph.getBaseGraph().execute("CREATE INDEX ON :Person(name)", null);
- this.graph.getBaseGraph().execute("CREATE INDEX ON :Product(name)", null);
- this.graph.getBaseGraph().execute("CREATE INDEX ON :Corporate(name)", null);
-
- this.graph.tx().commit();
- this.graph.addVertex(T.label, "Person", "name", "marko");
- this.graph.addVertex(T.label, "Person", "name", "john");
- this.graph.addVertex(T.label, "Person", "name", "pete");
- this.graph.addVertex(T.label, "Product", "name", "marko");
- this.graph.addVertex(T.label, "Product", "name", "john");
- this.graph.addVertex(T.label, "Product", "name", "pete");
- this.graph.addVertex(T.label, "Corporate", "name", "marko");
- this.graph.addVertex(T.label, "Corporate", "name", "john");
- this.graph.addVertex(T.label, "Corporate", "name", "pete");
- this.graph.tx().commit();
- assertEquals(1, this.g.V().has(T.label, "Person").has("name", "marko").has(T.label, "Person").count().next(), 0);
- assertEquals(1, this.g.V().has(T.label, "Product").has("name", "marko").has(T.label, "Product").count().next(), 0);
- assertEquals(1, this.g.V().has(T.label, "Corporate").has("name", "marko").has(T.label, "Corporate").count().next(), 0);
- assertEquals(0, this.g.V().has(T.label, "Person").has("name", "marko").has(T.label, "Product").count().next(), 0);
- assertEquals(0, this.g.V().has(T.label, "Product").has("name", "marko").has(T.label, "Person").count().next(), 0);
- assertEquals(0, this.g.V().has(T.label, "Corporate").has("name", "marko").has(T.label, "Person").count().next(), 0);
- }
-
- @Test
- public void shouldNotGenerateVerticesOrEdgesForGraphVariables() {
- graph.tx().readWrite();
- graph.variables().set("namespace", "rdf-xml");
- tryCommit(graph, graph -> {
- assertEquals("rdf-xml", graph.variables().get("namespace").get());
- assertEquals(0, graph.traversal().V().count().next().intValue());
- assertEquals(0, graph.traversal().E().count().next().intValue());
- assertEquals(0, IteratorUtils.count(graph.getBaseGraph().allNodes()));
- assertEquals(0, IteratorUtils.count(graph.getBaseGraph().allRelationships()));
- });
- }
-
- @Test
- public void shouldNotGenerateNodesAndRelationshipsForNoMultiPropertiesNoMetaProperties() {
- graph.tx().readWrite();
- tryCommit(graph, g -> validateCounts(g, 0, 0, 0, 0));
- Vertex vertex = graph.addVertex(T.label, "person");
- tryCommit(graph, g -> validateCounts(g, 1, 0, 1, 0));
- vertex.property(VertexProperty.Cardinality.list, "name", "marko");
- assertEquals("marko", vertex.value("name"));
- tryCommit(graph, g -> validateCounts(g, 1, 0, 1, 0));
- vertex.property(VertexProperty.Cardinality.list, "name", "okram");
- tryCommit(graph, g -> {
- validateCounts(g, 1, 0, 1, 0);
- assertEquals("okram", vertex.value("name"));
- });
- VertexProperty vertexProperty = vertex.property("name");
- tryCommit(graph, g -> {
- assertTrue(vertexProperty.isPresent());
- assertEquals("name", vertexProperty.key());
- assertEquals("okram", vertexProperty.value());
- validateCounts(g, 1, 0, 1, 0);
- });
- try {
- vertexProperty.property("acl", "private");
- } catch (UnsupportedOperationException e) {
- assertEquals(VertexProperty.Exceptions.metaPropertiesNotSupported().getMessage(), e.getMessage());
- }
- }
-
- @Test
- public void shouldNotGenerateNodesAndRelationshipsForMultiPropertiesWithSingle() {
- graph.tx().readWrite();
- tryCommit(graph, g -> validateCounts(g, 0, 0, 0, 0));
- Vertex vertex = graph.addVertex(T.label, "person");
- tryCommit(graph, g -> validateCounts(g, 1, 0, 1, 0));
- vertex.property(VertexProperty.Cardinality.list, "name", "marko");
- assertEquals("marko", vertex.value("name"));
- tryCommit(graph, g -> validateCounts(g, 1, 0, 1, 0));
- vertex.property(VertexProperty.Cardinality.single, "name", "okram");
- tryCommit(graph, g -> {
- validateCounts(g, 1, 0, 1, 0);
- assertEquals("okram", vertex.value("name"));
- });
- VertexProperty vertexProperty = vertex.property("name");
- tryCommit(graph, g -> {
- assertTrue(vertexProperty.isPresent());
- assertEquals("name", vertexProperty.key());
- assertEquals("okram", vertexProperty.value());
- validateCounts(g, 1, 0, 1, 0);
- });
-
- // now make it a meta property (and thus, force node/relationship creation)
- vertexProperty.property("acl", "private");
- tryCommit(graph, g -> {
- assertEquals("private", vertexProperty.value("acl"));
- validateCounts(g, 1, 0, 2, 1);
- });
-
- }
-
-
- @Test
- public void shouldGenerateNodesAndRelationshipsCorrectlyForVertexProperties() {
- // todo: review this feature check - this test does a lot of stuff - maybe losing some important assertions this way
- if (graph.features().vertex().supportsMultiProperties()) {
- graph.tx().readWrite();
- Neo4jVertex a = (Neo4jVertex) graph.addVertex("name", "marko", "name", "okram");
- Neo4jVertex b = (Neo4jVertex) graph.addVertex("name", "stephen", "location", "virginia");
-
- tryCommit(graph, graph -> {
- assertEquals(2, graph.traversal().V().count().next().intValue());
- // assertEquals(2, a.properties("name").count().next().intValue());
- // assertEquals(1, b.properties("name").count().next().intValue());
- // assertEquals(1, b.properties("location").count().next().intValue());
- // assertEquals(0, g.E().count().next().intValue());
-
- assertEquals(4l, graph.execute("MATCH n RETURN COUNT(n)", null).next().get("COUNT(n)"));
- assertEquals(2l, graph.execute("MATCH (n)-[r]->(m) RETURN COUNT(r)", null).next().get("COUNT(r)"));
- assertEquals(2l, graph.execute("MATCH (a)-[r]->() WHERE id(a) = " + a.id() + " RETURN COUNT(r)", null).next().get("COUNT(r)"));
- final AtomicInteger counter = new AtomicInteger(0);
- a.getBaseVertex().relationships(Neo4jDirection.OUTGOING).forEach(relationship -> {
- assertEquals(FullNeo4jVertexProperty.VERTEX_PROPERTY_PREFIX.concat("name"), relationship.type());
- counter.incrementAndGet();
- });
- assertEquals(2, counter.getAndSet(0));
- graph.execute("MATCH (a)-[]->(m) WHERE id(a) = " + a.id() + " RETURN labels(m)", null).forEachRemaining(results -> {
- assertEquals(VertexProperty.DEFAULT_LABEL, ((List<String>) results.get("labels(m)")).get(0));
- counter.incrementAndGet();
- });
- assertEquals(2, counter.getAndSet(0));
- IteratorUtils.stream(a.getBaseVertex().relationships(Neo4jDirection.OUTGOING)).map(Neo4jRelationship::end).forEach(node -> {
- assertEquals(2, IteratorUtils.count(node.getKeys()));
- assertEquals("name", node.getProperty(T.key.getAccessor()));
- assertTrue("marko".equals(node.getProperty(T.value.getAccessor())) || "okram".equals(node.getProperty(T.value.getAccessor())));
- assertEquals(0, node.degree(Neo4jDirection.OUTGOING, null));
- assertEquals(1, node.degree(Neo4jDirection.INCOMING, null));
- assertEquals(FullNeo4jVertexProperty.VERTEX_PROPERTY_PREFIX.concat("name"), node.relationships(Neo4jDirection.INCOMING).iterator().next().type());
- counter.incrementAndGet();
- });
- assertEquals(2, counter.getAndSet(0));
-
- assertEquals(2, IteratorUtils.count(b.getBaseVertex().getKeys()));
- assertEquals("stephen", b.getBaseVertex().getProperty("name"));
- assertEquals("virginia", b.getBaseVertex().getProperty("location"));
- });
-
- a.property("name", "the marko");
- tryCommit(graph, g -> {
- assertEquals(2, g.traversal().V().count().next().intValue());
- //assertEquals(1, a.prope rties().count().next().intValue());
- // assertEquals(1, b.properties("name").count().next().intValue());
- // assertEquals(1, b.properties("location").count().next().intValue());
- // assertEquals(0, g.E().count().next().intValue());
-
- assertEquals(2l, graph.execute("MATCH n RETURN COUNT(n)", null).next().get("COUNT(n)"));
- assertEquals(0l, graph.execute("MATCH (n)-[r]->(m) RETURN COUNT(r)", null).next().get("COUNT(r)"));
-
- assertEquals(1, IteratorUtils.count(a.getBaseVertex().getKeys()));
- assertEquals("the marko", a.getBaseVertex().getProperty("name"));
- assertEquals(2, IteratorUtils.count(b.getBaseVertex().getKeys()));
- assertEquals("stephen", b.getBaseVertex().getProperty("name"));
- assertEquals("virginia", b.getBaseVertex().getProperty("location"));
- });
-
- a.property("name").remove();
- tryCommit(graph, g -> {
- assertEquals(2, g.traversal().V().count().next().intValue());
- // assertEquals(0, a.properties().count().next().intValue());
- // assertEquals(2, b.properties().count().next().intValue());
- // assertEquals(0, g.E().count().next().intValue());
- assertEquals(2l, graph.execute("MATCH n RETURN COUNT(n)", null).next().get("COUNT(n)"));
- assertEquals(0l, graph.execute("MATCH (n)-[r]->(m) RETURN COUNT(r)", null).next().get("COUNT(r)"));
- assertEquals(0, IteratorUtils.count(a.getBaseVertex().getKeys()));
- assertEquals(2, IteratorUtils.count(b.getBaseVertex().getKeys()));
- });
-
- graph.tx().commit();
- a.property("name", "the marko", "acl", "private");
- tryCommit(graph, g -> {
- assertEquals(2, g.traversal().V().count().next().intValue());
- // assertEquals(1, a.properties("name").count().next().intValue());
- // assertEquals(1, b.properties("name").count().next().intValue());
- // assertEquals(1, b.properties("location").count().next().intValue());
- // assertEquals(0, g.E().count().next().intValue());
-
- assertEquals(3l, graph.execute("MATCH n RETURN COUNT(n)", null).next().get("COUNT(n)"));
- assertEquals(1l, graph.execute("MATCH (n)-[r]->(m) RETURN COUNT(r)", null).next().get("COUNT(r)"));
- assertEquals(1l, graph.execute("MATCH (a)-[r]->() WHERE id(a) = " + a.id() + " RETURN COUNT(r)", null).next().get("COUNT(r)"));
- final AtomicInteger counter = new AtomicInteger(0);
- a.getBaseVertex().relationships(Neo4jDirection.OUTGOING).forEach(relationship -> {
- assertEquals(FullNeo4jVertexProperty.VERTEX_PROPERTY_PREFIX.concat("name"), relationship.type());
- counter.incrementAndGet();
- });
- assertEquals(1, counter.getAndSet(0));
- graph.execute("MATCH (a)-[]->(m) WHERE id(a) = " + a.id() + " RETURN labels(m)", null).forEachRemaining(results -> {
- assertEquals(VertexProperty.DEFAULT_LABEL, ((List<String>) results.get("labels(m)")).get(0));
- counter.incrementAndGet();
- });
- assertEquals(1, counter.getAndSet(0));
- IteratorUtils.stream(a.getBaseVertex().relationships(Neo4jDirection.OUTGOING)).map(Neo4jRelationship::end).forEach(node -> {
- assertEquals(3, IteratorUtils.count(node.getKeys()));
- assertEquals("name", node.getProperty(T.key.getAccessor()));
- assertEquals("the marko", node.getProperty(T.value.getAccessor()));
- assertEquals("private", node.getProperty("acl"));
- assertEquals(0, node.degree(Neo4jDirection.OUTGOING, null));
- assertEquals(1, node.degree(Neo4jDirection.INCOMING, null));
- assertEquals(FullNeo4jVertexProperty.VERTEX_PROPERTY_PREFIX.concat("name"), node.relationships(Neo4jDirection.INCOMING).iterator().next().type());
- counter.incrementAndGet();
- });
- assertEquals(1, counter.getAndSet(0));
-
- assertEquals(1, IteratorUtils.count(a.getBaseVertex().getKeys()));
- assertTrue(a.getBaseVertex().hasProperty("name"));
- assertEquals(FullNeo4jVertexProperty.VERTEX_PROPERTY_TOKEN, a.getBaseVertex().getProperty("name"));
- assertEquals(2, IteratorUtils.count(b.getBaseVertex().getKeys()));
- assertEquals("stephen", b.getBaseVertex().getProperty("name"));
- assertEquals("virginia", b.getBaseVertex().getProperty("location"));
- });
-
- a.property(VertexProperty.Cardinality.list, "name", "marko", "acl", "private");
- a.property(VertexProperty.Cardinality.list, "name", "okram", "acl", "public");
- graph.tx().commit(); // TODO tx.commit() THIS IS REQUIRED: ?! Why does Neo4j not delete vertices correctly?
- a.property(VertexProperty.Cardinality.single, "name", "the marko", "acl", "private");
- tryCommit(graph, g -> {
- assertEquals(2, g.traversal().V().count().next().intValue());
- // assertEquals(1, a.properties("name").count().next().intValue());
- // assertEquals(1, b.properties("name").count().next().intValue());
- // assertEquals(1, b.properties("location").count().next().intValue());
- // assertEquals(0, g.E().count().next().intValue());
-
- assertEquals(3l, graph.execute("MATCH n RETURN COUNT(n)", null).next().get("COUNT(n)"));
- assertEquals(1l, graph.execute("MATCH (n)-[r]->(m) RETURN COUNT(r)", null).next().get("COUNT(r)"));
- assertEquals(1l, graph.execute("MATCH (a)-[r]->() WHERE id(a) = " + a.id() + " RETURN COUNT(r)", null).next().get("COUNT(r)"));
- final AtomicInteger counter = new AtomicInteger(0);
- a.getBaseVertex().relationships(Neo4jDirection.OUTGOING).forEach(relationship -> {
- assertEquals(FullNeo4jVertexProperty.VERTEX_PROPERTY_PREFIX.concat("name"), relationship.type());
- counter.incrementAndGet();
- });
- assertEquals(1, counter.getAndSet(0));
- graph.execute("MATCH (a)-[]->(m) WHERE id(a) = " + a.id() + " RETURN labels(m)", null).forEachRemaining(results -> {
- assertEquals(VertexProperty.DEFAULT_LABEL, ((List<String>) results.get("labels(m)")).get(0));
- counter.incrementAndGet();
- });
- assertEquals(1, counter.getAndSet(0));
- IteratorUtils.stream(a.getBaseVertex().relationships(Neo4jDirection.OUTGOING)).map(Neo4jRelationship::end).forEach(node -> {
- assertEquals(3, IteratorUtils.count(node.getKeys()));
- assertEquals("name", node.getProperty(T.key.getAccessor()));
- assertEquals("the marko", node.getProperty(T.value.getAccessor()));
- assertEquals("private", node.getProperty("acl"));
- assertEquals(0, node.degree(Neo4jDirection.OUTGOING, null));
- assertEquals(1, node.degree(Neo4jDirection.INCOMING, null));
- assertEquals(FullNeo4jVertexProperty.VERTEX_PROPERTY_PREFIX.concat("name"), node.relationships(Neo4jDirection.INCOMING).iterator().next().type());
- counter.incrementAndGet();
- });
- assertEquals(1, counter.getAndSet(0));
-
- assertEquals(1, IteratorUtils.count(a.getBaseVertex().getKeys()));
- assertTrue(a.getBaseVertex().hasProperty("name"));
- assertEquals(FullNeo4jVertexProperty.VERTEX_PROPERTY_TOKEN, a.getBaseVertex().getProperty("name"));
- assertEquals(2, IteratorUtils.count(b.getBaseVertex().getKeys()));
- assertEquals("stephen", b.getBaseVertex().getProperty("name"));
- assertEquals("virginia", b.getBaseVertex().getProperty("location"));
- });
- }
- }
-
- @Test
- public void shouldSupportNeo4jMultiLabels() {
- final Neo4jVertex vertex = (Neo4jVertex) graph.addVertex(T.label, "animal::person", "name", "marko");
- tryCommit(graph, g -> {
- assertTrue(vertex.label().equals("animal::person"));
- assertEquals(2, vertex.labels().size());
- assertTrue(vertex.labels().contains("person"));
- assertTrue(vertex.labels().contains("animal"));
- assertEquals(2, IteratorUtils.count(vertex.getBaseVertex().labels().iterator()));
- });
-
- vertex.addLabel("organism");
- tryCommit(graph, g -> {
- assertTrue(vertex.label().equals("animal::organism::person"));
- assertEquals(3, vertex.labels().size());
- assertTrue(vertex.labels().contains("person"));
- assertTrue(vertex.labels().contains("animal"));
- assertTrue(vertex.labels().contains("organism"));
- assertEquals(3, IteratorUtils.count(vertex.getBaseVertex().labels().iterator()));
- });
-
- vertex.removeLabel("person");
- tryCommit(graph, g -> {
- assertTrue(vertex.label().equals("animal::organism"));
- assertEquals(2, vertex.labels().size());
- assertTrue(vertex.labels().contains("animal"));
- assertTrue(vertex.labels().contains("organism"));
- });
-
- vertex.addLabel("organism"); // repeat add
- vertex.removeLabel("person"); // repeat remove
- tryCommit(graph, g -> {
- assertTrue(vertex.label().equals("animal::organism"));
- assertEquals(2, vertex.labels().size());
- assertTrue(vertex.labels().contains("animal"));
- assertTrue(vertex.labels().contains("organism"));
- assertEquals(2, IteratorUtils.count(vertex.getBaseVertex().labels().iterator()));
- });
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/c850d5e7/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/process/NativeNeo4jCypherTest.java
----------------------------------------------------------------------
diff --git a/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/process/NativeNeo4jCypherTest.java b/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/process/NativeNeo4jCypherTest.java
new file mode 100644
index 0000000..0c8c014
--- /dev/null
+++ b/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/process/NativeNeo4jCypherTest.java
@@ -0,0 +1,126 @@
+/*
+ * 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.neo4j.process;
+
+import org.apache.tinkerpop.gremlin.LoadGraphWith;
+import org.apache.tinkerpop.gremlin.neo4j.AbstractNeo4jGremlinTest;
+import org.apache.tinkerpop.gremlin.process.traversal.Scope;
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.Assert.*;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class NativeNeo4jCypherTest extends AbstractNeo4jGremlinTest {
+
+ @Test
+ @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
+ public void shouldExecuteCypher() throws Exception {
+ this.graph.addVertex("name", "marko");
+ this.graph.tx().commit();
+ final Iterator<Map<String, Object>> result = this.getGraph().cypher("MATCH (a {name:\"marko\"}) RETURN a", Collections.emptyMap());
+ assertNotNull(result);
+ assertTrue(result.hasNext());
+ }
+
+ @Test
+ @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
+ public void shouldExecuteCypherWithArgs() throws Exception {
+ this.graph.addVertex("name", "marko");
+ this.graph.tx().commit();
+ final Map<String, Object> bindings = new HashMap<>();
+ bindings.put("n", "marko");
+ final Iterator<Map<String, Object>> result = this.getGraph().cypher("MATCH (a {name:{n}}) RETURN a", bindings);
+ assertNotNull(result);
+ assertTrue(result.hasNext());
+ }
+
+ @Test
+ @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
+ public void shouldExecuteCypherWithArgsUsingVertexIdList() throws Exception {
+ final Vertex v = this.graph.addVertex("name", "marko");
+ final List<Object> idList = Arrays.asList(v.id());
+ this.graph.tx().commit();
+
+ final Map<String, Object> bindings = new HashMap<>();
+ bindings.put("ids", idList);
+ final Iterator<String> result = this.getGraph().cypher("START n=node({ids}) RETURN n", bindings).select(Scope.local, "n").values("name");
+ assertNotNull(result);
+ assertTrue(result.hasNext());
+ assertEquals("marko", result.next());
+ }
+
+ @Test
+ @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
+ public void shouldExecuteCypherAndBackToGremlin() throws Exception {
+ this.graph.addVertex("name", "marko", "age", 29, "color", "red");
+ this.graph.addVertex("name", "marko", "age", 30, "color", "yellow");
+
+ this.graph.tx().commit();
+ final Traversal result = this.getGraph().cypher("MATCH (a {name:\"marko\"}) RETURN a").select(Scope.local, "a").has("age", 29).values("color");
+ assertNotNull(result);
+ assertTrue(result.hasNext());
+ assertEquals("red", result.next().toString());
+ }
+
+ @Test
+ @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
+ public void shouldExecuteMultiIdWhereCypher() throws Exception {
+ this.graph.addVertex("name", "marko", "age", 29, "color", "red");
+ this.graph.addVertex("name", "marko", "age", 30, "color", "yellow");
+ this.graph.addVertex("name", "marko", "age", 30, "color", "orange");
+ this.graph.tx().commit();
+
+ final List<Object> result = this.getGraph().cypher("MATCH n WHERE id(n) IN [1,2] RETURN n").select(Scope.local, "n").id().toList();
+ assertNotNull(result);
+ assertEquals(2, result.size());
+ assertTrue(result.contains(1l));
+ assertTrue(result.contains(2l));
+ }
+
+ @Test
+ @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
+ public void shouldExecuteMultiIdWhereWithParamCypher() throws Exception {
+ final Vertex v1 = this.graph.addVertex("name", "marko", "age", 29, "color", "red");
+ final Vertex v2 = this.graph.addVertex("name", "marko", "age", 30, "color", "yellow");
+ this.graph.addVertex("name", "marko", "age", 30, "color", "orange");
+ this.graph.tx().commit();
+
+ final List<Object> ids = Arrays.asList(v1.id(), v2.id());
+ final Map<String, Object> m = new HashMap<>();
+ m.put("ids", ids);
+ final List<Object> result = this.getGraph().cypher("MATCH n WHERE id(n) IN {ids} RETURN n", m).select(Scope.local, "n").id().toList();
+ assertNotNull(result);
+ assertEquals(2, result.size());
+ assertTrue(result.contains(v1.id()));
+ assertTrue(result.contains(v2.id()));
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/c850d5e7/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/process/Neo4jCypherStartTest.java
----------------------------------------------------------------------
diff --git a/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/process/Neo4jCypherStartTest.java b/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/process/Neo4jCypherStartTest.java
deleted file mode 100644
index aab5ea0..0000000
--- a/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/process/Neo4jCypherStartTest.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * 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.neo4j.process;
-
-import org.apache.tinkerpop.gremlin.neo4j.BaseNeo4jGraphTest;
-import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
-import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.junit.Test;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import static org.junit.Assert.*;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- * @author Stephen Mallette (http://stephen.genoprime.com)
- */
-public class Neo4jCypherStartTest extends BaseNeo4jGraphTest {
- @Test
- public void shouldExecuteCypher() throws Exception {
- this.graph.addVertex("name", "marko");
- this.graph.tx().commit();
- final Iterator<Map<String, Object>> result = graph.cypher("MATCH (a {name:\"marko\"}) RETURN a", Collections.emptyMap());
- assertNotNull(result);
- assertTrue(result.hasNext());
- }
-
- @Test
- public void shouldExecuteCypherWithArgs() throws Exception {
- this.graph.addVertex("name", "marko");
- this.graph.tx().commit();
- final Map<String, Object> bindings = new HashMap<>();
- bindings.put("n", "marko");
- final Iterator<Map<String, Object>> result = graph.cypher("MATCH (a {name:{n}}) RETURN a", bindings);
- assertNotNull(result);
- assertTrue(result.hasNext());
- }
-
- @Test
- public void shouldExecuteCypherWithArgsUsingVertexIdList() throws Exception {
- final Vertex v = this.graph.addVertex("name", "marko");
- final List<Object> idList = Arrays.asList(v.id());
- this.graph.tx().commit();
-
- final Map<String, Object> bindings = new HashMap<>();
- bindings.put("ids", idList);
- final Iterator<String> result = graph.cypher("START n=node({ids}) RETURN n", bindings).select("n").values("name");
- assertNotNull(result);
- assertTrue(result.hasNext());
- assertEquals("marko", result.next());
- }
-
- @Test
- public void shouldExecuteCypherAndBackToGremlin() throws Exception {
- this.graph.addVertex("name", "marko", "age", 29, "color", "red");
- this.graph.addVertex("name", "marko", "age", 30, "color", "yellow");
-
- this.graph.tx().commit();
- final Traversal result = graph.cypher("MATCH (a {name:\"marko\"}) RETURN a").select("a").has("age", 29).values("color");
- assertNotNull(result);
- assertTrue(result.hasNext());
- assertEquals("red", result.next().toString());
- }
-
- @Test
- public void shouldExecuteMultiIdWhereCypher() throws Exception {
- this.graph.addVertex("name", "marko", "age", 29, "color", "red");
- this.graph.addVertex("name", "marko", "age", 30, "color", "yellow");
- this.graph.addVertex("name", "marko", "age", 30, "color", "orange");
- this.graph.tx().commit();
-
- final List<Object> result = graph.cypher("MATCH n WHERE id(n) IN [1,2] RETURN n").select("n").id().toList();
- assertNotNull(result);
- assertEquals(2, result.size());
- assertTrue(result.contains(1l));
- assertTrue(result.contains(2l));
- }
-
- @Test
- public void shouldExecuteMultiIdWhereWithParamCypher() throws Exception {
- final Vertex v1 = this.graph.addVertex("name", "marko", "age", 29, "color", "red");
- final Vertex v2 = this.graph.addVertex("name", "marko", "age", 30, "color", "yellow");
- this.graph.addVertex("name", "marko", "age", 30, "color", "orange");
- this.graph.tx().commit();
-
- final List<Object> ids = Arrays.asList(v1.id(), v2.id());
- final Map<String, Object> m = new HashMap<>();
- m.put("ids", ids);
- final List<Object> result = graph.cypher("MATCH n WHERE id(n) IN {ids} RETURN n", m).select("n").id().toList();
- assertNotNull(result);
- assertEquals(2, result.size());
- assertTrue(result.contains(v1.id()));
- assertTrue(result.contains(v2.id()));
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/c850d5e7/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/structure/FullNeo4jGraphNativeNeo4jTest.java
----------------------------------------------------------------------
diff --git a/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/structure/FullNeo4jGraphNativeNeo4jTest.java b/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/structure/FullNeo4jGraphNativeNeo4jTest.java
new file mode 100644
index 0000000..d0c25a5
--- /dev/null
+++ b/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/structure/FullNeo4jGraphNativeNeo4jTest.java
@@ -0,0 +1,36 @@
+/*
+ *
+ * * 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.neo4j.structure;
+
+import org.apache.tinkerpop.gremlin.GraphProviderClass;
+import org.apache.tinkerpop.gremlin.neo4j.FullNeo4jGraphProvider;
+import org.apache.tinkerpop.gremlin.neo4j.NativeNeo4jSuite;
+import org.apache.tinkerpop.gremlin.neo4j.structure.full.FullNeo4jGraph;
+import org.junit.runner.RunWith;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+@RunWith(NativeNeo4jSuite.class)
+@GraphProviderClass(provider = FullNeo4jGraphProvider.class, graph = FullNeo4jGraph.class)
+public class FullNeo4jGraphNativeNeo4jTest {
+}