Class JdbcExecutor<T extends JdbcExecutor<T>>
Supported dbTypes: DbTypes
Await for asserts default: awaitMs, can be changed globally by: setAwaitMs(int), or once for specific assert by withAwaitMs(int)
Path to template files for insert default: templatesPath, can be changed by: setTemplatesDirectory(String)
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedprotectedJdbcExecutor(DbTypes dbType, String getColumnsQuery) Constructs db client configuration. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidassertCountInTableBuilder(String tableName, String conditions, Object[][] conditionsArray, String expectedCount, int awaitMs) voiddeleteFromTable(String tableName) Deletes all records from the table.voiddeleteFromTable(String tableName, Object[][] conditionsArray) Deletes all records from the table matching the specified conditions (in an Object[][] array).voiddeleteFromTable(String tableName, String conditions) Deletes all records from the table matching the specified conditions (hardcoded SQL condition string).Returns a human-readable summary of the current SQL configuration.protected String[]getTableColumns(String tableName) Returns the list of columns in the table.voidinsertIntoTable(String tableName, Object[][] providedArray) Merge arrays with template datavoidinsertIntoTable(String tableName, Object[][] templateArray, Object[][] providedArray) Merge arrays with data for insert into tablevoidinsertIntoTable(String tableName, String providedJson) Merge arrays with template dataprotected voidrecordExistsBuilder(String tableName, String conditions, Object[][] conditionsArray, int awaitMs) voidrenameTable(String tableName) Renames the specified table by adding the"_X_"suffix.voidrollbackTable(String tableName) Rolls back the table name by removing the"_X_"suffix added bySqlPost.renameTable(java.lang.String).voidExecutes the specified SQL script manually.voidrunScriptFromFile(String path) Executes an SQL script from a file.protected voidseeInDbByCondMethod(String tableName, String conditions) voidseeRecordExistsInTable(String tableName, Object[][] conditionsArray) Asserts that the table has at least one record by conditions (in an Object[][] array).voidseeRecordExistsInTable(String tableName, String providedJson) Asserts that the table has at least one record by conditions (in a JSON string).voidseeRecordExistsInTableCustom(String tableName, String conditions) Asserts that the table has at least one record by conditions (hardcoded SQL condition string).voidseeRowsCountInTableExactly(String tableName, int expectedCount) Asserts that the table contains exactly the expected number of records.voidseeRowsCountInTableExactly(String tableName, Object[][] conditionsArray, int expectedCount) Asserts that the table contains exactly the expected number of records matching the specified conditions (in an Object[][] array).voidseeRowsCountInTableExactly(String tableName, String providedJson, int expectedCount) Asserts that the table contains exactly the expected number of records matching the specified conditions (in a JSON string).voidseeRowsCountInTableExactlyCustom(String tableName, String conditions, int expectedCount) Asserts that the table contains exactly the expected number of records matching the specified conditions (hardcoded SQL conditions string).voidseeTableIsEmpty(String tableName) Asserts that the table has no records.voidseeTableIsNotEmpty(String tableName) Asserts that the table is not empty.protected Tself()setAwaitMs(int awaitMs) Configures the global await timeout for assertions that use await.setTemplatesDirectory(String templatesPath) Configures the directory in resources containing tables templates.voidshowDataByCondition(String tableName, Object[][] conditionsArray) Creates an attachment containing all records matching the specified conditions.voidshowDataFromTable(String tableName) /** Creates an attachment containing all records and columns from the table.protected voidshowDataFromTableMethod(String tableName) voidtruncateTable(String tableName) Truncates the table.voidtruncateTables(String... tablesNames) Truncates the tables.voidupdateTable(String tableName, Object[][] setArray) Updates all records in the table.voidupdateTable(String tableName, Object[][] setArray, Object[][] conditionsArray) Updates all records in the table matching the specified conditions (in an Object[][] array).voidupdateTable(String tableName, String conditions) Updates all records in the table matching the specified conditions (hardcoded SQL condition string).withAwaitMs(int specificAwaitMs) Sets a custom await timeout for the next assertion.
-
Field Details
-
jdbc
-
getColumnsQuery
-
url
-
username
-
password
-
SELECT_ALL
- See Also:
-
COUNT
- See Also:
-
-
Constructor Details
-
JdbcExecutor
-
JdbcExecutor
Constructs db client configuration.Loads configuration values from a YAML file.
Default file:
bugreaper.ymlCustom file: using
-DbugreaperEnv=testloadsbugreaper-test.ymlRequired configuration keys:
Supported dbTypes: values of
DbTypesmodules.db.{dbType}.urlmodules.db.{dbType}.portmodules.db.{dbType}.usernamemodules.db.{dbType}.password
Optional configuration keys:
modules.db.{dbType}.await
- Parameters:
dbType- the database type identifier values ofDbTypes(e.g., "mariadb", "custom-db");getColumnsQuery- query to get all columns names from table;Missing required keys will result in configuration errors. Missing optional keys will fall back to predefined defaults.
-
-
Method Details
-
self
-
setAwaitMs
Description copied from interface:SqlConfigConfigures the global await timeout for assertions that use await.- Specified by:
setAwaitMsin interfaceSqlConfig<T extends JdbcExecutor<T>>- Parameters:
awaitMs- await timeout in milliseconds- Returns:
- this instance for method chaining
-
withAwaitMs
Description copied from interface:SqlConfigSets a custom await timeout for the next assertion.After the operation is completed, the timeout is reset to the global value configured by
SqlConfig.setAwaitMs(int).- Specified by:
withAwaitMsin interfaceSqlConfig<T extends JdbcExecutor<T>>- Parameters:
specificAwaitMs- await timeout in milliseconds- Returns:
- this instance for method chaining
-
setTemplatesDirectory
Description copied from interface:SqlConfigConfigures the directory in resources containing tables templates.- Specified by:
setTemplatesDirectoryin interfaceSqlConfig<T extends JdbcExecutor<T>>- Parameters:
templatesPath- path to the templates directory in resources (example:"my_dir/sub_dir/")- Returns:
- this instance for method chaining
-
getConfigSummary
Description copied from interface:SqlConfigReturns a human-readable summary of the current SQL configuration.The returned string typically includes all configuration values such as query text, parameters, execution options, timeouts, or any other settings managed by the implementing class.
As a side effect, this method logs the generated summary at the INFO level. This can be useful for debugging or tracing configuration usage during test execution.
- Specified by:
getConfigSummaryin interfaceSqlConfig<T extends JdbcExecutor<T>>- Returns:
- a string containing a formatted summary of all configuration values
-
insertIntoTable
Description copied from interface:SqlPostMerge arrays with data for insert into tableWrap this method with table name and template to provide only providedArray
example:
tableName: "schema.table1" templateArray {{"id", 2}, {"name", "Alex"}, {"age", 21}, {"fee", "33.05"}} providedArray {{"name", "Nikita"}, {"fee", null}} result: INSERT INTO schema.table1 (id, name, age, fee) VALUES(2, 'Nikita', 21, null)- Specified by:
insertIntoTablein interfaceSqlPost- Parameters:
tableName- table name in the formatschema_name.table_nametemplateArray- Object[][] with template {{"column1", "value1"},...}providedArray- Object[][] with test data for merge {{"column1", "test_value1"},...}
NOTE: for oracleDb dateTime insert supported 3 elements {"CREATE_DATE", "2020-01-01 10:00:00", "TIMESTAMP"}
CREATE_DATE = TO_DATE('2020-01-01 10:00:00', 'YYYY-MM-DD HH24:MI:SS'),
-
insertIntoTable
Description copied from interface:SqlPostMerge arrays with template dataexample:
tableName: "schema.table1"
(will search in resources file templates/{database_type}/schema.table1.json)
database_types :DbTypes
default path can be changed bysetTemplatesDirectory(String)
{ "id": 2, "name": "Alex", "age": 21, "fee": 33.05 }providedArray {{"name", "Nikita"}, {"fee", null}}
result:
INSERT INTO schema.table1
(id, name, age, fee)
VALUES(2, 'Nikita', 21, null)
NOTE: for oracleDb dateTime insert supported 3 elements in json {"CREATE_DATE:TIMESTAMP", "2020-01-01 10:00:00"}
CREATE_DATE = TO_DATE('2020-01-01 10:00:00', 'YYYY-MM-DD HH24:MI:SS'),- Specified by:
insertIntoTablein interfaceSqlPost- Parameters:
tableName- table name in the formatschema_name.table_nameprovidedArray- Object[][] with test data for merge {{"column1", "test_value1"},...}
NOTE: for oracleDb dateTime insert supported 3 elements {"CREATE_DATE", "2020-01-01 10:00:00", "TIMESTAMP"}
CREATE_DATE = TO_DATE('2020-01-01 10:00:00', 'YYYY-MM-DD HH24:MI:SS'),
-
insertIntoTable
Description copied from interface:SqlPostMerge arrays with template dataexample:
tableName: "schema.table1"
(will search in resources file templates/${database_type}/schema.table1.json)
database_types :DbTypes
default path can be changed bysetTemplatesDirectory(String){ "id": 2, "name": "Alex", "age": 21, "fee": 33.05 }providedJson:{ "name": "Nikita", "fee": null }result:
INSERT INTO schema.table1
(id, name, age, fee)
VALUES(2, 'Nikita', 21, null)- Specified by:
insertIntoTablein interfaceSqlPost- Parameters:
tableName- table name in the formatschema_name.table_nameprovidedJson- String with json to merge """{"column1": "test_value1", ...}"""
NOTE: for oracleDb dateTime insert supported 3 elements in json {"CREATE_DATE:TIMESTAMP", "2020-01-01 10:00:00"}
CREATE_DATE = TO_DATE('2020-01-01 10:00:00', 'YYYY-MM-DD HH24:MI:SS'),
-
runScriptFromFile
Description copied from interface:SqlPostExecutes an SQL script from a file.Used to initialize the database at test startup or in other cases.
- Specified by:
runScriptFromFilein interfaceSqlPost- Parameters:
path- path to the file in test resources
-
runScript
Description copied from interface:SqlPostExecutes the specified SQL script manually.Used for manual scripts and not recommended for regular test operations.
-
truncateTable
Description copied from interface:SqlPostTruncates the table.- Specified by:
truncateTablein interfaceSqlPost- Parameters:
tableName- table name in the formatschema_name.table_name
-
truncateTables
Description copied from interface:SqlPostTruncates the tables.- Specified by:
truncateTablesin interfaceSqlPost- Parameters:
tablesNames- list of tables
-
updateTable
Description copied from interface:SqlPostUpdates all records in the table.- Specified by:
updateTablein interfaceSqlPost- Parameters:
tableName- table name in the formatschema_name.table_namesetArray- values to update in the format{{"column1", "value1"}, ...}
-
updateTable
Description copied from interface:SqlPostUpdates all records in the table matching the specified conditions (in an Object[][] array).- Specified by:
updateTablein interfaceSqlPost- Parameters:
tableName- table name in the formatschema_name.table_namesetArray- Object[][] {{"column1", "value1"},...}conditionsArray- Object[][] {{"column1", "value1"},...}
-
updateTable
@Step("(DB) Delete from table \'{tableName}\' {conditions}") public void updateTable(String tableName, String conditions) Description copied from interface:SqlPostUpdates all records in the table matching the specified conditions (hardcoded SQL condition string).- Specified by:
updateTablein interfaceSqlPost- Parameters:
tableName- table name in the formatschema_name.table_nameconditions- String "SET USERNAME='Alex' where ID=5"
-
deleteFromTable
Description copied from interface:SqlPostDeletes all records from the table.- Specified by:
deleteFromTablein interfaceSqlPost- Parameters:
tableName- table name in the formatschema_name.table_name
-
deleteFromTable
Description copied from interface:SqlPostDeletes all records from the table matching the specified conditions (in an Object[][] array).- Specified by:
deleteFromTablein interfaceSqlPost- Parameters:
tableName- table name in the formatschema_name.table_nameconditionsArray- Object[][] {{"column1", "value1"},...}
-
deleteFromTable
@Step("(DB) Delete from table \'{tableName}\' {conditions}") public void deleteFromTable(String tableName, String conditions) Description copied from interface:SqlPostDeletes all records from the table matching the specified conditions (hardcoded SQL condition string).- Specified by:
deleteFromTablein interfaceSqlPost- Parameters:
tableName- table name in the formatschema_name.table_nameconditions- String "where id=1"
-
renameTable
Description copied from interface:SqlPostRenames the specified table by adding the"_X_"suffix.Note: Roll back the table name after the test using
SqlPost.rollbackTable(java.lang.String).- Specified by:
renameTablein interfaceSqlPost- Parameters:
tableName- table name in the formatschema_name.table_name
-
rollbackTable
Description copied from interface:SqlPostRolls back the table name by removing the"_X_"suffix added bySqlPost.renameTable(java.lang.String).- Specified by:
rollbackTablein interfaceSqlPost- Parameters:
tableName- table name in the formatschema_name.table_name
-
seeRowsCountInTableExactly
public void seeRowsCountInTableExactly(String tableName, Object[][] conditionsArray, int expectedCount) Description copied from interface:SqlGetAsserts that the table contains exactly the expected number of records matching the specified conditions (in an Object[][] array).Uses await.
for example:
db.seeRowsCountInTableExactly("test.users", new Object[][]{ {"name", "Alex"}, {"id", ">=", 2} }, 1);- Specified by:
seeRowsCountInTableExactlyin interfaceSqlGet- Parameters:
tableName- table name in the formatschema_name.table_nameconditionsArray- conditions in Object[][] format support up to 2 options after field (column, condition, date, oracle-enum)
{"COLUMN NAME", ">= ", "2020-01-01", "DATE"}for oracleexpectedCount- expected rows count
-
seeRowsCountInTableExactly
Description copied from interface:SqlGetAsserts that the table contains exactly the expected number of records matching the specified conditions (in a JSON string).Uses await.
for example:
db.seeRowsCountInTableExactly("test.users", """ { "name": "Alex", "id:>": 2 }"""), 1;- Specified by:
seeRowsCountInTableExactlyin interfaceSqlGet- Parameters:
tableName- table name in the formatschema_name.table_nameprovidedJson- conditions in JSON format support up to 2 options in key after field (column:condition:oracle-enum)
"CREATE_DATE:>="
"CREATE_DATE:=:TIMESTAMP"(for oracleDd)expectedCount- expected rows count
-
seeRowsCountInTableExactlyCustom
public void seeRowsCountInTableExactlyCustom(String tableName, String conditions, int expectedCount) Description copied from interface:SqlGetAsserts that the table contains exactly the expected number of records matching the specified conditions (hardcoded SQL conditions string).Uses await.
for example:
db.seeRowsCountInTableExactly("test.users", "where id=1", 1);- Specified by:
seeRowsCountInTableExactlyCustomin interfaceSqlGet- Parameters:
tableName- table name in the formatschema_name.table_nameconditions- hardcoded SQL conditions stringfor example:
"where id=1"expectedCount- expected rows count
-
seeRowsCountInTableExactly
Description copied from interface:SqlGetAsserts that the table contains exactly the expected number of records.Uses await.
- Specified by:
seeRowsCountInTableExactlyin interfaceSqlGet- Parameters:
tableName- table name in the formatschema_name.table_nameexpectedCount- expected rows count
-
seeTableIsEmpty
Description copied from interface:SqlGetAsserts that the table has no records.Uses await.
- Specified by:
seeTableIsEmptyin interfaceSqlGet- Parameters:
tableName- table name in the formatschema_name.table_name
-
seeRecordExistsInTableCustom
Description copied from interface:SqlGetAsserts that the table has at least one record by conditions (hardcoded SQL condition string).Uses await.
for example:
db.seeRecordExistsInTableCustom("test.users", "where id=1");- Specified by:
seeRecordExistsInTableCustomin interfaceSqlGet- Parameters:
tableName- table name in the formatschema_name.table_nameconditions- hardcoded SQL condition stringfor example:
"where id=1"
-
seeRecordExistsInTable
Description copied from interface:SqlGetAsserts that the table has at least one record by conditions (in a JSON string).Uses await.
for example:
db.seeRecordExistsInTable("test.users", """ { "name": "Alex", "id:>": 2 }""");- Specified by:
seeRecordExistsInTablein interfaceSqlGet- Parameters:
tableName- table name in the formatschema_name.table_nameprovidedJson- conditions in JSON format support up to 2 options in key after field (column:condition:oracle-enum)
"CREATE_DATE:>="
"CREATE_DATE:=:TIMESTAMP"(for oracleDd)
-
seeRecordExistsInTable
Description copied from interface:SqlGetAsserts that the table has at least one record by conditions (in an Object[][] array).Uses await.
for example:
db.seeRecordExistsInTable("test.users", new Object[][]{ {"name", "Alex"}, {"id", ">=", 2} });- Specified by:
seeRecordExistsInTablein interfaceSqlGet- Parameters:
tableName- table name in the formatschema_name.table_nameconditionsArray- conditions in Object[][] format support up to 2 options after field (column, condition, date, oracle-enum)
{"COLUMN NAME", ">= ", "2020-01-01", "DATE"}for oracle
-
seeTableIsNotEmpty
Description copied from interface:SqlGetAsserts that the table is not empty.Uses await.
- Specified by:
seeTableIsNotEmptyin interfaceSqlGet- Parameters:
tableName- table name in the formatschema_name.table_name
-
showDataByCondition
Description copied from interface:SqlGetCreates an attachment containing all records matching the specified conditions.db.showDataByCondition("test.users", new Object[][]{ {"ID", 1}, {"NAME", "Alex"} });- Specified by:
showDataByConditionin interfaceSqlGet- Parameters:
tableName- table name in the formatschema_name.table_nameconditionsArray- conditions in the format{{"ID", "1"}, {"NAME", "Alex"}}
-
showDataFromTable
Description copied from interface:SqlGet/** Creates an attachment containing all records and columns from the table.- Specified by:
showDataFromTablein interfaceSqlGet- Parameters:
tableName- table name in the formatschema_name.table_name
-
assertCountInTableBuilder
-
recordExistsBuilder
-
showDataFromTableMethod
-
seeInDbByCondMethod
-
getTableColumns
Returns the list of columns in the table.- Parameters:
tableName- table name in the formatschema_name.table_name- Returns:
- array containing column names
-