use of com.tinkerpop.frames.FramedGraph in project frames by tinkerpop.
the class FramedGraphQueryImplTest method testDelegation.
@Test
public void testDelegation() {
GraphQuery mockGraphQuery = mock(GraphQuery.class);
FramedGraph framedGraph = new FramedGraphFactory().create(null);
FramedGraphQueryImpl query = new FramedGraphQueryImpl(framedGraph, mockGraphQuery);
stub(mockGraphQuery.has("")).toReturn(mockGraphQuery);
query.has("");
verify(mockGraphQuery).has("");
stub(mockGraphQuery.has("", "bar")).toReturn(mockGraphQuery);
query.has("", "bar");
verify(mockGraphQuery).has("", "bar");
Predicate predicate = new Predicate() {
@Override
public boolean evaluate(Object first, Object second) {
return false;
}
};
stub(mockGraphQuery.has("", predicate, "bar")).toReturn(mockGraphQuery);
query.has("", predicate, "bar");
verify(mockGraphQuery).has(eq(""), same(predicate), eq("bar"));
stub(mockGraphQuery.has("", 2, Compare.EQUAL)).toReturn(mockGraphQuery);
query.has("", 2, Compare.EQUAL);
verify(mockGraphQuery).has(eq(""), same(2), eq(Compare.EQUAL));
stub(mockGraphQuery.hasNot("")).toReturn(mockGraphQuery);
query.hasNot("");
verify(mockGraphQuery).hasNot(eq(""));
stub(mockGraphQuery.hasNot("", "bar")).toReturn(mockGraphQuery);
query.hasNot("", "bar");
verify(mockGraphQuery).hasNot(eq(""), eq("bar"));
stub(mockGraphQuery.interval("", "bar", "bif")).toReturn(mockGraphQuery);
query.interval("", "bar", "bif");
verify(mockGraphQuery).interval(eq(""), eq("bar"), eq("bif"));
stub(mockGraphQuery.limit(1)).toReturn(mockGraphQuery);
query.limit(1);
verify(mockGraphQuery).limit(1);
List<Vertex> v = new ArrayList<Vertex>();
stub(mockGraphQuery.vertices()).toReturn(v);
query.vertices();
verify(mockGraphQuery).vertices();
Iterable<Person> people = query.vertices(Person.class);
verify(mockGraphQuery, times(2)).vertices();
assertFalse(people.iterator().hasNext());
List<Edge> e = new ArrayList<Edge>();
stub(mockGraphQuery.edges()).toReturn(e);
query.edges();
verify(mockGraphQuery).edges();
Iterable<Knows> knows = query.edges(Knows.class);
verify(mockGraphQuery, times(2)).edges();
assertFalse(knows.iterator().hasNext());
}
use of com.tinkerpop.frames.FramedGraph in project frames by tinkerpop.
the class FramedVertexSetTest method testFramedSet.
public void testFramedSet() {
Graph graph = TinkerGraphFactory.createTinkerGraph();
FramedGraph<Graph> framedGraph = new FramedGraph<Graph>(graph);
Set<Vertex> vertices = new HashSet<Vertex>();
vertices.add(graph.getVertex(1));
vertices.add(graph.getVertex(4));
vertices.add(graph.getVertex(6));
FramedVertexSet<Person> set = new FramedVertexSet<Person>(framedGraph, vertices, Person.class);
assertEquals(set.size(), 3);
assertTrue(set.contains(graph.getVertex(1)));
assertTrue(set.contains(graph.getVertex(4)));
assertTrue(set.contains(graph.getVertex(6)));
assertTrue(set.contains(framedGraph.frame(graph.getVertex(1), Person.class)));
assertTrue(set.contains(framedGraph.frame(graph.getVertex(4), Person.class)));
assertTrue(set.contains(framedGraph.frame(graph.getVertex(6), Person.class)));
int counter = 0;
for (Person person : set) {
assertTrue(person.asVertex().getId().equals("1") || person.asVertex().getId().equals("4") || person.asVertex().getId().equals("6"));
counter++;
}
assertEquals(counter, 3);
}
use of com.tinkerpop.frames.FramedGraph in project frames by tinkerpop.
the class TypeResolverTest method testExtendedTypes.
@Test
public void testExtendedTypes() {
Graph graph = TinkerGraphFactory.createTinkerGraph();
FramedGraphFactory factory = new FramedGraphFactory(new AbstractModule() {
@Override
public void doConfigure(FramedGraphConfiguration config) {
config.addTypeResolver(new TypeResolver() {
@Override
public Class<?>[] resolveTypes(Edge e, Class<?> defaultType) {
return new Class[0];
}
@Override
public Class<?>[] resolveTypes(Vertex v, Class<?> defaultType) {
return new Class[] { ExtendedPerson.class };
}
});
}
});
framedGraph = factory.create(graph);
Person marko = framedGraph.getVertex(1, Person.class);
Assert.assertTrue(marko instanceof ExtendedPerson);
}
use of com.tinkerpop.frames.FramedGraph in project frames by tinkerpop.
the class TypeResolverTest method testAdditionalTypes.
@Test
public void testAdditionalTypes() {
Graph graph = TinkerGraphFactory.createTinkerGraph();
FramedGraphFactory factory = new FramedGraphFactory(new AbstractModule() {
@Override
public void doConfigure(FramedGraphConfiguration config) {
config.addTypeResolver(new TypeResolver() {
@Override
public Class<?>[] resolveTypes(Edge e, Class<?> defaultType) {
return new Class[] { AdditionalEdge.class };
}
@Override
public Class<?>[] resolveTypes(Vertex v, Class<?> defaultType) {
return new Class[] { AdditionalVertex.class };
}
});
}
});
framedGraph = factory.create(graph);
Person marko = framedGraph.getVertex(1, Person.class);
Assert.assertTrue(marko instanceof AdditionalVertex);
Assert.assertFalse(marko instanceof AdditionalEdge);
Knows knows = marko.getKnows().iterator().next();
Assert.assertTrue(knows instanceof AdditionalEdge);
Assert.assertFalse(knows instanceof AdditionalVertex);
}
Aggregations