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:
MariaDb, MsSQL, MySQL, OracleDb, PostgreSQL

public abstract class JdbcExecutor<T extends JdbcExecutor<T>> extends Object implements SqlPost, SqlGet, SqlConfig<T>
  • Field Details

  • Constructor Details

    • JdbcExecutor

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

      protected JdbcExecutor(String 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: DbTypes

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

      Optional configuration keys:

      • modules.db.${dbType}.await

      Missing required keys will result in configuration errors. Missing optional keys will fall back to predefined defaults.

  • Method Details

    • self

      protected T self()
    • withAwaitMs

      public T withAwaitMs(int awaitMs)
      Description copied from interface: SqlConfig
      Configure await in asserts with await
      Specified by:
      withAwaitMs in interface SqlConfig<T extends JdbcExecutor<T>>
      Parameters:
      awaitMs - ms await
      Returns:
      this instance for method chaining
    • setTemplatesDirectory

      public T setTemplatesDirectory(String templatesPath)
      Description copied from interface: SqlConfig
      Configure directory in resources for tables templates
      Specified by:
      setTemplatesDirectory in interface SqlConfig<T extends JdbcExecutor<T>>
      Parameters:
      templatesPath - path in resources "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 - 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 - 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 - 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
      Execute sql script from file used for init db on test startUp
      Specified by:
      runScriptFromFile in interface SqlPost
      Parameters:
      path - path to file in resources
    • runScript

      @Step("(DB) {script}") public void runScript(String script)
      Description copied from interface: SqlPost
      Execute sql script manual used for manual scripts (not recommended)
      Specified by:
      runScript in interface SqlPost
      Parameters:
      script - hardcode SQL script
    • truncateTable

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

      @Step("(DB) Truncate tables: {tablesNames}") public void truncateTables(String... tablesNames)
      Description copied from interface: SqlPost
      Truncate(clean) 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
      Update all records in table
      Specified by:
      updateTable in interface SqlPost
      Parameters:
      tableName - schema_name.table_name
      setArray - Object[][] {{"column1", "value1"},...}
    • updateTable

      public void updateTable(String tableName, Object[][] setArray, Object[][] conditionsArray)
      Description copied from interface: SqlPost
      Update records in table by conditions
      Specified by:
      updateTable in interface SqlPost
      Parameters:
      tableName - schema_name.table_name
      setArray - 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: SqlPost
      Update records in table by conditions
      Specified by:
      updateTable in interface SqlPost
      Parameters:
      tableName - schema_name.table_name
      conditions - String "SET USERNAME='Alex' where ID=5"
    • deleteFromTable

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

      public void deleteFromTable(String tableName, Object[][] conditionsArray)
      Description copied from interface: SqlPost
      Delete from table by conditions
      Specified by:
      deleteFromTable in interface SqlPost
      Parameters:
      tableName - schema_name.table_name
      conditionsArray - Object[][] {{"column1", "value1"},...}
    • deleteFromTable

      @Step("(DB) Delete from {tableName} {conditions}") public void deleteFromTable(String tableName, String conditions)
      Description copied from interface: SqlPost
      Delete from table by conditions
      Specified by:
      deleteFromTable in interface SqlPost
      Parameters:
      tableName - schema_name.table_name
      conditions - String "where id=1"
    • renameTable

      @Step("(DB) Rename table {tableName}") public void renameTable(String tableName)
    • rollbackTable

      @Step("(DB) Rollback renamed table {tableName}") public void rollbackTable(String tableName)
    • seeRowsCountInTableExactly

      public void seeRowsCountInTableExactly(String tableName, Object[][] conditionsArray, int expectedCount)
      Description copied from interface: SqlGet
      Assert of records EXACTLY count by conditions with await
      Specified by:
      seeRowsCountInTableExactly in interface SqlGet
      Parameters:
      tableName - schema_name.table_name
      conditionsArray - Object[][] with template {{"column1", "value1"},...}
      expectedCount - expected rows count
    • seeRowsCountInTableExactly

      public void seeRowsCountInTableExactly(String tableName, String providedJson, int expectedCount)
      Description copied from interface: SqlGet
      Assert of records EXACTLY count with await

      Use custom sql conditions only if it`s necessary, otherwise use SqlGet.seeRowsCountInTableExactly(java.lang.String, java.lang.Object[][], int)

      Specified by:
      seeRowsCountInTableExactly in interface SqlGet
      Parameters:
      tableName - schema_name.table_name
      providedJson - 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
    • seeRowsCountInTableExactly

      public void seeRowsCountInTableExactly(String tableName, Object[][] conditionsArray, int expectedCount, int awaitMs)
      Description copied from interface: SqlGet
      Assert of records EXACTLY count by conditions with custom await
      Specified by:
      seeRowsCountInTableExactly in interface SqlGet
      Parameters:
      tableName - schema_name.table_name
      conditionsArray - Object[][] with template {{"column1", "value1"},...}
      expectedCount - expected rows count
      awaitMs - await in ms
    • seeRowsCountInTableExactlyCustom

      public void seeRowsCountInTableExactlyCustom(String tableName, String conditions, int expectedCount)
      Description copied from interface: SqlGet
      Assert of records EXACTLY count by conditions with await
      Specified by:
      seeRowsCountInTableExactlyCustom in interface SqlGet
      Parameters:
      tableName - schema_name.table_name
      conditions - String "where id=1"
      expectedCount - expected rows count
    • seeRowsCountInTableExactlyCustom

      public void seeRowsCountInTableExactlyCustom(String tableName, String conditions, int expectedCount, int awaitMs)
      Description copied from interface: SqlGet
      Assert of records EXACTLY count by conditions with custom await
      Specified by:
      seeRowsCountInTableExactlyCustom in interface SqlGet
      Parameters:
      tableName - schema_name.table_name
      conditions - String "where id=1"
      expectedCount - expected rows count
      awaitMs - await in ms
    • seeRowsCountInTableExactly

      public void seeRowsCountInTableExactly(String tableName, int expectedCount)
      Description copied from interface: SqlGet
      Assert of records EXACTLY count with await
      Specified by:
      seeRowsCountInTableExactly in interface SqlGet
      Parameters:
      tableName - schema_name.table_name
      expectedCount - expected rows count
    • seeRowsCountInTableExactly

      public void seeRowsCountInTableExactly(String tableName, int expectedCount, int awaitMs)
      Description copied from interface: SqlGet
      Assert of records EXACTLY count with custom await
      Specified by:
      seeRowsCountInTableExactly in interface SqlGet
      Parameters:
      tableName - schema_name.table_name
      expectedCount - expected rows count
      awaitMs - await in ms
    • seeTableIsEmpty

      public void seeTableIsEmpty(String tableName)
      Description copied from interface: SqlGet
      Assert That table has at least one record with await
      Specified by:
      seeTableIsEmpty in interface SqlGet
      Parameters:
      tableName - schema_name.table_name
    • seeRecordExistsInTableCustom

      public void seeRecordExistsInTableCustom(String tableName, String conditions)
      Description copied from interface: SqlGet
      Assert that exists at least one record by conditions with await

      Use custom sql conditions only if it`s necessary, otherwise use SqlGet.seeRecordExistsInTable(java.lang.String, java.lang.Object[][])

      Specified by:
      seeRecordExistsInTableCustom in interface SqlGet
      Parameters:
      tableName - schema_name.table_name
      conditions - String "where id=1"
    • seeRecordExistsInTable

      public void seeRecordExistsInTable(String tableName, String providedJson)
      Description copied from interface: SqlGet
      Assert that exists at least one record by conditions with await
      Specified by:
      seeRecordExistsInTable in interface SqlGet
      Parameters:
      tableName - schema_name.table_name
      providedJson - String with json """{"column1": "test_value1", ...}"""
      support up to 2 options in key after field
      "CREATE_DATE:>="
      "CREATE_DATE:=:TIMESTAMP" (for oracleDd)
    • seeRecordExistsInTable

      public void seeRecordExistsInTable(String tableName, Object[][] conditionsArray)
      Description copied from interface: SqlGet
      Assert that exists at least one record by conditions with await
      Specified by:
      seeRecordExistsInTable in interface SqlGet
      Parameters:
      tableName - schema_name.table_name
      conditionsArray - Object[][] with template {{"column1", "value1"},...}
    • seeTableDoesNotEmpty

      public void seeTableDoesNotEmpty(String tableName)
      Description copied from interface: SqlGet
      Assert That table has no records with await
      Specified by:
      seeTableDoesNotEmpty in interface SqlGet
      Parameters:
      tableName - schema_name.table_name
    • showDataByCondition

      public void showDataByCondition(String tableName, Object[][] conditionsArray)
      Description copied from interface: SqlGet
      Method to show full record/records by condition if exists
      Specified by:
      showDataByCondition in interface SqlGet
      Parameters:
      tableName - schema_name.table_name
      conditionsArray - Object[][] with conditions {{"ID", "1"}, {"NAME", "Alex"}}
    • showDataFromTable

      @Step("(DB) Show data from table {tableName}") public void showDataFromTable(String tableName)
      Description copied from interface: SqlGet
      Method to create attachment with all rows by all columns in table
      Specified by:
      showDataFromTable in interface SqlGet
      Parameters:
      tableName - schema_name.table_name
    • assertCountInTableBuilder

      @Step("(DB)[ASSERT] Count records in {tableName} {conditions} EQUAL {expectedCount}") protected void assertCountInTableBuilder(String tableName, String conditions, @Param(mode=HIDDEN) Object[][] conditionsArray, String expectedCount, @Param(mode=HIDDEN) int awaitMs)
    • recordExistsBuilder

      @Step("(DB)[ASSERT] Record/s exists in {tableName} {conditions}") protected void recordExistsBuilder(String tableName, String conditions, @Param(mode=HIDDEN) Object[][] conditionsArray, @Param(mode=HIDDEN) int awaitMs)
    • showDataFromTableMethod

      public void showDataFromTableMethod(String tableName)
    • seeInDbByCondMethod

      @Step("(DB)[ASSERT] Records exists in {tableName}: {conditions}") protected void seeInDbByCondMethod(String tableName, String conditions)
    • getTableColumns

      protected String[] getTableColumns(String tableName)
      Get array with table column list