Skip to content
Snippets Groups Projects
Commit 4cc48f35 authored by Jeffrey Phillips Freeman's avatar Jeffrey Phillips Freeman :boom:
Browse files

Added JavaHandler example to the frames examples.

parent fba2f470
No related branches found
No related tags found
No related merge requests found
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;
}
}
}
......@@ -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());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment