printPerformance(graph.toString(), null, "graph-example-3 loaded", this.stopWatch());
this.stopWatch();
// FIXME Should not explicitly define the Graph type (TinkerGraph)
// here. Need to accept 2 graphs as input params?
Graph toGraph = new TinkerGraph();
GraphMigrator.migrateGraph(graph, toGraph);
printPerformance(toGraph.toString(), null, "graph-example-3 migrated", this.stopWatch());
// Specific Graph Characteristics
assertEquals(count(toGraph.getVertex("1").getEdges(Direction.OUT)), 3);
assertEquals(count(toGraph.getVertex("1").getEdges(Direction.IN)), 0);
Vertex marko = toGraph.getVertex("1");
assertEquals(marko.getProperty("name"), "marko");
assertEquals(marko.getProperty("age"), 29);
assertEquals(marko.getProperty("_id"), 2);
int counter = 0;
for (Edge e : toGraph.getVertex("1").getEdges(Direction.OUT)) {
if (e.getVertex(Direction.IN).getId().equals("2")) {
// assertEquals(e.getProperty("weight"), 0.5);
assertEquals(e.getProperty("_id"), 8);
assertEquals(e.getProperty("_label"), "has high fived");
assertEquals(e.getLabel(), "knows");
assertEquals(e.getId(), "7");
counter++;
} else if (e.getVertex(Direction.IN).getId().equals("3")) {
assertEquals(Math.round((Float) e.getProperty("weight")), 0);
assertEquals(e.getProperty("_id"), 10);
assertEquals(e.getProperty("_label"), "has high fived");
assertEquals(e.getLabel(), "created");
assertEquals(e.getId(), "9");
counter++;
} else if (e.getVertex(Direction.IN).getId().equals("4")) {
assertEquals(Math.round((Float) e.getProperty("weight")), 1);
assertEquals(e.getProperty("_id"), 9);
assertEquals(e.getProperty("_label"), "has high fived");
assertEquals(e.getLabel(), "knows");
assertEquals(e.getId(), "8");
counter++;
}
}
assertEquals(count(toGraph.getVertex("2").getEdges(Direction.OUT)), 0);
assertEquals(count(toGraph.getVertex("2").getEdges(Direction.IN)), 1);
Vertex vadas = toGraph.getVertex("2");
assertEquals(vadas.getProperty("name"), "vadas");
assertEquals(vadas.getProperty("age"), 27);
assertEquals(vadas.getProperty("_id"), 3);
assertEquals(count(toGraph.getVertex("3").getEdges(Direction.OUT)), 0);
assertEquals(count(toGraph.getVertex("3").getEdges(Direction.IN)), 3);
Vertex lop = toGraph.getVertex("3");
assertEquals(lop.getProperty("name"), "lop");
assertEquals(lop.getProperty("lang"), "java");
assertEquals(lop.getProperty("_id"), 4);
assertEquals(count(toGraph.getVertex("4").getEdges(Direction.OUT)), 2);
assertEquals(count(toGraph.getVertex("4").getEdges(Direction.IN)), 1);
Vertex josh = toGraph.getVertex("4");
assertEquals(josh.getProperty("name"), "josh");
assertEquals(josh.getProperty("age"), 32);
for (Edge e : toGraph.getVertex("4").getEdges(Direction.OUT)) {
if (e.getVertex(Direction.IN).getId().equals("3")) {
assertEquals(Math.round((Float) e.getProperty("weight")), 0);
assertEquals(e.getProperty("_id"), 13);
assertEquals(e.getProperty("_label"), null);
assertEquals(e.getLabel(), "created");
assertEquals(e.getId(), "11");
counter++;
} else if (e.getVertex(Direction.IN).getId().equals("5")) {
assertEquals(Math.round((Float) e.getProperty("weight")), 1);
assertEquals(e.getProperty("_id"), 11);
assertEquals(e.getProperty("_label"), "has high fived");
assertEquals(e.getLabel(), "created");
assertEquals(e.getId(), "10");
counter++;
}
}
assertEquals(count(toGraph.getVertex("5").getEdges(Direction.OUT)), 0);
assertEquals(count(toGraph.getVertex("5").getEdges(Direction.IN)), 1);
Vertex ripple = toGraph.getVertex("5");
assertEquals(ripple.getProperty("name"), "ripple");
assertEquals(ripple.getProperty("lang"), "java");
assertEquals(ripple.getProperty("_id"), 7);
assertEquals(count(toGraph.getVertex("6").getEdges(Direction.OUT)), 1);
assertEquals(count(toGraph.getVertex("6").getEdges(Direction.IN)), 0);
Vertex peter = toGraph.getVertex("6");
assertEquals(peter.getProperty("name"), "peter");
assertEquals(peter.getProperty("age"), 35);
for (Edge e : toGraph.getVertex("6").getEdges(Direction.OUT)) {
if (e.getVertex(Direction.IN).getId().equals("3")) {
assertEquals(Math.round((Float) e.getProperty("weight")), 0);
assertEquals(e.getProperty("_id"), null);
assertEquals(e.getProperty("_label"), null);
assertEquals(e.getLabel(), "created");
assertEquals(e.getId(), "12");
counter++;
}
}
assertEquals(counter, 6);
// General Graph Characteristics
Set<String> vertexIds = new HashSet<String>();
Set<String> vertexKeys = new HashSet<String>();
int vertexCount = 0;
for (Vertex v : toGraph.getVertices()) {
vertexCount++;
vertexIds.add(v.getId().toString());
for (String key : v.getPropertyKeys())
vertexKeys.add(key);
}
Set<String> edgeIds = new HashSet<String>();
Set<String> edgeKeys = new HashSet<String>();
int edgeCount = 0;
for (Edge e : toGraph.getEdges()) {
edgeCount++;
edgeIds.add(e.getId().toString());
for (String key : e.getPropertyKeys())
edgeKeys.add(key);
}