Search in sources :

Example 1 with Value

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

the class PrettyPrinterTest method prettyPrintExplainInformation.

@Test
public void prettyPrintExplainInformation() {
    // 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(false);
    when(resultSummary.plan()).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: \"EXPLAIN\"\n" + "Statement: \"READ_ONLY\"\n" + "Version: \"3.1\"\n" + "Planner: \"COST\"\n" + "Runtime: \"INTERPRETED\"\n" + "Time: 12";
    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 2 with Value

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

the class PrettyPrinterTest method prettyPrintNode.

@Test
public void prettyPrintNode() {
    // given
    Record record = mock(Record.class);
    Value value = mock(Value.class);
    Node node = mock(Node.class);
    HashMap<String, Object> propertiesAsMap = new HashMap<>();
    propertiesAsMap.put("prop1", "prop1_value");
    propertiesAsMap.put("prop2", "prop2_value");
    when(value.type()).thenReturn(InternalTypeSystem.TYPE_SYSTEM.NODE());
    when(value.asNode()).thenReturn(node);
    when(node.labels()).thenReturn(asList("label1", "label2"));
    when(node.asMap(anyObject())).thenReturn(unmodifiableMap(propertiesAsMap));
    when(record.keys()).thenReturn(asList("col1", "col2"));
    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("col1, col2" + NEWLINE + "(:label1:label2 {prop2: prop2_value, prop1: prop1_value})" + NEWLINE));
}
Also used : ListBoltResult(org.neo4j.shell.state.ListBoltResult) HashMap(java.util.HashMap) 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)

Example 3 with Value

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

the class TableOutputFormatterTest method prettyPrintPlanInformation.

@Test
public void prettyPrintPlanInformation() throws IOException {
    // given
    ResultSummary resultSummary = mock(ResultSummary.class);
    Map<String, Value> argumentMap = Values.parameters("Version", "3.1", "Planner", "COST", "Runtime", "INTERPRETED", "GlobalMemory", 10, "DbHits", 2, "Rows", 3, "EstimatedRows", 10, "Time", 15, "Order", "a", "PageCacheHits", 22, "PageCacheMisses", 2, "Memory", 5).asMap(v -> v);
    ProfiledPlan plan = mock(ProfiledPlan.class);
    when(plan.dbHits()).thenReturn(1000L);
    when(plan.records()).thenReturn(20L);
    when(plan.arguments()).thenReturn(argumentMap);
    when(plan.operatorType()).thenReturn("MyOp");
    when(plan.identifiers()).thenReturn(Arrays.asList("a", "b"));
    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);
    when(plan.arguments()).thenReturn(argumentMap);
    BoltResult result = new ListBoltResult(Collections.emptyList(), resultSummary);
    // when
    String actual = verbosePrinter.format(result);
    // then
    String expected = IOUtils.toString(getClass().getResource("/org/neo4j/shell/prettyprint/expected-pretty-print-plan-information.txt"), UTF_8).replace("\n", NEWLINE);
    assertThat(actual, startsWith(expected));
}
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) 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) StringContains.containsString(org.hamcrest.core.StringContains.containsString) BoltResult(org.neo4j.shell.state.BoltResult) ListBoltResult(org.neo4j.shell.state.ListBoltResult) Test(org.junit.Test)

Example 4 with Value

use of org.neo4j.driver.Value 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 5 with Value

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

Aggregations

Value (org.neo4j.driver.Value)37 Test (org.junit.Test)29 ListBoltResult (org.neo4j.shell.state.ListBoltResult)22 Record (org.neo4j.driver.Record)21 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)16 BoltResult (org.neo4j.shell.state.BoltResult)15 ResultSummary (org.neo4j.driver.summary.ResultSummary)14 HashMap (java.util.HashMap)12 StringContains.containsString (org.hamcrest.core.StringContains.containsString)9 DurationValue (org.neo4j.driver.internal.value.DurationValue)9 NodeValue (org.neo4j.driver.internal.value.NodeValue)9 PathValue (org.neo4j.driver.internal.value.PathValue)9 PointValue (org.neo4j.driver.internal.value.PointValue)9 RelationshipValue (org.neo4j.driver.internal.value.RelationshipValue)9 InternalRecord (org.neo4j.driver.internal.InternalRecord)8 Plan (org.neo4j.driver.summary.Plan)7 Node (org.neo4j.driver.types.Node)7 Relationship (org.neo4j.driver.types.Relationship)7 ProfiledPlan (org.neo4j.driver.summary.ProfiledPlan)6 FloatValue (org.neo4j.driver.internal.value.FloatValue)5