Search in sources :

Example 1 with AnsiLogger

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

the class CommandHelperTest method shouldIgnoreCaseForCommands.

@Test
public void shouldIgnoreCaseForCommands() {
    // Given
    AnsiLogger logger = new AnsiLogger(false);
    CommandHelper commandHelper = new CommandHelper(logger, Historian.empty, new CypherShell(logger, PrettyConfig.DEFAULT, false, new ShellParameterMap()));
    // When
    Command begin = commandHelper.getCommand(":BEGIN");
    // Then
    assertTrue(begin instanceof Begin);
}
Also used : ShellParameterMap(org.neo4j.shell.ShellParameterMap) Command(org.neo4j.shell.commands.Command) Begin(org.neo4j.shell.commands.Begin) CypherShell(org.neo4j.shell.CypherShell) AnsiLogger(org.neo4j.shell.log.AnsiLogger) CommandHelper(org.neo4j.shell.commands.CommandHelper) Test(org.junit.Test)

Example 2 with AnsiLogger

use of org.neo4j.shell.log.AnsiLogger 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 3 with AnsiLogger

use of org.neo4j.shell.log.AnsiLogger 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 4 with AnsiLogger

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

the class MainIntegrationTest method expectDatabaseUnavailable.

private void expectDatabaseUnavailable(Throwable e, String dbName) {
    String msg = new AnsiLogger(false).getFormattedMessage(e);
    assertThat(msg, anyOf(containsString("Database '" + dbName + "' is unavailable"), containsString("Database '" + dbName + "' unavailable"), containsString("Unable to get a routing table for database '" + dbName + "' because this database is unavailable")));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) AnsiLogger(org.neo4j.shell.log.AnsiLogger)

Example 5 with AnsiLogger

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

the class MainIntegrationTest method shouldFailIfInputFileDoesntExist.

@Test
public void shouldFailIfInputFileDoesntExist() {
    // given
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Logger logger = new AnsiLogger(false, Format.VERBOSE, new PrintStream(out), new PrintStream(out));
    // when
    executeFileNonInteractively("what.cypher", logger);
    // then
    assertThat(out.toString(), containsString(format("what.cypher (No such file or directory)%n")));
}
Also used : PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Logger(org.neo4j.shell.log.Logger) AnsiLogger(org.neo4j.shell.log.AnsiLogger) AnsiLogger(org.neo4j.shell.log.AnsiLogger) Test(org.junit.Test)

Aggregations

AnsiLogger (org.neo4j.shell.log.AnsiLogger)5 Logger (org.neo4j.shell.log.Logger)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 PrintStream (java.io.PrintStream)2 Test (org.junit.Test)2 CommandHelper (org.neo4j.shell.commands.CommandHelper)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 CypherShell (org.neo4j.shell.CypherShell)1 OfflineTestShell (org.neo4j.shell.OfflineTestShell)1 ShellParameterMap (org.neo4j.shell.ShellParameterMap)1 Begin (org.neo4j.shell.commands.Begin)1 Command (org.neo4j.shell.commands.Command)1 ShellStatementParser (org.neo4j.shell.parser.ShellStatementParser)1 PrettyConfig (org.neo4j.shell.prettyprint.PrettyConfig)1 PrettyPrinter (org.neo4j.shell.prettyprint.PrettyPrinter)1 BoltStateHandler (org.neo4j.shell.state.BoltStateHandler)1