use of org.neo4j.driver.exceptions.ClientException in project neo4j by neo4j.
the class InteractiveShellRunnerTest method setup.
@Before
public void setup() throws Exception {
statementParser = new ShellStatementParser();
logger = mock(Logger.class);
cmdExecuter = mock(StatementExecuter.class);
txHandler = mock(TransactionHandler.class);
databaseManager = mock(DatabaseManager.class);
connectionConfig = mock(ConnectionConfig.class);
historyFile = temp.newFile();
badLineError = new ClientException("Found a bad line");
userMessagesHandler = mock(UserMessagesHandler.class);
when(databaseManager.getActualDatabaseAsReportedByServer()).thenReturn("mydb");
when(userMessagesHandler.getWelcomeMessage()).thenReturn("Welcome to cypher-shell!");
when(userMessagesHandler.getExitMessage()).thenReturn("Exit message");
when(connectionConfig.username()).thenReturn("myusername");
doThrow(badLineError).when(cmdExecuter).execute(contains("bad"));
doReturn(System.out).when(logger).getOutputStream();
}
use of org.neo4j.driver.exceptions.ClientException in project neo4j by neo4j.
the class BoltStateHandlerTest method handleErrorsOnRollback.
@Test
public void handleErrorsOnRollback() throws CommandException {
reset(mockDriver);
var mockSession = spy(FakeSession.class);
var mockTx = mock(Transaction.class);
doThrow(new ClientException("Failed to rollback :(")).when(mockTx).rollback();
when(mockSession.beginTransaction()).thenReturn(mockTx);
when(mockDriver.session(any())).thenReturn(mockSession);
boltStateHandler.connect();
boltStateHandler.beginTransaction();
assertThrows(ClientException.class, boltStateHandler::rollbackTransaction);
assertFalse(boltStateHandler.isTransactionOpen());
}
use of org.neo4j.driver.exceptions.ClientException in project neo4j by neo4j.
the class BoltStateHandlerTest method exceptionFromRunQueryDoesNotResetActualDatabaseNameToUnresolved.
@Test
public void exceptionFromRunQueryDoesNotResetActualDatabaseNameToUnresolved() throws CommandException {
Session sessionMock = mock(Session.class);
Result resultMock = mock(Result.class);
Driver driverMock = stubResultSummaryInAnOpenSession(resultMock, sessionMock, "9.4.1-ALPHA", "my_default_db");
ClientException databaseNotFound = new ClientException("Neo.ClientError.Database.DatabaseNotFound", "blah");
when(sessionMock.run(any(Query.class))).thenThrow(databaseNotFound).thenReturn(resultMock);
BoltStateHandler handler = new BoltStateHandler((s, authToken, config) -> driverMock, false);
handler.connect(config);
try {
handler.runCypher("RETURN \"hello\"", Collections.emptyMap());
fail("should fail on runCypher");
} catch (Exception e) {
assertThat(e, is(databaseNotFound));
assertEquals("my_default_db", handler.getActualDatabaseAsReportedByServer());
}
}
use of org.neo4j.driver.exceptions.ClientException in project neo4j by neo4j.
the class BoltStateHandler method getPing.
private ThrowingAction<CommandException> getPing() {
return () -> {
try {
Result run = session.run("CALL db.ping()");
ResultSummary summary = run.consume();
BoltStateHandler.this.protocolVersion = summary.server().protocolVersion();
updateActualDbName(summary);
} catch (ClientException e) {
// In older versions there is no db.ping procedure, use legacy method.
if (procedureNotFound(e)) {
Result run = session.run(isSystemDb() ? "CALL db.indexes()" : "RETURN 1");
ResultSummary summary = run.consume();
BoltStateHandler.this.protocolVersion = summary.server().protocolVersion();
updateActualDbName(summary);
} else {
throw e;
}
}
};
}
use of org.neo4j.driver.exceptions.ClientException in project neo4j by neo4j.
the class InteractiveShellRunnerTest method testSwitchToNonExistingDatabase.
@Test
public void testSwitchToNonExistingDatabase() throws Exception {
// given
String input = ":use foo;\n";
TestInteractiveShellRunner sr = setupInteractiveTestShellRunner(input);
// when
when(sr.mockedBoltStateHandler.getActualDatabaseAsReportedByServer()).thenReturn("mydb");
doThrow(new ClientException("Non existing")).when(sr.mockedBoltStateHandler).setActiveDatabase("foo");
sr.runner.runUntilEnd();
// then
assertThat(sr.output.toString(), containsString("myusername@mydb> "));
assertThat(sr.error.toString(), containsString("Non existing"));
}
Aggregations