use of org.neo4j.driver.Value 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\"}) |"));
}
use of org.neo4j.driver.Value in project neo4j by neo4j.
the class TablePlanFormatterTest method withEmptyDetails.
@Test
public void withEmptyDetails() {
Plan plan = mock(Plan.class);
Map<String, Value> args = new HashMap<String, Value>(2) {
{
put("EstimatedRows", new FloatValue(55));
put("Details", new StringValue(""));
}
};
when(plan.arguments()).thenReturn(args);
when(plan.operatorType()).thenReturn("Projection");
assertThat(tablePlanFormatter.formatPlan(plan), is(String.join(NEWLINE, "+-------------+---------+----------------+", "| Operator | Details | Estimated Rows |", "+-------------+---------+----------------+", "| +Projection | | 55 |", "+-------------+---------+----------------+", "")));
}
use of org.neo4j.driver.Value in project neo4j by neo4j.
the class TablePlanFormatterTest method renderShortDetails.
@Test
public void renderShortDetails() {
Plan plan = mock(Plan.class);
Map<String, Value> args = Collections.singletonMap("Details", new StringValue("x.prop AS prop"));
when(plan.arguments()).thenReturn(args);
when(plan.operatorType()).thenReturn("Projection");
assertThat(tablePlanFormatter.formatPlan(plan), is(String.join(NEWLINE, "+-------------+----------------+", "| Operator | Details |", "+-------------+----------------+", "| +Projection | x.prop AS prop |", "+-------------+----------------+", "")));
}
use of org.neo4j.driver.Value in project neo4j by neo4j.
the class TablePlanFormatterTest method renderExactMaxLengthDetails.
@Test
public void renderExactMaxLengthDetails() {
Plan plan = mock(Plan.class);
String details = stringOfLength(TablePlanFormatter.MAX_DETAILS_COLUMN_WIDTH);
Map<String, Value> args = Collections.singletonMap("Details", new StringValue(details));
when(plan.arguments()).thenReturn(args);
when(plan.operatorType()).thenReturn("Projection");
assertThat(tablePlanFormatter.formatPlan(plan), containsString("| +Projection | " + details + " |"));
}
use of org.neo4j.driver.Value in project neo4j by neo4j.
the class BoltStateHandlerTest method triesAgainOnSessionExpired.
@Test
public void triesAgainOnSessionExpired() throws Exception {
Session sessionMock = mock(Session.class);
Result resultMock = mock(Result.class);
Record recordMock = mock(Record.class);
Value valueMock = mock(Value.class);
Driver driverMock = stubResultSummaryInAnOpenSession(resultMock, sessionMock, "neo4j-version");
when(resultMock.list()).thenReturn(singletonList(recordMock));
when(valueMock.toString()).thenReturn("999");
when(recordMock.get(0)).thenReturn(valueMock);
when(sessionMock.run(any(Query.class))).thenThrow(new SessionExpiredException("leaderswitch")).thenReturn(resultMock);
OfflineBoltStateHandler boltStateHandler = new OfflineBoltStateHandler(driverMock);
boltStateHandler.connect();
BoltResult boltResult = boltStateHandler.runCypher("RETURN 999", new HashMap<>()).get();
verify(driverMock, times(2)).session(any());
verify(sessionMock, times(2)).run(any(Query.class));
assertEquals("999", boltResult.getRecords().get(0).get(0).toString());
}
Aggregations