Unverified Commit 62a5007d authored by Patrick Beuks's avatar Patrick Beuks Committed by GitHub
Browse files

Added keyValues for addFramedVertex with class type

###--------------------------------------------------------###
feat(internal): Added keyValues for addFramedVertex with class type

Added the function `<T> T addFramedVertex(final Class<T> kind, final Object... keyValues)`
 as a way to add key values to vertex elements. This includes tests for this new function.
###--------------------------------------------------------###
parent c9bec6c5
......@@ -324,6 +324,11 @@ public class DelegatingFramedGraph<G extends Graph> implements WrappedFramedGrap
}
}
@Override
public <T> T addFramedVertex(final Class<T> kind, final Object... keyValues) {
return this.addFramedVertex(new DefaultClassInitializer<>(kind), keyValues);
}
@Override
public <T> T addFramedVertex(final Class<T> kind) {
return this.addFramedVertex(new DefaultClassInitializer<>(kind));
......
......@@ -51,6 +51,18 @@ public interface FramedGraph extends AutoCloseable {
* @return The framed vertex.
*/
<T> T addFramedVertex(ClassInitializer<T> initializer, Object... keyValues);
/**
* Add a vertex to the graph
*
* @param <T> The type used to frame the element.
* @param kind
* The kind of the frame.
* @param keyValues
* the recommended object identifier
* @return The framed vertex.
*/
<T> T addFramedVertex(Class<T> kind, Object... keyValues);
/**
* Add a vertex to the graph
......
......@@ -28,6 +28,7 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.MockitoAnnotations;
import com.syncleus.ferma.typeresolvers.PolymorphicTypeResolver;
import org.apache.tinkerpop.gremlin.structure.T;
public class FramedGraphTest {
......@@ -214,6 +215,52 @@ public class FramedGraphTest {
Assert.assertNotNull(julia.getElement().property(PolymorphicTypeResolver.TYPE_RESOLUTION_KEY).value());
}
@Test
public void testKeyValues() {
final Graph g = TinkerGraph.open();
final FramedGraph fg = new DelegatingFramedGraph(g, true, false);
final Person p1 = fg.addFramedVertex(Programmer.DEFAULT_INITIALIZER, "key", "value");
p1.setName("Bryn");
final Person p2 = fg.addFramedVertex(Person.DEFAULT_INITIALIZER, T.label, "label");
p2.setName("Julia");
final Person bryn = fg.traverse(
input -> input.V().has("key", "value")).next(Person.class);
final Person julia = fg.traverse(
input -> input.V().hasLabel("label")).next(Person.class);
Assert.assertEquals(Programmer.class, bryn.getClass());
Assert.assertEquals(Person.class, julia.getClass());
Assert.assertNotNull(bryn.getElement().property(PolymorphicTypeResolver.TYPE_RESOLUTION_KEY).value());
Assert.assertNotNull(julia.getElement().property(PolymorphicTypeResolver.TYPE_RESOLUTION_KEY).value());
}
@Test
public void testKeyValuesByClass() {
final Graph g = TinkerGraph.open();
final FramedGraph fg = new DelegatingFramedGraph(g, true, false);
final Person p1 = fg.addFramedVertex(Programmer.class, "key", "value");
p1.setName("Bryn");
final Person p2 = fg.addFramedVertex(Person.class, T.label, "label");
p2.setName("Julia");
final Person bryn = fg.traverse(
input -> input.V().has("key", "value")).next(Person.class);
final Person julia = fg.traverse(
input -> input.V().hasLabel("label")).next(Person.class);
Assert.assertEquals(Programmer.class, bryn.getClass());
Assert.assertEquals(Person.class, julia.getClass());
Assert.assertNotNull(bryn.getElement().property(PolymorphicTypeResolver.TYPE_RESOLUTION_KEY).value());
Assert.assertNotNull(julia.getElement().property(PolymorphicTypeResolver.TYPE_RESOLUTION_KEY).value());
}
@Test
public void testJavaTypingAddExplicit() {
final Graph g = TinkerGraph.open();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment