use of org.neo4j.driver.Result in project neo4j by neo4j.
the class TableOutputFormatterTest method wrapStringContentWithTwoColumns.
@Test
public void wrapStringContentWithTwoColumns() {
// GIVEN
Result result = mockResult(asList("c1", "c2"), "a", "b", "aa", "bb", "aaa", "b", "a", "bbb", "aaaa", "bb", "aa", "bbbb", "aaaaa", "bbbbb");
// WHEN
ToStringLinePrinter printer = new ToStringLinePrinter();
new TableOutputFormatter(true, 2).formatAndCount(new ListBoltResult(result.list(), result.consume()), printer);
String table = printer.result();
// THEN
assertThat(table, is(String.join(NEWLINE, "+-------------+", "| c1 | c2 |", "+-------------+", "| \"a\" | \"b\" |", "| \"aa\" | \"bb\" |", "| \"aaa | \"b\" |", "\\ \" | |", "| \"a\" | \"bbb |", "| \\ \" |", "| \"aaa | \"bb\" |", "\\ a\" | |", "| \"aa\" | \"bbb |", "| \\ b\" |", "| \"aaa | \"bbb |", "\\ aa\" \\ bb\" |", "+-------------+", NEWLINE)));
}
use of org.neo4j.driver.Result in project neo4j by neo4j.
the class TableOutputFormatterTest method mockResult.
private Result mockResult(List<String> cols, Object... data) {
Result result = mock(Result.class);
Query query = mock(Query.class);
ResultSummary summary = mock(ResultSummary.class);
when(summary.query()).thenReturn(query);
when(result.keys()).thenReturn(cols);
List<Record> records = new ArrayList<>();
List<Object> input = asList(data);
int width = cols.size();
for (int row = 0; row < input.size() / width; row++) {
records.add(record(cols, input.subList(row * width, (row + 1) * width)));
}
when(result.list()).thenReturn(records);
when(result.consume()).thenReturn(summary);
when(result.consume()).thenReturn(summary);
return result;
}
use of org.neo4j.driver.Result in project neo4j by neo4j.
the class BoltStateHandlerTest method exceptionsFromSilentDisconnectAreSuppressedToReportOriginalErrors.
@Test
public void exceptionsFromSilentDisconnectAreSuppressedToReportOriginalErrors() {
Session session = mock(Session.class);
Result resultMock = mock(Result.class);
RuntimeException originalException = new RuntimeException("original exception");
RuntimeException thrownFromSilentDisconnect = new RuntimeException("exception from silent disconnect");
Driver mockedDriver = stubResultSummaryInAnOpenSession(resultMock, session, "neo4j-version");
OfflineBoltStateHandler boltStateHandler = new OfflineBoltStateHandler(mockedDriver);
when(resultMock.consume()).thenThrow(originalException);
doThrow(thrownFromSilentDisconnect).when(session).close();
try {
boltStateHandler.connect();
fail("should fail on silent disconnect");
} catch (Exception e) {
assertThat(e.getSuppressed()[0], is(thrownFromSilentDisconnect));
assertThat(e, is(originalException));
}
}
use of org.neo4j.driver.Result in project neo4j by neo4j.
the class BoltStateHandlerTest method shouldChangePasswordAndKeepSystemDbBookmark.
@Test
public void shouldChangePasswordAndKeepSystemDbBookmark() throws CommandException {
// Given
ConnectionConfig config = new ConnectionConfig("bolt", "", -1, "", "", Encryption.DEFAULT, ABSENT_DB_NAME);
config.setNewPassword("newPW");
Bookmark bookmark = InternalBookmark.parse("myBookmark");
Session sessionMock = mock(Session.class);
Result resultMock = mock(Result.class);
Driver driverMock = stubResultSummaryInAnOpenSession(resultMock, sessionMock, "Neo4j/9.4.1-ALPHA", "my_default_db");
when(sessionMock.run("CALL dbms.security.changePassword($n)", Values.parameters("n", config.newPassword()))).thenReturn(resultMock);
when(sessionMock.lastBookmark()).thenReturn(bookmark);
BoltStateHandler handler = new OfflineBoltStateHandler(driverMock);
// When
handler.changePassword(config);
// Then
assertEquals("newPW", config.password());
assertNull(config.newPassword());
assertNull(handler.session);
// When connecting to system db again
handler.connect(new ConnectionConfig("bolt", "", -1, "", "", Encryption.DEFAULT, SYSTEM_DB_NAME));
// Then use bookmark for system DB
verify(driverMock).session(SessionConfig.builder().withDefaultAccessMode(AccessMode.WRITE).withDatabase(SYSTEM_DB_NAME).withBookmarks(bookmark).build());
}
use of org.neo4j.driver.Result in project neo4j by neo4j.
the class BoltStateHandlerTest method fallbackToLegacyPing.
@Test
public void fallbackToLegacyPing() throws CommandException {
// given
Session sessionMock = mock(Session.class);
Result failing = mock(Result.class);
Result other = mock(Result.class, RETURNS_DEEP_STUBS);
when(failing.consume()).thenThrow(new ClientException("Neo.ClientError.Procedure.ProcedureNotFound", "No procedure CALL db.ping(()"));
when(sessionMock.run("CALL db.ping()")).thenReturn(failing);
when(sessionMock.run("RETURN 1")).thenReturn(other);
Driver driverMock = mock(Driver.class);
when(driverMock.session(any())).thenReturn(sessionMock);
OfflineBoltStateHandler boltStateHandler = new OfflineBoltStateHandler(driverMock);
// when
boltStateHandler.connect();
// then
verify(sessionMock).run("RETURN 1");
}
Aggregations