Class SqlDatabaseGSpec


  • public class SqlDatabaseGSpec
    extends BaseGSpec
    Steps definitions for working with relational databases (postgresql and mysql)
    Author:
    Jose Fernandez
    • Constructor Detail

      • SqlDatabaseGSpec

        public SqlDatabaseGSpec​(CommonG spec)
    • Method Detail

      • connectDatabase

        @Given("^I( securely)? connect with JDBC to database \'(.+?)\' type \'(mysql|postgresql)\' on host \'(.+?)\' and port \'(.+?)\' with user \'(.+?)\'( and password \'(.+?)\')?$")
        public void connectDatabase​(String isSecured,
                                    String database,
                                    String dataBaseType,
                                    String host,
                                    String port,
                                    String user,
                                    String password)
        Attempts to establish a connection with the given parameters. The DriverManager attempts to select an appropriate driver from the set of registered JDBC drivers.
        Parameters:
        isSecured - True if secure connection
        database - Name of the remote database
        dataBaseType - Database type (currently MYSQL/POSTGRESQL)
        host - URL of remote host
        port - Database port
        user - Database user
        password - Database password
      • disconnectDatabase

        @Then("^I close database connection$")
        public void disconnectDatabase()
        Close the Database connection
      • executeQuery

        @When("^I execute query \'(.+?)\'$")
        public void executeQuery​(String query)
        Executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement.
        Parameters:
        query - An SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement.
      • verifyTableExists

        @Then("^table \'(.+?)\' exists$")
        public void verifyTableExists​(String tableName)
        Verify if a table exists
        Parameters:
        tableName - Table name
      • verifyTableDoesNotExists

        @Then("^table \'(.+?)\' doesn\'t exists$")
        public void verifyTableDoesNotExists​(String tableName)
        Verify if a table does not exists
        Parameters:
        tableName - Table name
      • executeSelectQuery

        @When("^I query the database with \'(.+?)\'$")
        public void executeSelectQuery​(String query)
        Executes the given SQL statement, which returns a single ResultSet object.
        Parameters:
        query - An SQL statement to be sent to the database, typically a static SQL SELECT statement
      • compareTable

        @Then("^I check that result is:$")
        public void compareTable​(io.cucumber.datatable.DataTable dataTable)
        Verifies the results of a SELECT query against a DataTable
        Parameters:
        dataTable - list of casses to assert in a table format
      • verifyTableContent

        @Then("^I check that table \'(.+?)\' is iqual to$")
        public void verifyTableContent​(String tableName,
                                       io.cucumber.datatable.DataTable dataTable)
        Verify if the content of a table matches the given DataTable
        Parameters:
        tableName - Table name
        dataTable - DataTable to match against
      • executeQueryFromFile

        @Then("^I execute query from \'(.+?)\'")
        public void executeQueryFromFile​(String baseData)
                                  throws IOException
        Executes an SQL from a file. The SQL could be of any kind (a typical SELECT or a SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE) or even SQL Scripts. If the SQL returns a ResultSet, it is stored internally so further steps can use it
        Parameters:
        baseData - File location (typically schemas/myfile.sql)
        Throws:
        IOException - IOException
      • saveSqlResultInVariable

        @Then("^I save the value of the row number \'(\\d+?)\' and the column with name \'(.+?)\' in environment variable \'(.+?)\'$")
        public void saveSqlResultInVariable​(int rowNumber,
                                            String columnName,
                                            String envVar)
        Save an specific element (by row and column) in an environmental variable
        Parameters:
        rowNumber - the row number
        columnName - the column name
        envVar - the env var Name