From 4f168cfe2964f8d4b835c3eaf08e2e0d26daa989 Mon Sep 17 00:00:00 2001 From: Jeffrey Phillips Freeman <jeffrey.freeman@syncleus.com> Date: Fri, 22 Sep 2017 22:38:40 -0400 Subject: [PATCH] feat(annotations): can now specify the operation as a parameter to an annotation. --- CHANGELOG.md | 6 +- .../syncleus/ferma/annotations/Adjacency.java | 11 ++ .../syncleus/ferma/annotations/Incidence.java | 11 ++ .../syncleus/ferma/annotations/Property.java | 20 ++- .../annotation/IncidenceMethodHandler.java | 4 +- .../annotation/ReflectionUtility.java | 121 +++++++++++++++++- .../AdjacencyMethodHandlerTest.java | 102 ++++++++++++++- .../com/syncleus/ferma/annotations/God.java | 30 +++++ .../IncidenceMethodHandlerTest.java | 77 +++++++++++ .../PropertyMethodHandlerTest.java | 61 +++++++++ 10 files changed, 433 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60b3727b..d2d48d75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,11 @@ * Added nexus staging deployment plugin. * Removed explicit version from licensing plugin. * Pom updated to require maven 3.0.4 -* Added additional constructor to DelegatingFramedGraph which accepts a package name to scan instead of needing to explicitly pass all the model's classes as a set. +* Added additional constructor to DelegatingFramedGraph which accepts a package name to scan instead of needing to + explicitly pass all the model's classes as a set. +* Added `operation` parameter to the following annotations: `@Adjacency`, `@Incidence`, `@Property`. Setting the + parameter will override the auto discovery of the method prefix previously used to discovery the operation of the + method. ## 3.1.0 diff --git a/src/main/java/com/syncleus/ferma/annotations/Adjacency.java b/src/main/java/com/syncleus/ferma/annotations/Adjacency.java index 416c7836..f3b8f5db 100644 --- a/src/main/java/com/syncleus/ferma/annotations/Adjacency.java +++ b/src/main/java/com/syncleus/ferma/annotations/Adjacency.java @@ -54,4 +54,15 @@ public @interface Adjacency { * @since 2.0.0 */ Direction direction() default Direction.OUT; + + /** + * The operation the method is performing on the vertex. + * + * @return The operation to be performed. + */ + Adjacency.Operation operation() default Adjacency.Operation.AUTO; + + enum Operation { + GET, ADD, REMOVE, SET, AUTO + }; } diff --git a/src/main/java/com/syncleus/ferma/annotations/Incidence.java b/src/main/java/com/syncleus/ferma/annotations/Incidence.java index 913f25d6..7e2d0dc0 100644 --- a/src/main/java/com/syncleus/ferma/annotations/Incidence.java +++ b/src/main/java/com/syncleus/ferma/annotations/Incidence.java @@ -55,4 +55,15 @@ public @interface Incidence { * @since 2.0.0 */ Direction direction() default Direction.OUT; + + /** + * The operation the method is performing on the vertex. + * + * @return The operation to be performed. + */ + Operation operation() default Operation.AUTO; + + enum Operation { + GET, ADD, REMOVE, AUTO + }; } diff --git a/src/main/java/com/syncleus/ferma/annotations/Property.java b/src/main/java/com/syncleus/ferma/annotations/Property.java index 6267f1d0..b1d43727 100644 --- a/src/main/java/com/syncleus/ferma/annotations/Property.java +++ b/src/main/java/com/syncleus/ferma/annotations/Property.java @@ -21,11 +21,27 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** - * Property annotations are for getter and setters to manipulate the property value of an Element. + * Property annotations are for getter and setters to manipulate the property value of an Element. They can also be used + * on methods intended to remove the property all together. */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface Property { - + /** + * The name of the property. + * + * @return The property's name + */ String value(); + + /** + * The operation the method is performing on the property. + * + * @return The operation to be performed. + */ + Operation operation() default Operation.AUTO; + + enum Operation { + GET, SET, REMOVE, AUTO + }; } 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 9899968a..4503ba67 100644 --- a/src/main/java/com/syncleus/ferma/framefactories/annotation/IncidenceMethodHandler.java +++ b/src/main/java/com/syncleus/ferma/framefactories/annotation/IncidenceMethodHandler.java @@ -63,7 +63,7 @@ public class IncidenceMethodHandler implements MethodHandler { return this.addEdgeByObjectUntypedEdge(builder, method, annotation); else if (arguments.length == 2) { if (!(ClassInitializer.class.isAssignableFrom(arguments[1].getType()))) - throw new IllegalStateException(method.getName() + " was annotated with @Adjacency, had two arguments, but the second argument was not of the type ClassInitializer"); + throw new IllegalStateException(method.getName() + " was annotated with @Incidence, had two arguments, but the second argument was not of the type ClassInitializer"); if (ClassInitializer.class.isAssignableFrom(arguments[0].getType())) return this.addEdgeByTypeTypedEdge(builder, method, annotation); @@ -71,7 +71,7 @@ public class IncidenceMethodHandler implements MethodHandler { return this.addEdgeByObjectTypedEdge(builder, method, annotation); } else - throw new IllegalStateException(method.getName() + " was annotated with @Adjacency but had more than 1 arguments."); + throw new IllegalStateException(method.getName() + " was annotated with @Incidence but had more than 1 arguments."); if (ReflectionUtility.isGetMethod(method)) if (arguments == null || arguments.length == 0) if (Iterator.class.isAssignableFrom(method.getReturnType())) 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 e8bda98d..c31b4209 100644 --- a/src/main/java/com/syncleus/ferma/framefactories/annotation/ReflectionUtility.java +++ b/src/main/java/com/syncleus/ferma/framefactories/annotation/ReflectionUtility.java @@ -15,6 +15,9 @@ */ package com.syncleus.ferma.framefactories.annotation; +import com.syncleus.ferma.annotations.Adjacency; +import com.syncleus.ferma.annotations.Incidence; +import com.syncleus.ferma.annotations.Property; import org.apache.tinkerpop.gremlin.structure.Vertex; import java.lang.reflect.*; @@ -31,18 +34,132 @@ public class ReflectionUtility { private static final String CAN = "can"; public static boolean isGetMethod(final Method method) { + final Property propertyAnnotation = method.getAnnotation(Property.class); + if( propertyAnnotation != null ) { + final Property.Operation operation = propertyAnnotation.operation(); + if( operation != null && operation != Property.Operation.AUTO ) { + if( operation == Property.Operation.GET) + return true; + else + return false; + } + } + + final Incidence incidenceAnnotation = method.getAnnotation(Incidence.class); + if( incidenceAnnotation != null ) { + final Incidence.Operation operation = incidenceAnnotation.operation(); + if( operation != null && operation != Incidence.Operation.AUTO ) { + if( operation == Incidence.Operation.GET) + return true; + else + return false; + } + } + + final Adjacency adjacencyAnnotation = method.getAnnotation(Adjacency.class); + if( adjacencyAnnotation != null ) { + final Adjacency.Operation operation = adjacencyAnnotation.operation(); + if( operation != null && operation != Adjacency.Operation.AUTO ) { + if( operation == Adjacency.Operation.GET) + return true; + else + return false; + } + } + final Class<?> returnType = method.getReturnType(); return (method.getName().startsWith(GET) || (returnType == Boolean.class || returnType == Boolean.TYPE) && (method.getName().startsWith(IS) || method.getName().startsWith(CAN))); } public static boolean isSetMethod(final Method method) { + Property propertyAnnotation = method.getAnnotation(Property.class); + if( propertyAnnotation != null ) { + Property.Operation operation = propertyAnnotation.operation(); + if( operation != null && operation != Property.Operation.AUTO ) { + if( operation == Property.Operation.SET) + return true; + else + return false; + } + } + + final Adjacency adjacencyAnnotation = method.getAnnotation(Adjacency.class); + if( adjacencyAnnotation != null ) { + final Adjacency.Operation operation = adjacencyAnnotation.operation(); + if( operation != null && operation != Adjacency.Operation.AUTO ) { + if( operation == Adjacency.Operation.SET) + return true; + else + return false; + } + } + return method.getName().startsWith(SET); } public static boolean isRemoveMethod(final Method method) { + Property propertyAnnotation = method.getAnnotation(Property.class); + if( propertyAnnotation != null ) { + Property.Operation operation = propertyAnnotation.operation(); + if( operation != null && operation != Property.Operation.AUTO ) { + if( operation == Property.Operation.REMOVE) + return true; + else + return false; + } + } + + final Incidence incidenceAnnotation = method.getAnnotation(Incidence.class); + if( incidenceAnnotation != null ) { + final Incidence.Operation operation = incidenceAnnotation.operation(); + if( operation != null && operation != Incidence.Operation.AUTO ) { + if( operation == Incidence.Operation.REMOVE) + return true; + else + return false; + } + } + + final Adjacency adjacencyAnnotation = method.getAnnotation(Adjacency.class); + if( adjacencyAnnotation != null ) { + final Adjacency.Operation operation = adjacencyAnnotation.operation(); + if( operation != null && operation != Adjacency.Operation.AUTO ) { + if( operation == Adjacency.Operation.REMOVE) + return true; + else + return false; + } + } + return method.getName().startsWith(REMOVE); } + public static boolean isAddMethod(final Method method) { + final Incidence incidenceAnnotation = method.getAnnotation(Incidence.class); + if( incidenceAnnotation != null ) { + final Incidence.Operation operation = incidenceAnnotation.operation(); + if( operation != null && operation != Incidence.Operation.AUTO ) { + if( operation == Incidence.Operation.ADD) + return true; + else + return false; + } + } + + final Adjacency adjacencyAnnotation = method.getAnnotation(Adjacency.class); + if( adjacencyAnnotation != null ) { + final Adjacency.Operation operation = adjacencyAnnotation.operation(); + if( operation != null && operation != Adjacency.Operation.AUTO ) { + if( operation == Adjacency.Operation.ADD) + return true; + else + return false; + } + } + + return method.getName().startsWith(ADD); + } + public static boolean acceptsIterator(final Method method) { return 1 == method.getParameterTypes().length && Iterator.class.isAssignableFrom(method.getParameterTypes()[0]); } @@ -59,10 +176,6 @@ public class ReflectionUtility { return Map.class.isAssignableFrom(method.getReturnType()); } - public static boolean isAddMethod(final Method method) { - return method.getName().startsWith(ADD); - } - public static Type getType(final Type[] types, final int pos) { if (pos >= types.length) throw new RuntimeException("No type can be found at position " diff --git a/src/test/java/com/syncleus/ferma/annotations/AdjacencyMethodHandlerTest.java b/src/test/java/com/syncleus/ferma/annotations/AdjacencyMethodHandlerTest.java index e3c1d44f..0b425f1b 100644 --- a/src/test/java/com/syncleus/ferma/annotations/AdjacencyMethodHandlerTest.java +++ b/src/test/java/com/syncleus/ferma/annotations/AdjacencyMethodHandlerTest.java @@ -30,7 +30,6 @@ 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})); - private static final String TEST_MODEL_PACKAGE = "com.syncleus.ferma"; @Test public void testGetSonsDefault() { @@ -80,6 +79,30 @@ public class AdjacencyMethodHandlerTest { Assert.assertTrue(child instanceof GodExtended); } + @Test + public void testObtainSonsByType() { + final TinkerGraph godGraph = TinkerGraph.open(); + GodGraphLoader.load(godGraph); + + final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); + + final List<? extends God> gods = framedGraph.traverse( + input -> 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.obtainSons(); + 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(); @@ -278,6 +301,27 @@ public class AdjacencyMethodHandlerTest { Assert.assertFalse(childVertex.getElement().property("name").isPresent()); } + @Test + public void testincludeSon() { + final TinkerGraph godGraph = TinkerGraph.open(); + GodGraphLoader.load(godGraph); + + final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); + + final List<? extends God> gods = framedGraph.traverse( + input -> 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.includeSon(God.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(); @@ -357,6 +401,36 @@ public class AdjacencyMethodHandlerTest { Assert.assertNull(child.getName()); } + @Test + public void testApplySons() { + final TinkerGraph godGraph = TinkerGraph.open(); + GodGraphLoader.load(godGraph); + + final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); + + final List<? extends God> gods = framedGraph.traverse( + input -> 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.applySons(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(); @@ -383,6 +457,32 @@ public class AdjacencyMethodHandlerTest { Assert.assertFalse(father.getSons(God.class).hasNext()); } + @Test + public void testDeleteSon() { + final TinkerGraph godGraph = TinkerGraph.open(); + GodGraphLoader.load(godGraph); + + final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); + + final List<? extends God> gods = framedGraph.traverse( + input -> 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.deleteSon(child); + Assert.assertFalse(father.getSons(God.class).hasNext()); + } + @Test(expected = IllegalStateException.class) public void testGetSonsNoArgumentGetClass() { diff --git a/src/test/java/com/syncleus/ferma/annotations/God.java b/src/test/java/com/syncleus/ferma/annotations/God.java index e783f9a6..480a27a5 100644 --- a/src/test/java/com/syncleus/ferma/annotations/God.java +++ b/src/test/java/com/syncleus/ferma/annotations/God.java @@ -27,12 +27,21 @@ public interface God extends VertexFrame { @Property("name") String getName(); + @Property(value = "name", operation = Property.Operation.GET) + String obtainName(); + @Property("name") void setName(String newName); + @Property(value = "name", operation = Property.Operation.SET) + void applyName(String newName); + @Property("name") void removeName(); + @Property(value = "name", operation = Property.Operation.REMOVE) + void deleteName(); + @Property("age") Integer getAge(); @@ -42,6 +51,9 @@ public interface God extends VertexFrame { @Adjacency(label = "father", direction = Direction.IN) Iterator<? extends God> getSons(); + @Adjacency(label = "father", direction = Direction.IN, operation = Adjacency.Operation.GET) + Iterator<? extends God> obtainSons(); + @Adjacency(label = "father", direction = Direction.IN) God getSon(); @@ -57,6 +69,9 @@ public interface God extends VertexFrame { @Adjacency(label = "father", direction = Direction.IN) <N extends God> N addSon(ClassInitializer<? extends N> type); + @Adjacency(label = "father", direction = Direction.IN, operation = Adjacency.Operation.ADD) + <N extends God> N includeSon(ClassInitializer<? extends N> type); + @Adjacency(label = "father", direction = Direction.IN) <N extends God> N addSon(ClassInitializer<? extends N> type, ClassInitializer<? extends FatherEdge> edge); @@ -72,9 +87,15 @@ public interface God extends VertexFrame { @Adjacency(label = "father", direction = Direction.IN) void setSons(Iterator<? extends God> vertexSet); + @Adjacency(label = "father", direction = Direction.IN, operation = Adjacency.Operation.SET) + void applySons(Iterator<? extends God> vertexSet); + @Adjacency(label = "father", direction = Direction.IN) void removeSon(God son); + @Adjacency(label = "father", direction = Direction.IN, operation = Adjacency.Operation.REMOVE) + void deleteSon(God son); + @Incidence(label = "father", direction = Direction.IN) Iterator<? extends EdgeFrame> getSonEdges(); @@ -89,4 +110,13 @@ public interface God extends VertexFrame { @Incidence(label = "father", direction = Direction.IN) void removeSonEdge(FatherEdge edge); + + @Incidence(label = "father", direction = Direction.IN, operation = Incidence.Operation.GET) + <N extends FatherEdge> Iterator<? extends N> obtainSonEdges(Class<? extends N> type); + + @Incidence(label = "father", direction = Direction.IN, operation = Incidence.Operation.REMOVE) + void deleteSonEdge(FatherEdge edge); + + @Incidence(label = "father", direction = Direction.IN, operation = Incidence.Operation.ADD) + void includeSonEdge(God son, ClassInitializer<? extends FatherEdge> type); } diff --git a/src/test/java/com/syncleus/ferma/annotations/IncidenceMethodHandlerTest.java b/src/test/java/com/syncleus/ferma/annotations/IncidenceMethodHandlerTest.java index 90415445..ba7558ce 100644 --- a/src/test/java/com/syncleus/ferma/annotations/IncidenceMethodHandlerTest.java +++ b/src/test/java/com/syncleus/ferma/annotations/IncidenceMethodHandlerTest.java @@ -78,6 +78,29 @@ public class IncidenceMethodHandlerTest { Assert.assertEquals(edge.getElement().outVertex().property("name").value(), "hercules"); } + @Test + public void testObtainSonEdgesByType() { + final TinkerGraph godGraph = TinkerGraph.open(); + GodGraphLoader.load(godGraph); + + final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); + + final List<? extends God> gods = framedGraph.traverse( + input -> 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 FatherEdge> childEdgeIterator = father.obtainSonEdges(FatherEdge.class); + Assert.assertTrue(childEdgeIterator.hasNext()); + final FatherEdge childEdge = childEdgeIterator.next(); + Assert.assertTrue(childEdge != null); + final EdgeFrame edge = childEdge; + Assert.assertEquals(edge.getElement().outVertex().property("name").value(), "hercules"); + } + @Test public void testGetSonEdgesExtended() { final TinkerGraph godGraph = TinkerGraph.open(); @@ -167,4 +190,58 @@ public class IncidenceMethodHandlerTest { Assert.assertFalse(father.getSonEdges(FatherEdge.class).hasNext()); } + + @Test + public void testDeleteSonEdge() { + final TinkerGraph godGraph = TinkerGraph.open(); + GodGraphLoader.load(godGraph); + + final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); + + final List<? extends God> gods = framedGraph.traverse( + input -> 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 FatherEdge child = father.getSonEdge(FatherEdge.class); + Assert.assertNotNull(child); + Assert.assertTrue(child instanceof EdgeFrame); + final EdgeFrame childEdge = child; + Assert.assertEquals(childEdge.getRawTraversal().outV().next().property("name").value(), "hercules"); + + father.deleteSonEdge(child); + + Assert.assertFalse(father.getSonEdges(FatherEdge.class).hasNext()); + } + + @Test + public void testIncludeSonEdge() { + final TinkerGraph godGraph = TinkerGraph.open(); + GodGraphLoader.load(godGraph); + + final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); + + final List<? extends God> gods = framedGraph.traverse( + input -> 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 FatherEdge fatherEdge = father.getSonEdge(FatherEdge.class); + Assert.assertNotNull(fatherEdge); + Assert.assertEquals(fatherEdge.getRawTraversal().outV().next().property("name").value(), "hercules"); + final God child = fatherEdge.getSon(); + + father.deleteSonEdge(fatherEdge); + + Assert.assertFalse(father.getSonEdges(FatherEdge.class).hasNext()); + + father.includeSonEdge(child, FatherEdge.DEFAULT_INITIALIZER); + Assert.assertTrue(father.getSonEdges(FatherEdge.class).hasNext()); + } } diff --git a/src/test/java/com/syncleus/ferma/annotations/PropertyMethodHandlerTest.java b/src/test/java/com/syncleus/ferma/annotations/PropertyMethodHandlerTest.java index fe60332a..f5d04f56 100644 --- a/src/test/java/com/syncleus/ferma/annotations/PropertyMethodHandlerTest.java +++ b/src/test/java/com/syncleus/ferma/annotations/PropertyMethodHandlerTest.java @@ -50,6 +50,23 @@ public class PropertyMethodHandlerTest { Assert.assertEquals("jupiter", father.getName()); } + @Test + public void testObtainName() { + final Graph godGraph = TinkerGraph.open(); + GodGraphLoader.load(godGraph); + + final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); + + final List<? extends God> gods = framedGraph.traverse( + input -> 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"); + Assert.assertEquals("jupiter", father.obtainName()); + } + @Test public void testSetName() { final Graph godGraph = TinkerGraph.open(); @@ -75,6 +92,31 @@ public class PropertyMethodHandlerTest { Assert.assertEquals(fatherVertex.getProperty("name"), "joopiter"); } + @Test + public void testApplyName() { + final Graph godGraph = TinkerGraph.open(); + GodGraphLoader.load(godGraph); + + final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); + + List<? extends God> gods = framedGraph.traverse( + input -> input.V().has("name", "jupiter")).toList(God.class); + + God father = gods.iterator().next(); + Assert.assertTrue(father != null); + VertexFrame fatherVertex = father; + Assert.assertEquals(fatherVertex.getProperty("name"), "jupiter"); + father.applyName("joopiter"); + + gods = framedGraph.traverse( + input -> input.V().has("name", "joopiter")).toList(God.class); + + father = gods.iterator().next(); + Assert.assertTrue(father != null); + fatherVertex = father; + Assert.assertEquals(fatherVertex.getProperty("name"), "joopiter"); + } + @Test public void testRemoveName() { final Graph godGraph = TinkerGraph.open(); @@ -93,4 +135,23 @@ public class PropertyMethodHandlerTest { Assert.assertNull(fatherVertex.getProperty("name")); } + + @Test + public void testDeleteName() { + final Graph godGraph = TinkerGraph.open(); + GodGraphLoader.load(godGraph); + + final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_TYPES); + + List<? extends God> gods = framedGraph.traverse( + input -> 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"); + father.deleteName(); + + Assert.assertNull(fatherVertex.getProperty("name")); + } } -- GitLab