Search in sources :

Example 1 with Logger

use of org.neo4j.shell.log.Logger in project neo4j by neo4j.

the class InteractiveShellRunnerTest method setupInteractiveTestShellRunner.

private TestInteractiveShellRunner setupInteractiveTestShellRunner(String input) throws Exception {
    // NOTE: Tests using this will test a bit more of the stack using OfflineTestShell
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    ByteArrayOutputStream error = new ByteArrayOutputStream();
    BoltStateHandler mockedBoltStateHandler = mock(BoltStateHandler.class);
    when(mockedBoltStateHandler.getProtocolVersion()).thenReturn("");
    final PrettyPrinter mockedPrettyPrinter = mock(PrettyPrinter.class);
    Logger logger = new AnsiLogger(false, Format.VERBOSE, new PrintStream(output), new PrintStream(error));
    OfflineTestShell offlineTestShell = new OfflineTestShell(logger, mockedBoltStateHandler, mockedPrettyPrinter);
    CommandHelper commandHelper = new CommandHelper(logger, Historian.empty, offlineTestShell);
    offlineTestShell.setCommandHelper(commandHelper);
    InputStream inputStream = new ByteArrayInputStream(input.getBytes());
    InteractiveShellRunner runner = new InteractiveShellRunner(offlineTestShell, offlineTestShell, offlineTestShell, logger, new ShellStatementParser(), inputStream, historyFile, userMessagesHandler, connectionConfig);
    return new TestInteractiveShellRunner(runner, output, error, mockedBoltStateHandler);
}
Also used : PrintStream(java.io.PrintStream) ShellStatementParser(org.neo4j.shell.parser.ShellStatementParser) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OfflineTestShell(org.neo4j.shell.OfflineTestShell) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Logger(org.neo4j.shell.log.Logger) AnsiLogger(org.neo4j.shell.log.AnsiLogger) AnsiLogger(org.neo4j.shell.log.AnsiLogger) CommandHelper(org.neo4j.shell.commands.CommandHelper) PrettyPrinter(org.neo4j.shell.prettyprint.PrettyPrinter) ByteArrayInputStream(java.io.ByteArrayInputStream) BoltStateHandler(org.neo4j.shell.state.BoltStateHandler)

Example 2 with Logger

use of org.neo4j.shell.log.Logger in project neo4j by neo4j.

the class Main method startShell.

void startShell(@Nonnull CliArgs cliArgs) {
    if (cliArgs.getVersion()) {
        out.println("Cypher-Shell " + Build.version());
    }
    if (cliArgs.getDriverVersion()) {
        out.println("Neo4j Driver " + Build.driverVersion());
    }
    if (cliArgs.getVersion() || cliArgs.getDriverVersion()) {
        return;
    }
    Logger logger = new AnsiLogger(cliArgs.getDebugMode());
    PrettyConfig prettyConfig = new PrettyConfig(cliArgs);
    CypherShell shell = new CypherShell(logger, prettyConfig, ShellRunner.shouldBeInteractive(cliArgs), cliArgs.getParameters());
    int exitCode = runShell(cliArgs, shell, logger);
    System.exit(exitCode);
}
Also used : Logger(org.neo4j.shell.log.Logger) AnsiLogger(org.neo4j.shell.log.AnsiLogger) AnsiLogger(org.neo4j.shell.log.AnsiLogger) PrettyConfig(org.neo4j.shell.prettyprint.PrettyConfig)

Example 3 with Logger

use of org.neo4j.shell.log.Logger 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();
}
Also used : ShellStatementParser(org.neo4j.shell.parser.ShellStatementParser) StatementExecuter(org.neo4j.shell.StatementExecuter) DatabaseManager(org.neo4j.shell.DatabaseManager) TransactionHandler(org.neo4j.shell.TransactionHandler) ClientException(org.neo4j.driver.exceptions.ClientException) Logger(org.neo4j.shell.log.Logger) AnsiLogger(org.neo4j.shell.log.AnsiLogger) ConnectionConfig(org.neo4j.shell.ConnectionConfig) UserMessagesHandler(org.neo4j.shell.UserMessagesHandler) Before(org.junit.Before)

Example 4 with Logger

use of org.neo4j.shell.log.Logger in project neo4j by neo4j.

the class ParamsTest method setup.

@Before
public void setup() throws CommandException {
    vars = new HashMap<>();
    logger = mock(Logger.class);
    ParameterMap shell = mock(ParameterMap.class);
    when(shell.getAllAsUserInput()).thenReturn(vars);
    cmd = new Params(logger, shell);
}
Also used : ParameterMap(org.neo4j.shell.ParameterMap) Logger(org.neo4j.shell.log.Logger) Before(org.junit.Before)

Example 5 with Logger

use of org.neo4j.shell.log.Logger in project neo4j by neo4j.

the class MainIntegrationTest method shouldHandleInvalidCypherFromFile.

@Test
public void shouldHandleInvalidCypherFromFile() {
    // given
    Logger logger = mock(Logger.class);
    // when
    String actual = executeFileNonInteractively(fileFromResource("invalid.cypher"), logger);
    // then we print the first valid row
    assertEquals(format("result%n42%n"), actual);
    // and print errors to the error log
    verify(logger).printError(any(ClientException.class));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ClientException(org.neo4j.driver.exceptions.ClientException) Logger(org.neo4j.shell.log.Logger) AnsiLogger(org.neo4j.shell.log.AnsiLogger) Test(org.junit.Test)

Aggregations

Logger (org.neo4j.shell.log.Logger)6 AnsiLogger (org.neo4j.shell.log.AnsiLogger)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 PrintStream (java.io.PrintStream)2 Before (org.junit.Before)2 Test (org.junit.Test)2 ClientException (org.neo4j.driver.exceptions.ClientException)2 ShellStatementParser (org.neo4j.shell.parser.ShellStatementParser)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 ConnectionConfig (org.neo4j.shell.ConnectionConfig)1 DatabaseManager (org.neo4j.shell.DatabaseManager)1 OfflineTestShell (org.neo4j.shell.OfflineTestShell)1 ParameterMap (org.neo4j.shell.ParameterMap)1 StatementExecuter (org.neo4j.shell.StatementExecuter)1 TransactionHandler (org.neo4j.shell.TransactionHandler)1 UserMessagesHandler (org.neo4j.shell.UserMessagesHandler)1 CommandHelper (org.neo4j.shell.commands.CommandHelper)1 PrettyConfig (org.neo4j.shell.prettyprint.PrettyConfig)1