Neo4jCypherInterpreter extends Interpreter { private InterpreterResult renderTable(List<String> cols, List<List<String>> lines) { LOGGER.info("Executing renderTable method"); StringBuilder msg = null; if (cols.isEmpty()) { msg = new StringBuilder(); } else { msg = new StringBuilder(TABLE); msg.append(NEW_LINE); msg.append(StringUtils.join(cols, TAB)); msg.append(NEW_LINE); for (List<String> line : lines) { if (line.size() < cols.size()) { for (int i = line.size(); i < cols.size(); i++) { line.add(null); } } msg.append(StringUtils.join(line, TAB)); msg.append(NEW_LINE); } } return new InterpreterResult(Code.SUCCESS, msg.toString()); } Neo4jCypherInterpreter(Properties properties); @Override void open(); @Override void close(); Map<String, String> getLabels(boolean refresh); @Override InterpreterResult interpret(String cypherQuery, InterpreterContext interpreterContext); @Override Scheduler getScheduler(); @Override int getProgress(InterpreterContext context); @Override FormType getFormType(); @Override void cancel(InterpreterContext context); static final String NEW_LINE; static final String TAB; }
@Test public void testRenderTable() { interpreter.open(); InterpreterResult result = interpreter.interpret("MATCH (n:Person) " + "WHERE n.name IN ['name1', 'name2', 'name3'] " + "RETURN n.name AS name, n.age AS age, " + "n.address AS address, n.birth AS birth", context); assertEquals(Code.SUCCESS, result.code()); final String tableResult = "name\tage\taddress\tbirth\n" + "\"name1\"\t1\tPoint{srid=4979, x=56.7, y=12.78, z=8.0}\t1984-04-04\n" + "\"name2\"\t2\tPoint{srid=4979, x=56.7, y=12.78, z=8.0}\t1984-04-04\n" + "\"name3\"\t3\tPoint{srid=4979, x=56.7, y=12.78, z=8.0}\t1984-04-04\n"; assertEquals(tableResult, result.toString().replace(TABLE_RESULT_PREFIX, StringUtils.EMPTY)); }