use of org.neo4j.graphdb.traversal.TraversalDescription in project neo4j by neo4j.
the class TestPath method testBidirectionalPath.
@Test
public void testBidirectionalPath() throws Exception {
TraversalDescription side = getGraphDb().traversalDescription().uniqueness(Uniqueness.NODE_PATH);
BidirectionalTraversalDescription bidirectional = getGraphDb().bidirectionalTraversalDescription().mirroredSides(side);
Path bidirectionalPath = Iterables.first(bidirectional.traverse(a, e));
assertPathIsCorrect(bidirectionalPath);
assertEquals(a, Iterables.first(bidirectional.traverse(a, e)).startNode());
// White box testing below: relationships(), nodes(), reverseRelationships(), reverseNodes()
// does cache the start node if not already cached, so just make sure they to it properly.
bidirectionalPath = Iterables.first(bidirectional.traverse(a, e));
bidirectionalPath.relationships();
assertEquals(a, bidirectionalPath.startNode());
bidirectionalPath = Iterables.first(bidirectional.traverse(a, e));
bidirectionalPath.nodes();
assertEquals(a, bidirectionalPath.startNode());
bidirectionalPath = Iterables.first(bidirectional.traverse(a, e));
bidirectionalPath.reverseRelationships();
assertEquals(a, bidirectionalPath.startNode());
bidirectionalPath = Iterables.first(bidirectional.traverse(a, e));
bidirectionalPath.reverseNodes();
assertEquals(a, bidirectionalPath.startNode());
bidirectionalPath = Iterables.first(bidirectional.traverse(a, e));
bidirectionalPath.iterator();
assertEquals(a, bidirectionalPath.startNode());
}
use of org.neo4j.graphdb.traversal.TraversalDescription in project neo4j by neo4j.
the class TestTraversalWithIterable method traverseWithIterableForStartNodes.
@Test
public void traverseWithIterableForStartNodes() throws Exception {
/*
* (a)-->(b)-->(c)
* (d)-->(e)-->(f)
*
*/
createGraph("a TO b", "b TO c", "d TO e", "e TO f");
try (Transaction tx = beginTx()) {
TraversalDescription basicTraverser = getGraphDb().traversalDescription().evaluator(Evaluators.atDepth(2));
Collection<Node> startNodes = new ArrayList<>();
startNodes.add(getNodeWithName("a"));
startNodes.add(getNodeWithName("d"));
Iterable<Node> iterableStartNodes = startNodes;
expectPaths(basicTraverser.traverse(iterableStartNodes), "a,b,c", "d,e,f");
tx.success();
}
}
use of org.neo4j.graphdb.traversal.TraversalDescription in project neo4j by neo4j.
the class TestTraversalWithLoops method traverseThroughNodeWithLoop.
@Test
public void traverseThroughNodeWithLoop() throws Exception {
/*
* (a)-->(b)-->(c)-->(d)-->(e)
* / \ / \
* \__/ \__/
*/
createGraph("a TO b", "b TO c", "c TO c", "c TO d", "d TO d", "d TO e");
try (Transaction tx = beginTx()) {
Node a = getNodeWithName("a");
final Node e = getNodeWithName("e");
Evaluator onlyEndNode = new Evaluator() {
@Override
public Evaluation evaluate(Path path) {
return Evaluation.ofIncludes(path.endNode().equals(e));
}
};
TraversalDescription basicTraverser = getGraphDb().traversalDescription().evaluator(onlyEndNode);
expectPaths(basicTraverser.traverse(a), "a,b,c,d,e");
expectPaths(basicTraverser.uniqueness(Uniqueness.RELATIONSHIP_PATH).traverse(a), "a,b,c,d,e", "a,b,c,c,d,e", "a,b,c,d,d,e", "a,b,c,c,d,d,e");
tx.success();
}
}
use of org.neo4j.graphdb.traversal.TraversalDescription in project neo4j by neo4j.
the class SpecificDepthTraversalTest method shouldGetStartNodeWhenFromToIsZeroBreadthFirst.
@Test
public void shouldGetStartNodeWhenFromToIsZeroBreadthFirst() {
TraversalDescription description = getGraphDb().traversalDescription().breadthFirst().evaluator(Evaluators.fromDepth(0)).evaluator(Evaluators.toDepth(0));
expectNodes(description.traverse(getNodeWithName("0")), "0");
}
use of org.neo4j.graphdb.traversal.TraversalDescription in project neo4j by neo4j.
the class SpecificDepthTraversalTest method shouldGetCorrectNodesFromToDepthOne.
@Test
public void shouldGetCorrectNodesFromToDepthOne() {
TraversalDescription description = getGraphDb().traversalDescription().evaluator(Evaluators.fromDepth(1)).evaluator(Evaluators.toDepth(1));
expectNodes(description.traverse(getNodeWithName("6")), "5");
}
Aggregations