Skip to content
Snippets Groups Projects
Commit 5ce1efd7 authored by Jeffrey Phillips Freeman's avatar Jeffrey Phillips Freeman :boom:
Browse files

Added some more unit tests.

Change-Id: I953a76baafa9462e3c71c50cfbec849dd2d3971b
parent 1e73eb2b
No related branches found
No related tags found
No related merge requests found
...@@ -40,6 +40,15 @@ public interface ExceptionGod { ...@@ -40,6 +40,15 @@ public interface ExceptionGod {
@TypedAdjacency(label="Father", direction = Direction.IN) @TypedAdjacency(label="Father", direction = Direction.IN)
<N extends ExceptionGod> Iterable<? extends N> getSons(String badStuff); <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) @TypedAdjacency(label="Father", direction = Direction.IN)
<N extends ExceptionGod> Iterable<? extends N> badSons(Class<? extends N> type); <N extends ExceptionGod> Iterable<? extends N> badSons(Class<? extends N> type);
......
/******************************************************************************
* *
* 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;
}
}
/******************************************************************************
* *
* 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;
}
}
/******************************************************************************
* *
* 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);
}
}
/******************************************************************************
* *
* 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);
}
}
...@@ -63,7 +63,7 @@ public class TypedAdjacencyHandlerTest { ...@@ -63,7 +63,7 @@ public class TypedAdjacencyHandlerTest {
} }
@Test(expected = IllegalStateException.class) @Test(expected = IllegalStateException.class)
public void testGetSonsNoArgument() { public void testGetSonsNoArgumentGet() {
final TitanGraph godGraph = TitanGods.create("./target/TitanTestDB"); final TitanGraph godGraph = TitanGods.create("./target/TitanTestDB");
final FramedGraphFactory factory = new GrailGraphFactory(Collections.<Module>emptyList(), TypedAdjacencyHandlerTest.EXCEPTION_TEST_TYPES); final FramedGraphFactory factory = new GrailGraphFactory(Collections.<Module>emptyList(), TypedAdjacencyHandlerTest.EXCEPTION_TEST_TYPES);
...@@ -78,7 +78,21 @@ public class TypedAdjacencyHandlerTest { ...@@ -78,7 +78,21 @@ public class TypedAdjacencyHandlerTest {
} }
@Test(expected = IllegalStateException.class) @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 TitanGraph godGraph = TitanGods.create("./target/TitanTestDB");
final FramedGraphFactory factory = new GrailGraphFactory(Collections.<Module>emptyList(), TypedAdjacencyHandlerTest.EXCEPTION_TEST_TYPES); final FramedGraphFactory factory = new GrailGraphFactory(Collections.<Module>emptyList(), TypedAdjacencyHandlerTest.EXCEPTION_TEST_TYPES);
...@@ -93,7 +107,7 @@ public class TypedAdjacencyHandlerTest { ...@@ -93,7 +107,7 @@ public class TypedAdjacencyHandlerTest {
} }
@Test(expected = IllegalStateException.class) @Test(expected = IllegalStateException.class)
public void testGetSonsWrongArgument() { public void testGetSonsWrongArgumentGet() {
final TitanGraph godGraph = TitanGods.create("./target/TitanTestDB"); final TitanGraph godGraph = TitanGods.create("./target/TitanTestDB");
final FramedGraphFactory factory = new GrailGraphFactory(Collections.<Module>emptyList(), TypedAdjacencyHandlerTest.EXCEPTION_TEST_TYPES); final FramedGraphFactory factory = new GrailGraphFactory(Collections.<Module>emptyList(), TypedAdjacencyHandlerTest.EXCEPTION_TEST_TYPES);
...@@ -107,6 +121,34 @@ public class TypedAdjacencyHandlerTest { ...@@ -107,6 +121,34 @@ public class TypedAdjacencyHandlerTest {
Assert.assertTrue(!children.iterator().hasNext()); 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) @Test(expected = IllegalStateException.class)
public void testGetSonsWrongPrefix() { public void testGetSonsWrongPrefix() {
final TitanGraph godGraph = TitanGods.create("./target/TitanTestDB"); final TitanGraph godGraph = TitanGods.create("./target/TitanTestDB");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment