Search in sources :

Example 66 with RelationshipType

use of org.neo4j.graphdb.RelationshipType in project graphdb by neo4j-attic.

the class TestTraversal method testSanityChecks2.

@Test
public void testSanityChecks2() throws Exception {
    // ------------- with traverser direction -------------
    // Valid data
    Node root = getGraphDb().createNode();
    RelationshipType[] traversableRels = new RelationshipType[] { MyRelTypes.TEST };
    Direction[] traversableDirs = new Direction[] { Direction.OUTGOING };
    // Null traversable relationships
    this.sanityCheckTraverser("Sanity check failed: null traversable " + "rels should throw an " + "IllegalArgumentException", BREADTH_FIRST, root, null, traversableDirs[0], StopEvaluator.END_OF_GRAPH, ReturnableEvaluator.ALL);
    // Null traversable directions
    this.sanityCheckTraverser("Sanity check failed: null traversable " + "rels should throw an " + "IllegalArgumentException", BREADTH_FIRST, root, traversableRels[0], null, StopEvaluator.END_OF_GRAPH, ReturnableEvaluator.ALL);
    // Null stop evaluator
    this.sanityCheckTraverser("Sanity check failed: null stop eval " + "should throw an IllegalArgumentException", BREADTH_FIRST, root, traversableRels[0], traversableDirs[0], null, ReturnableEvaluator.ALL);
    // Null returnable evaluator
    this.sanityCheckTraverser("Sanity check failed: null returnable " + "evaluator should throw an " + "IllegalArgumentException", BREADTH_FIRST, root, traversableRels[0], traversableDirs[0], StopEvaluator.END_OF_GRAPH, null);
    // traversable relationships length not equal to traversable directions
    // length
    this.sanityCheckTraverser("Sanity check failed: null returnable " + "evaluator should throw an " + "IllegalArgumentException", BREADTH_FIRST, root, traversableRels[0], null, StopEvaluator.END_OF_GRAPH, null);
    this.sanityCheckTraverser("Sanity check failed: null returnable " + "evaluator should throw an " + "IllegalArgumentException", BREADTH_FIRST, root, null, traversableDirs[0], StopEvaluator.END_OF_GRAPH, null);
    root.delete();
}
Also used : Node(org.neo4j.graphdb.Node) RelationshipType(org.neo4j.graphdb.RelationshipType) Direction(org.neo4j.graphdb.Direction) Test(org.junit.Test)

Example 67 with RelationshipType

use of org.neo4j.graphdb.RelationshipType in project graphdb by neo4j-attic.

the class TestTraversal method testMultiRelBreadthTraversal.

// Traverses the test "ise-tree-like" population breadth first,
// but only traverses "ise" (TEST) relationships (the population also
// contains
// "ise_clone" (TEST_TRAVERSAL) rels)
@Test
public void testMultiRelBreadthTraversal() throws Exception {
    Node root = this.buildIseTreePopulation();
    RelationshipType[] traversableRels = new RelationshipType[] { MyRelTypes.TEST };
    Traverser traverser = root.traverse(BREADTH_FIRST, StopEvaluator.END_OF_GRAPH, ReturnableEvaluator.ALL, traversableRels[0], Direction.BOTH);
    try {
        this.assertLevelsOfNodes(traverser, new String[][] { new String[] { "1" }, new String[] { "2", "3", "4" }, new String[] { "5", "6", "7" }, new String[] { "10", "11", "12", "13" } });
        assertTrue("Too many nodes returned from traversal", traverser.iterator().hasNext() == false);
    } catch (java.util.NoSuchElementException nsee) {
        fail("Too few nodes returned from traversal");
    } finally {
        this.deleteNodeTreeRecursively(root, 0);
    }
}
Also used : Node(org.neo4j.graphdb.Node) Traverser(org.neo4j.graphdb.Traverser) RelationshipType(org.neo4j.graphdb.RelationshipType) Test(org.junit.Test)

Example 68 with RelationshipType

use of org.neo4j.graphdb.RelationshipType in project graphdb by neo4j-attic.

the class TestTraversal method testStopOnPreviousNode.

// Verifies that the stop evaluator can stop based on the previous node
@Test
public void testStopOnPreviousNode() throws Exception {
    // Build ise tree
    Node root = this.buildIseTreePopulation();
    // Traverse only ISE relationships
    RelationshipType[] traversableRels = new RelationshipType[] { MyRelTypes.TEST };
    // Construct a stop evaluator that stops on nodes 2, 3, and 4
    // (ie root's children)
    StopEvaluator stopEvaluator = new StopEvaluator() {

        public boolean isStopNode(TraversalPosition position) {
            try {
                Node node = position.previousNode();
                String nodeId = (String) node.getProperty("node.test.id");
                return nodeId.equals("1");
            } catch (Exception e) {
                return false;
            }
        }
    };
    // Create a traverser
    Traverser traverser = root.traverse(BREADTH_FIRST, stopEvaluator, ReturnableEvaluator.ALL, traversableRels[0], Direction.BOTH);
    try {
        this.assertNextNodeId(traverser, "1");
        this.assertNextNodeId(traverser, "2");
        this.assertNextNodeId(traverser, "3");
        this.assertNextNodeId(traverser, "4");
        assertTrue("Too many nodes returned from traversal", traverser.iterator().hasNext() == false);
    } catch (java.util.NoSuchElementException nsee) {
        fail("Too few nodes returned from traversal");
    } finally {
        // Delete ise tree and commmit work
        this.deleteNodeTreeRecursively(root, 0);
    }
}
Also used : StopEvaluator(org.neo4j.graphdb.StopEvaluator) Node(org.neo4j.graphdb.Node) Traverser(org.neo4j.graphdb.Traverser) RelationshipType(org.neo4j.graphdb.RelationshipType) TraversalPosition(org.neo4j.graphdb.TraversalPosition) NotFoundException(org.neo4j.graphdb.NotFoundException) Test(org.junit.Test)

Example 69 with RelationshipType

use of org.neo4j.graphdb.RelationshipType in project graphdb by neo4j-attic.

the class TestTraversal method testBruteBreadthTraversal.

// Traverses the full test "ise-tree-like" population breadth first
// and verifies that it is returned in correct order
@Test
public void testBruteBreadthTraversal() throws Exception {
    Node root = this.buildIseTreePopulation();
    RelationshipType[] traversableRels = new RelationshipType[] { MyRelTypes.TEST, MyRelTypes.TEST_TRAVERSAL };
    Traverser traverser = root.traverse(BREADTH_FIRST, StopEvaluator.END_OF_GRAPH, ReturnableEvaluator.ALL, traversableRels[0], Direction.BOTH, traversableRels[1], Direction.BOTH);
    try {
        this.assertLevelsOfNodes(traverser, new String[][] { new String[] { "1" }, new String[] { "2", "3", "4" }, new String[] { "5", "6", "7", "8", "9" }, new String[] { "10", "11", "12", "13", "14" } });
        assertTrue("Too many nodes returned from traversal", traverser.iterator().hasNext() == false);
    } catch (java.util.NoSuchElementException nsee) {
        fail("Too few nodes returned from traversal");
    } finally {
        this.deleteNodeTreeRecursively(root, 0);
    }
}
Also used : Node(org.neo4j.graphdb.Node) Traverser(org.neo4j.graphdb.Traverser) RelationshipType(org.neo4j.graphdb.RelationshipType) Test(org.junit.Test)

Example 70 with RelationshipType

use of org.neo4j.graphdb.RelationshipType in project graphdb by neo4j-attic.

the class TestTraversal method testBruteDepthTraversal.

// Traverses the full test "ise-tree-like" population depth first
// and verifies that it is returned in correct order
@Test
public void testBruteDepthTraversal() throws Exception {
    Node root = this.buildIseTreePopulation();
    RelationshipType[] traversableRels = new RelationshipType[] { MyRelTypes.TEST, MyRelTypes.TEST_TRAVERSAL };
    Traverser traverser = root.traverse(DEPTH_FIRST, StopEvaluator.END_OF_GRAPH, ReturnableEvaluator.ALL, traversableRels[0], Direction.BOTH, traversableRels[1], Direction.BOTH);
    try {
        this.assertNodes(traverser, "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14");
        assertTrue("Too many nodes returned from traversal", traverser.iterator().hasNext() == false);
    } catch (java.util.NoSuchElementException nsee) {
        fail("Too few nodes returned from traversal");
    } finally {
        this.deleteNodeTreeRecursively(root, 0);
    }
}
Also used : Node(org.neo4j.graphdb.Node) Traverser(org.neo4j.graphdb.Traverser) RelationshipType(org.neo4j.graphdb.RelationshipType) Test(org.junit.Test)

Aggregations

RelationshipType (org.neo4j.graphdb.RelationshipType)97 Node (org.neo4j.graphdb.Node)53 Test (org.junit.Test)45 Relationship (org.neo4j.graphdb.Relationship)38 Transaction (org.neo4j.graphdb.Transaction)18 Direction (org.neo4j.graphdb.Direction)15 Traverser (org.neo4j.graphdb.Traverser)10 NotFoundException (org.neo4j.graphdb.NotFoundException)9 DynamicRelationshipType (org.neo4j.graphdb.DynamicRelationshipType)7 Label (org.neo4j.graphdb.Label)7 RelationshipRecord (org.neo4j.kernel.impl.nioneo.store.RelationshipRecord)7 Collection (java.util.Collection)6 HashSet (java.util.HashSet)6 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)6 Path (org.neo4j.graphdb.Path)6 StopEvaluator (org.neo4j.graphdb.StopEvaluator)6 TraversalPosition (org.neo4j.graphdb.TraversalPosition)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 LinkedList (java.util.LinkedList)4