diff --git a/src/main/java/com/syncleus/titangraph/example/titangods/LocationExtended.java b/src/main/java/com/syncleus/titangraph/example/titangods/LocationExtended.java new file mode 100644 index 0000000000000000000000000000000000000000..cbc6e63db1584c02d3adae6794f534208abc871d --- /dev/null +++ b/src/main/java/com/syncleus/titangraph/example/titangods/LocationExtended.java @@ -0,0 +1,8 @@ +package com.syncleus.titangraph.example.titangods; + +import com.tinkerpop.frames.Property; + +public interface LocationExtended extends Location { + @Property("other") + public String getOther(); +} diff --git a/src/main/java/com/syncleus/titangraph/example/titangods/TitanGods.java b/src/main/java/com/syncleus/titangraph/example/titangods/TitanGods.java index 4e13c1c26958391503dbce0aff22def59b9e5e7c..c8d7ff54ba7438fcfab560415e0168f1790de24b 100644 --- a/src/main/java/com/syncleus/titangraph/example/titangods/TitanGods.java +++ b/src/main/java/com/syncleus/titangraph/example/titangods/TitanGods.java @@ -72,7 +72,7 @@ public class TitanGods { saturn.setProperty("type", "titan"); Vertex sky = graph.addVertex(null); - ElementHelper.setProperties(sky, "name", "sky", "type", "location"); + ElementHelper.setProperties(sky, "name", "sky", "type", "location", "other", "more useless info"); Vertex sea = graph.addVertex(null); ElementHelper.setProperties(sea, "name", "sea", "type", "location"); diff --git a/src/test/java/com/syncleus/titangraph/example/titangods/FramesTest.java b/src/test/java/com/syncleus/titangraph/example/titangods/FramesTest.java index 57c443b63d879fdbb8ed07315f704871725f5b82..412d0f39b70c752398b31caa06172e5edc013aa2 100644 --- a/src/test/java/com/syncleus/titangraph/example/titangods/FramesTest.java +++ b/src/test/java/com/syncleus/titangraph/example/titangods/FramesTest.java @@ -1,9 +1,9 @@ package com.syncleus.titangraph.example.titangods; -import com.syncleus.titangraph.example.titangods.TitanGods; -import com.syncleus.titangraph.example.titangods.TitanGods.God; import com.thinkaurelius.titan.core.TitanGraph; +import com.tinkerpop.blueprints.*; import com.tinkerpop.frames.*; +import com.tinkerpop.frames.modules.*; import com.tinkerpop.frames.modules.gremlingroovy.GremlinGroovyModule; import com.tinkerpop.frames.modules.javahandler.JavaHandlerModule; import org.junit.*; @@ -33,4 +33,39 @@ public class FramesTest { Assert.assertEquals(god.getName(), "saturn"); Assert.assertTrue(god.isAgeEven()); } + + @Test + public void testFramesTypeResolver() { + final TitanGraph godGraph = TitanGods.create("./target/TitanTestDB"); + + final TypeResolver resolver = new TypeResolver() { + + @Override + public Class<?>[] resolveTypes(final Vertex v, final Class<?> defaultType) { + if( v.getPropertyKeys().contains("other") ) { + return new Class<?>[]{LocationExtended.class}; + } + return new Class<?>[0]; + } + + @Override + public Class<?>[] resolveTypes(final Edge e, final Class<?> defaultType) { + return new Class<?>[0]; + } + }; + + final Module resolverModule = new AbstractModule() { + public void doConfigure(FramedGraphConfiguration config) { + config.addTypeResolver(resolver); + } + }; + + final FramedGraphFactory factory = new FramedGraphFactory(new JavaHandlerModule(), new GremlinGroovyModule(), resolverModule); + + final FramedGraph framedGraph = factory.create(godGraph); + + final Iterable<Location> skys = (Iterable<Location>) framedGraph.getVertices("name", "sky", Location.class); + final Location sky = skys.iterator().next(); + Assert.assertTrue(sky instanceof LocationExtended); + } }