diff --git a/src/main/java/com/syncleus/ferma/DelegatingFramedGraph.java b/src/main/java/com/syncleus/ferma/DelegatingFramedGraph.java index 3d3a649798ed420d3ba01f0116ec6705056ddcf7..a4a50a8f6fd415df90839c23704c957c55c82fb6 100644 --- a/src/main/java/com/syncleus/ferma/DelegatingFramedGraph.java +++ b/src/main/java/com/syncleus/ferma/DelegatingFramedGraph.java @@ -343,7 +343,7 @@ public class DelegatingFramedGraph<G extends Graph> implements WrappedFramedGrap @Override public <T> T addFramedEdge(final VertexFrame source, final VertexFrame destination, final String label, final ClassInitializer<T> initializer, final Object... keyValues) { - final Edge baseEdge = destination.getElement().addEdge(label, source.getElement(), keyValues); + final Edge baseEdge = source.getElement().addEdge(label, destination.getElement(), keyValues); final T framedEdge = frameNewElement(baseEdge, initializer); return framedEdge; } @@ -355,7 +355,7 @@ public class DelegatingFramedGraph<G extends Graph> implements WrappedFramedGrap @Override public <T> T addFramedEdgeExplicit(final VertexFrame source, final VertexFrame destination, final String label, final ClassInitializer<T> initializer) { - final T framedEdge = frameNewElementExplicit(destination.getElement().addEdge(label, source.getElement(), null), initializer); + final T framedEdge = frameNewElementExplicit(source.getElement().addEdge(label, destination.getElement(), null), initializer); return framedEdge; } diff --git a/src/main/java/com/syncleus/ferma/framefactories/annotation/AdjacencyMethodHandler.java b/src/main/java/com/syncleus/ferma/framefactories/annotation/AdjacencyMethodHandler.java index 470bdcdb9e27bbd38790e0ea5c4615038ba5e4ec..04b0d6fdc4087c2da5a6f3ea6eeb613d49e23408 100644 --- a/src/main/java/com/syncleus/ferma/framefactories/annotation/AdjacencyMethodHandler.java +++ b/src/main/java/com/syncleus/ferma/framefactories/annotation/AdjacencyMethodHandler.java @@ -34,7 +34,6 @@ import net.bytebuddy.implementation.bind.annotation.This; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; import org.apache.tinkerpop.gremlin.structure.Direction; import org.apache.tinkerpop.gremlin.structure.Edge; -import org.apache.tinkerpop.gremlin.structure.Element; import org.apache.tinkerpop.gremlin.structure.Vertex; import javax.annotation.Nullable; @@ -75,7 +74,7 @@ public class AdjacencyMethodHandler implements MethodHandler { throw new IllegalStateException(method.getName() + " was annotated with @Adjacency but had more than 1 arguments."); else if (ReflectionUtility.isGetMethod(method)) if (arguments == null || arguments.length == 0) { - if (Iterable.class.isAssignableFrom(method.getReturnType())) + if (Iterator.class.isAssignableFrom(method.getReturnType())) return this.getVertexesDefault(builder, method, annotation); return this.getVertexDefault(builder, method, annotation); @@ -84,7 +83,7 @@ public class AdjacencyMethodHandler implements MethodHandler { if (!(Class.class.isAssignableFrom(arguments[0].getType()))) throw new IllegalStateException(method.getName() + " was annotated with @Adjacency, had a single argument, but that argument was not of the type Class"); - if (Iterable.class.isAssignableFrom(method.getReturnType())) + if (Iterator.class.isAssignableFrom(method.getReturnType())) return this.getVertexesByType(builder, method, annotation); return this.getVertexByType(builder, method, annotation); @@ -102,7 +101,7 @@ public class AdjacencyMethodHandler implements MethodHandler { if (arguments == null || arguments.length == 0) throw new IllegalStateException(method.getName() + " was annotated with @Adjacency but had no arguments."); else if (arguments.length == 1) { - if (!(Iterable.class.isAssignableFrom(arguments[0].getType()))) + if (!(Iterator.class.isAssignableFrom(arguments[0].getType()))) throw new IllegalStateException(method.getName() + " was annotated with @Adjacency, had a single argument, but that argument was not of the type Class"); return this.setVertex(builder, method, annotation); @@ -427,7 +426,7 @@ public class AdjacencyMethodHandler implements MethodHandler { public static final class SetVertexInterceptor { @RuntimeType - public static void setVertex(@This final VertexFrame thiz, @Origin final Method method, @RuntimeType @Argument(0) final Iterable vertexSet) { + public static void setVertex(@This final VertexFrame thiz, @Origin final Method method, @RuntimeType @Argument(0) final Iterator vertexSet) { assert thiz instanceof CachesReflection; final Adjacency annotation = ((CachesReflection) thiz).getReflectionCache().getAnnotation(method, Adjacency.class); final Direction direction = annotation.direction(); @@ -436,21 +435,32 @@ public class AdjacencyMethodHandler implements MethodHandler { switch (direction) { case BOTH: - thiz.getRawTraversal().bothE(label).remove(); - for (final VertexFrame newVertex : (Iterable<? extends VertexFrame>) vertexSet) { - thiz.getGraph().addFramedEdge(newVertex, thiz, label); - thiz.getGraph().addFramedEdge(thiz, newVertex, label); - } + thiz.unlinkBoth(null, label); + ((Iterator<? extends VertexFrame>)vertexSet).forEachRemaining(new Consumer<VertexFrame>() { + @Override + public void accept(VertexFrame vertexFrame) { + thiz.getGraph().addFramedEdge(vertexFrame, thiz, label); + thiz.getGraph().addFramedEdge(thiz, vertexFrame, label); + } + }); break; case IN: - thiz.getRawTraversal().inE(label).remove(); - for (final VertexFrame newVertex : (Iterable<? extends VertexFrame>) vertexSet) - thiz.getGraph().addFramedEdge(newVertex, thiz, label); + thiz.unlinkIn(null, label); + ((Iterator<? extends VertexFrame>)vertexSet).forEachRemaining(new Consumer<VertexFrame>() { + @Override + public void accept(VertexFrame vertexFrame) { + thiz.getGraph().addFramedEdge(vertexFrame, thiz, label); + } + }); break; case OUT: - thiz.getRawTraversal().outE(label).remove(); - for (final VertexFrame newVertex : (Iterable<? extends VertexFrame>) vertexSet) - thiz.getGraph().addFramedEdge(thiz, newVertex, label); + thiz.unlinkOut(null, label); + ((Iterator<? extends VertexFrame>)vertexSet).forEachRemaining(new Consumer<VertexFrame>() { + @Override + public void accept(VertexFrame vertexFrame) { + thiz.getGraph().addFramedEdge(thiz, vertexFrame, label); + } + }); break; default: throw new IllegalStateException(method.getName() + " is annotated with a direction other than BOTH, IN, or OUT."); diff --git a/src/main/java/com/syncleus/ferma/framefactories/annotation/IncidenceMethodHandler.java b/src/main/java/com/syncleus/ferma/framefactories/annotation/IncidenceMethodHandler.java index 81f8d1873f5f19ee53f3066ca1617624bd5c2b3a..27026fbc671a760289ea516394565abde1f1bdbd 100644 --- a/src/main/java/com/syncleus/ferma/framefactories/annotation/IncidenceMethodHandler.java +++ b/src/main/java/com/syncleus/ferma/framefactories/annotation/IncidenceMethodHandler.java @@ -74,7 +74,7 @@ public class IncidenceMethodHandler implements MethodHandler { throw new IllegalStateException(method.getName() + " was annotated with @Adjacency but had more than 1 arguments."); if (ReflectionUtility.isGetMethod(method)) if (arguments == null || arguments.length == 0) - if (Iterable.class.isAssignableFrom(method.getReturnType())) + if (Iterator.class.isAssignableFrom(method.getReturnType())) return this.getEdgesDefault(builder, method, annotation); else return this.getEdgeDefault(builder, method, annotation); @@ -82,7 +82,7 @@ public class IncidenceMethodHandler implements MethodHandler { if (!(Class.class.isAssignableFrom(arguments[0].getType()))) throw new IllegalStateException(method.getName() + " was annotated with @Incidence, had a single argument, but that argument was not of the type Class"); - if (Iterable.class.isAssignableFrom(method.getReturnType())) + if (Iterator.class.isAssignableFrom(method.getReturnType())) return this.getEdgesByType(builder, method, annotation); return this.getEdgeByType(builder, method, annotation); diff --git a/src/main/java/com/syncleus/ferma/framefactories/annotation/ReflectionUtility.java b/src/main/java/com/syncleus/ferma/framefactories/annotation/ReflectionUtility.java index 0850140829f88f31b778645748a8950ce746b46e..e8bda98d4d343a51bee5e87764c124f6e71eca3c 100644 --- a/src/main/java/com/syncleus/ferma/framefactories/annotation/ReflectionUtility.java +++ b/src/main/java/com/syncleus/ferma/framefactories/annotation/ReflectionUtility.java @@ -18,6 +18,7 @@ package com.syncleus.ferma.framefactories.annotation; import org.apache.tinkerpop.gremlin.structure.Vertex; import java.lang.reflect.*; +import java.util.Iterator; import java.util.Map; public class ReflectionUtility { @@ -42,12 +43,12 @@ public class ReflectionUtility { return method.getName().startsWith(REMOVE); } - public static boolean acceptsIterable(final Method method) { - return 1 == method.getParameterTypes().length && Iterable.class.isAssignableFrom(method.getParameterTypes()[0]); + public static boolean acceptsIterator(final Method method) { + return 1 == method.getParameterTypes().length && Iterator.class.isAssignableFrom(method.getParameterTypes()[0]); } - public static boolean returnsIterable(final Method method) { - return Iterable.class.isAssignableFrom(method.getReturnType()); + public static boolean returnsIterator(final Method method) { + return Iterator.class.isAssignableFrom(method.getReturnType()); } public static boolean returnsVertex(final Method method) { diff --git a/src/test/java/com/syncleus/ferma/annotations/AdjacencyMethodHandlerTest.java b/src/test/java/com/syncleus/ferma/annotations/AdjacencyMethodHandlerTest.java index 81bcda6e96475359900d9dcc145f2b1cc688e504..ca4a6041390c76447662684b0d3c83e886fd97c4 100644 --- a/src/test/java/com/syncleus/ferma/annotations/AdjacencyMethodHandlerTest.java +++ b/src/test/java/com/syncleus/ferma/annotations/AdjacencyMethodHandlerTest.java @@ -15,447 +15,573 @@ */ package com.syncleus.ferma.annotations; +import com.google.common.base.Function; import com.syncleus.ferma.*; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; import org.apache.tinkerpop.gremlin.structure.Direction; import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph; import org.junit.Assert; import org.junit.Test; +import javax.annotation.Nullable; import java.util.*; public class AdjacencyMethodHandlerTest { private static final Set<Class<?>> TEST_TYPES = new HashSet<>(Arrays.asList(new Class<?>[]{God.class, FatherEdge.class, GodExtended.class, GodAlternative.class})); -// @Test -// public void testGetSonsDefault() { -// final TinkerGraph godGraph = TinkerGraph.open(); -// GodGraphLoader.load(godGraph); -// -// final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); -// -// final List<? extends God> gods = framedGraph.v().has("name", "jupiter").toList(God.class); -// -// final God father = gods.iterator().next(); -// Assert.assertTrue(father != null); -// final VertexFrame fatherVertex = father; -// Assert.assertEquals(fatherVertex.getProperty("name"), "jupiter"); -// -// final Iterable<? extends God> children = father.getSons(); -// final Iterator<? extends God> childIterator = children.iterator(); -// Assert.assertTrue(childIterator.hasNext()); -// final God child = childIterator.next(); -// Assert.assertTrue(child != null); -// final VertexFrame childVertex = child; -// Assert.assertEquals(childVertex.getElement().getProperty("name"), "hercules"); -// Assert.assertTrue(child instanceof GodExtended); -// } -// -// @Test -// public void testGetSonsByType() { -// final TinkerGraph godGraph = TinkerGraph.open(); -// GodGraphLoader.load(godGraph); -// -// final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); -// -// final List<? extends God> gods = framedGraph.v().has("name", "jupiter").toList(God.class); -// -// final God father = gods.iterator().next(); -// Assert.assertTrue(father != null); -// final VertexFrame fatherVertex = father; -// Assert.assertEquals(fatherVertex.getProperty("name"), "jupiter"); -// -// final Iterable<? extends God> children = father.getSons(God.class); -// final Iterator<? extends God> childIterator = children.iterator(); -// Assert.assertTrue(childIterator.hasNext()); -// final God child = childIterator.next(); -// Assert.assertTrue(child != null); -// final VertexFrame childVertex = child; -// Assert.assertEquals(childVertex.getElement().getProperty("name"), "hercules"); -// Assert.assertTrue(child instanceof GodExtended); -// } -// -// @Test -// public void testGetSonsExtended() { -// final TinkerGraph godGraph = TinkerGraph.open(); -// GodGraphLoader.load(godGraph); -// -// final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); -// -// final List<? extends God> gods = framedGraph.v().has("name", "jupiter").toList(God.class); -// -// final God father = gods.iterator().next(); -// Assert.assertTrue(father != null); -// final VertexFrame fatherVertex = father; -// Assert.assertEquals(fatherVertex.getElement().getProperty("name"), "jupiter"); -// -// final Iterable<? extends God> children = father.getSons(GodExtended.class); -// final Iterator<? extends God> childIterator = children.iterator(); -// Assert.assertTrue(childIterator.hasNext()); -// final God child = childIterator.next(); -// Assert.assertTrue(child != null); -// final VertexFrame childVertex = child; -// Assert.assertEquals(childVertex.getElement().getProperty("name"), "hercules"); -// Assert.assertTrue(child instanceof GodExtended); -// } -// -// @Test -// public void testGetSonsForceAlternative() { -// final TinkerGraph godGraph = TinkerGraph.open(); -// GodGraphLoader.load(godGraph); -// -// final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); -// -// final List<? extends GodAlternative> gods = framedGraph.v().has("name", "jupiter").toList(GodAlternative.class); -// -// final GodAlternative father = gods.iterator().next(); -// Assert.assertTrue(father != null); -// Assert.assertTrue(father instanceof VertexFrame); -// final VertexFrame fatherVertex = father; -// Assert.assertEquals(fatherVertex.getElement().getProperty("name"), "jupiter"); -// -// final Iterable<? extends God> children = father.getSons(God.class); -// final Iterator<? extends God> childIterator = children.iterator(); -// Assert.assertTrue(childIterator.hasNext()); -// final God child = childIterator.next(); -// Assert.assertTrue(child != null); -// final VertexFrame childVertex = child; -// Assert.assertEquals(childVertex.getElement().getProperty("name"), "hercules"); -// Assert.assertTrue(child instanceof GodExtended); -// } -// -// @Test -// public void testGetSonsNoLabel() { -// final TinkerGraph godGraph = TinkerGraph.open(); -// GodGraphLoader.load(godGraph); -// -// final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); -// -// final List<? extends GodAlternative> gods = framedGraph.v().has("name", "jupiter").toList(GodAlternative.class); -// -// final GodAlternative father = gods.iterator().next(); -// Assert.assertTrue(father != null); -// final VertexFrame fatherVertex = father; -// Assert.assertEquals(fatherVertex.getElement().getProperty("name"), "jupiter"); -// -// final Iterable<? extends God> children = father.getNoLabel(God.class); -// final Iterator<? extends God> childIterator = children.iterator(); -// Assert.assertTrue(!childIterator.hasNext()); -// } -// -// @Test -// public void testGetSonDefault() { -// final TinkerGraph godGraph = TinkerGraph.open(); -// GodGraphLoader.load(godGraph); -// -// final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); -// -// final List<? extends God> gods = framedGraph.v().has("name", "jupiter").toList(God.class); -// -// final God father = gods.iterator().next(); -// Assert.assertTrue(father != null); -// final VertexFrame fatherVertex = father; -// Assert.assertEquals(fatherVertex.getProperty("name"), "jupiter"); -// -// final God child = father.getSon(); -// Assert.assertNotNull(child); -// Assert.assertTrue(child instanceof VertexFrame); -// final VertexFrame childVertex = child; -// Assert.assertEquals(childVertex.getElement().getProperty("name"), "hercules"); -// Assert.assertTrue(child instanceof GodExtended); -// } -// -// @Test -// public void testGetSonByType() { -// final TinkerGraph godGraph = TinkerGraph.open(); -// GodGraphLoader.load(godGraph); -// -// final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); -// -// final List<? extends God> gods = framedGraph.v().has("name", "jupiter").toList(God.class); -// -// final God father = gods.iterator().next(); -// Assert.assertTrue(father != null); -// final VertexFrame fatherVertex = father; -// Assert.assertEquals(fatherVertex.getProperty("name"), "jupiter"); -// -// final God child = father.getSon(God.class); -// Assert.assertNotNull(child); -// Assert.assertTrue(child instanceof VertexFrame); -// final VertexFrame childVertex = child; -// Assert.assertEquals(childVertex.getElement().getProperty("name"), "hercules"); -// Assert.assertTrue(child instanceof GodExtended); -// } -// -// @Test -// public void testAddSonDefault() { -// final TinkerGraph godGraph = TinkerGraph.open(); -// GodGraphLoader.load(godGraph); -// -// final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); -// -// final List<? extends God> gods = framedGraph.v().has("name", "jupiter").toList(God.class); -// -// final God father = gods.iterator().next(); -// Assert.assertTrue(father != null); -// final VertexFrame fatherVertex = father; -// Assert.assertEquals(fatherVertex.getProperty("name"), "jupiter"); -// -// final VertexFrame childVertex = father.addSon(); -// Assert.assertNull(childVertex.getElement().getProperty("name")); -// } -// -// @Test -// public void testAddSonByTypeUntypedEdge() { -// final TinkerGraph godGraph = TinkerGraph.open(); -// GodGraphLoader.load(godGraph); -// -// final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); -// -// final List<? extends God> gods = framedGraph.v().has("name", "jupiter").toList(God.class); -// -// final God father = gods.iterator().next(); -// Assert.assertTrue(father != null); -// final VertexFrame fatherVertex = father; -// Assert.assertEquals(fatherVertex.getProperty("name"), "jupiter"); -// -// final God child = father.addSon(God.DEFAULT_INITIALIZER); -// Assert.assertTrue(child != null); -// final VertexFrame childVertex = child; -// Assert.assertNull(childVertex.getElement().getProperty("name")); -// } -// -// @Test -// public void testAddSonByObjectUntypedEdge() { -// final TinkerGraph godGraph = TinkerGraph.open(); -// GodGraphLoader.load(godGraph); -// -// final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); -// -// final List<? extends God> gods = framedGraph.v().has("name", "jupiter").toList(God.class); -// -// final God father = gods.iterator().next(); -// Assert.assertTrue(father != null); -// final VertexFrame fatherVertex = father; -// Assert.assertEquals(fatherVertex.getProperty("name"), "jupiter"); -// -// final God child = framedGraph.addFramedVertex(God.DEFAULT_INITIALIZER); -// father.addSon(child); -// -// Assert.assertTrue(child != null); -// final VertexFrame childVertex = child; -// Assert.assertNull(childVertex.getElement().getProperty("name")); -// } -// -// @Test -// public void testAddSonByTypeTypedEdge() { -// final TinkerGraph godGraph = TinkerGraph.open(); -// GodGraphLoader.load(godGraph); -// -// final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); -// -// final List<? extends God> gods = framedGraph.v().has("name", "jupiter").toList(God.class); -// -// final God father = gods.iterator().next(); -// Assert.assertTrue(father != null); -// final VertexFrame fatherVertex = father; -// Assert.assertEquals(fatherVertex.getProperty("name"), "jupiter"); -// -// final God child = father.addSon(God.DEFAULT_INITIALIZER, FatherEdge.DEFAULT_INITIALIZER); -// Assert.assertTrue(child != null); -// final VertexFrame childVertex = child; -// Assert.assertNull(childVertex.getElement().getProperty("name")); -// } -// -// @Test -// public void testAddSonByObjectTypedEdge() { -// final TinkerGraph godGraph = TinkerGraph.open(); -// GodGraphLoader.load(godGraph); -// -// final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); -// -// final List<? extends God> gods = framedGraph.v().has("name", "jupiter").toList(God.class); -// -// final God father = gods.iterator().next(); -// Assert.assertTrue(father != null); -// final VertexFrame fatherVertex = father; -// Assert.assertEquals(fatherVertex.getProperty("name"), "jupiter"); -// -// final God child = framedGraph.addFramedVertex(God.DEFAULT_INITIALIZER); -// father.addSon(child, FatherEdge.DEFAULT_INITIALIZER); -// -// Assert.assertTrue(child != null); -// final VertexFrame childVertex = child; -// Assert.assertNull(childVertex.getElement().getProperty("name")); -// } -// -// @Test -// public void testSetSonsEmpty() { -// final TinkerGraph godGraph = TinkerGraph.open(); -// GodGraphLoader.load(godGraph); -// -// final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); -// -// final List<? extends God> gods = framedGraph.v().has("name", "jupiter").toList(God.class); -// -// final God father = gods.iterator().next(); -// Assert.assertTrue(father != null); -// final VertexFrame fatherVertex = father; -// Assert.assertEquals(fatherVertex.getProperty("name"), "jupiter"); -// -// final God child = father.getSon(God.class); -// Assert.assertNotNull(child); -// Assert.assertTrue(child instanceof VertexFrame); -// final VertexFrame childVertex = child; -// Assert.assertEquals(childVertex.getElement().getProperty("name"), "hercules"); -// Assert.assertTrue(child instanceof GodExtended); -// -// father.setSons(Collections.<God>emptySet()); -// Assert.assertFalse(father.getSons(God.class).iterator().hasNext()); -// } -// -// @Test -// public void testSetSons() { -// final TinkerGraph godGraph = TinkerGraph.open(); -// GodGraphLoader.load(godGraph); -// -// final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); -// -// final List<? extends God> gods = framedGraph.v().has("name", "jupiter").toList(God.class); -// -// final God father = gods.iterator().next(); -// Assert.assertTrue(father != null); -// final VertexFrame fatherVertex = father; -// Assert.assertEquals(fatherVertex.getProperty("name"), "jupiter"); -// -// God child = father.getSon(God.class); -// Assert.assertNotNull(child); -// Assert.assertTrue(child instanceof VertexFrame); -// final VertexFrame childVertex = child; -// Assert.assertEquals(childVertex.getElement().getProperty("name"), "hercules"); -// Assert.assertTrue(child instanceof GodExtended); -// -// father.setSons(Arrays.asList(framedGraph.addFramedVertex(God.DEFAULT_INITIALIZER))); -// -// child = father.getSon(God.class); -// Assert.assertNotNull(child); -// Assert.assertNull(child.getName()); -// } -// -// @Test -// public void testRemoveSon() { -// final TinkerGraph godGraph = TinkerGraph.open(); -// GodGraphLoader.load(godGraph); -// -// final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); -// -// final List<? extends God> gods = framedGraph.v().has("name", "jupiter").toList(God.class); -// -// final God father = gods.iterator().next(); -// Assert.assertTrue(father != null); -// final VertexFrame fatherVertex = father; -// Assert.assertEquals(fatherVertex.getProperty("name"), "jupiter"); -// -// final God child = father.getSon(God.class); -// Assert.assertNotNull(child); -// Assert.assertTrue(child instanceof VertexFrame); -// final VertexFrame childVertex = child; -// Assert.assertEquals(childVertex.getElement().getProperty("name"), "hercules"); -// Assert.assertTrue(child instanceof GodExtended); -// -// father.removeSon(child); -// Assert.assertFalse(father.getSons(God.class).iterator().hasNext()); -// } -// -// @Test(expected = IllegalStateException.class) -// public void testGetSonsNoArgumentGetClass() { -// -// final Set<Class<?>> exceptionTypes = new HashSet<>(Arrays.asList(new Class<?>[]{BadGetSonsArgumentClass.class})); -// -// final TinkerGraph godGraph = TinkerGraph.open(); -// GodGraphLoader.load(godGraph); -// -// final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, exceptionTypes); -// -// final List<? extends BadGetSonsArgumentClass> gods = framedGraph.v().has("name", "jupiter").toList(BadGetSonsArgumentClass.class); -// -// final BadGetSonsArgumentClass father = gods.iterator().next(); -// } -// -// @Test(expected = IllegalStateException.class) -// public void testGetSonsNoArgumentGetInterface() { -// -// final Set<Class<?>> exceptionTypes = new HashSet<>(Arrays.asList(new Class<?>[]{BadGetSonsArgumentInterface.class})); -// -// final TinkerGraph godGraph = TinkerGraph.open(); -// GodGraphLoader.load(godGraph); -// -// final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, exceptionTypes); -// -// final List<? extends BadGetSonsArgumentInterface> gods = framedGraph.v().has("name", "jupiter").toList(BadGetSonsArgumentInterface.class); -// -// final BadGetSonsArgumentInterface father = gods.iterator().next(); -// } -// -// @Test(expected = IllegalStateException.class) -// public void testAddSonNoArgument() { -// -// final Set<Class<?>> exceptionTypes = new HashSet<>(Arrays.asList(new Class<?>[]{BadAddSonNoArguments.class})); -// -// final TinkerGraph godGraph = TinkerGraph.open(); -// GodGraphLoader.load(godGraph); -// -// final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, exceptionTypes); -// -// final List<? extends BadGetSonsArgumentInterface> gods = framedGraph.v().has("name", "jupiter").toList(BadGetSonsArgumentInterface.class); -// -// final BadGetSonsArgumentInterface father = gods.iterator().next(); -// } -// -// @Test(expected = IllegalStateException.class) -// public void testAddSonBadArgument() { -// -// final Set<Class<?>> exceptionTypes = new HashSet<>(Arrays.asList(new Class<?>[]{BadAddSonArgument.class})); -// -// final TinkerGraph godGraph = TinkerGraph.open(); -// GodGraphLoader.load(godGraph); -// -// final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, exceptionTypes); -// -// final List<? extends BadGetSonsArgumentInterface> gods = framedGraph.v().has("name", "jupiter").toList(BadGetSonsArgumentInterface.class); -// -// final BadGetSonsArgumentInterface father = gods.iterator().next(); -// } -// -// @Test(expected = IllegalStateException.class) -// public void testAddSonExtraArgument() { -// -// final Set<Class<?>> exceptionTypes = new HashSet<>(Arrays.asList(new Class<?>[]{BadAddSonExtraArgument.class})); -// -// final TinkerGraph godGraph = TinkerGraph.open(); -// GodGraphLoader.load(godGraph); -// -// final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, exceptionTypes); -// -// final List<? extends BadGetSonsArgumentInterface> gods = framedGraph.v().has("name", "jupiter").toList(BadGetSonsArgumentInterface.class); -// -// final BadGetSonsArgumentInterface father = gods.iterator().next(); -// } -// -// @Test(expected = IllegalStateException.class) -// public void testBadSonMethodName() { -// -// final Set<Class<?>> exceptionTypes = new HashSet<>(Arrays.asList(new Class<?>[]{BadSonMethodName.class})); -// -// final TinkerGraph godGraph = TinkerGraph.open(); -// GodGraphLoader.load(godGraph); -// -// final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, exceptionTypes); -// -// final List<? extends BadGetSonsArgumentInterface> gods = framedGraph.v().has("name", "jupiter").toList(BadGetSonsArgumentInterface.class); -// -// final BadGetSonsArgumentInterface father = gods.iterator().next(); -// } + @Test + public void testGetSonsDefault() { + final TinkerGraph godGraph = TinkerGraph.open(); + GodGraphLoader.load(godGraph); + + final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); + + final List<? extends God> gods = framedGraph.traverse(new Function<GraphTraversalSource, GraphTraversal<?, ?>>() { + @Nullable + @Override + public GraphTraversal<?, ?> apply(@Nullable final GraphTraversalSource input) { + return input.V().has("name", "jupiter"); + } + }).toList(God.class); + + final God father = gods.iterator().next(); + Assert.assertTrue(father != null); + final VertexFrame fatherVertex = father; + Assert.assertEquals(fatherVertex.getProperty("name"), "jupiter"); + + final Iterator<? extends God> childIterator = father.getSons(); + Assert.assertTrue(childIterator.hasNext()); + final God child = childIterator.next(); + Assert.assertTrue(child != null); + final VertexFrame childVertex = child; + Assert.assertEquals(childVertex.getElement().property("name").value(), "hercules"); + Assert.assertTrue(child instanceof GodExtended); + } + + @Test + public void testGetSonsByType() { + final TinkerGraph godGraph = TinkerGraph.open(); + GodGraphLoader.load(godGraph); + + final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); + + final List<? extends God> gods = framedGraph.traverse(new Function<GraphTraversalSource, GraphTraversal<?, ?>>() { + @Nullable + @Override + public GraphTraversal<?, ?> apply(@Nullable final GraphTraversalSource input) { + return input.V().has("name", "jupiter"); + } + }).toList(God.class); + + final God father = gods.iterator().next(); + Assert.assertTrue(father != null); + final VertexFrame fatherVertex = father; + Assert.assertEquals(fatherVertex.getProperty("name"), "jupiter"); + + final Iterator<? extends God> childIterator = father.getSons(God.class); + Assert.assertTrue(childIterator.hasNext()); + final God child = childIterator.next(); + Assert.assertTrue(child != null); + final VertexFrame childVertex = child; + Assert.assertEquals(childVertex.getElement().property("name").value(), "hercules"); + Assert.assertTrue(child instanceof GodExtended); + } + + @Test + public void testGetSonsExtended() { + final TinkerGraph godGraph = TinkerGraph.open(); + GodGraphLoader.load(godGraph); + + final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); + + final List<? extends God> gods = framedGraph.traverse(new Function<GraphTraversalSource, GraphTraversal<?, ?>>() { + @Nullable + @Override + public GraphTraversal<?, ?> apply(@Nullable final GraphTraversalSource input) { + return input.V().has("name", "jupiter"); + } + }).toList(God.class); + + final God father = gods.iterator().next(); + Assert.assertTrue(father != null); + final VertexFrame fatherVertex = father; + Assert.assertEquals(fatherVertex.getElement().property("name").value(), "jupiter"); + + final Iterator<? extends God> childIterator = father.getSons(GodExtended.class); + Assert.assertTrue(childIterator.hasNext()); + final God child = childIterator.next(); + Assert.assertTrue(child != null); + final VertexFrame childVertex = child; + Assert.assertEquals(childVertex.getElement().property("name").value(), "hercules"); + Assert.assertTrue(child instanceof GodExtended); + } + + @Test + public void testGetSonsForceAlternative() { + final TinkerGraph godGraph = TinkerGraph.open(); + GodGraphLoader.load(godGraph); + + final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); + + final List<? extends GodAlternative> gods = framedGraph.traverse(new Function<GraphTraversalSource, GraphTraversal<?, ?>>() { + @Nullable + @Override + public GraphTraversal<?, ?> apply(@Nullable final GraphTraversalSource input) { + return input.V().has("name", "jupiter"); + } + }).toList(GodAlternative.class); + + final GodAlternative father = gods.iterator().next(); + Assert.assertTrue(father != null); + Assert.assertTrue(father instanceof VertexFrame); + final VertexFrame fatherVertex = father; + Assert.assertEquals(fatherVertex.getElement().property("name").value(), "jupiter"); + + final Iterator<? extends God> childIterator = father.getSons(God.class); + Assert.assertTrue(childIterator.hasNext()); + final God child = childIterator.next(); + Assert.assertTrue(child != null); + final VertexFrame childVertex = child; + Assert.assertEquals(childVertex.getElement().property("name").value(), "hercules"); + Assert.assertTrue(child instanceof GodExtended); + } + + @Test + public void testGetSonsNoLabel() { + final TinkerGraph godGraph = TinkerGraph.open(); + GodGraphLoader.load(godGraph); + + final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); + + final List<? extends GodAlternative> gods = framedGraph.traverse(new Function<GraphTraversalSource, GraphTraversal<?, ?>>() { + @Nullable + @Override + public GraphTraversal<?, ?> apply(@Nullable final GraphTraversalSource input) { + return input.V().has("name", "jupiter"); + } + }).toList(GodAlternative.class); + + final GodAlternative father = gods.iterator().next(); + Assert.assertTrue(father != null); + final VertexFrame fatherVertex = father; + Assert.assertEquals(fatherVertex.getElement().property("name").value(), "jupiter"); + + final Iterator<? extends God> childIterator = father.getNoLabel(God.class); + Assert.assertTrue(!childIterator.hasNext()); + } + + @Test + public void testGetSonDefault() { + final TinkerGraph godGraph = TinkerGraph.open(); + GodGraphLoader.load(godGraph); + + final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); + + final List<? extends God> gods = framedGraph.traverse(new Function<GraphTraversalSource, GraphTraversal<?, ?>>() { + @Nullable + @Override + public GraphTraversal<?, ?> apply(@Nullable final GraphTraversalSource input) { + return input.V().has("name", "jupiter"); + } + }).toList(God.class); + + final God father = gods.iterator().next(); + Assert.assertTrue(father != null); + final VertexFrame fatherVertex = father; + Assert.assertEquals(fatherVertex.getProperty("name"), "jupiter"); + + final God child = father.getSon(); + Assert.assertNotNull(child); + Assert.assertTrue(child instanceof VertexFrame); + final VertexFrame childVertex = child; + Assert.assertEquals(childVertex.getElement().property("name").value(), "hercules"); + Assert.assertTrue(child instanceof GodExtended); + } + + @Test + public void testGetSonByType() { + final TinkerGraph godGraph = TinkerGraph.open(); + GodGraphLoader.load(godGraph); + + final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); + + final List<? extends God> gods = framedGraph.traverse(new Function<GraphTraversalSource, GraphTraversal<?, ?>>() { + @Nullable + @Override + public GraphTraversal<?, ?> apply(@Nullable final GraphTraversalSource input) { + return input.V().has("name", "jupiter"); + } + }).toList(God.class); + + final God father = gods.iterator().next(); + Assert.assertTrue(father != null); + final VertexFrame fatherVertex = father; + Assert.assertEquals(fatherVertex.getProperty("name"), "jupiter"); + + final God child = father.getSon(God.class); + Assert.assertNotNull(child); + Assert.assertTrue(child instanceof VertexFrame); + final VertexFrame childVertex = child; + Assert.assertEquals(childVertex.getElement().property("name").value(), "hercules"); + Assert.assertTrue(child instanceof GodExtended); + } + + @Test + public void testAddSonDefault() { + final TinkerGraph godGraph = TinkerGraph.open(); + GodGraphLoader.load(godGraph); + + final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); + + final List<? extends God> gods = framedGraph.traverse(new Function<GraphTraversalSource, GraphTraversal<?, ?>>() { + @Nullable + @Override + public GraphTraversal<?, ?> apply(@Nullable final GraphTraversalSource input) { + return input.V().has("name", "jupiter"); + } + }).toList(God.class); + + final God father = gods.iterator().next(); + Assert.assertTrue(father != null); + final VertexFrame fatherVertex = father; + Assert.assertEquals(fatherVertex.getProperty("name"), "jupiter"); + + final VertexFrame childVertex = father.addSon(); + Assert.assertFalse(childVertex.getElement().property("name").isPresent()); + } + + @Test + public void testAddSonByTypeUntypedEdge() { + final TinkerGraph godGraph = TinkerGraph.open(); + GodGraphLoader.load(godGraph); + + final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); + + final List<? extends God> gods = framedGraph.traverse(new Function<GraphTraversalSource, GraphTraversal<?, ?>>() { + @Nullable + @Override + public GraphTraversal<?, ?> apply(@Nullable final GraphTraversalSource input) { + return input.V().has("name", "jupiter"); + } + }).toList(God.class); + + final God father = gods.iterator().next(); + Assert.assertTrue(father != null); + final VertexFrame fatherVertex = father; + Assert.assertEquals(fatherVertex.getProperty("name"), "jupiter"); + + final God child = father.addSon(God.DEFAULT_INITIALIZER); + Assert.assertTrue(child != null); + final VertexFrame childVertex = child; + Assert.assertFalse(childVertex.getElement().property("name").isPresent()); + } + + @Test + public void testAddSonByObjectUntypedEdge() { + final TinkerGraph godGraph = TinkerGraph.open(); + GodGraphLoader.load(godGraph); + + final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); + + final List<? extends God> gods = framedGraph.traverse(new Function<GraphTraversalSource, GraphTraversal<?, ?>>() { + @Nullable + @Override + public GraphTraversal<?, ?> apply(@Nullable final GraphTraversalSource input) { + return input.V().has("name", "jupiter"); + } + }).toList(God.class); + + final God father = gods.iterator().next(); + Assert.assertTrue(father != null); + final VertexFrame fatherVertex = father; + Assert.assertEquals(fatherVertex.getProperty("name"), "jupiter"); + + final God child = framedGraph.addFramedVertex(God.DEFAULT_INITIALIZER); + father.addSon(child); + + Assert.assertTrue(child != null); + final VertexFrame childVertex = child; + Assert.assertFalse(childVertex.getElement().property("name").isPresent()); + } + + @Test + public void testAddSonByTypeTypedEdge() { + final TinkerGraph godGraph = TinkerGraph.open(); + GodGraphLoader.load(godGraph); + + final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); + + final List<? extends God> gods = framedGraph.traverse(new Function<GraphTraversalSource, GraphTraversal<?, ?>>() { + @Nullable + @Override + public GraphTraversal<?, ?> apply(@Nullable final GraphTraversalSource input) { + return input.V().has("name", "jupiter"); + } + }).toList(God.class); + + final God father = gods.iterator().next(); + Assert.assertTrue(father != null); + final VertexFrame fatherVertex = father; + Assert.assertEquals(fatherVertex.getProperty("name"), "jupiter"); + + final God child = father.addSon(God.DEFAULT_INITIALIZER, FatherEdge.DEFAULT_INITIALIZER); + Assert.assertTrue(child != null); + final VertexFrame childVertex = child; + Assert.assertFalse(childVertex.getElement().property("name").isPresent()); + } + + @Test + public void testAddSonByObjectTypedEdge() { + final TinkerGraph godGraph = TinkerGraph.open(); + GodGraphLoader.load(godGraph); + + final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); + + final List<? extends God> gods = framedGraph.traverse(new Function<GraphTraversalSource, GraphTraversal<?, ?>>() { + @Nullable + @Override + public GraphTraversal<?, ?> apply(@Nullable final GraphTraversalSource input) { + return input.V().has("name", "jupiter"); + } + }).toList(God.class); + + final God father = gods.iterator().next(); + Assert.assertTrue(father != null); + final VertexFrame fatherVertex = father; + Assert.assertEquals(fatherVertex.getProperty("name"), "jupiter"); + + final God child = framedGraph.addFramedVertex(God.DEFAULT_INITIALIZER); + father.addSon(child, FatherEdge.DEFAULT_INITIALIZER); + + Assert.assertTrue(child != null); + final VertexFrame childVertex = child; + Assert.assertFalse(childVertex.getElement().property("name").isPresent()); + } + + @Test + public void testSetSonsEmpty() { + final TinkerGraph godGraph = TinkerGraph.open(); + GodGraphLoader.load(godGraph); + + final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); + + final List<? extends God> gods = framedGraph.traverse(new Function<GraphTraversalSource, GraphTraversal<?, ?>>() { + @Nullable + @Override + public GraphTraversal<?, ?> apply(@Nullable final GraphTraversalSource input) { + return input.V().has("name", "jupiter"); + } + }).toList(God.class); + + final God father = gods.iterator().next(); + Assert.assertTrue(father != null); + final VertexFrame fatherVertex = father; + Assert.assertEquals(fatherVertex.getProperty("name"), "jupiter"); + + final God child = father.getSon(God.class); + Assert.assertNotNull(child); + Assert.assertTrue(child instanceof VertexFrame); + final VertexFrame childVertex = child; + Assert.assertEquals(childVertex.getElement().property("name").value(), "hercules"); + Assert.assertTrue(child instanceof GodExtended); + + father.setSons(Collections.<God>emptySet().iterator()); + Assert.assertFalse(father.getSons(God.class).hasNext()); + } + + @Test + public void testSetSons() { + final TinkerGraph godGraph = TinkerGraph.open(); + GodGraphLoader.load(godGraph); + + final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); + + final List<? extends God> gods = framedGraph.traverse(new Function<GraphTraversalSource, GraphTraversal<?, ?>>() { + @Nullable + @Override + public GraphTraversal<?, ?> apply(@Nullable final GraphTraversalSource input) { + return input.V().has("name", "jupiter"); + } + }).toList(God.class); + + final God father = gods.iterator().next(); + Assert.assertTrue(father != null); + final VertexFrame fatherVertex = father; + Assert.assertEquals(fatherVertex.getProperty("name"), "jupiter"); + + God child = father.getSon(God.class); + Assert.assertNotNull(child); + Assert.assertTrue(child instanceof VertexFrame); + final VertexFrame childVertex = child; + Assert.assertEquals(childVertex.getElement().property("name").value(), "hercules"); + Assert.assertTrue(child instanceof GodExtended); + + father.setSons(Arrays.asList(framedGraph.addFramedVertex(God.DEFAULT_INITIALIZER)).iterator()); + + child = father.getSon(God.class); + + Assert.assertNotNull(child); + Assert.assertNull(child.getName()); + } + + @Test + public void testRemoveSon() { + final TinkerGraph godGraph = TinkerGraph.open(); + GodGraphLoader.load(godGraph); + + final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); + + final List<? extends God> gods = framedGraph.traverse(new Function<GraphTraversalSource, GraphTraversal<?, ?>>() { + @Nullable + @Override + public GraphTraversal<?, ?> apply(@Nullable final GraphTraversalSource input) { + return input.V().has("name", "jupiter"); + } + }).toList(God.class); + + final God father = gods.iterator().next(); + Assert.assertTrue(father != null); + final VertexFrame fatherVertex = father; + Assert.assertEquals(fatherVertex.getProperty("name"), "jupiter"); + + final God child = father.getSon(God.class); + Assert.assertNotNull(child); + Assert.assertTrue(child instanceof VertexFrame); + final VertexFrame childVertex = child; + Assert.assertEquals(childVertex.getElement().property("name").value(), "hercules"); + Assert.assertTrue(child instanceof GodExtended); + + father.removeSon(child); + Assert.assertFalse(father.getSons(God.class).hasNext()); + } + + @Test(expected = IllegalStateException.class) + public void testGetSonsNoArgumentGetClass() { + + final Set<Class<?>> exceptionTypes = new HashSet<>(Arrays.asList(new Class<?>[]{BadGetSonsArgumentClass.class})); + + final TinkerGraph godGraph = TinkerGraph.open(); + GodGraphLoader.load(godGraph); + + final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, exceptionTypes); + + final List<? extends BadGetSonsArgumentClass> gods = framedGraph.traverse(new Function<GraphTraversalSource, GraphTraversal<?, ?>>() { + @Nullable + @Override + public GraphTraversal<?, ?> apply(@Nullable GraphTraversalSource input) { + return input.V().has("name", "jupiter"); + } + }).toList(BadGetSonsArgumentClass.class); + + final BadGetSonsArgumentClass father = gods.iterator().next(); + } + + @Test(expected = IllegalStateException.class) + public void testGetSonsNoArgumentGetInterface() { + + final Set<Class<?>> exceptionTypes = new HashSet<>(Arrays.asList(new Class<?>[]{BadGetSonsArgumentInterface.class})); + + final TinkerGraph godGraph = TinkerGraph.open(); + GodGraphLoader.load(godGraph); + + final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, exceptionTypes); + + final List<? extends BadGetSonsArgumentInterface> gods = framedGraph.traverse(new Function<GraphTraversalSource, GraphTraversal<?, ?>>() { + @Nullable + @Override + public GraphTraversal<?, ?> apply(@Nullable GraphTraversalSource input) { + return input.V().has("name", "jupiter"); + } + }).toList(BadGetSonsArgumentInterface.class); + + final BadGetSonsArgumentInterface father = gods.iterator().next(); + } + + @Test(expected = IllegalStateException.class) + public void testAddSonNoArgument() { + + final Set<Class<?>> exceptionTypes = new HashSet<>(Arrays.asList(new Class<?>[]{BadAddSonNoArguments.class})); + + final TinkerGraph godGraph = TinkerGraph.open(); + GodGraphLoader.load(godGraph); + + final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, exceptionTypes); + + final List<? extends BadGetSonsArgumentInterface> gods = framedGraph.traverse(new Function<GraphTraversalSource, GraphTraversal<?, ?>>() { + @Nullable + @Override + public GraphTraversal<?, ?> apply(@Nullable GraphTraversalSource input) { + return input.V().has("name", "jupiter"); + } + }).toList(BadGetSonsArgumentInterface.class); + + final BadGetSonsArgumentInterface father = gods.iterator().next(); + } + + @Test(expected = IllegalStateException.class) + public void testAddSonBadArgument() { + + final Set<Class<?>> exceptionTypes = new HashSet<>(Arrays.asList(new Class<?>[]{BadAddSonArgument.class})); + + final TinkerGraph godGraph = TinkerGraph.open(); + GodGraphLoader.load(godGraph); + + final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, exceptionTypes); + + final List<? extends BadGetSonsArgumentInterface> gods = framedGraph.traverse(new Function<GraphTraversalSource, GraphTraversal<?, ?>>() { + @Nullable + @Override + public GraphTraversal<?, ?> apply(@Nullable GraphTraversalSource input) { + return input.V().has("name", "jupiter"); + } + }).toList(BadGetSonsArgumentInterface.class); + + final BadGetSonsArgumentInterface father = gods.iterator().next(); + } + + @Test(expected = IllegalStateException.class) + public void testAddSonExtraArgument() { + + final Set<Class<?>> exceptionTypes = new HashSet<>(Arrays.asList(new Class<?>[]{BadAddSonExtraArgument.class})); + + final TinkerGraph godGraph = TinkerGraph.open(); + GodGraphLoader.load(godGraph); + + final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, exceptionTypes); + + final List<? extends BadGetSonsArgumentInterface> gods = framedGraph.traverse(new Function<GraphTraversalSource, GraphTraversal<?, ?>>() { + @Nullable + @Override + public GraphTraversal<?, ?> apply(@Nullable GraphTraversalSource input) { + return input.V().has("name", "jupiter"); + } + }).toList(BadGetSonsArgumentInterface.class); + + final BadGetSonsArgumentInterface father = gods.iterator().next(); + } + + @Test(expected = IllegalStateException.class) + public void testBadSonMethodName() { + + final Set<Class<?>> exceptionTypes = new HashSet<>(Arrays.asList(new Class<?>[]{BadSonMethodName.class})); + + final TinkerGraph godGraph = TinkerGraph.open(); + GodGraphLoader.load(godGraph); + + final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, exceptionTypes); + + final List<? extends BadGetSonsArgumentInterface> gods = framedGraph.traverse(new Function<GraphTraversalSource, GraphTraversal<?, ?>>() { + @Nullable + @Override + public GraphTraversal<?, ?> apply(@Nullable GraphTraversalSource input) { + return input.V().has("name", "jupiter"); + } + }).toList(BadGetSonsArgumentInterface.class); + + final BadGetSonsArgumentInterface father = gods.iterator().next(); + } public interface BadSonMethodName extends VertexFrame { diff --git a/src/test/java/com/syncleus/ferma/annotations/God.java b/src/test/java/com/syncleus/ferma/annotations/God.java index 36bda82f094c7cbe08a7ad38e74d82e6f91a8adb..42fcaf22d7e6ed30209f058633db58c384ddbfd9 100644 --- a/src/test/java/com/syncleus/ferma/annotations/God.java +++ b/src/test/java/com/syncleus/ferma/annotations/God.java @@ -18,6 +18,8 @@ package com.syncleus.ferma.annotations; import com.syncleus.ferma.*; import org.apache.tinkerpop.gremlin.structure.Direction; +import java.util.Iterator; + public interface God extends VertexFrame { static final ClassInitializer<God> DEFAULT_INITIALIZER = new DefaultClassInitializer(God.class); @@ -37,16 +39,16 @@ public interface God extends VertexFrame { String getType(); @Adjacency(label = "father", direction = Direction.IN) - Iterable<? extends God> getSons(); + Iterator<? extends God> getSons(); @Adjacency(label = "father", direction = Direction.IN) God getSon(); @Adjacency(label = "father", direction = Direction.IN) - <N extends God> Iterable<? extends N> getSons(Class<? extends N> type); + <N extends God> Iterator<? extends N> getSons(Class<? extends N> type); @Adjacency(label = "father", direction = Direction.OUT) - <N extends God> Iterable<? extends N> getParents(); + <N extends God> Iterator<? extends N> getParents(); @Adjacency(label = "father", direction = Direction.IN) <N extends God> N getSon(Class<? extends N> type); @@ -67,16 +69,16 @@ public interface God extends VertexFrame { God addSon(God son, ClassInitializer<? extends FatherEdge> edge); @Adjacency(label = "father", direction = Direction.IN) - void setSons(Iterable<? extends God> vertexSet); + void setSons(Iterator<? extends God> vertexSet); @Adjacency(label = "father", direction = Direction.IN) void removeSon(God son); @Incidence(label = "father", direction = Direction.IN) - Iterable<? extends EdgeFrame> getSonEdges(); + Iterator<? extends EdgeFrame> getSonEdges(); @Incidence(label = "father", direction = Direction.IN) - <N extends FatherEdge> Iterable<? extends N> getSonEdges(Class<? extends N> type); + <N extends FatherEdge> Iterator<? extends N> getSonEdges(Class<? extends N> type); @Incidence(label = "father", direction = Direction.IN) EdgeFrame getSonEdge(); diff --git a/src/test/java/com/syncleus/ferma/annotations/GodAlternative.java b/src/test/java/com/syncleus/ferma/annotations/GodAlternative.java index 1e8f69e9d982a7a05e0db2a6c9817a9bd39de922..5aadcc4c96f08358f7a2741bcdaa67e9eb720e5b 100644 --- a/src/test/java/com/syncleus/ferma/annotations/GodAlternative.java +++ b/src/test/java/com/syncleus/ferma/annotations/GodAlternative.java @@ -18,11 +18,13 @@ package com.syncleus.ferma.annotations; import com.syncleus.ferma.*; import org.apache.tinkerpop.gremlin.structure.Direction; +import java.util.Iterator; + public interface GodAlternative extends VertexFrame { static final ClassInitializer<GodAlternative> DEFAULT_INITIALIZER = new DefaultClassInitializer(GodAlternative.class); @Adjacency(label = "father", direction = Direction.IN) - <N extends God> Iterable<? extends N> getSons(Class<? extends N> type); + <N extends God> Iterator<? extends N> getSons(Class<? extends N> type); @Adjacency(label = "father", direction = Direction.IN) <N extends God> N getSon(Class<? extends N> type); @@ -31,5 +33,5 @@ public interface GodAlternative extends VertexFrame { <N extends God> N addSon(ClassInitializer<? extends N> type); @Adjacency(label = "") - <N extends God> Iterable<? extends N> getNoLabel(Class<? extends N> type); + <N extends God> Iterator<? extends N> getNoLabel(Class<? extends N> type); } diff --git a/src/test/java/com/syncleus/ferma/annotations/GodGraphLoader.java b/src/test/java/com/syncleus/ferma/annotations/GodGraphLoader.java index d7f9d1ed500c7aae142a728fcf80442c5fa27bd4..f403a632e5e6a6edc7d55154d7a20841d87d1662 100644 --- a/src/test/java/com/syncleus/ferma/annotations/GodGraphLoader.java +++ b/src/test/java/com/syncleus/ferma/annotations/GodGraphLoader.java @@ -93,9 +93,5 @@ public class GodGraphLoader { cerberus.addEdge("lives", tartarus); ElementHelper.attachProperties(cerberus.addEdge("battled", alcmene), "time", 5); - - // commit the transaction to disk - if(graph.tx() != null) - graph.tx().commit(); } }