From 5ce1efd773ab7b6ddb7cf53f47e52e7ce521ac8b Mon Sep 17 00:00:00 2001
From: Jeffrey Phillips Freeman <jeffrey.freeman@syncleus.com>
Date: Mon, 10 Nov 2014 12:21:52 -0500
Subject: [PATCH] Added some more unit tests.
Change-Id: I953a76baafa9462e3c71c50cfbec849dd2d3971b
---
.../syncleus/grail/graph/ExceptionGod.java | 9 +++
.../com/syncleus/grail/graph/MockElement.java | 57 ++++++++++++++++++
.../com/syncleus/grail/graph/MockVertex.java | 43 ++++++++++++++
.../TypedAdjacencyMethodHandlerTest.java | 58 ++++++++++++++++++
.../TypedIncidenceMethodHandlerTest.java | 59 +++++++++++++++++++
.../titangraph/TypedAdjacencyHandlerTest.java | 48 ++++++++++++++-
6 files changed, 271 insertions(+), 3 deletions(-)
create mode 100644 src/test/java/com/syncleus/grail/graph/MockElement.java
create mode 100644 src/test/java/com/syncleus/grail/graph/MockVertex.java
create mode 100644 src/test/java/com/syncleus/grail/graph/TypedAdjacencyMethodHandlerTest.java
create mode 100644 src/test/java/com/syncleus/grail/graph/TypedIncidenceMethodHandlerTest.java
diff --git a/src/test/java/com/syncleus/grail/graph/ExceptionGod.java b/src/test/java/com/syncleus/grail/graph/ExceptionGod.java
index 1c7fe28..eb92935 100644
--- a/src/test/java/com/syncleus/grail/graph/ExceptionGod.java
+++ b/src/test/java/com/syncleus/grail/graph/ExceptionGod.java
@@ -40,6 +40,15 @@ public interface ExceptionGod {
@TypedAdjacency(label="Father", direction = Direction.IN)
<N extends ExceptionGod> Iterable<? extends N> getSons(String badStuff);
+ @TypedAdjacency(label="father", direction=Direction.IN)
+ <N extends God> N addSon();
+
+ @TypedAdjacency(label="father", direction=Direction.IN)
+ <N extends God> N addSon(String badArg);
+
+ @TypedAdjacency(label="father", direction=Direction.IN)
+ <N extends God> N addSon(String badArg, String worseArg);
+
@TypedAdjacency(label="Father", direction = Direction.IN)
<N extends ExceptionGod> Iterable<? extends N> badSons(Class<? extends N> type);
diff --git a/src/test/java/com/syncleus/grail/graph/MockElement.java b/src/test/java/com/syncleus/grail/graph/MockElement.java
new file mode 100644
index 0000000..cea14f3
--- /dev/null
+++ b/src/test/java/com/syncleus/grail/graph/MockElement.java
@@ -0,0 +1,57 @@
+/******************************************************************************
+ * *
+ * Copyright: (c) Syncleus, Inc. *
+ * *
+ * You may redistribute and modify this source code under the terms and *
+ * conditions of the Open Source Community License - Type C version 1.0 *
+ * or any later version as published by Syncleus, Inc. at www.syncleus.com. *
+ * There should be a copy of the license included with this file. If a copy *
+ * of the license is not included you are granted no right to distribute or *
+ * otherwise use this file except through a legal and valid license. You *
+ * should also contact Syncleus, Inc. at the information below if you cannot *
+ * find a license: *
+ * *
+ * Syncleus, Inc. *
+ * 2604 South 12th Street *
+ * Philadelphia, PA 19148 *
+ * *
+ ******************************************************************************/
+package com.syncleus.grail.graph;
+
+
+import com.tinkerpop.blueprints.Element;
+
+import java.util.Set;
+
+public class MockElement implements Element {
+
+ @Override
+ public <T> T getProperty(final String key) {
+ return null;
+ }
+
+ @Override
+ public Set<String> getPropertyKeys() {
+ return null;
+ }
+
+ @Override
+ public void setProperty(final String key, final Object value) {
+
+ }
+
+ @Override
+ public <T> T removeProperty(final String key) {
+ return null;
+ }
+
+ @Override
+ public void remove() {
+
+ }
+
+ @Override
+ public Object getId() {
+ return null;
+ }
+}
diff --git a/src/test/java/com/syncleus/grail/graph/MockVertex.java b/src/test/java/com/syncleus/grail/graph/MockVertex.java
new file mode 100644
index 0000000..d3dc11a
--- /dev/null
+++ b/src/test/java/com/syncleus/grail/graph/MockVertex.java
@@ -0,0 +1,43 @@
+/******************************************************************************
+ * *
+ * Copyright: (c) Syncleus, Inc. *
+ * *
+ * You may redistribute and modify this source code under the terms and *
+ * conditions of the Open Source Community License - Type C version 1.0 *
+ * or any later version as published by Syncleus, Inc. at www.syncleus.com. *
+ * There should be a copy of the license included with this file. If a copy *
+ * of the license is not included you are granted no right to distribute or *
+ * otherwise use this file except through a legal and valid license. You *
+ * should also contact Syncleus, Inc. at the information below if you cannot *
+ * find a license: *
+ * *
+ * Syncleus, Inc. *
+ * 2604 South 12th Street *
+ * Philadelphia, PA 19148 *
+ * *
+ ******************************************************************************/
+package com.syncleus.grail.graph;
+
+import com.tinkerpop.blueprints.*;
+
+public class MockVertex extends MockElement implements Vertex {
+ @Override
+ public Iterable<Edge> getEdges(final Direction direction, final String... labels) {
+ return null;
+ }
+
+ @Override
+ public Iterable<Vertex> getVertices(final Direction direction, final String... labels) {
+ return null;
+ }
+
+ @Override
+ public VertexQuery query() {
+ return null;
+ }
+
+ @Override
+ public Edge addEdge(final String label, final Vertex inVertex) {
+ return null;
+ }
+}
diff --git a/src/test/java/com/syncleus/grail/graph/TypedAdjacencyMethodHandlerTest.java b/src/test/java/com/syncleus/grail/graph/TypedAdjacencyMethodHandlerTest.java
new file mode 100644
index 0000000..d32a737
--- /dev/null
+++ b/src/test/java/com/syncleus/grail/graph/TypedAdjacencyMethodHandlerTest.java
@@ -0,0 +1,58 @@
+/******************************************************************************
+ * *
+ * Copyright: (c) Syncleus, Inc. *
+ * *
+ * You may redistribute and modify this source code under the terms and *
+ * conditions of the Open Source Community License - Type C version 1.0 *
+ * or any later version as published by Syncleus, Inc. at www.syncleus.com. *
+ * There should be a copy of the license included with this file. If a copy *
+ * of the license is not included you are granted no right to distribute or *
+ * otherwise use this file except through a legal and valid license. You *
+ * should also contact Syncleus, Inc. at the information below if you cannot *
+ * find a license: *
+ * *
+ * Syncleus, Inc. *
+ * 2604 South 12th Street *
+ * Philadelphia, PA 19148 *
+ * *
+ ******************************************************************************/
+package com.syncleus.grail.graph;
+
+import com.tinkerpop.blueprints.Element;
+import com.tinkerpop.frames.*;
+import org.junit.Test;
+import java.lang.reflect.Method;
+
+public class TypedAdjacencyMethodHandlerTest {
+ private static final TypedAdjacencyMethodHandler HANDLER = new TypedAdjacencyMethodHandler(null);
+ private static final Method GET_SON_METHOD;
+ private static final TypedAdjacency TYPED_ANNOTATION;
+ private static final Object MOCK_FRAME = new Object();
+ private static final Element MOCK_ELEMENT = new MockElement();
+ private static final Element MOCK_VERTEX = new MockVertex();
+
+ static {
+ try {
+ GET_SON_METHOD = God.class.getMethod("getSon", Class.class);
+ }
+ catch( final NoSuchMethodException caught ) {
+ throw new IllegalStateException(caught);
+ }
+
+ TYPED_ANNOTATION = GET_SON_METHOD.getAnnotation(TypedAdjacency.class);
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void testNoVertex() {
+ final FramedGraph framedGraph = BlankGraphFactory.makeTinkerGraph();
+
+ HANDLER.processElement(MOCK_FRAME, GET_SON_METHOD, new Object[]{God.class}, TYPED_ANNOTATION, framedGraph, MOCK_ELEMENT);
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void testNullArguments() {
+ final FramedGraph framedGraph = BlankGraphFactory.makeTinkerGraph();
+
+ HANDLER.processElement(MOCK_FRAME, GET_SON_METHOD, null, TYPED_ANNOTATION, framedGraph, MOCK_VERTEX);
+ }
+}
diff --git a/src/test/java/com/syncleus/grail/graph/TypedIncidenceMethodHandlerTest.java b/src/test/java/com/syncleus/grail/graph/TypedIncidenceMethodHandlerTest.java
new file mode 100644
index 0000000..a9ec114
--- /dev/null
+++ b/src/test/java/com/syncleus/grail/graph/TypedIncidenceMethodHandlerTest.java
@@ -0,0 +1,59 @@
+/******************************************************************************
+ * *
+ * Copyright: (c) Syncleus, Inc. *
+ * *
+ * You may redistribute and modify this source code under the terms and *
+ * conditions of the Open Source Community License - Type C version 1.0 *
+ * or any later version as published by Syncleus, Inc. at www.syncleus.com. *
+ * There should be a copy of the license included with this file. If a copy *
+ * of the license is not included you are granted no right to distribute or *
+ * otherwise use this file except through a legal and valid license. You *
+ * should also contact Syncleus, Inc. at the information below if you cannot *
+ * find a license: *
+ * *
+ * Syncleus, Inc. *
+ * 2604 South 12th Street *
+ * Philadelphia, PA 19148 *
+ * *
+ ******************************************************************************/
+package com.syncleus.grail.graph;
+
+import com.tinkerpop.blueprints.Element;
+import com.tinkerpop.frames.FramedGraph;
+import org.junit.Test;
+
+import java.lang.reflect.Method;
+
+public class TypedIncidenceMethodHandlerTest {
+ private static final TypedIncidenceMethodHandler HANDLER = new TypedIncidenceMethodHandler(null);
+ private static final Method GET_SON_EDGE_METHOD;
+ private static final TypedIncidence TYPED_ANNOTATION;
+ private static final Object MOCK_FRAME = new Object();
+ private static final Element MOCK_ELEMENT = new MockElement();
+ private static final Element MOCK_VERTEX = new MockVertex();
+
+ static {
+ try {
+ GET_SON_EDGE_METHOD = God.class.getMethod("getSonEdge", Class.class);
+ }
+ catch( final NoSuchMethodException caught ) {
+ throw new IllegalStateException(caught);
+ }
+
+ TYPED_ANNOTATION = GET_SON_EDGE_METHOD.getAnnotation(TypedIncidence.class);
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void testNoVertex() {
+ final FramedGraph framedGraph = BlankGraphFactory.makeTinkerGraph();
+
+ HANDLER.processElement(MOCK_FRAME, GET_SON_EDGE_METHOD, new Object[]{God.class}, TYPED_ANNOTATION, framedGraph, MOCK_ELEMENT);
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void testNullArguments() {
+ final FramedGraph framedGraph = BlankGraphFactory.makeTinkerGraph();
+
+ HANDLER.processElement(MOCK_FRAME, GET_SON_EDGE_METHOD, null, TYPED_ANNOTATION, framedGraph, MOCK_VERTEX);
+ }
+}
diff --git a/src/test/java/com/syncleus/grail/graph/titangraph/TypedAdjacencyHandlerTest.java b/src/test/java/com/syncleus/grail/graph/titangraph/TypedAdjacencyHandlerTest.java
index be95d98..14cae9e 100644
--- a/src/test/java/com/syncleus/grail/graph/titangraph/TypedAdjacencyHandlerTest.java
+++ b/src/test/java/com/syncleus/grail/graph/titangraph/TypedAdjacencyHandlerTest.java
@@ -63,7 +63,7 @@ public class TypedAdjacencyHandlerTest {
}
@Test(expected = IllegalStateException.class)
- public void testGetSonsNoArgument() {
+ public void testGetSonsNoArgumentGet() {
final TitanGraph godGraph = TitanGods.create("./target/TitanTestDB");
final FramedGraphFactory factory = new GrailGraphFactory(Collections.<Module>emptyList(), TypedAdjacencyHandlerTest.EXCEPTION_TEST_TYPES);
@@ -78,7 +78,21 @@ public class TypedAdjacencyHandlerTest {
}
@Test(expected = IllegalStateException.class)
- public void testGetSonsExtraArgument() {
+ public void testGetSonsNoArgumentAdd() {
+ final TitanGraph godGraph = TitanGods.create("./target/TitanTestDB");
+ final FramedGraphFactory factory = new GrailGraphFactory(Collections.<Module>emptyList(), TypedAdjacencyHandlerTest.EXCEPTION_TEST_TYPES);
+
+ final FramedGraph<?> framedGraph = factory.create(godGraph);
+
+ final Iterable<ExceptionGod> gods = (Iterable<ExceptionGod>) framedGraph.getVertices("name", "jupiter", ExceptionGod.class);
+ final ExceptionGod father = gods.iterator().next();
+ Assert.assertEquals(father.getName(), "jupiter");
+
+ father.addSon();
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void testGetSonsExtraArgumentGet() {
final TitanGraph godGraph = TitanGods.create("./target/TitanTestDB");
final FramedGraphFactory factory = new GrailGraphFactory(Collections.<Module>emptyList(), TypedAdjacencyHandlerTest.EXCEPTION_TEST_TYPES);
@@ -93,7 +107,7 @@ public class TypedAdjacencyHandlerTest {
}
@Test(expected = IllegalStateException.class)
- public void testGetSonsWrongArgument() {
+ public void testGetSonsWrongArgumentGet() {
final TitanGraph godGraph = TitanGods.create("./target/TitanTestDB");
final FramedGraphFactory factory = new GrailGraphFactory(Collections.<Module>emptyList(), TypedAdjacencyHandlerTest.EXCEPTION_TEST_TYPES);
@@ -107,6 +121,34 @@ public class TypedAdjacencyHandlerTest {
Assert.assertTrue(!children.iterator().hasNext());
}
+ @Test(expected = IllegalStateException.class)
+ public void testGetSonsWrongArgumentAdd() {
+ final TitanGraph godGraph = TitanGods.create("./target/TitanTestDB");
+ final FramedGraphFactory factory = new GrailGraphFactory(Collections.<Module>emptyList(), TypedAdjacencyHandlerTest.EXCEPTION_TEST_TYPES);
+
+ final FramedGraph<?> framedGraph = factory.create(godGraph);
+
+ final Iterable<ExceptionGod> gods = (Iterable<ExceptionGod>) framedGraph.getVertices("name", "jupiter", ExceptionGod.class);
+ final ExceptionGod father = gods.iterator().next();
+ Assert.assertEquals(father.getName(), "jupiter");
+
+ father.addSon("bad stuff will now happen");
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void testGetSonsExtraArgumentAdd() {
+ final TitanGraph godGraph = TitanGods.create("./target/TitanTestDB");
+ final FramedGraphFactory factory = new GrailGraphFactory(Collections.<Module>emptyList(), TypedAdjacencyHandlerTest.EXCEPTION_TEST_TYPES);
+
+ final FramedGraph<?> framedGraph = factory.create(godGraph);
+
+ final Iterable<ExceptionGod> gods = (Iterable<ExceptionGod>) framedGraph.getVertices("name", "jupiter", ExceptionGod.class);
+ final ExceptionGod father = gods.iterator().next();
+ Assert.assertEquals(father.getName(), "jupiter");
+
+ father.addSon("bad stuff will now happen", "even worse");
+ }
+
@Test(expected = IllegalStateException.class)
public void testGetSonsWrongPrefix() {
final TitanGraph godGraph = TitanGods.create("./target/TitanTestDB");
--
GitLab