Search in sources :

Example 26 with Record

use of org.neo4j.driver.Record in project neo4j by neo4j.

the class PrettyPrinterTest method prettyPrintRelationships.

@Test
public void prettyPrintRelationships() {
    // given
    Record record = mock(Record.class);
    Value value = mock(Value.class);
    Relationship relationship = mock(Relationship.class);
    HashMap<String, Object> propertiesAsMap = new HashMap<>();
    propertiesAsMap.put("prop1", "prop1_value");
    propertiesAsMap.put("prop2", "prop2_value");
    when(value.type()).thenReturn(InternalTypeSystem.TYPE_SYSTEM.RELATIONSHIP());
    when(value.asRelationship()).thenReturn(relationship);
    when(relationship.type()).thenReturn("RELATIONSHIP_TYPE");
    when(relationship.asMap(anyObject())).thenReturn(unmodifiableMap(propertiesAsMap));
    when(record.keys()).thenReturn(asList("rel"));
    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("rel" + NEWLINE + "[:RELATIONSHIP_TYPE {prop2: prop2_value, prop1: prop1_value}]" + NEWLINE));
}
Also used : ListBoltResult(org.neo4j.shell.state.ListBoltResult) HashMap(java.util.HashMap) Relationship(org.neo4j.driver.types.Relationship) Value(org.neo4j.driver.Value) ResultSummary(org.neo4j.driver.summary.ResultSummary) Record(org.neo4j.driver.Record) Matchers.anyObject(org.mockito.Matchers.anyObject) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) BoltResult(org.neo4j.shell.state.BoltResult) ListBoltResult(org.neo4j.shell.state.ListBoltResult) Test(org.junit.Test)

Example 27 with Record

use of org.neo4j.driver.Record in project neo4j by neo4j.

the class PrettyPrinterTest method prettyPrintList.

@Test
public void prettyPrintList() {
    // given
    Record record1 = mock(Record.class);
    Record record2 = mock(Record.class);
    Value value1 = Values.value("val1_1", "val1_2");
    Value value2 = Values.value(new String[] { "val2_1" });
    when(record1.keys()).thenReturn(asList("col1", "col2"));
    when(record1.values()).thenReturn(asList(value1, value2));
    when(record2.values()).thenReturn(asList(value2));
    BoltResult result = new ListBoltResult(asList(record1, record2), mock(ResultSummary.class));
    // when
    String actual = plainPrinter.format(result);
    // then
    assertThat(actual, is(String.join(NEWLINE, "col1, col2", "[\"val1_1\", \"val1_2\"], [\"val2_1\"]", "[\"val2_1\"]", "")));
}
Also used : ListBoltResult(org.neo4j.shell.state.ListBoltResult) Value(org.neo4j.driver.Value) ResultSummary(org.neo4j.driver.summary.ResultSummary) Record(org.neo4j.driver.Record) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) BoltResult(org.neo4j.shell.state.BoltResult) ListBoltResult(org.neo4j.shell.state.ListBoltResult) Test(org.junit.Test)

Example 28 with Record

use of org.neo4j.driver.Record in project neo4j by neo4j.

the class PrettyPrinterTest method prettyPrintPaths.

@Test
public void prettyPrintPaths() {
    // given
    Record record = mock(Record.class);
    Value value = mock(Value.class);
    Node start = mock(Node.class);
    HashMap<String, Object> startProperties = new HashMap<>();
    startProperties.put("prop1", "prop1_value");
    when(start.labels()).thenReturn(asList("start"));
    when(start.id()).thenReturn(1L);
    Node middle = mock(Node.class);
    when(middle.labels()).thenReturn(asList("middle"));
    when(middle.id()).thenReturn(2L);
    Node end = mock(Node.class);
    HashMap<String, Object> endProperties = new HashMap<>();
    endProperties.put("prop2", "prop2_value");
    when(end.labels()).thenReturn(asList("end"));
    when(end.id()).thenReturn(3L);
    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);
    Path.Segment segment1 = mock(Path.Segment.class);
    when(segment1.start()).thenReturn(start);
    when(segment1.end()).thenReturn(middle);
    when(segment1.relationship()).thenReturn(relationship);
    Path.Segment segment2 = mock(Path.Segment.class);
    when(segment2.start()).thenReturn(middle);
    when(segment2.end()).thenReturn(end);
    when(segment2.relationship()).thenReturn(relationship);
    when(value.type()).thenReturn(InternalTypeSystem.TYPE_SYSTEM.PATH());
    when(value.asPath()).thenReturn(path);
    when(path.iterator()).thenReturn(asList(segment1, segment2).iterator());
    when(start.asMap(anyObject())).thenReturn(unmodifiableMap(startProperties));
    when(end.asMap(anyObject())).thenReturn(unmodifiableMap(endProperties));
    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 {prop1: prop1_value})-[:RELATIONSHIP_TYPE]->" + "(:middle)<-[:RELATIONSHIP_TYPE]-(:end {prop2: prop2_value})" + NEWLINE));
}
Also used : Path(org.neo4j.driver.types.Path) HashMap(java.util.HashMap) Node(org.neo4j.driver.types.Node) ResultSummary(org.neo4j.driver.summary.ResultSummary) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) BoltResult(org.neo4j.shell.state.BoltResult) ListBoltResult(org.neo4j.shell.state.ListBoltResult) ListBoltResult(org.neo4j.shell.state.ListBoltResult) Relationship(org.neo4j.driver.types.Relationship) Value(org.neo4j.driver.Value) Record(org.neo4j.driver.Record) Matchers.anyObject(org.mockito.Matchers.anyObject) Test(org.junit.Test)

Example 29 with Record

use of org.neo4j.driver.Record in project neo4j by neo4j.

the class PrettyPrinterTest method checkMapForPrettyPrint.

private void checkMapForPrettyPrint(Map<String, String> map, String expectedResult) {
    // given
    Record record = mock(Record.class);
    Value value = mock(Value.class);
    when(value.type()).thenReturn(InternalTypeSystem.TYPE_SYSTEM.MAP());
    when(value.asMap((Function<Value, String>) anyObject())).thenReturn(map);
    when(record.keys()).thenReturn(asList("map"));
    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(expectedResult));
}
Also used : ListBoltResult(org.neo4j.shell.state.ListBoltResult) Value(org.neo4j.driver.Value) ResultSummary(org.neo4j.driver.summary.ResultSummary) Record(org.neo4j.driver.Record) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) BoltResult(org.neo4j.shell.state.BoltResult) ListBoltResult(org.neo4j.shell.state.ListBoltResult)

Example 30 with Record

use of org.neo4j.driver.Record 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)

Aggregations

Record (org.neo4j.driver.Record)33 Test (org.junit.Test)21 Value (org.neo4j.driver.Value)21 ListBoltResult (org.neo4j.shell.state.ListBoltResult)18 ResultSummary (org.neo4j.driver.summary.ResultSummary)12 BoltResult (org.neo4j.shell.state.BoltResult)11 InternalRecord (org.neo4j.driver.internal.InternalRecord)10 HashMap (java.util.HashMap)9 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)8 Result (org.neo4j.driver.Result)8 StringContains.containsString (org.hamcrest.core.StringContains.containsString)7 Node (org.neo4j.driver.types.Node)7 Relationship (org.neo4j.driver.types.Relationship)7 Session (org.neo4j.driver.Session)6 ArrayList (java.util.ArrayList)5 Driver (org.neo4j.driver.Driver)5 List (java.util.List)4 DurationValue (org.neo4j.driver.internal.value.DurationValue)4 NodeValue (org.neo4j.driver.internal.value.NodeValue)4 PathValue (org.neo4j.driver.internal.value.PathValue)4