Class JdbcExecutor<T extends JdbcExecutor<T>>

java.lang.Object
net.bugreaper.modules.db.jdbc.JdbcExecutor<T>
All Implemented Interfaces:
SqlConfig<T>, SqlGet, SqlPost
Direct Known Subclasses:
CustomDb, MariaDb, MsSQL, MySQL, OracleDb, PostgreSQL

public abstract class JdbcExecutor<T extends JdbcExecutor<T>> extends Object implements SqlPost, SqlGet, SqlConfig<T>
Parent class for interacting with Databases

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 Details

  • Constructor Details

    • JdbcExecutor

      protected JdbcExecutor(String url, String username, String password, String getColumnsQuery, DbTypes dbType)
    • JdbcExecutor

      protected JdbcExecutor(DbTypes dbType, String getColumnsQuery)
      Constructs db client configuration.

      Loads configuration values from a YAML file.

      Default file: bugreaper.yml

      Custom file: using -DbugreaperEnv=test loads bugreaper-test.yml

      Required configuration keys:

      Supported dbTypes: values of DbTypes

      • modules.db.{dbType}.url
      • modules.db.{dbType}.port
      • modules.db.{dbType}.username
      • modules.db.{dbType}.password

      Optional configuration keys:

      • modules.db.{dbType}.await
      Parameters:
      dbType - the database type identifier values of DbTypes (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

      protected T self()
    • setAwaitMs

      public T setAwaitMs(int awaitMs)
      Description copied from interface: SqlConfig
      Configures the global await timeout for assertions that use await.
      Specified by:
      setAwaitMs in interface SqlConfig<T extends JdbcExecutor<T>>
      Parameters:
      awaitMs - await timeout in milliseconds
      Returns:
      this instance for method chaining
    • withAwaitMs

      public T withAwaitMs(int specificAwaitMs)
      Description copied from interface: SqlConfig
      Sets 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:
      withAwaitMs in interface SqlConfig<T extends JdbcExecutor<T>>
      Parameters:
      specificAwaitMs - await timeout in milliseconds
      Returns:
      this instance for method chaining
    • setTemplatesDirectory

      public T setTemplatesDirectory(String templatesPath)
      Description copied from interface: SqlConfig
      Configures the directory in resources containing tables templates.
      Specified by:
      setTemplatesDirectory in interface SqlConfig<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

      public String getConfigSummary()
      Description copied from interface: SqlConfig
      Returns 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:
      getConfigSummary in interface SqlConfig<T extends JdbcExecutor<T>>
      Returns:
      a string containing a formatted summary of all configuration values
    • insertIntoTable

      public void insertIntoTable(String tableName, Object[][] templateArray, Object[][] providedArray)
      Description copied from interface: SqlPost
      Merge arrays with data for insert into table

      Wrap 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:
      insertIntoTable in interface SqlPost
      Parameters:
      tableName - table name in the format schema_name.table_name
      templateArray - 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

      public void insertIntoTable(String tableName, Object[][] providedArray)
      Description copied from interface: SqlPost
      Merge arrays with template data

      example:
      tableName: "schema.table1"
      (will search in resources file templates/{database_type}/schema.table1.json)
      database_types : DbTypes
      default path can be changed by setTemplatesDirectory(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:
      insertIntoTable in interface SqlPost
      Parameters:
      tableName - table name in the format schema_name.table_name
      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

      public void insertIntoTable(String tableName, String providedJson)
      Description copied from interface: SqlPost
      Merge arrays with template data

      example:
      tableName: "schema.table1"
      (will search in resources file templates/${database_type}/schema.table1.json)
      database_types : DbTypes
      default path can be changed by setTemplatesDirectory(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:
      insertIntoTable in interface SqlPost
      Parameters:
      tableName - table name in the format schema_name.table_name
      providedJson - 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

      @Step("(DB) Run script from file \'{path}\'") public void runScriptFromFile(String path)
      Description copied from interface: SqlPost
      Executes an SQL script from a file.

      Used to initialize the database at test startup or in other cases.

      Specified by:
      runScriptFromFile in interface SqlPost
      Parameters:
      path - path to the file in test resources
    • runScript

      @Step("(DB) Run SQL script: {script}") public void runScript(String script)
      Description copied from interface: SqlPost
      Executes the specified SQL script manually.

      Used for manual scripts and not recommended for regular test operations.

      Specified by:
      runScript in interface SqlPost
      Parameters:
      script - hardcoded SQL script
    • truncateTable

      @Step("(DB) Truncate table \'{tableName}\'") public void truncateTable(String tableName)
      Description copied from interface: SqlPost
      Truncates the table.
      Specified by:
      truncateTable in interface SqlPost
      Parameters:
      tableName - table name in the format schema_name.table_name
    • truncateTables

      @Step("(DB) Truncate tables: {tablesNames}") public void truncateTables(String... tablesNames)
      Description copied from interface: SqlPost
      Truncates the tables.
      Specified by:
      truncateTables in interface SqlPost
      Parameters:
      tablesNames - list of tables
    • updateTable

      public void updateTable(String tableName, Object[][] setArray)
      Description copied from interface: SqlPost
      Updates all records in the table.
      Specified by:
      updateTable in interface SqlPost
      Parameters:
      tableName - table name in the format schema_name.table_name
      setArray - values to update in the format {{"column1", "value1"}, ...}
    • updateTable

      public void updateTable(String tableName, Object[][] setArray, Object[][] conditionsArray)
      Description copied from interface: SqlPost
      Updates all records in the table matching the specified conditions (in an Object[][] array).
      Specified by:
      updateTable in interface SqlPost
      Parameters:
      tableName - table name in the format schema_name.table_name
      setArray - 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: SqlPost
      Updates all records in the table matching the specified conditions (hardcoded SQL condition string).
      Specified by:
      updateTable in interface SqlPost
      Parameters:
      tableName - table name in the format schema_name.table_name
      conditions - String "SET USERNAME='Alex' where ID=5"
    • deleteFromTable

      @Step("(DB) Delete from table \'{tableName}\'") public void deleteFromTable(String tableName)
      Description copied from interface: SqlPost
      Deletes all records from the table.
      Specified by:
      deleteFromTable in interface SqlPost
      Parameters:
      tableName - table name in the format schema_name.table_name
    • deleteFromTable

      public void deleteFromTable(String tableName, Object[][] conditionsArray)
      Description copied from interface: SqlPost
      Deletes all records from the table matching the specified conditions (in an Object[][] array).
      Specified by:
      deleteFromTable in interface SqlPost
      Parameters:
      tableName - table name in the format schema_name.table_name
      conditionsArray - Object[][] {{"column1", "value1"},...}
    • deleteFromTable

      @Step("(DB) Delete from table \'{tableName}\' {conditions}") public void deleteFromTable(String tableName, String conditions)
      Description copied from interface: SqlPost
      Deletes all records from the table matching the specified conditions (hardcoded SQL condition string).
      Specified by:
      deleteFromTable in interface SqlPost
      Parameters:
      tableName - table name in the format schema_name.table_name
      conditions - String "where id=1"
    • renameTable

      @Step("(DB) Rename table \'{tableName}\'") public void renameTable(String tableName)
      Description copied from interface: SqlPost
      Renames 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:
      renameTable in interface SqlPost
      Parameters:
      tableName - table name in the format schema_name.table_name
    • rollbackTable

      @Step("(DB) Rollback renamed table \'{tableName}\'") public void rollbackTable(String tableName)
      Description copied from interface: SqlPost
      Rolls back the table name by removing the "_X_" suffix added by SqlPost.renameTable(java.lang.String).
      Specified by:
      rollbackTable in interface SqlPost
      Parameters:
      tableName - table name in the format schema_name.table_name
    • seeRowsCountInTableExactly

      public void seeRowsCountInTableExactly(String tableName, Object[][] conditionsArray, int expectedCount)
      Description copied from interface: SqlGet
      Asserts 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:
      seeRowsCountInTableExactly in interface SqlGet
      Parameters:
      tableName - table name in the format schema_name.table_name
      conditionsArray - conditions in Object[][] format support up to 2 options after field (column, condition, date, oracle-enum)
      {"COLUMN NAME", ">= ", "2020-01-01", "DATE"} for oracle
      expectedCount - expected rows count
    • seeRowsCountInTableExactly

      public void seeRowsCountInTableExactly(String tableName, String providedJson, int expectedCount)
      Description copied from interface: SqlGet
      Asserts 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:
      seeRowsCountInTableExactly in interface SqlGet
      Parameters:
      tableName - table name in the format schema_name.table_name
      providedJson - 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: SqlGet
      Asserts 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:
      seeRowsCountInTableExactlyCustom in interface SqlGet
      Parameters:
      tableName - table name in the format schema_name.table_name
      conditions - hardcoded SQL conditions string

      for example: "where id=1"

      expectedCount - expected rows count
    • seeRowsCountInTableExactly

      public void seeRowsCountInTableExactly(String tableName, int expectedCount)
      Description copied from interface: SqlGet
      Asserts that the table contains exactly the expected number of records.

      Uses await.

      Specified by:
      seeRowsCountInTableExactly in interface SqlGet
      Parameters:
      tableName - table name in the format schema_name.table_name
      expectedCount - expected rows count
    • seeTableIsEmpty

      public void seeTableIsEmpty(String tableName)
      Description copied from interface: SqlGet
      Asserts that the table has no records.

      Uses await.

      Specified by:
      seeTableIsEmpty in interface SqlGet
      Parameters:
      tableName - table name in the format schema_name.table_name
    • seeRecordExistsInTableCustom

      public void seeRecordExistsInTableCustom(String tableName, String conditions)
      Description copied from interface: SqlGet
      Asserts 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:
      seeRecordExistsInTableCustom in interface SqlGet
      Parameters:
      tableName - table name in the format schema_name.table_name
      conditions - hardcoded SQL condition string

      for example: "where id=1"

    • seeRecordExistsInTable

      public void seeRecordExistsInTable(String tableName, String providedJson)
      Description copied from interface: SqlGet
      Asserts 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:
      seeRecordExistsInTable in interface SqlGet
      Parameters:
      tableName - table name in the format schema_name.table_name
      providedJson - 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

      public void seeRecordExistsInTable(String tableName, Object[][] conditionsArray)
      Description copied from interface: SqlGet
      Asserts 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:
      seeRecordExistsInTable in interface SqlGet
      Parameters:
      tableName - table name in the format schema_name.table_name
      conditionsArray - 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

      public void seeTableIsNotEmpty(String tableName)
      Description copied from interface: SqlGet
      Asserts that the table is not empty.

      Uses await.

      Specified by:
      seeTableIsNotEmpty in interface SqlGet
      Parameters:
      tableName - table name in the format schema_name.table_name
    • showDataByCondition

      public void showDataByCondition(String tableName, Object[][] conditionsArray)
      Description copied from interface: SqlGet
      Creates an attachment containing all records matching the specified conditions.
      
       db.showDataByCondition("test.users", new Object[][]{
            {"ID", 1},
            {"NAME", "Alex"}
       });
      Specified by:
      showDataByCondition in interface SqlGet
      Parameters:
      tableName - table name in the format schema_name.table_name
      conditionsArray - conditions in the format {{"ID", "1"}, {"NAME", "Alex"}}
    • showDataFromTable

      @Step("(DB) Show data from table \'{tableName}\'") public void showDataFromTable(String tableName)
      Description copied from interface: SqlGet
      /** Creates an attachment containing all records and columns from the table.
      Specified by:
      showDataFromTable in interface SqlGet
      Parameters:
      tableName - table name in the format schema_name.table_name
    • assertCountInTableBuilder

      @Step("(DB)[ASSERT] Table: \'{tableName}\' contains EXACTLY <{expectedCount}> record/s {conditions}") protected void assertCountInTableBuilder(String tableName, String conditions, @Param(mode=HIDDEN) Object[][] conditionsArray, String expectedCount, @Param(mode=HIDDEN) int awaitMs)
    • recordExistsBuilder

      @Step("(DB)[ASSERT] Table \'{tableName}\' contains records {conditions}") protected void recordExistsBuilder(String tableName, String conditions, @Param(mode=HIDDEN) Object[][] conditionsArray, @Param(mode=HIDDEN) int awaitMs)
    • showDataFromTableMethod

      protected void showDataFromTableMethod(String tableName)
    • seeInDbByCondMethod

      @Step("(DB) Show data from table \'{tableName}\' {conditions}") protected void seeInDbByCondMethod(String tableName, String conditions)
    • getTableColumns

      protected String[] getTableColumns(String tableName)
      Returns the list of columns in the table.
      Parameters:
      tableName - table name in the format schema_name.table_name
      Returns:
      array containing column names