in gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphTest.java [175:251]
public void shouldHandleSelfLoops() {
assertEquals(0l, IteratorUtils.count(graph.vertices()));
assertEquals(0l, IteratorUtils.count(graph.edges()));
final Vertex vertex = graph.addVertex("person");
final VertexProperty<String> vertexProperty = vertex.property("name", "furnace");
final Edge edge = vertex.addEdge("self", vertex);
final Property<String> edgeProperty = edge.property("acl", "private");
assertEquals(1l, IteratorUtils.count(graph.vertices()));
assertEquals(1l, IteratorUtils.count(graph.edges()));
assertEquals(1l, IteratorUtils.count(vertex.properties()));
assertEquals(1l, IteratorUtils.count(edge.properties()));
assertEquals(vertexProperty, vertex.properties().next());
assertEquals(edgeProperty, edge.properties().next());
///
final StarGraph starGraph = StarGraph.of(vertex);
final StarGraph.StarVertex starVertex = starGraph.getStarVertex();
final Edge starEdge = starVertex.edges(Direction.OUT).next();
assertEquals(vertex, starVertex);
assertEquals(edge, starEdge);
assertEquals(1l, IteratorUtils.count(starVertex.properties()));
assertEquals("furnace", starVertex.value("name"));
assertEquals(2l, IteratorUtils.count(starVertex.vertices(Direction.BOTH, "self")));
assertEquals(1l, IteratorUtils.count(starVertex.vertices(Direction.OUT, "self")));
assertEquals(1l, IteratorUtils.count(starVertex.vertices(Direction.IN, "self")));
Iterator<Vertex> vertexIterator = starVertex.vertices(Direction.BOTH, "self");
assertEquals(starVertex, vertexIterator.next());
assertEquals(starVertex, vertexIterator.next());
assertFalse(vertexIterator.hasNext());
assertEquals(starVertex, starVertex.vertices(Direction.OUT, "self").next());
assertEquals(starVertex, starVertex.vertices(Direction.IN, "self").next());
///
assertEquals(2l, IteratorUtils.count(starVertex.vertices(Direction.BOTH)));
assertEquals(1l, IteratorUtils.count(starVertex.vertices(Direction.OUT)));
assertEquals(1l, IteratorUtils.count(starVertex.vertices(Direction.IN)));
vertexIterator = starVertex.vertices(Direction.BOTH);
assertEquals(starVertex, vertexIterator.next());
assertEquals(starVertex, vertexIterator.next());
assertFalse(vertexIterator.hasNext());
assertEquals(starVertex, starVertex.vertices(Direction.OUT).next());
assertEquals(starVertex, starVertex.vertices(Direction.IN).next());
///
assertEquals(2l, IteratorUtils.count(starVertex.edges(Direction.BOTH, "self", "nothing")));
assertEquals(1l, IteratorUtils.count(starVertex.edges(Direction.OUT, "self", "nothing")));
assertEquals(1l, IteratorUtils.count(starVertex.edges(Direction.IN, "self", "nothing")));
Iterator<Edge> edgeIterator = starVertex.edges(Direction.BOTH, "self", "nothing");
Edge tempEdge = edgeIterator.next();
assertEquals(1l, IteratorUtils.count(tempEdge.properties()));
assertEquals("private", tempEdge.value("acl"));
assertEquals(starEdge, tempEdge);
tempEdge = edgeIterator.next();
assertEquals(1l, IteratorUtils.count(tempEdge.properties()));
assertEquals("private", tempEdge.value("acl"));
assertEquals(starEdge, tempEdge);
assertFalse(edgeIterator.hasNext());
assertEquals(starEdge, starVertex.edges(Direction.OUT, "self", "nothing").next());
assertEquals(starEdge, starVertex.edges(Direction.IN, "self", "nothing").next());
//
final StarGraph starGraphCopy = serializeDeserialize(starGraph).getValue0();
TestHelper.validateVertexEquality(vertex, starGraph.getStarVertex(), true);
TestHelper.validateVertexEquality(vertex, starGraphCopy.getStarVertex(), true);
TestHelper.validateVertexEquality(starGraph.getStarVertex(), starGraphCopy.getStarVertex(), true);
// test native non-clone-based methods
final StarGraph starGraphNative = StarGraph.open();
Vertex v1 = starGraphNative.addVertex(T.label, "thing", T.id, "v1");
assertEquals("v1", v1.id());
assertEquals("thing", v1.label());
Edge e1 = v1.addEdge("self", v1, "name", "pipes");
assertEquals(2l, IteratorUtils.count(v1.vertices(Direction.BOTH, "self", "nothing")));
assertEquals(1l, IteratorUtils.count(v1.vertices(Direction.OUT)));
assertEquals(1l, IteratorUtils.count(v1.vertices(Direction.IN, "self")));
edgeIterator = v1.edges(Direction.BOTH);
TestHelper.validateEdgeEquality(e1, edgeIterator.next());
TestHelper.validateEdgeEquality(e1, edgeIterator.next());
assertFalse(edgeIterator.hasNext());
TestHelper.validateEdgeEquality(e1, v1.edges(Direction.OUT, "self", "nothing").next());
TestHelper.validateEdgeEquality(e1, v1.edges(Direction.IN).next());
}