Class JdbcExecutor<T extends JdbcExecutor<T>>
Asserts:
seeRowsCountInTableExactly(String, Object[][], int)
seeRowsCountInTableExactlyCustom(String, String, int)
seeRowsCountInTableExactly(String, int)
seeTableIsEmpty(String)
seeTableDoesNotEmpty(String)
seeRecordExistsInTable(String, Object[][])
seeRecordExistsInTable(String, String)
Operations with data:
insertIntoTable(String, Object[][], Object[][])
insertIntoTable(String, Object[][])
insertIntoTable(String, String)
runScriptFromFile(String)
runScript(String)
truncateTable(String)
truncateTables(String...)
deleteFromTable(String)
deleteFromTable(String, Object[][])
deleteFromTable(String, String)
updateTable(String, Object[][])
updateTable(String, Object[][], Object[][])
deleteFromTable(String, String)
For attachments:
showDataFromTable(String)
showDataByCondition(String, Object[][])
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
ConstructorsModifierConstructorDescriptionprotectedJdbcExecutor(String dbType, String getColumnsQuery) Constructs db client configuration.protected -
Method Summary
Modifier and TypeMethodDescriptionprotected voidassertCountInTableBuilder(String tableName, String conditions, Object[][] conditionsArray, String expectedCount, int awaitMs) voiddeleteFromTable(String tableName) Delete all records in tablevoiddeleteFromTable(String tableName, Object[][] conditionsArray) Delete from table by conditionsvoiddeleteFromTable(String tableName, String conditions) Delete from table by conditionsReturns a human-readable summary of the current SQL configuration.protected String[]getTableColumns(String tableName) Get array with table column listvoidinsertIntoTable(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) Rename table(add suffix "_X_")voidrollbackTable(String tableName) Rollback table(remove suffix "_X_") afterSqlPost.renameTable(java.lang.String)voidExecute sql script manual used for manual scripts (not recommended)voidrunScriptFromFile(String path) Execute sql script from file used for init db on test startUpprotected voidseeInDbByCondMethod(String tableName, String conditions) voidseeRecordExistsInTable(String tableName, Object[][] conditionsArray) Assert that exists at least one record by conditionsvoidseeRecordExistsInTable(String tableName, String providedJson) Assert that exists at least one record by conditionsvoidseeRecordExistsInTableCustom(String tableName, String conditions) Assert that exists at least one record by conditions with awaitvoidseeRowsCountInTableExactly(String tableName, int expectedCount) Assert of records EXACTLY countvoidseeRowsCountInTableExactly(String tableName, Object[][] conditionsArray, int expectedCount) Assert of records EXACTLY count by conditionsvoidseeRowsCountInTableExactly(String tableName, String providedJson, int expectedCount) Assert of records EXACTLY countvoidseeRowsCountInTableExactlyCustom(String tableName, String conditions, int expectedCount) Assert of records EXACTLY count by conditionsvoidseeTableDoesNotEmpty(String tableName) Assert That table has at least one recordvoidseeTableIsEmpty(String tableName) Assert That table has no recordsprotected Tself()setAwaitMs(int awaitMs) Configure global await for asserts with awaitsetTemplatesDirectory(String templatesPath) Configure directory in resources for tables templatesvoidshowDataByCondition(String tableName, Object[][] conditionsArray) Method to show full record/records by condition if existsvoidshowDataFromTable(String tableName) Method to create attachment with all rows by all columns in tableprotected voidshowDataFromTableMethod(String tableName) voidtruncateTable(String tableName) Truncate(clean) tablevoidtruncateTables(String... tablesNames) Truncate(clean) tablesvoidupdateTable(String tableName, Object[][] setArray) Update all records in tablevoidupdateTable(String tableName, Object[][] setArray, Object[][] conditionsArray) Update records in table by conditionsvoidupdateTable(String tableName, String conditions) Update records in table by conditionswithAwaitMs(int specificAwaitMs) Configure await for next assert with await (than await rollback to global) globalSqlConfig.setAwaitMs(int)will be ignored
-
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:
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 (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:SqlConfigConfigure global await for asserts with await- Specified by:
setAwaitMsin interfaceSqlConfig<T extends JdbcExecutor<T>>- Parameters:
awaitMs- ms await- Returns:
- this instance for method chaining
-
withAwaitMs
Description copied from interface:SqlConfigConfigure await for next assert with await (than await rollback to global) globalSqlConfig.setAwaitMs(int)will be ignored- Specified by:
withAwaitMsin interfaceSqlConfig<T extends JdbcExecutor<T>>- Parameters:
specificAwaitMs- ms await- Returns:
- this instance for method chaining
-
setTemplatesDirectory
Description copied from interface:SqlConfigConfigure directory in resources for tables templates- Specified by:
setTemplatesDirectoryin interfaceSqlConfig<T extends JdbcExecutor<T>>- Parameters:
templatesPath- path in resources "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- schema_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- schema_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- schema_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:SqlPostExecute sql script from file used for init db on test startUp- Specified by:
runScriptFromFilein interfaceSqlPost- Parameters:
path- path to file in resources
-
runScript
Description copied from interface:SqlPostExecute sql script manual used for manual scripts (not recommended) -
truncateTable
Description copied from interface:SqlPostTruncate(clean) table- Specified by:
truncateTablein interfaceSqlPost- Parameters:
tableName- schema_name.table_name
-
truncateTables
Description copied from interface:SqlPostTruncate(clean) tables- Specified by:
truncateTablesin interfaceSqlPost- Parameters:
tablesNames- list of tables
-
updateTable
Description copied from interface:SqlPostUpdate all records in table- Specified by:
updateTablein interfaceSqlPost- Parameters:
tableName- schema_name.table_namesetArray- Object[][] {{"column1", "value1"},...}
-
updateTable
Description copied from interface:SqlPostUpdate records in table by conditions- Specified by:
updateTablein interfaceSqlPost- Parameters:
tableName- schema_name.table_namesetArray- Object[][] {{"column1", "value1"},...}conditionsArray- Object[][] {{"column1", "value1"},...}
-
updateTable
@Step("(DB) Delete from {tableName} {conditions}") public void updateTable(String tableName, String conditions) Description copied from interface:SqlPostUpdate records in table by conditions- Specified by:
updateTablein interfaceSqlPost- Parameters:
tableName- schema_name.table_nameconditions- String "SET USERNAME='Alex' where ID=5"
-
deleteFromTable
Description copied from interface:SqlPostDelete all records in table- Specified by:
deleteFromTablein interfaceSqlPost- Parameters:
tableName- schema_name.table_name
-
deleteFromTable
Description copied from interface:SqlPostDelete from table by conditions- Specified by:
deleteFromTablein interfaceSqlPost- Parameters:
tableName- schema_name.table_nameconditionsArray- Object[][] {{"column1", "value1"},...}
-
deleteFromTable
@Step("(DB) Delete from {tableName} {conditions}") public void deleteFromTable(String tableName, String conditions) Description copied from interface:SqlPostDelete from table by conditions- Specified by:
deleteFromTablein interfaceSqlPost- Parameters:
tableName- schema_name.table_nameconditions- String "where id=1"
-
renameTable
Description copied from interface:SqlPostRename table(add suffix "_X_")Note: After test rollback with
SqlPost.rollbackTable(java.lang.String).- Specified by:
renameTablein interfaceSqlPost- Parameters:
tableName- schema_name.table_name
-
rollbackTable
Description copied from interface:SqlPostRollback table(remove suffix "_X_") afterSqlPost.renameTable(java.lang.String)- Specified by:
rollbackTablein interfaceSqlPost- Parameters:
tableName- schema_name.table_name
-
seeRowsCountInTableExactly
public void seeRowsCountInTableExactly(String tableName, Object[][] conditionsArray, int expectedCount) Description copied from interface:SqlGetAssert of records EXACTLY count by conditionswith await
- Specified by:
seeRowsCountInTableExactlyin interfaceSqlGet- Parameters:
tableName- schema_name.table_nameconditionsArray- Object[][] with template {{"column1", "value1"},...}expectedCount- expected rows count
-
seeRowsCountInTableExactly
Description copied from interface:SqlGetAssert of records EXACTLY countwith await
Use custom sql conditions only if it`s necessary, otherwise use
SqlGet.seeRowsCountInTableExactly(java.lang.String, java.lang.Object[][], int)- Specified by:
seeRowsCountInTableExactlyin interfaceSqlGet- Parameters:
tableName- schema_name.table_nameprovidedJson- String with json """{"column1": "test_value1", ...}"""
support up to 2 options in key after field
"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:SqlGetAssert of records EXACTLY count by conditionswith await
- Specified by:
seeRowsCountInTableExactlyCustomin interfaceSqlGet- Parameters:
tableName- schema_name.table_nameconditions- String "where id=1"expectedCount- expected rows count
-
seeRowsCountInTableExactly
Description copied from interface:SqlGetAssert of records EXACTLY countwith await
- Specified by:
seeRowsCountInTableExactlyin interfaceSqlGet- Parameters:
tableName- schema_name.table_nameexpectedCount- expected rows count
-
seeTableIsEmpty
Description copied from interface:SqlGetAssert That table has no recordswith await
- Specified by:
seeTableIsEmptyin interfaceSqlGet- Parameters:
tableName- schema_name.table_name
-
seeRecordExistsInTableCustom
Description copied from interface:SqlGetAssert that exists at least one record by conditions with awaitUse custom sql conditions only if it`s necessary, otherwise use
SqlGet.seeRecordExistsInTable(java.lang.String, java.lang.Object[][])- Specified by:
seeRecordExistsInTableCustomin interfaceSqlGet- Parameters:
tableName- schema_name.table_nameconditions- String "where id=1"
-
seeRecordExistsInTable
Description copied from interface:SqlGetAssert that exists at least one record by conditionswith await
- Specified by:
seeRecordExistsInTablein interfaceSqlGet- Parameters:
tableName- schema_name.table_nameprovidedJson- String with json """{"column1": "test_value1", ...}"""
support up to 2 options in key after field
"CREATE_DATE:>="
"CREATE_DATE:=:TIMESTAMP" (for oracleDd)
-
seeRecordExistsInTable
Description copied from interface:SqlGetAssert that exists at least one record by conditionswith await
- Specified by:
seeRecordExistsInTablein interfaceSqlGet- Parameters:
tableName- schema_name.table_nameconditionsArray- Object[][] with template {{"column1", "value1"},...}
-
seeTableDoesNotEmpty
Description copied from interface:SqlGetAssert That table has at least one recordwith await
- Specified by:
seeTableDoesNotEmptyin interfaceSqlGet- Parameters:
tableName- schema_name.table_name
-
showDataByCondition
Description copied from interface:SqlGetMethod to show full record/records by condition if exists- Specified by:
showDataByConditionin interfaceSqlGet- Parameters:
tableName- schema_name.table_nameconditionsArray- Object[][] with conditions {{"ID", "1"}, {"NAME", "Alex"}}
-
showDataFromTable
Description copied from interface:SqlGetMethod to create attachment with all rows by all columns in table- Specified by:
showDataFromTablein interfaceSqlGet- Parameters:
tableName- schema_name.table_name
-
assertCountInTableBuilder
-
recordExistsBuilder
-
showDataFromTableMethod
-
seeInDbByCondMethod
-
getTableColumns
Get array with table column list- Parameters:
tableName- table name- Returns:
- Strings... with columns names
-