Search in sources :

Example 1 with JLineShellComponent

use of org.springframework.shell.core.JLineShellComponent in project incubator-rya by apache.

the class AccumuloRyaConnectionCommandsIT method connectToInstance.

@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());
}
Also used : JLineShellComponent(org.springframework.shell.core.JLineShellComponent) ApplicationContext(org.springframework.context.ApplicationContext) ShellState(org.apache.rya.shell.SharedShellState.ShellState) MiniAccumuloCluster(org.apache.accumulo.minicluster.MiniAccumuloCluster) Bootstrap(org.springframework.shell.Bootstrap) InstallConfiguration(org.apache.rya.api.client.Install.InstallConfiguration) PasswordPrompt(org.apache.rya.shell.util.PasswordPrompt) InstallPrompt(org.apache.rya.shell.util.InstallPrompt) CommandResult(org.springframework.shell.core.CommandResult) Test(org.junit.Test)

Example 2 with JLineShellComponent

use of org.springframework.shell.core.JLineShellComponent in project incubator-rya by apache.

the class AccumuloRyaConnectionCommandsIT method disconnect.

@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());
}
Also used : JLineShellComponent(org.springframework.shell.core.JLineShellComponent) ApplicationContext(org.springframework.context.ApplicationContext) MiniAccumuloCluster(org.apache.accumulo.minicluster.MiniAccumuloCluster) Bootstrap(org.springframework.shell.Bootstrap) PasswordPrompt(org.apache.rya.shell.util.PasswordPrompt) CommandResult(org.springframework.shell.core.CommandResult) Test(org.junit.Test)

Example 3 with JLineShellComponent

use of org.springframework.shell.core.JLineShellComponent in project incubator-rya by apache.

the class AccumuloRyaConnectionCommandsIT method connectAccumulo.

@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());
}
Also used : JLineShellComponent(org.springframework.shell.core.JLineShellComponent) ApplicationContext(org.springframework.context.ApplicationContext) MiniAccumuloCluster(org.apache.accumulo.minicluster.MiniAccumuloCluster) Bootstrap(org.springframework.shell.Bootstrap) PasswordPrompt(org.apache.rya.shell.util.PasswordPrompt) CommandResult(org.springframework.shell.core.CommandResult) Test(org.junit.Test)

Example 4 with JLineShellComponent

use of org.springframework.shell.core.JLineShellComponent in project incubator-rya by apache.

the class AccumuloRyaConnectionCommandsIT method connectAccumulo_wrongCredentials.

@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());
}
Also used : JLineShellComponent(org.springframework.shell.core.JLineShellComponent) ApplicationContext(org.springframework.context.ApplicationContext) MiniAccumuloCluster(org.apache.accumulo.minicluster.MiniAccumuloCluster) Bootstrap(org.springframework.shell.Bootstrap) PasswordPrompt(org.apache.rya.shell.util.PasswordPrompt) CommandResult(org.springframework.shell.core.CommandResult) Test(org.junit.Test)

Example 5 with JLineShellComponent

use of org.springframework.shell.core.JLineShellComponent in project incubator-rya by apache.

the class AccumuloRyaConnectionCommandsIT method connectToInstance_instanceDoesNotExist.

@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());
}
Also used : JLineShellComponent(org.springframework.shell.core.JLineShellComponent) ApplicationContext(org.springframework.context.ApplicationContext) MiniAccumuloCluster(org.apache.accumulo.minicluster.MiniAccumuloCluster) Bootstrap(org.springframework.shell.Bootstrap) PasswordPrompt(org.apache.rya.shell.util.PasswordPrompt) CommandResult(org.springframework.shell.core.CommandResult) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)14 CommandResult (org.springframework.shell.core.CommandResult)14 JLineShellComponent (org.springframework.shell.core.JLineShellComponent)14 ApplicationContext (org.springframework.context.ApplicationContext)8 Bootstrap (org.springframework.shell.Bootstrap)8 PasswordPrompt (org.apache.rya.shell.util.PasswordPrompt)7 MiniAccumuloCluster (org.apache.accumulo.minicluster.MiniAccumuloCluster)6 InstallConfiguration (org.apache.rya.api.client.Install.InstallConfiguration)2 ShellState (org.apache.rya.shell.SharedShellState.ShellState)2 InstallPrompt (org.apache.rya.shell.util.InstallPrompt)2