Search in sources :

Example 1 with Traverser

use of org.neo4j.graphdb.traversal.Traverser in project neo4j by neo4j.

the class TreeGraphTest method pathsIteratorReturnAllNodes.

@Test
public void pathsIteratorReturnAllNodes() throws Exception {
    try (Transaction transaction = beginTx()) {
        Traverser traverser = getGraphDb().traversalDescription().traverse(node("1"));
        int count = 0;
        for (Path path : traverser) {
            assertNotNull("returned paths should not be null. path #" + count, path);
            count++;
        }
        assertEquals(13, count);
    }
}
Also used : Path(org.neo4j.graphdb.Path) Transaction(org.neo4j.graphdb.Transaction) Traverser(org.neo4j.graphdb.traversal.Traverser) Test(org.junit.Test)

Example 2 with Traverser

use of org.neo4j.graphdb.traversal.Traverser in project neo4j by neo4j.

the class DepthPitfallGraphTest method testAllUniqueRelationshipPathsAreReturned.

private void testAllUniqueRelationshipPathsAreReturned(TraversalDescription description) throws Exception {
    Set<String> expected = new HashSet<String>(Arrays.asList(NODE_UNIQUE_PATHS));
    expected.addAll(Arrays.asList(RELATIONSHIP_UNIQUE_EXTRA_PATHS));
    Traverser traverser = description.uniqueness(Uniqueness.RELATIONSHIP_PATH).traverse(node("1"));
    expectPaths(traverser, expected);
}
Also used : Traverser(org.neo4j.graphdb.traversal.Traverser) HashSet(java.util.HashSet)

Example 3 with Traverser

use of org.neo4j.graphdb.traversal.Traverser in project neo4j by neo4j.

the class DepthPitfallGraphTest method testSmallestPossibleInit.

@Test
public void testSmallestPossibleInit() throws Exception {
    Traverser traversal = getGraphDb().traversalDescription().traverse(node("1"));
    int count = 0;
    try (Transaction transaction = beginTx()) {
        for (Path position : traversal) {
            count++;
            assertNotNull(position);
            assertNotNull(position.endNode());
            if (position.length() > 0) {
                assertNotNull(position.lastRelationship());
            }
            assertNotNull(position.length());
        }
        assertFalse("empty traversal", count == 0);
    }
}
Also used : Path(org.neo4j.graphdb.Path) Transaction(org.neo4j.graphdb.Transaction) Traverser(org.neo4j.graphdb.traversal.Traverser) Test(org.junit.Test)

Example 4 with Traverser

use of org.neo4j.graphdb.traversal.Traverser in project neo4j by neo4j.

the class DepthPitfallGraphTest method testAllNodesAreReturnedOnce.

private void testAllNodesAreReturnedOnce(TraversalDescription traversal) {
    Traverser traverser = traversal.uniqueness(Uniqueness.NODE_GLOBAL).traverse(node("1"));
    expectNodes(traverser, "1", "2", "3", "4", "5", "6");
}
Also used : Traverser(org.neo4j.graphdb.traversal.Traverser)

Example 5 with Traverser

use of org.neo4j.graphdb.traversal.Traverser in project neo4j by neo4j.

the class DepthPitfallGraphTest method testRelationshipsAreReturnedOnceWhenSufficientRecentlyUnique.

private void testRelationshipsAreReturnedOnceWhenSufficientRecentlyUnique(TraversalDescription description) throws Exception {
    Traverser traverser = description.uniqueness(Uniqueness.RELATIONSHIP_RECENT, THE_WORLD_AS_WE_KNOW_IT.length).traverse(node("1"));
    expectRelationships(traverser, THE_WORLD_AS_WE_KNOW_IT);
}
Also used : Traverser(org.neo4j.graphdb.traversal.Traverser)

Aggregations

Traverser (org.neo4j.graphdb.traversal.Traverser)44 Test (org.junit.Test)19 Path (org.neo4j.graphdb.Path)15 Transaction (org.neo4j.graphdb.Transaction)10 HashSet (java.util.HashSet)6 Node (org.neo4j.graphdb.Node)6 Predicate (org.neo4j.helpers.Predicate)6 Set (java.util.Set)4 Stack (java.util.Stack)4 WeightedPath (org.neo4j.graphalgo.WeightedPath)4 BestFirstSelectorFactory (org.neo4j.graphalgo.impl.util.BestFirstSelectorFactory)4 StopAfterWeightIterator (org.neo4j.graphalgo.impl.util.StopAfterWeightIterator)4 Relationship (org.neo4j.graphdb.Relationship)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LiteDepthFirstSelector (org.neo4j.graphalgo.impl.util.LiteDepthFirstSelector)2 BranchOrderingPolicy (org.neo4j.graphdb.traversal.BranchOrderingPolicy)2 BranchSelector (org.neo4j.graphdb.traversal.BranchSelector)2 TraversalBranch (org.neo4j.graphdb.traversal.TraversalBranch)2 TraversalDescription (org.neo4j.graphdb.traversal.TraversalDescription)2