Database Reference
In-Depth Information
ExecutionResult result = engine.execute(query);
Iterator <Object> objResult =
result.columnAs("n");
//Check that Database has only 1 Node and not
more than 1 node
Assert.assertTrue(objResult.size()==1);
while(objResult.hasNext()){
Node cypherNode = (Node)objResult.next();
//Check that Label matches with the same Label
what was created initially
Assert.assertTrue(cypherNode.hasLabel(DynamicLabel.label(testLabel)));
}
transaction.success();
}
}
Let's understand the preceding JUnit test:
graphDb.createNode(DynamicLabel.label(testLabel));
The preceding line creates a node in the test database with the provided label.
//Execute Cypher query and retrieve all Nodes from
Neo4j Database
ExecutionEngine engine = new ExecutionEngine(graphDb,
StringLogger.SYSTEM);
String query = "MATCH (n) return n";
ExecutionResult result = engine.execute(query);
Iterator <Object> objResult = result.columnAs("n");
After creating node in the test database, the preceding code then executes the
Cypher query to get the results from the same database.
Assert.assertTrue(objResult.size()==1);
Next, the preceding code checks whether the Cypher query has returned only one
node. Not more and not less!
Search WWH ::




Custom Search