Search in sources :

Example 16 with ListBoltResult

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

the class PrettyPrinterTest method prettyPrintProfileInformationIfGlobalMemoryIsMissing.

@Test
public void prettyPrintProfileInformationIfGlobalMemoryIsMissing() {
    // given
    ResultSummary resultSummary = mock(ResultSummary.class);
    ProfiledPlan plan = mock(ProfiledPlan.class);
    when(plan.dbHits()).thenReturn(1000L);
    when(plan.records()).thenReturn(20L);
    when(resultSummary.hasPlan()).thenReturn(true);
    when(resultSummary.hasProfile()).thenReturn(true);
    when(resultSummary.plan()).thenReturn(plan);
    when(resultSummary.profile()).thenReturn(plan);
    when(resultSummary.resultAvailableAfter(anyObject())).thenReturn(5L);
    when(resultSummary.resultConsumedAfter(anyObject())).thenReturn(7L);
    when(resultSummary.queryType()).thenReturn(QueryType.READ_ONLY);
    Map<String, Value> argumentMap = Values.parameters("Version", "3.1", "Planner", "COST", "Runtime", "INTERPRETED").asMap(v -> v);
    when(plan.arguments()).thenReturn(argumentMap);
    BoltResult result = new ListBoltResult(Collections.emptyList(), resultSummary);
    // when
    String actual = plainPrinter.format(result);
    // then
    String expected = "Plan: \"PROFILE\"\n" + "Statement: \"READ_ONLY\"\n" + "Version: \"3.1\"\n" + "Planner: \"COST\"\n" + "Runtime: \"INTERPRETED\"\n" + "Time: 12\n" + "Rows: 20\n" + "DbHits: 1000\n" + "Memory (Bytes): \"?\"";
    Stream.of(expected.split("\n")).forEach(e -> assertThat(actual, containsString(e)));
}
Also used : ProfiledPlan(org.neo4j.driver.summary.ProfiledPlan) ListBoltResult(org.neo4j.shell.state.ListBoltResult) ResultSummary(org.neo4j.driver.summary.ResultSummary) Value(org.neo4j.driver.Value) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) BoltResult(org.neo4j.shell.state.BoltResult) ListBoltResult(org.neo4j.shell.state.ListBoltResult) Test(org.junit.Test)

Example 17 with ListBoltResult

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

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

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

the class PrettyPrinterTest method prettyPrintProfileInformation.

@Test
public void prettyPrintProfileInformation() {
    // given
    ResultSummary resultSummary = mock(ResultSummary.class);
    ProfiledPlan plan = mock(ProfiledPlan.class);
    when(plan.dbHits()).thenReturn(1000L);
    when(plan.records()).thenReturn(20L);
    when(resultSummary.hasPlan()).thenReturn(true);
    when(resultSummary.hasProfile()).thenReturn(true);
    when(resultSummary.plan()).thenReturn(plan);
    when(resultSummary.profile()).thenReturn(plan);
    when(resultSummary.resultAvailableAfter(anyObject())).thenReturn(5L);
    when(resultSummary.resultConsumedAfter(anyObject())).thenReturn(7L);
    when(resultSummary.queryType()).thenReturn(QueryType.READ_ONLY);
    Map<String, Value> argumentMap = Values.parameters("Version", "3.1", "Planner", "COST", "Runtime", "INTERPRETED", "GlobalMemory", 10).asMap(v -> v);
    when(plan.arguments()).thenReturn(argumentMap);
    BoltResult result = new ListBoltResult(Collections.emptyList(), resultSummary);
    // when
    String actual = plainPrinter.format(result);
    // then
    String expected = "Plan: \"PROFILE\"\n" + "Statement: \"READ_ONLY\"\n" + "Version: \"3.1\"\n" + "Planner: \"COST\"\n" + "Runtime: \"INTERPRETED\"\n" + "Time: 12\n" + "Rows: 20\n" + "DbHits: 1000\n" + "Memory (Bytes): 10";
    Stream.of(expected.split("\n")).forEach(e -> assertThat(actual, containsString(e)));
}
Also used : ProfiledPlan(org.neo4j.driver.summary.ProfiledPlan) ListBoltResult(org.neo4j.shell.state.ListBoltResult) ResultSummary(org.neo4j.driver.summary.ResultSummary) Value(org.neo4j.driver.Value) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) BoltResult(org.neo4j.shell.state.BoltResult) ListBoltResult(org.neo4j.shell.state.ListBoltResult) Test(org.junit.Test)

Example 20 with ListBoltResult

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

the class TableOutputFormatterTest method truncateContent.

@Test
public void truncateContent() {
    // GIVEN
    Result result = mockResult(asList("c1"), "a", "bb", "ccc", "dddd", "eeeee");
    // WHEN
    ToStringLinePrinter printer = new ToStringLinePrinter();
    new TableOutputFormatter(false, 2).formatAndCount(new ListBoltResult(result.list(), result.consume()), printer);
    String table = printer.result();
    // THEN
    assertThat(table, is(String.join(NEWLINE, "+------+", "| c1   |", "+------+", "| \"a\"  |", "| \"bb\" |", "| \"cc… |", "| \"dd… |", "| \"ee… |", "+------+", NEWLINE)));
}
Also used : ListBoltResult(org.neo4j.shell.state.ListBoltResult) StringContains.containsString(org.hamcrest.core.StringContains.containsString) BoltResult(org.neo4j.shell.state.BoltResult) ListBoltResult(org.neo4j.shell.state.ListBoltResult) Result(org.neo4j.driver.Result) 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