Search in sources :

Example 11 with CliArgs

use of org.neo4j.shell.cli.CliArgs in project neo4j by neo4j.

the class MainIntegrationTest method executeFileNonInteractively.

private String executeFileNonInteractively(String filename, Logger logger) {
    CliArgs cliArgs = new CliArgs();
    cliArgs.setUsername(USER, "");
    cliArgs.setPassword(PASSWORD, "");
    cliArgs.setInputFilename(filename);
    return executeNonInteractively(cliArgs, logger);
}
Also used : CliArgs(org.neo4j.shell.cli.CliArgs)

Example 12 with CliArgs

use of org.neo4j.shell.cli.CliArgs in project neo4j by neo4j.

the class MainIntegrationTest method startsAgainstSystemDatabaseWhenDefaultDatabaseUnavailableIfInteractive.

@Test
public void startsAgainstSystemDatabaseWhenDefaultDatabaseUnavailableIfInteractive() throws Exception {
    shell.setCommandHelper(new CommandHelper(mock(Logger.class), Historian.empty, shell));
    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();
        // Connect to system database
        CliArgs cliArgs = new CliArgs();
        cliArgs.setUsername("neo4j", "");
        cliArgs.setPassword("neo", "");
        cliArgs.setDatabase("system");
        ShellAndConnection sac = getShell(cliArgs);
        // Use the new shell and connection config from here on
        shell = sac.shell;
        connectionConfig = sac.connectionConfig;
        main.connectMaybeInteractively(shell, connectionConfig, true, false, true);
        // then
        assertTrue(shell.isConnected());
    } finally {
        // Start the default database again
        ensureDefaultDatabaseStarted();
    }
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) CommandHelper(org.neo4j.shell.commands.CommandHelper) CliArgs(org.neo4j.shell.cli.CliArgs) Test(org.junit.Test)

Example 13 with CliArgs

use of org.neo4j.shell.cli.CliArgs in project neo4j by neo4j.

the class MainIntegrationTest method args.

private CliArgs args(String db, String user, String pass, String cypher) {
    CliArgs cliArgs = new CliArgs();
    cliArgs.setUsername(user, "");
    cliArgs.setPassword(pass, "");
    cliArgs.setDatabase(db);
    cliArgs.setCypher(cypher);
    return cliArgs;
}
Also used : CliArgs(org.neo4j.shell.cli.CliArgs)

Example 14 with CliArgs

use of org.neo4j.shell.cli.CliArgs in project neo4j by neo4j.

the class MainIntegrationTest method shouldAskForCredentialsWhenConnectingWithAFile.

@Test
public void shouldAskForCredentialsWhenConnectingWithAFile() throws Exception {
    // given
    assertEquals("", connectionConfig.username());
    assertEquals("", connectionConfig.password());
    // when
    CliArgs cliArgs = new CliArgs();
    cliArgs.setInputFilename(fileFromResource("single.cypher"));
    ShellAndConnection sac = getShell(cliArgs);
    CypherShell shell = sac.shell;
    ConnectionConfig connectionConfig = sac.connectionConfig;
    main.connectMaybeInteractively(shell, connectionConfig, true, true, true);
    // then we should have prompted and set the username and password
    assertEquals(format("username: neo4j%npassword: ***%n"), baos.toString());
    assertEquals("neo4j", connectionConfig.username());
    assertEquals("neo", connectionConfig.password());
}
Also used : CliArgs(org.neo4j.shell.cli.CliArgs) Test(org.junit.Test)

Aggregations

CliArgs (org.neo4j.shell.cli.CliArgs)14 Test (org.junit.Test)8 PrintStream (java.io.PrintStream)3 CommandHelper (org.neo4j.shell.commands.CommandHelper)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Before (org.junit.Before)1 ShellRunner.getShellRunner (org.neo4j.shell.ShellRunner.getShellRunner)1 NonInteractiveShellRunner (org.neo4j.shell.cli.NonInteractiveShellRunner)1 Logger (org.neo4j.shell.log.Logger)1 PrettyConfig (org.neo4j.shell.prettyprint.PrettyConfig)1