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());
}
}
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));
}
}
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)));
}
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)));
}
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)));
}
Aggregations