diff --git a/CHANGELOG.md b/CHANGELOG.md index 60b3727bdde8cf0cc07e9f083cdac45d563f48b9..d2d48d753cb21fb2bb5c6c58cc0d21accf82bb70 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 416c7836cf4b3f2388e85ba23f9a11f39294f459..f3b8f5dbc77b6329dd2b60654e6edd5d06efa9d3 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 913f25d601e063d0c8352cabeb38ab2ba7bf11bc..7e2d0dc0ccdb2410e54f7e587e08dd3d59f30633 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 6267f1d03bb7f15aa9aa885bfd24aa763f04900f..b1d4372798355de30378984b007b5a363f3a475a 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 9899968a4375009e48e4f5abecf8284967159a1d..4503ba67cde3985cfbbe7c4ea3363e7a7cbbe092 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 e8bda98d4d343a51bee5e87764c124f6e71eca3c..c31b4209cdaf26edf8a2eb9ce108c24cf8706cb9 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 e3c1d44f5fb354f7530340c9067e51ef4239d84b..0b425f1b0e6adb0c4dcf64cc8ceaa24c65749b93 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 e783f9a63816c987ce5cb334b0ab43f64668bba0..480a27a5d41ab3c72d2ac80f70a286a2167402dc 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 9041544573bfd8cafc6585564cbb51d75e851987..ba7558ce2b287e5f15405b82ff950857e5ffe6bb 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 fe60332ab6fd4f34d5c5ec7e5e880a1956f55eea..f5d04f56e004f6a87fc9a9510704684d45f8df12 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")); + } }