Search in sources :

Example 6 with ListBoltResult

use of org.neo4j.shell.state.ListBoltResult 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 7 with ListBoltResult

use of org.neo4j.shell.state.ListBoltResult 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 8 with ListBoltResult

use of org.neo4j.shell.state.ListBoltResult in project neo4j by neo4j.

the class TableOutputFormatterTest method printRelationshipsAndNodesWithEscapingForSpecialCharacters.

@Test
public void printRelationshipsAndNodesWithEscapingForSpecialCharacters() {
    // given
    Record record = mock(Record.class);
    Map<String, Value> propertiesAsMap = new HashMap<>();
    propertiesAsMap.put("prop1", Values.value("prop1, value"));
    propertiesAsMap.put("prop2", Values.value(1));
    Value relVal = new RelationshipValue(new InternalRelationship(1, 1, 2, "RELATIONSHIP,TYPE", propertiesAsMap));
    List<String> labels = asList("label `1", "label2");
    Map<String, Value> nodeProperties = new HashMap<>();
    nodeProperties.put("prop1", Values.value("prop1:value"));
    String doubleQuotes = "\"\"";
    nodeProperties.put("1prop1", Values.value(doubleQuotes));
    nodeProperties.put("ä", Values.value("not-escaped"));
    Value nodeVal = new NodeValue(new InternalNode(1, labels, nodeProperties));
    Map<String, Value> recordMap = new LinkedHashMap<>();
    recordMap.put("rel", relVal);
    recordMap.put("node", nodeVal);
    List<String> keys = asList("rel", "node");
    when(record.keys()).thenReturn(keys);
    when(record.size()).thenReturn(2);
    when(record.get(0)).thenReturn(relVal);
    when(record.get(1)).thenReturn(nodeVal);
    when(record.<Value>asMap(anyObject())).thenReturn(recordMap);
    when(record.values()).thenReturn(asList(relVal, nodeVal));
    // when
    String actual = verbosePrinter.format(new ListBoltResult(asList(record), mock(ResultSummary.class)));
    // then
    assertThat(actual, containsString("| [:`RELATIONSHIP,TYPE` {prop2: 1, prop1: \"prop1, value\"}] |"));
    assertThat(actual, containsString("| (:`label ``1`:label2 {`1prop1`: \"\\\"\\\"\", " + "prop1: \"prop1:value\", ä: \"not-escaped\"}) |"));
}
Also used : NodeValue(org.neo4j.driver.internal.value.NodeValue) 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) InternalNode(org.neo4j.driver.internal.InternalNode) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 9 with ListBoltResult

use of org.neo4j.shell.state.ListBoltResult in project neo4j by neo4j.

the class PrettyPrinterTest method returnStatisticsForEmptyRecords.

@Test
public void returnStatisticsForEmptyRecords() {
    // given
    ResultSummary resultSummary = mock(ResultSummary.class);
    SummaryCounters summaryCounters = mock(SummaryCounters.class);
    BoltResult result = new ListBoltResult(Collections.emptyList(), resultSummary);
    when(resultSummary.counters()).thenReturn(summaryCounters);
    when(summaryCounters.labelsAdded()).thenReturn(1);
    when(summaryCounters.nodesCreated()).thenReturn(10);
    // when
    String actual = verbosePrinter.format(result);
    // then
    assertThat(actual, containsString("Added 10 nodes, Added 1 labels"));
}
Also used : ListBoltResult(org.neo4j.shell.state.ListBoltResult) ResultSummary(org.neo4j.driver.summary.ResultSummary) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) SummaryCounters(org.neo4j.driver.summary.SummaryCounters) BoltResult(org.neo4j.shell.state.BoltResult) ListBoltResult(org.neo4j.shell.state.ListBoltResult) Test(org.junit.Test)

Example 10 with ListBoltResult

use of org.neo4j.shell.state.ListBoltResult in project neo4j by neo4j.

the class PrettyPrinterTest method printRelationshipsAndNodesWithEscapingForSpecialCharacters.

@Test
public void printRelationshipsAndNodesWithEscapingForSpecialCharacters() {
    // given
    Record record = mock(Record.class);
    Value relVal = mock(Value.class);
    Value nodeVal = mock(Value.class);
    Relationship relationship = mock(Relationship.class);
    HashMap<String, Object> relProp = new HashMap<>();
    relProp.put("prop1", "\"prop1, value\"");
    relProp.put("prop2", "prop2_value");
    Node node = mock(Node.class);
    HashMap<String, Object> nodeProp = new HashMap<>();
    nodeProp.put("prop1", "\"prop1:value\"");
    nodeProp.put("1prop2", "\"\"");
    nodeProp.put("ä", "not-escaped");
    when(relVal.type()).thenReturn(InternalTypeSystem.TYPE_SYSTEM.RELATIONSHIP());
    when(nodeVal.type()).thenReturn(InternalTypeSystem.TYPE_SYSTEM.NODE());
    when(relVal.asRelationship()).thenReturn(relationship);
    when(relationship.type()).thenReturn("RELATIONSHIP,TYPE");
    when(relationship.asMap(anyObject())).thenReturn(unmodifiableMap(relProp));
    when(nodeVal.asNode()).thenReturn(node);
    when(node.labels()).thenReturn(asList("label `1", "label2"));
    when(node.asMap(anyObject())).thenReturn(unmodifiableMap(nodeProp));
    when(record.keys()).thenReturn(asList("rel", "node"));
    when(record.values()).thenReturn(asList(relVal, nodeVal));
    BoltResult result = new ListBoltResult(asList(record), mock(ResultSummary.class));
    // when
    String actual = plainPrinter.format(result);
    // then
    assertThat(actual, is("rel, node" + NEWLINE + "[:`RELATIONSHIP,TYPE` {prop2: prop2_value, prop1: \"prop1, value\"}], " + "(:`label ``1`:label2 {prop1: \"prop1:value\", `1prop2`: \"\", ä: not-escaped})" + NEWLINE));
}
Also used : ListBoltResult(org.neo4j.shell.state.ListBoltResult) HashMap(java.util.HashMap) Relationship(org.neo4j.driver.types.Relationship) Node(org.neo4j.driver.types.Node) 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)

Aggregations

ListBoltResult (org.neo4j.shell.state.ListBoltResult)26 Test (org.junit.Test)24 Value (org.neo4j.driver.Value)20 BoltResult (org.neo4j.shell.state.BoltResult)18 Record (org.neo4j.driver.Record)16 ResultSummary (org.neo4j.driver.summary.ResultSummary)14 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)12 StringContains.containsString (org.hamcrest.core.StringContains.containsString)12 DurationValue (org.neo4j.driver.internal.value.DurationValue)8 NodeValue (org.neo4j.driver.internal.value.NodeValue)8 PathValue (org.neo4j.driver.internal.value.PathValue)8 PointValue (org.neo4j.driver.internal.value.PointValue)8 RelationshipValue (org.neo4j.driver.internal.value.RelationshipValue)8 HashMap (java.util.HashMap)7 InternalRecord (org.neo4j.driver.internal.InternalRecord)7 Node (org.neo4j.driver.types.Node)6 Relationship (org.neo4j.driver.types.Relationship)6 Matchers.anyObject (org.mockito.Matchers.anyObject)4 Result (org.neo4j.driver.Result)4 ProfiledPlan (org.neo4j.driver.summary.ProfiledPlan)4