Package com.privalia.qa.specs
Class SqlDatabaseGSpec
- java.lang.Object
-
- com.privalia.qa.specs.BaseGSpec
-
- com.privalia.qa.specs.SqlDatabaseGSpec
-
public class SqlDatabaseGSpec extends BaseGSpec
Steps definitions for working with relational databases (postgresql and mysql)- Author:
- Jose Fernandez
-
-
Field Summary
-
Fields inherited from class com.privalia.qa.specs.BaseGSpec
commonspec
-
-
Constructor Summary
Constructors Constructor Description SqlDatabaseGSpec(CommonG spec)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
compareTable(io.cucumber.datatable.DataTable dataTable)
Verifies the results of a SELECT query against aDataTable
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.void
disconnectDatabase()
Close the Database connectionvoid
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.void
executeQueryFromFile(String baseData)
Executes an SQL from a file.void
executeSelectQuery(String query)
Executes the given SQL statement, which returns a single ResultSet object.void
saveSqlResultInVariable(int rowNumber, String columnName, String envVar)
Save an specific element (by row and column) in an environmental variablevoid
verifyTableContent(String tableName, io.cucumber.datatable.DataTable dataTable)
Verify if the content of a table matches the givenDataTable
void
verifyTableDoesNotExists(String tableName)
Verify if a table does not existsvoid
verifyTableExists(String tableName)
Verify if a table exists-
Methods inherited from class com.privalia.qa.specs.BaseGSpec
getCommonSpec
-
-
-
-
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 connectiondatabase
- Name of the remote databasedataBaseType
- Database type (currently MYSQL/POSTGRESQL)host
- URL of remote hostport
- Database portuser
- Database userpassword
- 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 aDataTable
- 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 givenDataTable
- Parameters:
tableName
- Table namedataTable
-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 aResultSet
, 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 numbercolumnName
- the column nameenvVar
- the env var Name
-
-