use of org.neo4j.driver.Record in project neo4j by neo4j.
the class BoltStateHandlerTest method shouldRunCypherQuery.
@Test
public void shouldRunCypherQuery() throws CommandException {
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))).thenReturn(resultMock);
OfflineBoltStateHandler boltStateHandler = new OfflineBoltStateHandler(driverMock);
boltStateHandler.connect();
BoltResult boltResult = boltStateHandler.runCypher("RETURN 999", new HashMap<>()).get();
verify(sessionMock).run(any(Query.class));
assertEquals("999", boltResult.getRecords().get(0).get(0).toString());
}
use of org.neo4j.driver.Record in project neo4j by neo4j.
the class CypherShellTest method setParamShouldAddParam.
@Test
public void setParamShouldAddParam() throws ParameterException, CommandException {
Value value = mock(Value.class);
Record recordMock = mock(Record.class);
BoltResult boltResult = mock(ListBoltResult.class);
when(mockedBoltStateHandler.runCypher(anyString(), anyMap())).thenReturn(Optional.of(boltResult));
when(boltResult.getRecords()).thenReturn(asList(recordMock));
when(recordMock.get("bob")).thenReturn(value);
when(value.asObject()).thenReturn("99");
assertTrue(offlineTestShell.getParameterMap().allParameterValues().isEmpty());
Object result = offlineTestShell.getParameterMap().setParameter("`bob`", "99");
assertEquals(99L, result);
assertEquals(99L, offlineTestShell.getParameterMap().allParameterValues().get("bob"));
}
use of org.neo4j.driver.Record in project neo4j by neo4j.
the class TableOutputFormatter method formatResultAndCountRows.
private int formatResultAndCountRows(String[] columns, Iterator<Record> records, LinePrinter output) {
List<Record> topRecords = take(records, numSampleRows);
int[] columnSizes = calculateColumnSizes(columns, topRecords, records.hasNext());
int totalWidth = 1;
for (int columnSize : columnSizes) {
totalWidth += columnSize + 3;
}
StringBuilder builder = new StringBuilder(totalWidth);
String headerLine = formatRow(builder, columnSizes, columns, new boolean[columnSizes.length]);
int lineWidth = totalWidth - 2;
String dashes = "+" + OutputFormatter.repeat('-', lineWidth) + "+";
output.printOut(dashes);
output.printOut(headerLine);
output.printOut(dashes);
int numberOfRows = 0;
for (Record record : topRecords) {
output.printOut(formatRecord(builder, columnSizes, record));
numberOfRows++;
}
while (records.hasNext()) {
output.printOut(formatRecord(builder, columnSizes, records.next()));
numberOfRows++;
}
output.printOut(String.format("%s%n", dashes));
return numberOfRows;
}
use of org.neo4j.driver.Record in project neo4j by neo4j.
the class TableOutputFormatter method formatInfo.
@Override
@Nonnull
public String formatInfo(@Nonnull ResultSummary summary) {
Map<String, Value> info = OutputFormatter.info(summary);
if (info.isEmpty()) {
return "";
}
String[] columns = info.keySet().toArray(new String[0]);
StringBuilder sb = new StringBuilder();
Record record = new InternalRecord(asList(columns), info.values().toArray(new Value[0]));
formatResultAndCountRows(columns, Collections.singletonList(record).iterator(), line -> sb.append(line).append(OutputFormatter.NEWLINE));
return sb.toString();
}
use of org.neo4j.driver.Record in project neo4j by neo4j.
the class PrettyPrinterTest method prettyPrintSingleNodePath.
@Test
public void prettyPrintSingleNodePath() {
// given
Record record = mock(Record.class);
Value value = mock(Value.class);
Node start = mock(Node.class);
when(start.labels()).thenReturn(asList("start"));
when(start.id()).thenReturn(1L);
Node end = mock(Node.class);
when(end.labels()).thenReturn(asList("end"));
when(end.id()).thenReturn(2L);
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);
Path.Segment segment1 = mock(Path.Segment.class);
when(segment1.start()).thenReturn(start);
when(segment1.end()).thenReturn(end);
when(segment1.relationship()).thenReturn(relationship);
when(value.type()).thenReturn(InternalTypeSystem.TYPE_SYSTEM.PATH());
when(value.asPath()).thenReturn(path);
when(path.iterator()).thenReturn(asList(segment1).iterator());
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)-[:RELATIONSHIP_TYPE]->(:end)" + NEWLINE));
}
Aggregations