@Test
  public void exampleQuery() throws Exception {
    // START SNIPPET: JavaQuery
    ExecutionEngine engine = new ExecutionEngine(db);
    ExecutionResult result = engine.execute("start n=node(0) where 1=1 return n");

    assertThat(result.columns(), hasItem("n"));
    Iterator<Node> n_column = result.columnAs("n");
    assertThat(asIterable(n_column), hasItem(db.getNodeById(0)));
    assertThat(result.toString(), containsString("Node[0]"));
    // END SNIPPET: JavaQuery
  }
  @Test
  public void shouldBeAbleToEmitJavaIterables() throws Exception {
    makeFriends(michaelaNode, andreasNode);
    makeFriends(michaelaNode, johanNode);

    ExecutionEngine engine = new ExecutionEngine(db);

    ExecutionResult result =
        engine.execute("start n=node(0) match n-->friend return collect(friend)");

    Iterable<Node> friends = (Iterable<Node>) result.columnAs("collect(friend)").next();
    assertThat(friends, hasItems(andreasNode, johanNode));
    assertThat(friends, instanceOf(Iterable.class));
  }
  @Test
  public void exampleWithParametersForQuery() throws Exception {
    // START SNIPPET: exampleWithParametersForQuery
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("query", "name:Andreas");
    ExecutionResult result = engine.execute("start n=node:people({query}) return n", params);
    // END SNIPPET: exampleWithParametersForQuery

    assertEquals(asList(andreasNode), this.<Node>toList(result, "n"));
  }
  @Test
  public void exampleWithParameterForMultipleNodeIds() throws Exception {
    // START SNIPPET: exampleWithParameterForMultipleNodeIds
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("id", Arrays.asList(0, 1, 2));
    ExecutionResult result = engine.execute("start n=node({id}) return n.name", params);
    // END SNIPPET: exampleWithParameterForMultipleNodeIds

    assertEquals(asList("Michaela", "Andreas", "Johan"), this.<String>toList(result, "n.name"));
  }
  @Test
  public void exampleWithStringLiteralAsParameter() throws Exception {
    // START SNIPPET: exampleWithStringLiteralAsParameter
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("name", "Johan");
    ExecutionResult result =
        engine.execute("start n=node(0,1,2) where n.name = {name} return n", params);
    // END SNIPPET: exampleWithStringLiteralAsParameter

    assertEquals(asList(johanNode), this.<Node>toList(result, "n"));
  }
  @Test
  public void exampleWithParameterForNodeObject() throws Exception {
    // START SNIPPET: exampleWithParameterForNodeObject
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("node", andreasNode);
    ExecutionResult result = engine.execute("start n=node({node}) return n.name", params);
    // END SNIPPET: exampleWithParameterForNodeObject

    assertThat(result.columns(), hasItem("n.name"));
    Iterator<Object> n_column = result.columnAs("n.name");
    assertEquals("Andreas", n_column.next());
  }
  @Test
  public void exampleWithParametersForIndexKeyAndValue() throws Exception {
    // START SNIPPET: exampleWithParametersForIndexKeyAndValue
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("key", "name");
    params.put("value", "Michaela");
    ExecutionResult result =
        engine.execute("start n=node:people({key} = {value}) return n", params);
    // END SNIPPET: exampleWithParametersForIndexKeyAndValue

    assertEquals(asList(michaelaNode), this.<Node>toList(result, "n"));
  }
 @Test
 public void testColumnAreInTheRightOrder() throws Exception {
   createTenNodes();
   String q =
       "start one=node(1), two=node(2), three=node(3), four=node(4), five=node(5), six=node(6), "
           + "seven=node(7), eight=node(8), nine=node(9), ten=node(10) "
           + "return one, two, three, four, five, six, seven, eight, nine, ten";
   ExecutionResult result = engine.execute(q);
   assertThat(
       result.toString(),
       matchesPattern("one.*two.*three.*four.*five.*six.*seven.*eight.*nine.*ten"));
 }
  @Test
  public void exampleWithParameterRegularExpression() throws Exception {
    // START SNIPPET: exampleWithParameterRegularExpression
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("regex", ".*h.*");
    ExecutionResult result =
        engine.execute("start n=node(0,1,2) where n.name =~ {regex} return n.name", params);
    // END SNIPPET: exampleWithParameterRegularExpression

    assertThat(result.columns(), hasItem("n.name"));
    Iterator<Object> n_column = result.columnAs("n.name");
    assertEquals("Michaela", n_column.next());
    assertEquals("Johan", n_column.next());
  }
  @Test
  public void exampleWithParameterForSkipAndLimit() throws Exception {
    // START SNIPPET: exampleWithParameterForSkipLimit
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("s", 1);
    params.put("l", 1);
    ExecutionResult result =
        engine.execute("start n=node(0,1,2) return n.name skip {s} limit {l}", params);
    // END SNIPPET: exampleWithParameterForSkipLimit

    assertThat(result.columns(), hasItem("n.name"));
    Iterator<Object> n_column = result.columnAs("n.name");
    assertEquals("Andreas", n_column.next());
  }