use of org.neo4j.shell.state.BoltResult 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)));
}
use of org.neo4j.shell.state.BoltResult 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));
}
use of org.neo4j.shell.state.BoltResult 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));
}
use of org.neo4j.shell.state.BoltResult 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"));
}
use of org.neo4j.shell.state.BoltResult 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));
}
Aggregations