Class PostgreSQL

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

public class PostgreSQL extends JdbcExecutor<PostgreSQL>
PostgreSQL helper that provides a common API for operating with PostgreSQL.

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

Provides:

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

For more information, see JdbcExecutor.

  • Field Details

  • Constructor Details

    • PostgreSQL

      public PostgreSQL(String dbUrl, String username, String passwd)
      Creates a new PostgreSQL database helper instance with the specified connection parameters.
      Parameters:
      dbUrl - the JDBC connection URL for the PostgreSQL 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
    • PostgreSQL

      public PostgreSQL()
      Constructs a PostgreSQL client using YAML configuration.

      Loads configuration values from a YAML file.

      Example:

      PostgreSQL db = new PostgreSQL();

       postgresql:
         url: 'jdbc:postgresql://localhost:5434/public'
         username: user
         password: pass
         await: 1000 (optional)
       
      See Also:
  • Method Details

    • getInstance

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

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

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

      @Step("(DB) Truncate table \'{tableName}\' CASCADE") public void truncateTableCascade(String tableName)
      Truncate(clean) table and all connected by foreign keys tables
      Parameters:
      tableName - schema_name.table_name
    • 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
      Overrides:
      renameTable in class JdbcExecutor<PostgreSQL>
      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
      Overrides:
      rollbackTable in class JdbcExecutor<PostgreSQL>
      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