use of org.neo4j.driver.types.Path in project neo4j by neo4j.
the class TableOutputFormatterTest method prettyPrintPath.
@Test
public void prettyPrintPath() {
// given
List<String> keys = asList("path");
Node n1 = mock(Node.class);
when(n1.id()).thenReturn(1L);
List<String> labels = asList("L1");
when(n1.labels()).thenReturn(labels);
when(n1.asMap(anyObject())).thenReturn(Collections.emptyMap());
Relationship r1 = mock(Relationship.class);
when(r1.startNodeId()).thenReturn(2L);
when(r1.type()).thenReturn("R1");
when(r1.asMap(anyObject())).thenReturn(Collections.emptyMap());
Node n2 = mock(Node.class);
when(n2.id()).thenReturn(2L);
when(n2.labels()).thenReturn(asList("L2"));
when(n2.asMap(anyObject())).thenReturn(Collections.emptyMap());
Relationship r2 = mock(Relationship.class);
when(r2.startNodeId()).thenReturn(2L);
when(r2.type()).thenReturn("R2");
when(r2.asMap(anyObject())).thenReturn(Collections.emptyMap());
Node n3 = mock(Node.class);
when(n3.id()).thenReturn(3L);
when(n3.labels()).thenReturn(asList("L3"));
when(n3.asMap(anyObject())).thenReturn(Collections.emptyMap());
Path.Segment s1 = mock(Path.Segment.class);
when(s1.relationship()).thenReturn(r1);
when(s1.start()).thenReturn(n1);
when(s1.end()).thenReturn(n2);
Path.Segment s2 = mock(Path.Segment.class);
when(s2.relationship()).thenReturn(r2);
when(s2.start()).thenReturn(n2);
when(s2.end()).thenReturn(n3);
List<Path.Segment> segments = asList(s1, s2);
List<Node> nodes = asList(n1, n2);
List<Relationship> relationships = asList(r1);
InternalPath internalPath = new InternalPath(segments, nodes, relationships);
Value value = new PathValue(internalPath);
Record record = new InternalRecord(keys, new Value[] { value });
// when
String actual = verbosePrinter.format(new ListBoltResult(asList(record), mock(ResultSummary.class)));
// then
assertThat(actual, containsString("| (:L1)<-[:R1]-(:L2)-[:R2]->(:L3) |"));
}
use of org.neo4j.driver.types.Path in project neo4j by neo4j.
the class PrettyPrinterTest method prettyPrintThreeSegmentPath.
@Test
public void prettyPrintThreeSegmentPath() {
// given
Record record = mock(Record.class);
Value value = mock(Value.class);
Node start = mock(Node.class);
when(start.labels()).thenReturn(asList("start"));
when(start.id()).thenReturn(1L);
Node second = mock(Node.class);
when(second.labels()).thenReturn(asList("second"));
when(second.id()).thenReturn(2L);
Node third = mock(Node.class);
when(third.labels()).thenReturn(asList("third"));
when(third.id()).thenReturn(3L);
Node end = mock(Node.class);
when(end.labels()).thenReturn(asList("end"));
when(end.id()).thenReturn(4L);
Path path = mock(Path.class);
when(path.start()).thenReturn(start);
Relationship relationship = mock(Relationship.class);
when(relationship.type()).thenReturn("RELATIONSHIP_TYPE");
when(relationship.startNodeId()).thenReturn(1L).thenReturn(3L).thenReturn(3L);
Path.Segment segment1 = mock(Path.Segment.class);
when(segment1.start()).thenReturn(start);
when(segment1.end()).thenReturn(second);
when(segment1.relationship()).thenReturn(relationship);
Path.Segment segment2 = mock(Path.Segment.class);
when(segment2.start()).thenReturn(second);
when(segment2.end()).thenReturn(third);
when(segment2.relationship()).thenReturn(relationship);
Path.Segment segment3 = mock(Path.Segment.class);
when(segment3.start()).thenReturn(third);
when(segment3.end()).thenReturn(end);
when(segment3.relationship()).thenReturn(relationship);
when(value.type()).thenReturn(InternalTypeSystem.TYPE_SYSTEM.PATH());
when(value.asPath()).thenReturn(path);
when(path.iterator()).thenReturn(asList(segment1, segment2, segment3).iterator());
when(record.keys()).thenReturn(asList("path"));
when(record.values()).thenReturn(asList(value));
BoltResult result = new ListBoltResult(singletonList(record), mock(ResultSummary.class));
// when
String actual = plainPrinter.format(result);
// then
assertThat(actual, is("path" + NEWLINE + "(:start)-[:RELATIONSHIP_TYPE]->" + "(:second)<-[:RELATIONSHIP_TYPE]-(:third)-[:RELATIONSHIP_TYPE]->(:end)" + NEWLINE));
}
use of org.neo4j.driver.types.Path in project neo4j by neo4j.
the class SnapshotExecutionTest method testEntityVirtualTypes.
// Since most test work with primitives (storable values), this is a smoke test that
// entity types work as result of Snapshot EE
@Test
void testEntityVirtualTypes() {
var query = joinAsLines("CREATE (n1:LABEL_1), (n2:LABEL_2)", "MERGE (n1) - [:TYPE_1] -> (n2)", "RETURN () - [] -> ()[0] AS p");
Path p = driver.session().run(query).stream().map(r -> r.get("p")).findFirst().get().asPath();
assertThat(p.start().labels()).containsExactly("LABEL_1");
assertThat(p.end().labels()).containsExactly("LABEL_2");
}
use of org.neo4j.driver.types.Path in project neo4j by neo4j.
the class OutputFormatter method pathAsString.
@Nonnull
default String pathAsString(@Nonnull Path path) {
List<String> list = new ArrayList<>(path.length());
Node lastTraversed = path.start();
if (lastTraversed != null) {
list.add(nodeAsString(lastTraversed));
for (Path.Segment segment : path) {
Relationship relationship = segment.relationship();
if (relationship.startNodeId() == lastTraversed.id()) {
list.add("-" + relationshipAsString(relationship) + "->");
} else {
list.add("<-" + relationshipAsString(relationship) + "-");
}
list.add(nodeAsString(segment.end()));
lastTraversed = segment.end();
}
}
return String.join("", list);
}
use of org.neo4j.driver.types.Path in project neo4j by neo4j.
the class PrettyPrinterTest method prettyPrintSingleNodePath.
@Test
public void prettyPrintSingleNodePath() {
// given
Record record = mock(Record.class);
Value value = mock(Value.class);
Node start = mock(Node.class);
when(start.labels()).thenReturn(asList("start"));
when(start.id()).thenReturn(1L);
Node end = mock(Node.class);
when(end.labels()).thenReturn(asList("end"));
when(end.id()).thenReturn(2L);
Path path = mock(Path.class);
when(path.start()).thenReturn(start);
Relationship relationship = mock(Relationship.class);
when(relationship.type()).thenReturn("RELATIONSHIP_TYPE");
when(relationship.startNodeId()).thenReturn(1L);
Path.Segment segment1 = mock(Path.Segment.class);
when(segment1.start()).thenReturn(start);
when(segment1.end()).thenReturn(end);
when(segment1.relationship()).thenReturn(relationship);
when(value.type()).thenReturn(InternalTypeSystem.TYPE_SYSTEM.PATH());
when(value.asPath()).thenReturn(path);
when(path.iterator()).thenReturn(asList(segment1).iterator());
when(record.keys()).thenReturn(asList("path"));
when(record.values()).thenReturn(asList(value));
BoltResult result = new ListBoltResult(asList(record), mock(ResultSummary.class));
// when
String actual = plainPrinter.format(result);
// then
assertThat(actual, is("path" + NEWLINE + "(:start)-[:RELATIONSHIP_TYPE]->(:end)" + NEWLINE));
}
Aggregations