org.umlg.sqlg.test.TestHas Maven / Gradle / Ivy
package org.umlg.sqlg.test;
import org.apache.tinkerpop.gremlin.LoadGraphWith;
import org.apache.tinkerpop.gremlin.process.traversal.P;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.junit.Assert;
import org.junit.Test;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.apache.tinkerpop.gremlin.LoadGraphWith.GraphData.MODERN;
/**
* Date: 2014/07/13
* Time: 6:36 PM
*/
@SuppressWarnings({"DuplicatedCode", "unused"})
public class TestHas extends BaseTest {
@Test
@LoadGraphWith(MODERN)
public void g_V_bothE_properties_dedup_hasKeyXweightX_hasValueXltX0d3XX_value() {
loadModern();
final Traversal traversal = this.sqlgGraph.traversal()
.V()
.bothE()
.properties().dedup().hasKey("weight").hasValue(P.lt(0.3)).value();
printTraversalForm(traversal);
checkResults(Collections.singletonList(0.2), traversal);
}
@Test
public void g_V_hasXblahX() {
loadModern();
final Traversal traversal = this.sqlgGraph.traversal().V().has("blah");
printTraversalForm(traversal);
Assert.assertFalse(traversal.hasNext());
}
@Test
public void testHasProperty() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a");
Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "name", "a");
this.sqlgGraph.addVertex(T.label, "A");
this.sqlgGraph.addVertex(T.label, "A");
this.sqlgGraph.tx().commit();
Assert.assertEquals(2, this.sqlgGraph.traversal().V().has("name").count().next(), 0);
Assert.assertTrue(this.sqlgGraph.traversal().V().has("name").toList().containsAll(Arrays.asList(a1, a2)));
}
@Test
public void testHasNotProperty() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a");
Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "name", "a");
Vertex a3 = this.sqlgGraph.addVertex(T.label, "A");
Vertex a4 = this.sqlgGraph.addVertex(T.label, "A");
this.sqlgGraph.tx().commit();
Assert.assertEquals(2, this.sqlgGraph.traversal().V().hasNot("name").count().next(), 0);
Assert.assertTrue(this.sqlgGraph.traversal().V().hasNot("name").toList().containsAll(Arrays.asList(a3, a4)));
}
@Test
public void g_V_in_hasIdXneqX1XX() {
loadModern();
Object marko = convertToVertex(this.sqlgGraph, "marko").id();
List vertices = this.sqlgGraph.traversal().V().in().hasId(P.neq(marko)).toList();
int count = 0;
for (Vertex vertex : vertices) {
Assert.assertTrue(vertex.value("name").equals("josh") || vertex.value("name").equals("peter"));
count++;
}
Assert.assertEquals(3, count);
}
@Test
public void testHasNotId() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A");
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B");
a1.addEdge("ab", b1);
this.sqlgGraph.tx().commit();
List vertices = this.sqlgGraph.traversal().V().in().hasId(P.neq(a1.id())).toList();
Assert.assertEquals(0, vertices.size());
}
@Test
public void g_V_hasId() {
loadModern();
assertModernGraph(this.sqlgGraph, true, false);
GraphTraversalSource g = this.sqlgGraph.traversal();
Object id = convertToVertexId("marko");
List traversala2 = g.V().has(T.id, id).toList();
Assert.assertEquals(1, traversala2.size());
Assert.assertEquals(convertToVertex(this.sqlgGraph, "marko"), traversala2.get(0));
traversala2 = g.V().hasId(id).toList();
Assert.assertEquals(1, traversala2.size());
Assert.assertEquals(convertToVertex(this.sqlgGraph, "marko"), traversala2.get(0));
}
@Test
public void testHasId() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A");
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B");
a1.addEdge("ab", b1);
this.sqlgGraph.tx().commit();
List vertices = this.sqlgGraph.traversal().V().hasId(a1.id()).toList();
Assert.assertEquals(1, vertices.size());
Assert.assertEquals(a1, vertices.get(0));
}
@Test
public void testHasIDDifferentLabels() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A");
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B");
Vertex b2 = this.sqlgGraph.addVertex(T.label, "B");
Vertex c1 = this.sqlgGraph.addVertex(T.label, "C");
Edge e1 = a1.addEdge("ab", b1);
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy