public static String dumpToSeparateFile(File dir, String testId, String content) {
   if (content == null || content.isEmpty()) {
     throw new IllegalArgumentException("The content can not be empty(" + content + ").");
   }
   String filename = testId + ".asciidoc";
   Writer writer = AsciiDocGenerator.getFW(new File(dir, "includes"), filename);
   String title = "";
   char firstChar = content.charAt(0);
   if (firstChar == '.' || firstChar == '_') {
     int pos = content.indexOf('\n');
     if (pos != -1) {
       title = content.substring(0, pos + 1);
       content = content.substring(pos + 1);
     }
   }
   try {
     writer.write(content);
   } catch (IOException e) {
     e.printStackTrace();
   } finally {
     try {
       writer.close();
     } catch (IOException e) {
       e.printStackTrace();
     }
   }
   return title + "include::includes/" + filename + "[]\n";
 }
Example #2
0
  @Test
  @Graph(
      value = {"John friend Sara", "John friend Joe", "Sara friend Maria", "Joe friend Steve"},
      autoIndexNodes = true)
  public void intro_examples() throws Exception {
    try (Transaction ignored = graphdb.beginTx()) {
      Writer fw = AsciiDocGenerator.getFW(DOCS_TARGET, gen.get().getTitle());
      data.get();
      fw.append("\nImagine an example graph like the following one:\n\n");
      fw.append(
          AsciiDocGenerator.dumpToSeparateFileWithType(
              new File(DOCS_TARGET),
              "intro.graph",
              AsciidocHelper.createGraphVizWithNodeId("Example Graph", graphdb(), "cypher-intro")));

      fw.append(
          "\nFor example, here is a query which finds a user called John and John's friends (though not "
              + "his direct friends) before returning both John and any friends-of-friends that are found.");
      fw.append("\n\n");
      String query = "MATCH (john {name: 'John'})-[:friend]->()-[:friend]->(fof) RETURN john, fof ";
      fw.append(
          AsciiDocGenerator.dumpToSeparateFileWithType(
              new File(DOCS_TARGET), "intro.query", createCypherSnippet(query)));
      fw.append("\nResulting in:\n\n");
      fw.append(
          AsciiDocGenerator.dumpToSeparateFileWithType(
              new File(DOCS_TARGET),
              "intro.result",
              createQueryResultSnippet(engine.execute(query).dumpToString())));

      fw.append(
          "\nNext up we will add filtering to set more parts "
              + "in motion:\n\nWe take a list of user names "
              + "and find all nodes with names from this list, match their friends and return "
              + "only those followed users who have a +name+ property starting with +S+.");
      query =
          "MATCH (user)-[:friend]->(follower) WHERE "
              + "user.name IN ['Joe', 'John', 'Sara', 'Maria', 'Steve'] AND follower.name =~ 'S.*' "
              + "RETURN user, follower.name ";
      fw.append("\n\n");
      fw.append(
          AsciiDocGenerator.dumpToSeparateFileWithType(
              new File(DOCS_TARGET), "intro.query", createCypherSnippet(query)));
      fw.append("\nResulting in:\n\n");
      fw.append(
          AsciiDocGenerator.dumpToSeparateFileWithType(
              new File(DOCS_TARGET),
              "intro.result",
              createQueryResultSnippet(engine.execute(query).dumpToString())));
      fw.close();
    }
  }