Search in sources :

Example 1 with InternalRecord

use of org.neo4j.driver.internal.InternalRecord 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) |"));
}
Also used : Path(org.neo4j.driver.types.Path) InternalPath(org.neo4j.driver.internal.InternalPath) PathValue(org.neo4j.driver.internal.value.PathValue) Node(org.neo4j.driver.types.Node) InternalNode(org.neo4j.driver.internal.InternalNode) InternalPath(org.neo4j.driver.internal.InternalPath) StringContains.containsString(org.hamcrest.core.StringContains.containsString) InternalRecord(org.neo4j.driver.internal.InternalRecord) ListBoltResult(org.neo4j.shell.state.ListBoltResult) Relationship(org.neo4j.driver.types.Relationship) InternalRelationship(org.neo4j.driver.internal.InternalRelationship) Value(org.neo4j.driver.Value) RelationshipValue(org.neo4j.driver.internal.value.RelationshipValue) NodeValue(org.neo4j.driver.internal.value.NodeValue) DurationValue(org.neo4j.driver.internal.value.DurationValue) PathValue(org.neo4j.driver.internal.value.PathValue) PointValue(org.neo4j.driver.internal.value.PointValue) InternalRecord(org.neo4j.driver.internal.InternalRecord) Record(org.neo4j.driver.Record) Test(org.junit.Test)

Example 2 with InternalRecord

use of org.neo4j.driver.internal.InternalRecord in project neo4j by neo4j.

the class TableOutputFormatterTest method prettyPrintDurationWithNoTrailingZeroes.

@Test
public void prettyPrintDurationWithNoTrailingZeroes() {
    // given
    List<String> keys = asList("d");
    Value duration = new DurationValue(new InternalIsoDuration(1, 2, 3, 0));
    Record record = new InternalRecord(keys, new Value[] { duration });
    // when
    String actual = verbosePrinter.format(new ListBoltResult(asList(record), mock(ResultSummary.class)));
    // then
    assertThat(actual, containsString("| P1M2DT3S |"));
}
Also used : InternalRecord(org.neo4j.driver.internal.InternalRecord) ListBoltResult(org.neo4j.shell.state.ListBoltResult) DurationValue(org.neo4j.driver.internal.value.DurationValue) Value(org.neo4j.driver.Value) RelationshipValue(org.neo4j.driver.internal.value.RelationshipValue) NodeValue(org.neo4j.driver.internal.value.NodeValue) DurationValue(org.neo4j.driver.internal.value.DurationValue) PathValue(org.neo4j.driver.internal.value.PathValue) PointValue(org.neo4j.driver.internal.value.PointValue) InternalRecord(org.neo4j.driver.internal.InternalRecord) Record(org.neo4j.driver.Record) StringContains.containsString(org.hamcrest.core.StringContains.containsString) InternalIsoDuration(org.neo4j.driver.internal.InternalIsoDuration) Test(org.junit.Test)

Example 3 with InternalRecord

use of org.neo4j.driver.internal.InternalRecord in project neo4j by neo4j.

the class TableOutputFormatter method formatInfo.

@Override
@Nonnull
public String formatInfo(@Nonnull ResultSummary summary) {
    Map<String, Value> info = OutputFormatter.info(summary);
    if (info.isEmpty()) {
        return "";
    }
    String[] columns = info.keySet().toArray(new String[0]);
    StringBuilder sb = new StringBuilder();
    Record record = new InternalRecord(asList(columns), info.values().toArray(new Value[0]));
    formatResultAndCountRows(columns, Collections.singletonList(record).iterator(), line -> sb.append(line).append(OutputFormatter.NEWLINE));
    return sb.toString();
}
Also used : InternalRecord(org.neo4j.driver.internal.InternalRecord) Value(org.neo4j.driver.Value) InternalRecord(org.neo4j.driver.internal.InternalRecord) Record(org.neo4j.driver.Record) Nonnull(javax.annotation.Nonnull)

Example 4 with InternalRecord

use of org.neo4j.driver.internal.InternalRecord in project neo4j by neo4j.

the class TableOutputFormatterTest method prettyPrintRelationships.

@Test
public void prettyPrintRelationships() {
    // given
    List<String> keys = asList("rel");
    Map<String, Value> propertiesAsMap = new HashMap<>();
    propertiesAsMap.put("prop1", Values.value("prop1_value"));
    propertiesAsMap.put("prop2", Values.value("prop2_value"));
    RelationshipValue relationship = new RelationshipValue(new InternalRelationship(1, 1, 2, "RELATIONSHIP_TYPE", propertiesAsMap));
    Record record = new InternalRecord(keys, new Value[] { relationship });
    // when
    String actual = verbosePrinter.format(new ListBoltResult(asList(record), mock(ResultSummary.class)));
    // then
    assertThat(actual, containsString("| [:RELATIONSHIP_TYPE {prop2: \"prop2_value\", prop1: \"prop1_value\"}] |"));
}
Also used : InternalRecord(org.neo4j.driver.internal.InternalRecord) InternalRelationship(org.neo4j.driver.internal.InternalRelationship) ListBoltResult(org.neo4j.shell.state.ListBoltResult) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Value(org.neo4j.driver.Value) RelationshipValue(org.neo4j.driver.internal.value.RelationshipValue) NodeValue(org.neo4j.driver.internal.value.NodeValue) DurationValue(org.neo4j.driver.internal.value.DurationValue) PathValue(org.neo4j.driver.internal.value.PathValue) PointValue(org.neo4j.driver.internal.value.PointValue) InternalRecord(org.neo4j.driver.internal.InternalRecord) Record(org.neo4j.driver.Record) StringContains.containsString(org.hamcrest.core.StringContains.containsString) RelationshipValue(org.neo4j.driver.internal.value.RelationshipValue) Test(org.junit.Test)

Example 5 with InternalRecord

use of org.neo4j.driver.internal.InternalRecord in project neo4j by neo4j.

the class TableOutputFormatterTest method prettyPrintPoint.

@Test
public void prettyPrintPoint() {
    // given
    List<String> keys = asList("p1", "p2");
    Value point2d = new PointValue(new InternalPoint2D(4326, 42.78, 56.7));
    Value point3d = new PointValue(new InternalPoint3D(4326, 1.7, 26.79, 34.23));
    Record record = new InternalRecord(keys, new Value[] { point2d, point3d });
    // when
    String actual = verbosePrinter.format(new ListBoltResult(asList(record), mock(ResultSummary.class)));
    // then
    assertThat(actual, containsString("| point({srid:4326, x:42.78, y:56.7}) |"));
    assertThat(actual, containsString("| point({srid:4326, x:1.7, y:26.79, z:34.23}) |"));
}
Also used : InternalRecord(org.neo4j.driver.internal.InternalRecord) ListBoltResult(org.neo4j.shell.state.ListBoltResult) PointValue(org.neo4j.driver.internal.value.PointValue) Value(org.neo4j.driver.Value) RelationshipValue(org.neo4j.driver.internal.value.RelationshipValue) NodeValue(org.neo4j.driver.internal.value.NodeValue) DurationValue(org.neo4j.driver.internal.value.DurationValue) PathValue(org.neo4j.driver.internal.value.PathValue) PointValue(org.neo4j.driver.internal.value.PointValue) InternalPoint3D(org.neo4j.driver.internal.InternalPoint3D) InternalRecord(org.neo4j.driver.internal.InternalRecord) Record(org.neo4j.driver.Record) StringContains.containsString(org.hamcrest.core.StringContains.containsString) InternalPoint2D(org.neo4j.driver.internal.InternalPoint2D) Test(org.junit.Test)

Aggregations

Record (org.neo4j.driver.Record)7 Value (org.neo4j.driver.Value)7 InternalRecord (org.neo4j.driver.internal.InternalRecord)7 StringContains.containsString (org.hamcrest.core.StringContains.containsString)6 Test (org.junit.Test)6 DurationValue (org.neo4j.driver.internal.value.DurationValue)6 NodeValue (org.neo4j.driver.internal.value.NodeValue)6 PathValue (org.neo4j.driver.internal.value.PathValue)6 PointValue (org.neo4j.driver.internal.value.PointValue)6 RelationshipValue (org.neo4j.driver.internal.value.RelationshipValue)6 ListBoltResult (org.neo4j.shell.state.ListBoltResult)6 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 InternalIsoDuration (org.neo4j.driver.internal.InternalIsoDuration)2 InternalNode (org.neo4j.driver.internal.InternalNode)2 InternalRelationship (org.neo4j.driver.internal.InternalRelationship)2 Nonnull (javax.annotation.Nonnull)1 InternalPath (org.neo4j.driver.internal.InternalPath)1 InternalPoint2D (org.neo4j.driver.internal.InternalPoint2D)1 InternalPoint3D (org.neo4j.driver.internal.InternalPoint3D)1