From ebc197d01a5dcc1a746c31e83b2b8fed3270bd00 Mon Sep 17 00:00:00 2001 From: Jeffrey Phillips Freeman <jeffrey.freeman@syncleus.com> Date: Sat, 1 Nov 2014 07:10:57 -0400 Subject: [PATCH] Added example using gremlin. --- pom.xml | 5 +++ .../titangraph/example/TitanGods.java | 3 +- .../titangraph/example/GremlinTest.java | 18 +++++++++++ .../titangraph/example/TitanGodsTest.java | 32 +++---------------- 4 files changed, 28 insertions(+), 30 deletions(-) create mode 100644 src/test/java/com/syncleus/titangraph/example/GremlinTest.java diff --git a/pom.xml b/pom.xml index 6c91884..3b3ad6f 100644 --- a/pom.xml +++ b/pom.xml @@ -117,5 +117,10 @@ <artifactId>titan-es</artifactId> <version>0.4.4</version> </dependency> + <dependency> + <groupId>com.tinkerpop.gremlin</groupId> + <artifactId>gremlin-java</artifactId> + <version>2.6.0</version> + </dependency> </dependencies> </project> diff --git a/src/main/java/com/syncleus/titangraph/example/TitanGods.java b/src/main/java/com/syncleus/titangraph/example/TitanGods.java index 3a5e1ed..17ef9dd 100644 --- a/src/main/java/com/syncleus/titangraph/example/TitanGods.java +++ b/src/main/java/com/syncleus/titangraph/example/TitanGods.java @@ -5,8 +5,7 @@ import com.thinkaurelius.titan.core.TitanGraph; import com.thinkaurelius.titan.core.TitanKey; import com.thinkaurelius.titan.core.attribute.Geoshape; import com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration; -import com.tinkerpop.blueprints.Edge; -import com.tinkerpop.blueprints.Vertex; +import com.tinkerpop.blueprints.*; import com.tinkerpop.blueprints.util.ElementHelper; import org.apache.commons.configuration.BaseConfiguration; import org.apache.commons.configuration.Configuration; diff --git a/src/test/java/com/syncleus/titangraph/example/GremlinTest.java b/src/test/java/com/syncleus/titangraph/example/GremlinTest.java new file mode 100644 index 0000000..594896b --- /dev/null +++ b/src/test/java/com/syncleus/titangraph/example/GremlinTest.java @@ -0,0 +1,18 @@ +package com.syncleus.titangraph.example; + +import com.thinkaurelius.titan.core.TitanGraph; +import com.tinkerpop.blueprints.Vertex; +import com.tinkerpop.gremlin.java.GremlinPipeline; +import org.junit.*; + +public class GremlinTest { + @Test + public void testGremlin() { + final TitanGraph godGraph = TitanGods.create("./target/TitanTestDB"); + final GremlinPipeline pipe = new GremlinPipeline(); + final Vertex saturnVertex = godGraph.getVertices("name", "saturn").iterator().next(); + final GremlinPipeline childsNamePipe = pipe.start(saturnVertex).in("father").property("name"); + final String childsName = childsNamePipe.next().toString(); + Assert.assertEquals(childsName, "jupiter"); + } +} diff --git a/src/test/java/com/syncleus/titangraph/example/TitanGodsTest.java b/src/test/java/com/syncleus/titangraph/example/TitanGodsTest.java index 76033e9..b89a9f2 100644 --- a/src/test/java/com/syncleus/titangraph/example/TitanGodsTest.java +++ b/src/test/java/com/syncleus/titangraph/example/TitanGodsTest.java @@ -2,37 +2,13 @@ package com.syncleus.titangraph.example; import com.thinkaurelius.titan.core.TitanGraph; import com.tinkerpop.blueprints.Vertex; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.*; -/** - * Unit test for simple App. - */ -public class TitanGodsTest - extends TestCase { - /** - * Create the test case - * - * @param testName name of the test case - */ - public TitanGodsTest(String testName) { - super(testName); - } - - /** - * @return the suite of tests being tested - */ - public static Test suite() { - return new TestSuite(TitanGodsTest.class); - } - - /** - * Rigourous Test :-) - */ +public class TitanGodsTest { + @Test public void testApp() { TitanGraph godGraph = TitanGods.create("./target/TitanTestDB"); Iterable<Vertex> skyVertices = godGraph.getVertices("name", "sky"); - assertTrue("no sky vertices found", skyVertices.iterator().hasNext()); + Assert.assertTrue("no sky vertices found", skyVertices.iterator().hasNext()); } } -- GitLab