Class CustomDb

All Implemented Interfaces:
SqlConfig<CustomDb>, SqlGet, SqlPost

public class CustomDb extends JdbcExecutor<CustomDb>
CustomDb helper that provides a common API for operating with SQL-database that is not yet fully supported.

It is recommended to use a single instance: CustomDb db = CustomDb.getInstance();

Supports only basic features:
  • Get all data for allure on failed not supported
  • Get data all data by conditions not supported
  • Get data all data from table not supported
  • Specific conditions(JSON_*, REGEX) not supported (only basic conditions)

Provides:

  • Assertions with await support
  • Data manipulation operations such as create, update, and clean

For more information, see JdbcExecutor.

  • Field Details

    • jdbc

      protected JdbcDirectivesHikari jdbc
    • getColumnsQuery

      protected String getColumnsQuery
    • url

      protected String url
    • username

      protected String username
    • password

      protected String password
    • SELECT_ALL

      protected static final String SELECT_ALL
      See Also:
    • COUNT

      protected static final String COUNT
      See Also:
    • awaitPollInterval

      protected volatile int awaitPollInterval
      Default await polling interval in milliseconds for tests.
    • enableEnchantedReport

      protected volatile boolean enableEnchantedReport
      Enables enhanced reporting with full table data attached to Allure and actual column values included in assertion exceptions.
  • Constructor Details

    • CustomDb

      public CustomDb(String dbUrl, String username, String passwd)
      Creates a new Custom database helper instance with the specified connection parameters.
      Parameters:
      dbUrl - the JDBC connection URL for the Custom database
      username - the username used to authenticate with the database
      passwd - the password used to authenticate with the database
      Throws:
      IllegalArgumentException - if any of the required parameters are null or empty
    • CustomDb

      public CustomDb()
      Constructs a CustomDb client for a database that is not yet fully supported, using YAML configuration.

      Loads configuration values from a YAML file.

      Example:

      CustomDb db = new CustomDb();

       modules:
         db:
           custom-db: # reserved type
             url: 'jdbc:mysql://localhost:3308'
             username: user
             password: pass
             await: 1000 (optional)
             enchanted-report: true # (optional)
       
      See Also:
    • CustomDb

      public CustomDb(String suffix)
      Constructs a CustomDb client for a database that is not yet fully supported, using YAML configuration.

      Loads configuration values from a YAML file.

      Example:

      CustomDb db = new CustomDb("-mydb");

       modules:
         db:
           custom-db-mydb: # reserved type
             url: 'jdbc:mysql://localhost:3308'
             username: user
             password: pass
             await: 1000 (optional)
             enchanted-report: true # (optional)
       
      Parameters:
      suffix - concatenation of CustomDb client (example CustomDb("-mydb") keys will be "modules.db.custom-db-mydb")
      See Also:
  • Method Details

    • getInstance

      public static CustomDb getInstance()
      Returns the instance of CustomDb with config builder CustomDb().

      This implementation is thread-safe using method-level synchronization.

      Returns:
      the shared instance of CustomDb
      Throws:
      IllegalArgumentException - if the configuration contains invalid values
      See Also:
    • getInstance

      public static CustomDb getInstance(String suffix)
      Returns a unique CustomDb helper instance for the specified suffix using YAML configuration.

      This method implements the Multiton pattern. A separate singleton instance is created for each CustomDb. Subsequent calls with the same suffix return the already created instance.

      Returns:
      unique CustomDb instance associated with the specified Redis data type
      Throws:
      IllegalArgumentException - if the configuration contains invalid values
      See Also:
    • 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 providedAwaitMs)
    • 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 providedAwaitMs)
    • 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