private static void debugVertex(final Vertex v) { System.out.println("vertex " + v + ":"); for (String key : v.getPropertyKeys()) { System.out.println("\t" + key + ":\t'" + v.getProperty(key) + "'"); } Iterator<Edge> i; i = v.getInEdges().iterator(); System.out.println("\t[in edges]:"); while (i.hasNext()) { System.out.println("\t\t" + i.next()); } i = v.getOutEdges().iterator(); System.out.println("\t[out edges]:"); while (i.hasNext()) { System.out.println("\t\t" + i.next()); } }
public void testTinkerGraphVertexAndEdges(Graph graph) throws Exception { if (config.supportsVertexIteration) { this.stopWatch(); GraphMLReader.inputGraph( graph, GraphMLReader.class.getResourceAsStream("graph-example-1.xml")); BaseTest.printPerformance(graph.toString(), null, "graph-example-1 loaded", this.stopWatch()); Vertex marko = null; Vertex peter = null; Vertex josh = null; Vertex vadas = null; Vertex lop = null; Vertex ripple = null; int count = 0; for (Vertex v : graph.getVertices()) { count++; String name = v.getProperty("name").toString(); if (name.equals("marko")) { marko = v; } else if (name.equals("peter")) { peter = v; } else if (name.equals("josh")) { josh = v; } else if (name.equals("vadas")) { vadas = v; } else if (name.equals("lop")) { lop = v; } else if (name.equals("ripple")) { ripple = v; } else { assertTrue(false); } } assertEquals(count, 6); assertTrue(null != marko); assertTrue(null != peter); assertTrue(null != josh); assertTrue(null != vadas); assertTrue(null != lop); assertTrue(null != ripple); // test marko Set<Vertex> vertices = new HashSet<Vertex>(); assertEquals(marko.getProperty("name"), "marko"); assertEquals(marko.getProperty("age"), 29); assertEquals(marko.getPropertyKeys().size(), 2); assertEquals(count(marko.getOutEdges()), 3); assertEquals(count(marko.getInEdges()), 0); for (Edge e : marko.getOutEdges()) { vertices.add(e.getInVertex()); } assertEquals(vertices.size(), 3); assertTrue(vertices.contains(lop)); assertTrue(vertices.contains(josh)); assertTrue(vertices.contains(vadas)); // test peter vertices = new HashSet<Vertex>(); assertEquals(peter.getProperty("name"), "peter"); assertEquals(peter.getProperty("age"), 35); assertEquals(peter.getPropertyKeys().size(), 2); assertEquals(count(peter.getOutEdges()), 1); assertEquals(count(peter.getInEdges()), 0); for (Edge e : peter.getOutEdges()) { vertices.add(e.getInVertex()); } assertEquals(vertices.size(), 1); assertTrue(vertices.contains(lop)); // test josh vertices = new HashSet<Vertex>(); assertEquals(josh.getProperty("name"), "josh"); assertEquals(josh.getProperty("age"), 32); assertEquals(josh.getPropertyKeys().size(), 2); assertEquals(count(josh.getOutEdges()), 2); assertEquals(count(josh.getInEdges()), 1); for (Edge e : josh.getOutEdges()) { vertices.add(e.getInVertex()); } assertEquals(vertices.size(), 2); assertTrue(vertices.contains(lop)); assertTrue(vertices.contains(ripple)); vertices = new HashSet<Vertex>(); for (Edge e : josh.getInEdges()) { vertices.add(e.getOutVertex()); } assertEquals(vertices.size(), 1); assertTrue(vertices.contains(marko)); // test vadas vertices = new HashSet<Vertex>(); assertEquals(vadas.getProperty("name"), "vadas"); assertEquals(vadas.getProperty("age"), 27); assertEquals(vadas.getPropertyKeys().size(), 2); assertEquals(count(vadas.getOutEdges()), 0); assertEquals(count(vadas.getInEdges()), 1); for (Edge e : vadas.getInEdges()) { vertices.add(e.getOutVertex()); } assertEquals(vertices.size(), 1); assertTrue(vertices.contains(marko)); // test lop vertices = new HashSet<Vertex>(); assertEquals(lop.getProperty("name"), "lop"); assertEquals(lop.getProperty("lang"), "java"); assertEquals(lop.getPropertyKeys().size(), 2); assertEquals(count(lop.getOutEdges()), 0); assertEquals(count(lop.getInEdges()), 3); for (Edge e : lop.getInEdges()) { vertices.add(e.getOutVertex()); } assertEquals(vertices.size(), 3); assertTrue(vertices.contains(marko)); assertTrue(vertices.contains(josh)); assertTrue(vertices.contains(peter)); // test ripple vertices = new HashSet<Vertex>(); assertEquals(ripple.getProperty("name"), "ripple"); assertEquals(ripple.getProperty("lang"), "java"); assertEquals(ripple.getPropertyKeys().size(), 2); assertEquals(count(ripple.getOutEdges()), 0); assertEquals(count(ripple.getInEdges()), 1); for (Edge e : ripple.getInEdges()) { vertices.add(e.getOutVertex()); } assertEquals(vertices.size(), 1); assertTrue(vertices.contains(josh)); } }