diff --git a/src/main/java/com/syncleus/titangraph/example/frames/God.java b/src/main/java/com/syncleus/titangraph/example/frames/God.java index 67cef59acf515c79b192833f8b82e18e1132dbe6..4cbbd45c209177375ec7d9c8d2b3e5056ea79019 100644 --- a/src/main/java/com/syncleus/titangraph/example/frames/God.java +++ b/src/main/java/com/syncleus/titangraph/example/frames/God.java @@ -1,14 +1,16 @@ package com.syncleus.titangraph.example.frames; +import com.tinkerpop.blueprints.Vertex; import com.tinkerpop.frames.*; import com.tinkerpop.frames.annotations.gremlin.GremlinGroovy; +import com.tinkerpop.frames.modules.javahandler.*; public interface God { @Property("name") public String getName(); @Property("age") - public String getAge(); + public Integer getAge(); @Property("type") public String getType(); @@ -21,4 +23,14 @@ public interface God { @Adjacency(label="lives") public Location getHome(); + + @JavaHandler + public boolean isAgeEven(); + + public abstract class Impl implements JavaHandlerContext<Vertex>, God { + + public boolean isAgeEven() { + return this.getAge() % 2 == 0; + } + } } diff --git a/src/test/java/com/syncleus/titangraph/example/FramesTest.java b/src/test/java/com/syncleus/titangraph/example/FramesTest.java index 423c1745badf75cf0f0dda9409b92dd624a66f51..90220834e5f0e7759bd86849f4e897352668f39d 100644 --- a/src/test/java/com/syncleus/titangraph/example/FramesTest.java +++ b/src/test/java/com/syncleus/titangraph/example/FramesTest.java @@ -4,17 +4,32 @@ import com.syncleus.titangraph.example.frames.God; import com.thinkaurelius.titan.core.TitanGraph; import com.tinkerpop.frames.*; import com.tinkerpop.frames.modules.gremlingroovy.GremlinGroovyModule; +import com.tinkerpop.frames.modules.javahandler.JavaHandlerModule; import org.junit.*; public class FramesTest { @Test - public void testFrames() { + public void testFramesGetGod() { final TitanGraph godGraph = TitanGods.create("./target/TitanTestDB"); - FramedGraphFactory factory = new FramedGraphFactory(new GremlinGroovyModule()); + final FramedGraphFactory factory = new FramedGraphFactory(new GremlinGroovyModule()); - FramedGraph framedGraph = factory.create(godGraph); + final FramedGraph framedGraph = factory.create(godGraph); - Iterable<God> gods = (Iterable<God>) framedGraph.getVertices("name", "saturn", God.class); + final Iterable<God> gods = (Iterable<God>) framedGraph.getVertices("name", "saturn", God.class); Assert.assertEquals(gods.iterator().next().getName(), "saturn"); + Assert.assertTrue(gods.iterator().next().getAge().equals(10000)); + } + + @Test + public void testFramesHandler() { + final TitanGraph godGraph = TitanGods.create("./target/TitanTestDB"); + final FramedGraphFactory factory = new FramedGraphFactory(new GremlinGroovyModule(), new JavaHandlerModule()); + + final FramedGraph framedGraph = factory.create(godGraph); + + final Iterable<God> gods = (Iterable<God>) framedGraph.getVertices("name", "saturn", God.class); + final God god = gods.iterator().next(); + Assert.assertEquals(god.getName(), "saturn"); + Assert.assertTrue(god.isAgeEven()); } }