Java Code Examples for org.springframework.shell.core.JLineShellComponent#executeCommand()

The following examples show how to use org.springframework.shell.core.JLineShellComponent#executeCommand() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AccumuloRyaConnectionCommandsIT.java    From rya with Apache License 2.0 6 votes vote down vote up
@Test
public void connectAccumulo() throws IOException {
    final MiniAccumuloCluster cluster = getCluster();
    final Bootstrap bootstrap = getTestBootstrap();
    final JLineShellComponent shell = getTestShell();

    // Mock the user entering the correct password.
    final ApplicationContext context = bootstrap.getApplicationContext();
    final PasswordPrompt mockPrompt = context.getBean( PasswordPrompt.class );
    when(mockPrompt.getPassword()).thenReturn("password".toCharArray());

    // Execute the connect command.
    final String cmd =
            RyaConnectionCommands.CONNECT_ACCUMULO_CMD + " " +
                    "--username root " +
                    "--instanceName " + cluster.getInstanceName() + " "+
                    "--zookeepers " + cluster.getZooKeepers();

    final CommandResult connectResult = shell.executeCommand(cmd);

    // Ensure the connection was successful.
    assertTrue( connectResult.isSuccess() );
}
 
Example 2
Source File: AccumuloRyaConnectionCommandsIT.java    From rya with Apache License 2.0 6 votes vote down vote up
@Test
public void connectAccumulo_wrongCredentials() throws IOException {
    final MiniAccumuloCluster cluster = getCluster();
    final Bootstrap bootstrap = getTestBootstrap();
    final JLineShellComponent shell = getTestShell();

    // Mock the user entering the wrong password.
    final ApplicationContext context = bootstrap.getApplicationContext();
    final PasswordPrompt mockPrompt = context.getBean( PasswordPrompt.class );
    when(mockPrompt.getPassword()).thenReturn("asjifo[ijwa".toCharArray());

    // Execute the command
    final String cmd =
            RyaConnectionCommands.CONNECT_ACCUMULO_CMD + " " +
                    "--username root " +
                    "--instanceName " + cluster.getInstanceName() + " "+
                    "--zookeepers " + cluster.getZooKeepers();

    final CommandResult connectResult = shell.executeCommand(cmd);

    // Ensure the command failed.
    assertFalse( connectResult.isSuccess() );
}
 
Example 3
Source File: AccumuloRyaConnectionCommandsIT.java    From rya with Apache License 2.0 6 votes vote down vote up
@Test
public void connectToInstance_instanceDoesNotExist() throws IOException {
    final MiniAccumuloCluster cluster = getCluster();
    final Bootstrap bootstrap = getTestBootstrap();
    final JLineShellComponent shell = getTestShell();

    // Mock the user entering the correct password.
    final ApplicationContext context = bootstrap.getApplicationContext();
    final PasswordPrompt mockPrompt = context.getBean( PasswordPrompt.class );
    when(mockPrompt.getPassword()).thenReturn("password".toCharArray());

    // Connect to the mini accumulo instance.
    String cmd =
            RyaConnectionCommands.CONNECT_ACCUMULO_CMD + " " +
                    "--username root " +
                    "--instanceName " + cluster.getInstanceName() + " "+
                    "--zookeepers " + cluster.getZooKeepers();
    shell.executeCommand(cmd);

    // Try to connect to a non-existing instance.
    cmd = RyaConnectionCommands.CONNECT_INSTANCE_CMD + " --instance doesNotExist";
    final CommandResult result = shell.executeCommand(cmd);
    assertFalse( result.isSuccess() );
}
 
Example 4
Source File: AccumuloRyaConnectionCommandsIT.java    From rya with Apache License 2.0 6 votes vote down vote up
@Test
public void disconnect() throws IOException {
    final MiniAccumuloCluster cluster = getCluster();
    final Bootstrap bootstrap = getTestBootstrap();
    final JLineShellComponent shell = getTestShell();

    // Mock the user entering the correct password.
    final ApplicationContext context = bootstrap.getApplicationContext();
    final PasswordPrompt mockPrompt = context.getBean( PasswordPrompt.class );
    when(mockPrompt.getPassword()).thenReturn("password".toCharArray());

    // Connect to the mini accumulo instance.
    final String cmd =
            RyaConnectionCommands.CONNECT_ACCUMULO_CMD + " " +
                    "--username root " +
                    "--instanceName " + cluster.getInstanceName() + " "+
                    "--zookeepers " + cluster.getZooKeepers();
    shell.executeCommand(cmd);

    // Disconnect from it.
    final CommandResult disconnectResult = shell.executeCommand( RyaConnectionCommands.DISCONNECT_COMMAND_NAME_CMD );
    assertTrue( disconnectResult.isSuccess() );
}
 
Example 5
Source File: MongoRyaShellIT.java    From rya with Apache License 2.0 6 votes vote down vote up
@Test
public void printConnectionDetails_connectedToMongo_noAuths() throws IOException {
    final JLineShellComponent shell = getTestShell();

    // Connect to the Mongo instance.
    final String cmd =
            RyaConnectionCommands.CONNECT_MONGO_CMD + " " +
                    "--hostname " + super.getMongoHostname() + " " +
                    "--port " + super.getMongoPort();
    shell.executeCommand(cmd);

    // Run the print connection details command.
    final CommandResult printResult = shell.executeCommand( RyaConnectionCommands.PRINT_CONNECTION_DETAILS_CMD );
    final String msg = (String) printResult.getResult();

    final String expected =
            "The shell is connected to an instance of MongoDB using the following parameters:\n" +
            "    Hostname: " + super.getMongoHostname() + "\n" +
            "    Port: " + super.getMongoPort() + "\n";
    assertEquals(expected, msg);
}
 
Example 6
Source File: MongoRyaShellIT.java    From rya with Apache License 2.0 6 votes vote down vote up
@Test
public void connectToInstance_instanceDoesNotExist() throws IOException {
    final JLineShellComponent shell = getTestShell();

    // Connect to the Mongo instance.
    String cmd =
            RyaConnectionCommands.CONNECT_MONGO_CMD + " " +
                    "--hostname " + super.getMongoHostname() + " " +
                    "--port " + super.getMongoPort();
    shell.executeCommand(cmd);

    // Try to connect to a non-existing instance.
    cmd = RyaConnectionCommands.CONNECT_INSTANCE_CMD + " --instance doesNotExist";
    final CommandResult result = shell.executeCommand(cmd);
    assertFalse( result.isSuccess() );
}
 
Example 7
Source File: ContextCommandsTest.java    From hdfs-shell with Apache License 2.0 5 votes vote down vote up
public void exists() throws Exception {
    Bootstrap bootstrap = new Bootstrap();

    JLineShellComponent shell = bootstrap.getJLineShellComponent();

    CommandResult cr = shell.executeCommand("exists /analytics");
    assertEquals(true, cr.isSuccess());
}
 
Example 8
Source File: AccumuloRyaConnectionCommandsIT.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void printConnectionDetails_notConnected() {
    final JLineShellComponent shell = getTestShell();

    // Run the print connection details command.
    final CommandResult printResult = shell.executeCommand( RyaConnectionCommands.PRINT_CONNECTION_DETAILS_CMD );
    final String msg = (String) printResult.getResult();

    final String expected = "The shell is not connected to anything.";
    assertEquals(expected, msg);
}
 
Example 9
Source File: AccumuloRyaConnectionCommandsIT.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void printConnectionDetails_connectedToAccumulo() throws IOException {
    final MiniAccumuloCluster cluster = getCluster();
    final Bootstrap bootstrap = getTestBootstrap();
    final JLineShellComponent shell = getTestShell();

    // Mock the user entering the correct password.
    final ApplicationContext context = bootstrap.getApplicationContext();
    final PasswordPrompt mockPrompt = context.getBean( PasswordPrompt.class );
    when(mockPrompt.getPassword()).thenReturn("password".toCharArray());

    // Connect to the mini accumulo instance.
    final String cmd =
            RyaConnectionCommands.CONNECT_ACCUMULO_CMD + " " +
                    "--username root " +
                    "--instanceName " + cluster.getInstanceName() + " "+
                    "--zookeepers " + cluster.getZooKeepers();
    shell.executeCommand(cmd);

    // Run the print connection details command.
    final CommandResult printResult = shell.executeCommand( RyaConnectionCommands.PRINT_CONNECTION_DETAILS_CMD );
    final String msg = (String) printResult.getResult();

    final String expected =
            "The shell is connected to an instance of Accumulo using the following parameters:\n" +
            "    Username: root\n" +
            "    Instance Name: " + cluster.getInstanceName() + "\n" +
            "    Zookeepers: " + cluster.getZooKeepers();
    assertEquals(expected, msg);
}
 
Example 10
Source File: MongoRyaShellIT.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void connectMongo_noAuth() throws IOException {
    final JLineShellComponent shell = getTestShell();

    // Connect to the Mongo instance.
    final String cmd =
            RyaConnectionCommands.CONNECT_MONGO_CMD + " " +
                    "--hostname " + super.getMongoHostname() + " " +
                    "--port " + super.getMongoPort();

    final CommandResult connectResult = shell.executeCommand(cmd);

    // Ensure the connection was successful.
    assertTrue(connectResult.isSuccess());
}
 
Example 11
Source File: MongoRyaShellIT.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void printConnectionDetails_notConnected() {
    final JLineShellComponent shell = getTestShell();

    // Run the print connection details command.
    final CommandResult printResult = shell.executeCommand( RyaConnectionCommands.PRINT_CONNECTION_DETAILS_CMD );
    final String msg = (String) printResult.getResult();

    final String expected = "The shell is not connected to anything.";
    assertEquals(expected, msg);
}
 
Example 12
Source File: MongoRyaShellIT.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void printConnectionDetails_connectedToMongo_auths() throws IOException {
    final Bootstrap bootstrap = getTestBootstrap();
    final JLineShellComponent shell = getTestShell();

    // Mock the user entering the correct password.
    final ApplicationContext context = bootstrap.getApplicationContext();
    final PasswordPrompt mockPrompt = context.getBean( PasswordPrompt.class );
    when(mockPrompt.getPassword()).thenReturn("password".toCharArray());

    // Connect to the Mongo instance.
    final String cmd =
            RyaConnectionCommands.CONNECT_MONGO_CMD + " " +
                    "--hostname " + super.getMongoHostname() + " " +
                    "--port " + super.getMongoPort() + " " +
                    "--username bob";
    shell.executeCommand(cmd);

    // Run the print connection details command.
    final CommandResult printResult = shell.executeCommand( RyaConnectionCommands.PRINT_CONNECTION_DETAILS_CMD );
    final String msg = (String) printResult.getResult();

    final String expected =
            "The shell is connected to an instance of MongoDB using the following parameters:\n" +
            "    Hostname: " + super.getMongoHostname() + "\n" +
            "    Port: " + super.getMongoPort() + "\n" +
            "    Username: bob\n";
    assertEquals(expected, msg);
}
 
Example 13
Source File: MongoRyaShellIT.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void connectToInstance_noAuths() throws IOException {
    final Bootstrap bootstrap = getTestBootstrap();
    final JLineShellComponent shell = getTestShell();

    // Connect to the Mongo instance.
    String cmd =
            RyaConnectionCommands.CONNECT_MONGO_CMD + " " +
                    "--hostname " + super.getMongoHostname() + " " +
                    "--port " + super.getMongoPort();
    shell.executeCommand(cmd);

    // Install an instance of rya.
    final String instanceName = "testInstance";
    final InstallConfiguration installConf = InstallConfiguration.builder().build();

    final ApplicationContext context = bootstrap.getApplicationContext();
    final InstallPrompt installPrompt = context.getBean( InstallPrompt.class );
    when(installPrompt.promptInstanceName()).thenReturn("testInstance");
    when(installPrompt.promptInstallConfiguration("testInstance")).thenReturn( installConf );
    when(installPrompt.promptVerified(instanceName, installConf)).thenReturn(true);

    CommandResult result = shell.executeCommand( RyaAdminCommands.INSTALL_CMD );
    assertTrue( result.isSuccess() );

    // Connect to the instance that was just installed.
    cmd = RyaConnectionCommands.CONNECT_INSTANCE_CMD + " --instance " + instanceName;
    result = shell.executeCommand(cmd);
    assertTrue( result.isSuccess() );

    // Verify the shell state indicates it is connected to an instance.
    final SharedShellState sharedState = context.getBean( SharedShellState.class );
    final ShellState state = sharedState.getShellState();
    assertEquals(ConnectionState.CONNECTED_TO_INSTANCE, state.getConnectionState());
}
 
Example 14
Source File: MongoRyaShellIT.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void disconnect() throws IOException {
    final JLineShellComponent shell = getTestShell();

    // Connect to the Mongo instance.
    final String cmd =
            RyaConnectionCommands.CONNECT_MONGO_CMD + " " +
                    "--hostname " + super.getMongoHostname() + " " +
                    "--port " + super.getMongoPort();
    shell.executeCommand(cmd);

    // Disconnect from it.
    final CommandResult disconnectResult = shell.executeCommand( RyaConnectionCommands.DISCONNECT_COMMAND_NAME_CMD );
    assertTrue( disconnectResult.isSuccess() );
}
 
Example 15
Source File: AccumuloRyaCommandsIT.java    From rya with Apache License 2.0 4 votes vote down vote up
@Test
public void loadsAndQueryData() throws Exception {
    final MiniAccumuloCluster cluster = getCluster();
    final Bootstrap bootstrap = getTestBootstrap();
    final JLineShellComponent shell = getTestShell();

    // Mock the user entering the correct password.
    final ApplicationContext context = bootstrap.getApplicationContext();
    final PasswordPrompt mockPrompt = context.getBean( PasswordPrompt.class );
    when(mockPrompt.getPassword()).thenReturn("password".toCharArray());

    // Connect to the mini accumulo instance.
    String cmd =
            RyaConnectionCommands.CONNECT_ACCUMULO_CMD + " " +
                    "--username root " +
                    "--instanceName " + cluster.getInstanceName() + " "+
                    "--zookeepers " + cluster.getZooKeepers();
    CommandResult result = shell.executeCommand(cmd);

    // Install an instance of rya.
    final String instanceName = "testInstance";
    final InstallConfiguration installConf = InstallConfiguration.builder().build();

    final InstallPrompt installPrompt = context.getBean( InstallPrompt.class );
    when(installPrompt.promptInstanceName()).thenReturn("testInstance");
    when(installPrompt.promptInstallConfiguration("testInstance")).thenReturn( installConf );
    when(installPrompt.promptVerified(instanceName, installConf)).thenReturn(true);

    result = shell.executeCommand( RyaAdminCommands.INSTALL_CMD );
    assertTrue( result.isSuccess() );

    // Connect to the instance that was just installed.
    cmd = RyaConnectionCommands.CONNECT_INSTANCE_CMD + " --instance " + instanceName;
    result = shell.executeCommand(cmd);
    assertTrue( result.isSuccess() );

    // Load a statements file into the instance.
    cmd = RyaCommands.LOAD_DATA_CMD + " --file src/test/resources/test-statements.nt";
    result = shell.executeCommand(cmd);
    assertTrue( result.isSuccess() );

    // Query for all of the statements that were loaded.
    final SparqlPrompt sparqlPrompt = context.getBean(SparqlPrompt.class);
    when(sparqlPrompt.getSparql()).thenReturn(Optional.of("select * where { ?s ?p ?o .}"));

    cmd = RyaCommands.SPARQL_QUERY_CMD;
    result = shell.executeCommand(cmd);
    assertTrue( result.isSuccess() );
}
 
Example 16
Source File: AccumuloRyaConnectionCommandsIT.java    From rya with Apache License 2.0 4 votes vote down vote up
@Test
public void connectToInstance() throws IOException {
    final MiniAccumuloCluster cluster = getCluster();
    final Bootstrap bootstrap = getTestBootstrap();
    final JLineShellComponent shell = getTestShell();

    // Mock the user entering the correct password.
    final ApplicationContext context = bootstrap.getApplicationContext();
    final PasswordPrompt mockPrompt = context.getBean( PasswordPrompt.class );
    when(mockPrompt.getPassword()).thenReturn("password".toCharArray());

    // Connect to the mini accumulo instance.
    String cmd =
            RyaConnectionCommands.CONNECT_ACCUMULO_CMD + " " +
                    "--username root " +
                    "--instanceName " + cluster.getInstanceName() + " "+
                    "--zookeepers " + cluster.getZooKeepers();
    CommandResult result = shell.executeCommand(cmd);

    // Install an instance of rya.
    final String instanceName = "testInstance";
    final InstallConfiguration installConf = InstallConfiguration.builder().build();

    final InstallPrompt installPrompt = context.getBean( InstallPrompt.class );
    when(installPrompt.promptInstanceName()).thenReturn("testInstance");
    when(installPrompt.promptInstallConfiguration("testInstance")).thenReturn( installConf );
    when(installPrompt.promptVerified(instanceName, installConf)).thenReturn(true);

    result = shell.executeCommand( RyaAdminCommands.INSTALL_CMD );
    assertTrue( result.isSuccess() );

    // Connect to the instance that was just installed.
    cmd = RyaConnectionCommands.CONNECT_INSTANCE_CMD + " --instance " + instanceName;
    result = shell.executeCommand(cmd);
    assertTrue( result.isSuccess() );

    // Verify the shell state indicates it is connected to an instance.
    final SharedShellState sharedState = context.getBean( SharedShellState.class );
    final ShellState state = sharedState.getShellState();
    assertEquals(ConnectionState.CONNECTED_TO_INSTANCE, state.getConnectionState());
}