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 se 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

    • suppressedDb

      public boolean suppressedDb()
    • suppressDb

      public void suppressDb(boolean suppressDb)
      Call this method from a constructor of your spec in cases you do not need DB connections. Calling from a "@Before" method will not work.
    • 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.

      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.
    • openTestConnections

      @BeforeEach public final void openTestConnections()
    • closeTestConnections

      @AfterEach public final void closeTestConnections()