Class DBSpec

All Implemented Interfaces:
JSpecSupport

public class DBSpec extends DBConfiguration implements JSpecSupport
Super class for tests that need to use a DB connection. The connection is configured in database.properties file. Test connection transactions work in the following manner:
  • A connection is opened, and the autocommit is set to false
  • The test method picks the connection from teh current thread, uses it to read/write data to the DB
  • Once the test method exits, the framework rolls back transaction and closes the connection
Since the framework rolls back changes in each test method, the test database stays pretty much the same, allowing each test method run in data isolation.
Author:
igor on 12/2/16.
  • Constructor Details

    • DBSpec

      public DBSpec()
  • Method Details

    • rollback

      public boolean rollback()
      Current state of 'rollback' flag.
      Returns:
      Current state of 'rollback' flag.
    • setRollback

      public void setRollback(boolean rollback)
      Set to true in order to rollback a transaction at the end of the test (default is true)..

      WARNING: if you set this value to false inside your test, the framework will not clean any remaining data you insert into your test database. Basically, this is a "manual mode" where you are responsible for cleaning after yourself.

      Parameters:
      rollback - true to rollback transactions at the end of the test, false to not rollback.
    • openConnections

      @BeforeEach public final void openConnections()
    • closeConnections

      @AfterEach public final void closeConnections()
    • initDBConfig

      @BeforeAll public static void initDBConfig()