Search in sources :

Example 1 with ShellStatementParser

use of org.neo4j.shell.parser.ShellStatementParser in project neo4j by neo4j.

the class InteractiveShellRunnerTest method testSignalHandleOutsideExecution.

@Test
public void testSignalHandleOutsideExecution() throws Exception {
    // given
    InputStream inputStream = new ByteArrayInputStream("".getBytes());
    InteractiveShellRunner runner = new InteractiveShellRunner(cmdExecuter, txHandler, databaseManager, logger, new ShellStatementParser(), inputStream, historyFile, userMessagesHandler, connectionConfig);
    // when
    runner.handle(new Signal(InteractiveShellRunner.INTERRUPT_SIGNAL));
    // then
    verify(cmdExecuter).lastNeo4jErrorCode();
    verifyNoMoreInteractions(cmdExecuter);
    verify(logger).printError("@|RED \nInterrupted (Note that Cypher queries must end with a |@" + "@|RED,BOLD semicolon. |@" + "@|RED Type |@@|RED,BOLD :exit|@@|RED,BOLD  |@" + "@|RED to exit the shell.)|@");
}
Also used : ShellStatementParser(org.neo4j.shell.parser.ShellStatementParser) Signal(sun.misc.Signal) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 2 with ShellStatementParser

use of org.neo4j.shell.parser.ShellStatementParser in project neo4j by neo4j.

the class InteractiveShellRunnerTest method multilineRequiresNewLineOrSemicolonToEnd.

@Test
public void multilineRequiresNewLineOrSemicolonToEnd() throws Exception {
    // given
    String inputString = "  \\   \nCREATE (n:Person) RETURN n\n";
    InputStream inputStream = new ByteArrayInputStream(inputString.getBytes());
    InteractiveShellRunner runner = new InteractiveShellRunner(cmdExecuter, txHandler, databaseManager, logger, new ShellStatementParser(), inputStream, historyFile, userMessagesHandler, connectionConfig);
    // when
    runner.runUntilEnd();
    // then
    verify(cmdExecuter).lastNeo4jErrorCode();
    verifyNoMoreInteractions(cmdExecuter);
}
Also used : ShellStatementParser(org.neo4j.shell.parser.ShellStatementParser) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 3 with ShellStatementParser

use of org.neo4j.shell.parser.ShellStatementParser in project neo4j by neo4j.

the class InteractiveShellRunnerTest method multilineEndsOnSemicolonOnSameLine.

@Test
public void multilineEndsOnSemicolonOnSameLine() throws Exception {
    // given
    String inputString = "\nCREATE (n:Person) RETURN n;\n";
    InputStream inputStream = new ByteArrayInputStream(inputString.getBytes());
    InteractiveShellRunner runner = new InteractiveShellRunner(cmdExecuter, txHandler, databaseManager, logger, new ShellStatementParser(), inputStream, historyFile, userMessagesHandler, connectionConfig);
    // when
    runner.runUntilEnd();
    // then
    verify(cmdExecuter).execute("CREATE (n:Person) RETURN n;");
}
Also used : ShellStatementParser(org.neo4j.shell.parser.ShellStatementParser) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 4 with ShellStatementParser

use of org.neo4j.shell.parser.ShellStatementParser in project neo4j by neo4j.

the class InteractiveShellRunnerTest method printsWelcomeAndExitMessage.

@Test
public void printsWelcomeAndExitMessage() throws Exception {
    // given
    String inputString = "\nCREATE (n:Person) RETURN n\n;\n";
    InputStream inputStream = new ByteArrayInputStream(inputString.getBytes());
    InteractiveShellRunner runner = new InteractiveShellRunner(cmdExecuter, txHandler, databaseManager, logger, new ShellStatementParser(), inputStream, historyFile, userMessagesHandler, connectionConfig);
    // when
    runner.runUntilEnd();
    // then
    verify(logger).printIfVerbose("Welcome to cypher-shell!");
    verify(logger).printIfVerbose("Exit message");
}
Also used : ShellStatementParser(org.neo4j.shell.parser.ShellStatementParser) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 5 with ShellStatementParser

use of org.neo4j.shell.parser.ShellStatementParser in project neo4j by neo4j.

the class InteractiveShellRunnerTest method justNewLineThrowsNoMoreInput.

@Test
public void justNewLineThrowsNoMoreInput() throws Exception {
    // then
    thrown.expect(NoMoreInputException.class);
    // given
    String inputString = "\n";
    InputStream inputStream = new ByteArrayInputStream(inputString.getBytes());
    InteractiveShellRunner runner = new InteractiveShellRunner(cmdExecuter, txHandler, databaseManager, logger, new ShellStatementParser(), inputStream, historyFile, userMessagesHandler, connectionConfig);
    // when
    runner.readUntilStatement();
}
Also used : ShellStatementParser(org.neo4j.shell.parser.ShellStatementParser) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Aggregations

ShellStatementParser (org.neo4j.shell.parser.ShellStatementParser)12 ByteArrayInputStream (java.io.ByteArrayInputStream)10 InputStream (java.io.InputStream)10 Test (org.junit.Test)9 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)7 Before (org.junit.Before)2 ClientException (org.neo4j.driver.exceptions.ClientException)2 AnsiLogger (org.neo4j.shell.log.AnsiLogger)2 Logger (org.neo4j.shell.log.Logger)2 BoltStateHandler (org.neo4j.shell.state.BoltStateHandler)2 Signal (sun.misc.Signal)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1 ConnectionConfig (org.neo4j.shell.ConnectionConfig)1 DatabaseManager (org.neo4j.shell.DatabaseManager)1 OfflineTestShell (org.neo4j.shell.OfflineTestShell)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