Search in sources :

Example 51 with Path

use of org.neo4j.graphdb.Path in project neo4j by neo4j.

the class UserFunctionIT method shouldCallFunctionReturningPaths.

@Test
public void shouldCallFunctionReturningPaths() throws Throwable {
    // Given
    try (Transaction ignore = db.beginTx()) {
        Node node1 = db.createNode();
        Node node2 = db.createNode();
        Relationship rel = node1.createRelationshipTo(node2, RelationshipType.withName("KNOWS"));
        // When
        Result res = db.execute("RETURN org.neo4j.procedure.nodePaths({node}) AS path", map("node", node1));
        // Then
        assertTrue(res.hasNext());
        Map<String, Object> value = res.next();
        Path path = (Path) value.get("path");
        assertThat(path.length(), equalTo(1));
        assertThat(path.startNode(), equalTo(node1));
        assertThat(asList(path.relationships()), equalTo(singletonList(rel)));
        assertThat(path.endNode(), equalTo(node2));
        assertFalse(res.hasNext());
    }
}
Also used : Path(org.neo4j.graphdb.Path) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) Result(org.neo4j.graphdb.Result) Test(org.junit.Test)

Example 52 with Path

use of org.neo4j.graphdb.Path in project neo4j by neo4j.

the class Neo4jPackTest method shouldNotBeAbleToUnpackPaths.

@Test
public void shouldNotBeAbleToUnpackPaths() throws IOException {
    for (Path path : ALL_PATHS) {
        // Expect
        exception.expect(BoltIOException.class);
        // When
        unpacked(packed(path));
    }
}
Also used : Path(org.neo4j.graphdb.Path) Test(org.junit.Test)

Example 53 with Path

use of org.neo4j.graphdb.Path in project neo4j by neo4j.

the class ValuePathTest method canConstructPathWithLengthTwo.

@Test
public void canConstructPathWithLengthTwo() {
    // Given A->C->D
    Path path = PATH_WITH_LENGTH_TWO;
    // Then
    assertThat(path.length(), equalTo(2));
    assertThat(path.startNode(), equalTo(ALICE));
    assertThat(path.endNode(), equalTo(DAVE));
    assertThat(nodes(path), equalTo(nodes(ALICE, CAROL, DAVE)));
    assertThat(path.lastRelationship(), equalTo(CAROL_MARRIED_TO_DAVE));
    assertThat(relationships(path), equalTo(relationships(ALICE_LIKES_CAROL, CAROL_MARRIED_TO_DAVE)));
}
Also used : Path(org.neo4j.graphdb.Path) Test(org.junit.Test)

Example 54 with Path

use of org.neo4j.graphdb.Path in project neo4j by neo4j.

the class ValuePathTest method canConstructPathWithNodesVisitedMultipleTimes.

@Test
public void canConstructPathWithNodesVisitedMultipleTimes() {
    // Given A->B<-A->C->B<-C
    Path path = PATH_WITH_NODES_VISITED_MULTIPLE_TIMES;
    // Then
    assertThat(path.length(), equalTo(5));
    assertThat(path.startNode(), equalTo(ALICE));
    assertThat(path.endNode(), equalTo(CAROL));
    assertThat(nodes(path), equalTo(nodes(ALICE, BOB, ALICE, CAROL, BOB, CAROL)));
    assertThat(path.lastRelationship(), equalTo(CAROL_DISLIKES_BOB));
    assertThat(relationships(path), equalTo(relationships(ALICE_KNOWS_BOB, ALICE_KNOWS_BOB, ALICE_LIKES_CAROL, CAROL_DISLIKES_BOB, CAROL_DISLIKES_BOB)));
}
Also used : Path(org.neo4j.graphdb.Path) Test(org.junit.Test)

Example 55 with Path

use of org.neo4j.graphdb.Path in project neo4j by neo4j.

the class ValuePathTest method canConstructPathWithLengthOne.

@Test
public void canConstructPathWithLengthOne() {
    // Given A->B
    Path path = PATH_WITH_LENGTH_ONE;
    // Then
    assertThat(path.length(), equalTo(1));
    assertThat(path.startNode(), equalTo(ALICE));
    assertThat(path.endNode(), equalTo(BOB));
    assertThat(nodes(path), equalTo(nodes(ALICE, BOB)));
    assertThat(path.lastRelationship(), equalTo(ALICE_KNOWS_BOB));
    assertThat(relationships(path), equalTo(relationships(ALICE_KNOWS_BOB)));
}
Also used : Path(org.neo4j.graphdb.Path) Test(org.junit.Test)

Aggregations

Path (org.neo4j.graphdb.Path)112 Test (org.junit.Test)66 Node (org.neo4j.graphdb.Node)49 Relationship (org.neo4j.graphdb.Relationship)30 WeightedPath (org.neo4j.graphalgo.WeightedPath)20 Transaction (org.neo4j.graphdb.Transaction)18 ArrayList (java.util.ArrayList)15 Traverser (org.neo4j.graphdb.traversal.Traverser)15 TraversalDescription (org.neo4j.graphdb.traversal.TraversalDescription)12 HashSet (java.util.HashSet)9 Evaluator (org.neo4j.graphdb.traversal.Evaluator)9 LinkedList (java.util.LinkedList)6 RelationshipType (org.neo4j.graphdb.RelationshipType)6 TraversalBranch (org.neo4j.graphdb.traversal.TraversalBranch)6 Predicate (org.neo4j.helpers.Predicate)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 PathFinder (org.neo4j.graphalgo.PathFinder)4 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)4 ExactDepthPathFinder (org.neo4j.graphalgo.impl.path.ExactDepthPathFinder)3