Search in sources :

Example 1 with CommandHelper

use of org.neo4j.shell.commands.CommandHelper in project neo4j by neo4j.

the class MainIntegrationTest method switchingToUnavailableDatabaseIfInteractive.

@Test
public void switchingToUnavailableDatabaseIfInteractive() throws Exception {
    shell.setCommandHelper(new CommandHelper(mock(Logger.class), Historian.empty, shell));
    inputBuffer.put(String.format("neo4j%nneo%n").getBytes());
    assertEquals("", connectionConfig.username());
    assertEquals("", connectionConfig.password());
    // when
    main.connectMaybeInteractively(shell, connectionConfig, true, true, true);
    // Multiple databases are only available from 4.0
    assumeTrue(majorVersion(shell.getServerVersion()) >= 4);
    // then
    // should be connected
    assertTrue(shell.isConnected());
    // should have prompted and set the username and password
    String expectedLoginOutput = format("username: neo4j%npassword: ***%n");
    assertEquals(expectedLoginOutput, baos.toString());
    assertEquals("neo4j", connectionConfig.username());
    assertEquals("neo", connectionConfig.password());
    // Stop the default database
    shell.execute(":use " + SYSTEM_DB_NAME);
    shell.execute("STOP DATABASE " + DatabaseManager.DEFAULT_DEFAULT_DB_NAME);
    try {
        // Should get exception that database is unavailable when trying to connect
        shell.execute(":use " + DatabaseManager.DEFAULT_DEFAULT_DB_NAME);
        fail("No exception thrown");
    } catch (TransientException | ServiceUnavailableException e) {
        expectDatabaseUnavailable(e, "neo4j");
    } finally {
        // Start the default database again
        ensureDefaultDatabaseStarted();
    }
}
Also used : TransientException(org.neo4j.driver.exceptions.TransientException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ServiceUnavailableException(org.neo4j.driver.exceptions.ServiceUnavailableException) CommandHelper(org.neo4j.shell.commands.CommandHelper) Test(org.junit.Test)

Example 2 with CommandHelper

use of org.neo4j.shell.commands.CommandHelper in project neo4j by neo4j.

the class MainIntegrationTest method interactiveShell.

private CypherShell interactiveShell(LinePrinter linePrinter) throws Exception {
    PrettyConfig prettyConfig = new PrettyConfig(new CliArgs());
    CypherShell shell = new CypherShell(linePrinter, prettyConfig, true, new ShellParameterMap());
    main.connectMaybeInteractively(shell, connectionConfig, true, true, true);
    shell.setCommandHelper(new CommandHelper(mock(Logger.class), Historian.empty, shell));
    return shell;
}
Also used : PrettyConfig(org.neo4j.shell.prettyprint.PrettyConfig) CommandHelper(org.neo4j.shell.commands.CommandHelper) CliArgs(org.neo4j.shell.cli.CliArgs)

Example 3 with CommandHelper

use of org.neo4j.shell.commands.CommandHelper in project neo4j by neo4j.

the class MainIntegrationTest method doesNotStartWhenDefaultDatabaseUnavailableIfInteractive.

@Test
public void doesNotStartWhenDefaultDatabaseUnavailableIfInteractive() throws Exception {
    shell.setCommandHelper(new CommandHelper(mock(Logger.class), Historian.empty, shell));
    inputBuffer.put(String.format("neo4j%nneo%n").getBytes());
    assertEquals("", connectionConfig.username());
    assertEquals("", connectionConfig.password());
    // when
    main.connectMaybeInteractively(shell, connectionConfig, true, true, true);
    // Multiple databases are only available from 4.0
    assumeTrue(majorVersion(shell.getServerVersion()) >= 4);
    // then
    // should be connected
    assertTrue(shell.isConnected());
    // should have prompted and set the username and password
    String expectedLoginOutput = format("username: neo4j%npassword: ***%n");
    assertEquals(expectedLoginOutput, baos.toString());
    assertEquals("neo4j", connectionConfig.username());
    assertEquals("neo", connectionConfig.password());
    // Stop the default database
    shell.execute(":use " + SYSTEM_DB_NAME);
    shell.execute("STOP DATABASE " + DatabaseManager.DEFAULT_DEFAULT_DB_NAME);
    try {
        shell.disconnect();
        // Should get exception that database is unavailable when trying to connect
        main.connectMaybeInteractively(shell, connectionConfig, true, true, true);
        fail("No exception thrown");
    } catch (TransientException | ServiceUnavailableException e) {
        expectDatabaseUnavailable(e, "neo4j");
    } finally {
        // Start the default database again
        ensureDefaultDatabaseStarted();
    }
}
Also used : TransientException(org.neo4j.driver.exceptions.TransientException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ServiceUnavailableException(org.neo4j.driver.exceptions.ServiceUnavailableException) CommandHelper(org.neo4j.shell.commands.CommandHelper) Test(org.junit.Test)

Example 4 with CommandHelper

use of org.neo4j.shell.commands.CommandHelper in project neo4j by neo4j.

the class MainIntegrationTest method getVersionAndCreateUserWithPasswordChangeRequired.

private int getVersionAndCreateUserWithPasswordChangeRequired() throws Exception {
    shell.setCommandHelper(new CommandHelper(mock(Logger.class), Historian.empty, shell));
    main.connectMaybeInteractively(shell, connectionConfig, true, true, true);
    String expectedLoginOutput = format("username: neo4j%npassword: ***%n");
    assertEquals(expectedLoginOutput, baos.toString());
    ensureUser();
    int majorVersion = majorVersion(shell.getServerVersion());
    shell.disconnect();
    return majorVersion;
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) CommandHelper(org.neo4j.shell.commands.CommandHelper)

Example 5 with CommandHelper

use of org.neo4j.shell.commands.CommandHelper 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)

Aggregations

CommandHelper (org.neo4j.shell.commands.CommandHelper)10 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5 Test (org.junit.Test)5 ServiceUnavailableException (org.neo4j.driver.exceptions.ServiceUnavailableException)3 TransientException (org.neo4j.driver.exceptions.TransientException)3 CliArgs (org.neo4j.shell.cli.CliArgs)2 AnsiLogger (org.neo4j.shell.log.AnsiLogger)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 PrintStream (java.io.PrintStream)1 Before (org.junit.Before)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 Logger (org.neo4j.shell.log.Logger)1 ShellStatementParser (org.neo4j.shell.parser.ShellStatementParser)1 PrettyConfig (org.neo4j.shell.prettyprint.PrettyConfig)1