@Test public void testSwitchToNonExistingDatabase() throws Exception { String input = ":use foo;\n"; TestInteractiveShellRunner sr = setupInteractiveTestShellRunner(input); when(sr.mockedBoltStateHandler.getActualDatabaseAsReportedByServer()).thenReturn("mydb"); doThrow(new ClientException("Non existing")).when(sr.mockedBoltStateHandler).setActiveDatabase("foo"); sr.runner.runUntilEnd(); assertThat(sr.output.toString(), containsString("myusername@mydb> ")); assertThat(sr.error.toString(), containsString("Non existing")); }
@Override public int runUntilEnd() { int exitCode = Main.EXIT_SUCCESS; boolean running = true; logger.printIfVerbose(userMessagesHandler.getWelcomeMessage()); while (running) { try { for (String statement : readUntilStatement()) { currentlyExecuting.set(true); executer.execute(statement); currentlyExecuting.set(false); } } catch (ExitException e) { exitCode = e.getCode(); running = false; } catch (NoMoreInputException e) { running = false; } catch (Throwable e) { logger.printError(e); } finally { currentlyExecuting.set(false); } } logger.printIfVerbose(userMessagesHandler.getExitMessage()); return exitCode; }
InteractiveShellRunner implements ShellRunner, SignalHandler { @Override public int runUntilEnd() { int exitCode = Main.EXIT_SUCCESS; boolean running = true; logger.printIfVerbose(userMessagesHandler.getWelcomeMessage()); while (running) { try { for (String statement : readUntilStatement()) { currentlyExecuting.set(true); executer.execute(statement); currentlyExecuting.set(false); } } catch (ExitException e) { exitCode = e.getCode(); running = false; } catch (NoMoreInputException e) { running = false; } catch (Throwable e) { logger.printError(e); } finally { currentlyExecuting.set(false); } } logger.printIfVerbose(userMessagesHandler.getExitMessage()); return exitCode; } }
InteractiveShellRunner implements ShellRunner, SignalHandler { @Override public int runUntilEnd() { int exitCode = Main.EXIT_SUCCESS; boolean running = true; logger.printIfVerbose(userMessagesHandler.getWelcomeMessage()); while (running) { try { for (String statement : readUntilStatement()) { currentlyExecuting.set(true); executer.execute(statement); currentlyExecuting.set(false); } } catch (ExitException e) { exitCode = e.getCode(); running = false; } catch (NoMoreInputException e) { running = false; } catch (Throwable e) { logger.printError(e); } finally { currentlyExecuting.set(false); } } logger.printIfVerbose(userMessagesHandler.getExitMessage()); return exitCode; } InteractiveShellRunner(@Nonnull StatementExecuter executer,
                                  @Nonnull TransactionHandler txHandler,
                                  @Nonnull DatabaseManager databaseManager,
                                  @Nonnull Logger logger,
                                  @Nonnull StatementParser statementParser,
                                  @Nonnull InputStream inputStream,
                                  @Nonnull File historyFile,
                                  @Nonnull UserMessagesHandler userMessagesHandler,
                                  @Nonnull ConnectionConfig connectionConfig); }
InteractiveShellRunner implements ShellRunner, SignalHandler { @Override public int runUntilEnd() { int exitCode = Main.EXIT_SUCCESS; boolean running = true; logger.printIfVerbose(userMessagesHandler.getWelcomeMessage()); while (running) { try { for (String statement : readUntilStatement()) { currentlyExecuting.set(true); executer.execute(statement); currentlyExecuting.set(false); } } catch (ExitException e) { exitCode = e.getCode(); running = false; } catch (NoMoreInputException e) { running = false; } catch (Throwable e) { logger.printError(e); } finally { currentlyExecuting.set(false); } } logger.printIfVerbose(userMessagesHandler.getExitMessage()); return exitCode; } InteractiveShellRunner(@Nonnull StatementExecuter executer,
                                  @Nonnull TransactionHandler txHandler,
                                  @Nonnull DatabaseManager databaseManager,
                                  @Nonnull Logger logger,
                                  @Nonnull StatementParser statementParser,
                                  @Nonnull InputStream inputStream,
                                  @Nonnull File historyFile,
                                  @Nonnull UserMessagesHandler userMessagesHandler,
                                  @Nonnull ConnectionConfig connectionConfig); @Override int runUntilEnd(); @Nonnull @Override Historian getHistorian(); @Nonnull List<String> readUntilStatement(); @Override void handle(final Signal signal); }
InteractiveShellRunner implements ShellRunner, SignalHandler { @Override public int runUntilEnd() { int exitCode = Main.EXIT_SUCCESS; boolean running = true; logger.printIfVerbose(userMessagesHandler.getWelcomeMessage()); while (running) { try { for (String statement : readUntilStatement()) { currentlyExecuting.set(true); executer.execute(statement); currentlyExecuting.set(false); } } catch (ExitException e) { exitCode = e.getCode(); running = false; } catch (NoMoreInputException e) { running = false; } catch (Throwable e) { logger.printError(e); } finally { currentlyExecuting.set(false); } } logger.printIfVerbose(userMessagesHandler.getExitMessage()); return exitCode; } InteractiveShellRunner(@Nonnull StatementExecuter executer,
                                  @Nonnull TransactionHandler txHandler,
                                  @Nonnull DatabaseManager databaseManager,
                                  @Nonnull Logger logger,
                                  @Nonnull StatementParser statementParser,
                                  @Nonnull InputStream inputStream,
                                  @Nonnull File historyFile,
                                  @Nonnull UserMessagesHandler userMessagesHandler,
                                  @Nonnull ConnectionConfig connectionConfig); @Override int runUntilEnd(); @Nonnull @Override Historian getHistorian(); @Nonnull List<String> readUntilStatement(); @Override void handle(final Signal signal);  }