5

I'm using the Neo4J Java Traversal API and have a number of tests around my code.

Debugging would be a lot easier if I could log an ASCII-art representation of the graph in a failing test.

Obviously "logging" a Neo4J graph is unwieldy in production code, but is practical in tests as the graphs only comprise a handful of nodes and relationships.

How best to get an ASCII art representation of a Neo4J graph, please?

Chris Beach
  • 4,302
  • 2
  • 31
  • 50

2 Answers2

1

That seems like that would be painful. What about using a library that generates visual graphs to an image file and generating/opening that file on failure? This post seems to have some good libraries for generating graph visualizations in java:

Java graph library for dynamic visualisation

Community
  • 1
  • 1
Brian Underwood
  • 10,746
  • 1
  • 22
  • 34
  • Agreed it would be painful, but images are not much of a solution; they might work in this narrow case maybe, but they can't be grepped of course. – FrobberOfBits Jan 09 '15 at 15:23
  • I don't know about ASCII art but the closest thing I can think of is maybe something like RDF Turtle. It's a simple text compact format for expressing a graph (albeit RDF, would need adaptation for neo4j). It would be hard to figure out how much to put on a line. If the graph was a tree root X with 3 children, should it be written as (X)->(A), (X)->(B), (X)->(C) or what? – FrobberOfBits Jan 09 '15 at 15:24
0

I checked out the various visualisation libraries, but it seems few, if any, work well with a simple embedded ImpermanentDatabase. I don't want to have to rely on an external tool for this.

I've settled on running adhoc Cypher queries and dumping the result to console:

println(new ExecutionEngine(db).execute(
  "match (p:USER)-[r]-(c:USER) return p.screenname, r, c.screenname"
).dumpToString())
Chris Beach
  • 4,302
  • 2
  • 31
  • 50