InsertOperation extends AbstractNeo4JOperation { @Override public void execute(final Connection connection, final Graph<Node, Edge> graph) throws SQLException { final List<Path> paths = graph.vertexSet().stream().map(n -> n.toPath().withAllAttributes().build()).collect(toList()); graph.edgeSet().stream().map(e -> e.toPath().withAllAttributes().build()).collect(toCollection(() -> paths)); final UpdateNext query = create(paths.toArray(new Path[paths.size()])); executeQuery(connection, query.toString()); }  @Override void execute(final Connection connection, final Graph<Node, Edge> graph);  }
@Test public void testExecute() throws Exception { final Node n1 = graphElementFactory.createNode("n1", Arrays.asList("A"), ImmutableMap.<String, Object>builder().put("id", 1l).build()); final Node n2 = graphElementFactory.createNode("n2", Arrays.asList("A"), ImmutableMap.<String, Object>builder().put("id", 2l).build()); final Edge e1 = graphElementFactory.createEdge(n1, n2, "e1", Arrays.asList("E"), ImmutableMap.<String, Object>builder().put("id", 3l).build()); final Graph<Node, Edge> graph = new DefaultDirectedGraph<>(new ClassBasedEdgeFactory<>(Edge.class)); graph.addVertex(n1); graph.addVertex(n2); graph.addEdge(e1.getSourceNode(), e1.getTargetNode(), e1); operation.execute(connection, graph); final ArgumentCaptor<String> queryCaptor = ArgumentCaptor.forClass(String.class); verify(operation).executeQuery(eq(connection), queryCaptor.capture()); final String query = queryCaptor.getValue(); assertThat(query, containsString("CREATE (n1:A {id:1}),(n2:A {id:2}),(n1)-[e1:E {id:3}]->(n2)")); }