Class SshGSpec


  • public class SshGSpec
    extends BaseGSpec
    Steps definitions for running bash commands and establishing SSH connections with a remote host
    Author:
    Jose Fernandez
    • Constructor Detail

      • SshGSpec

        public SshGSpec​(CommonG spec)
        Default constructor.
        Parameters:
        spec - CommonG object
    • Method Detail

      • openSSHConnection

        @Given("^I open a ssh connection to \'(.+?)\' with user \'(.+?)\'( and password \'(.+?)\')?( using pem file \'(.+?)\')?$")
        public void openSSHConnection​(String remoteHost,
                                      String user,
                                      String foo,
                                      String password,
                                      String bar,
                                      String pemFile)
                               throws Exception
        Opens a ssh connection to remote host
        Parameters:
        remoteHost - remote host
        user - remote user
        foo - the foo
        password - (required if pemFile null)
        bar - the bar
        pemFile - (required if password null)
        Throws:
        Exception - exception
      • copyFromRemoteFile

        @Given("^I inbound copy \'(.+?)\' through a ssh connection to \'(.+?)\'$")
        public void copyFromRemoteFile​(String remotePath,
                                       String localPath)
                                throws Exception
        Copies file/s from remote system into local system
        Parameters:
        remotePath - path where file is going to be copy
        localPath - path where file is located
        Throws:
        Exception - exception
      • copyToRemoteFile

        @Given("^I outbound copy \'(.+?)\' through a ssh connection to \'(.+?)\'$")
        public void copyToRemoteFile​(String localPath,
                                     String remotePath)
                              throws Exception
        Copies file/s from local system to remote system
        Parameters:
        localPath - path where file is located
        remotePath - path where file is going to be copy
        Throws:
        Exception - exception
      • executeLocalCommand

        @Given("^I run \'(.+?)\' locally( with exit status \'(.+?)\')?( and save the value in environment variable \'(.+?)\')?$")
        public void executeLocalCommand​(String command,
                                        Integer exitStatus,
                                        String envVar)
                                 throws Exception
        Executes the command specified in local system
        Parameters:
        command - command to be run locally
        exitStatus - command exit status
        envVar - environment variable name
        Throws:
        Exception - exception
      • executeCommand

        @Given("^I run \'(.+?)\' in the ssh connection( with exit status \'(.+?)\')?( and save the value in environment variable \'(.+?)\')?$")
        public void executeCommand​(String command,
                                   String foo,
                                   Integer exitStatus,
                                   String bar,
                                   String envVar)
                            throws Exception
        Executes the command specified in remote system
        Parameters:
        command - command to be run locally
        foo - regex needed to match method
        exitStatus - command exit status
        bar - regex needed to match method
        envVar - environment variable name
        Throws:
        Exception - exception
      • assertCommandExistsOnTimeOut

        @Then("^in less than \'(\\d+?)\' seconds, checking each \'(\\d+?)\' seconds, the command output \'(.+?)\' contains \'(.+?)\'$")
        public void assertCommandExistsOnTimeOut​(Integer timeout,
                                                 Integer wait,
                                                 String command,
                                                 String search)
                                          throws Exception
        Checks if expectedCount element is found, whithin a timeout and with a location method. Each negative lookup is followed by a wait of wait seconds. Selenium times are not accounted for the mentioned timeout.
        Parameters:
        timeout - the max timeto wait
        wait - checking interval
        command - the command
        search - text to search for
        Throws:
        Exception - exception
      • findShellOutput

        @Then("^the command output contains \'(.+?)\'$")
        public void findShellOutput​(String search)
                             throws Exception
        Check the existence of a text at a command output
        Parameters:
        search - Text to search
        Throws:
        Exception - Exception
      • notFindShellOutput

        @Then("^the command output does not contain \'(.+?)\'$")
        public void notFindShellOutput​(String search)
                                throws Exception
        Check the non existence of a text at a command output
        Parameters:
        search - Text to search
        Throws:
        Exception - Exception
      • checkShellExitStatus

        @Deprecated
        @Then("^the command exit status is \'(.+?)\'$")
        public void checkShellExitStatus​(int expectedExitStatus)
                                  throws Exception
        Deprecated.
        Success exit status is directly checked in the "execute remote command" method, so this is not needed anymore.
        Check the exitStatus of previous command execution matches the expected one
        Parameters:
        expectedExitStatus - Expected result of the command execution
        Throws:
        Exception - Exception