Example #1
0
  @Test
  public void testRemoveReferenceNode() throws Exception {
    GraphDatabaseService db = new ImpermanentGraphDatabase();
    final GraphDatabaseShellServer server = new GraphDatabaseShellServer(db, false);
    ShellClient client = new SameJvmClient(server);

    Documenter doc = new Documenter("sample session", client);
    doc.add("pwd", "", "where are we?");
    doc.add("set name \"Jon\"", "", "On the current node, set the key \"name\" to value \"Jon\"");
    doc.add("start n=node(0) return n", "Jon", "send a cypher query");
    doc.add(
        "mkrel -c -d i -t LIKES --np \"{'app':'foobar'}\"",
        "",
        "make an incoming relationship of type LIKES, create the end node with the node properties specified.");
    doc.add("ls", "1", "where are we?");
    doc.add("cd 1", "", "change to the newly created node");
    doc.add("ls -avr", "LIKES", "list relationships, including relationshship id");

    doc.add(
        "mkrel -c -d i -t KNOWS --np \"{'name':'Bob'}\"",
        "",
        "create one more KNOWS relationship and the end node");
    doc.add("pwd", "0", "print current history stack");
    doc.add("ls -avr", "KNOWS", "verbose list relationships");
    doc.run();
    // TODO: implement support for removing root node and previous nodes in the history stack of PWD
    // client.getServer().interpretLine( "rmnode -f 0", client.session(), client.getOutput() );
    //        client.getServer().interpretLine( "cd", client.session(), client.getOutput() );
    //        client.getServer().interpretLine( "pwd", client.session(), client.getOutput() );
    server.shutdown();
    db.shutdown();
  }
Example #2
0
  @Test
  public void testMatrix() throws Exception {
    GraphDatabaseService db =
        new ImpermanentGraphDatabase(
            loadStrictly(new File("src/test/resources/autoindex.properties")));
    final GraphDatabaseShellServer server = new GraphDatabaseShellServer(db, false);
    ShellClient client = new SameJvmClient(server);

    Documenter doc = new Documenter("a matrix example", client);
    doc.add("mkrel -t ROOT -c -v", "created", "create the Thomas Andersson node");
    doc.add("cd 1", "", "go to the new node");
    doc.add("set name \"Thomas Andersson\"", "", "set the name property");
    doc.add("mkrel -t KNOWS -cv", "", "create Thomas direct friends");
    doc.add("cd 2", "", "go to the new node");
    doc.add("set name \"Trinity\"", "", "set the name property");
    doc.add("cd ..", "", "go back in the history stack");
    doc.add("mkrel -t KNOWS -cv", "", "create Thomas direct friends");
    doc.add("cd 3", "", "go to the new node");
    doc.add("set name \"Morpheus\"", "", "set the name property");
    doc.add("mkrel -t KNOWS -n 2", "", "create relationship to Trinity");

    doc.add("ls -rv", "", "list the relationships of node 3");
    doc.add("cd -r 2", "", "change the current position to relationship #2");

    doc.add("set -t int age 3", "", "set the age property on the relationship");
    doc.add("cd ..", "", "back to Morpheus");
    doc.add("cd -r 3", "", "next relationsip");
    doc.add("set -t int age 90", "", "set the age property on the relationship");
    doc.add("cd start", "", "position to the start node of the current relationship");

    doc.add(
        "", "", "We're now standing on Morpheus node, so let's create the rest of the friends.");
    doc.add("mkrel -t KNOWS -c", "", "new node");
    doc.add("ls -r", "", "list relationships on the current node");
    doc.add("cd 4", "", "go to Cypher");
    doc.add("set name Cypher", "", "set the name");
    doc.add("mkrel -ct KNOWS", "", "create new node from Cypher");
    // TODO: how to list outgoing relationships?
    // doc.add( "ls -rd out", "", "list relationships" );
    doc.add("ls -r", "", "list relationships");
    doc.add("cd 5", "", "go to the Agent Smith node");
    doc.add("set name \"Agent Smith\"", "", "set the name");
    doc.add("mkrel -cvt CODED_BY", "", "outgoing relationship and new node");
    doc.add("cd 6", "", "go there");
    doc.add("set name \"The Architect\"", "", "set the name");
    doc.add("cd", "", "go to the first node in the history stack");

    doc.add("", "", "Now, let's ask some questions");
    doc.add(
        "start morpheus = node:node_auto_index(name='Morpheus') "
            + "match morpheus-[:KNOWS]-zionist "
            + "return zionist.name",
        "",
        "Morpheus' friends, looking up Morpheus by name in the Neo4j autoindex");
    doc.run();
    server.shutdown();
    db.shutdown();
  }