Package org.javalite.activejdbc.test
Class DBSpec
- java.lang.Object
-
- org.javalite.activejdbc.connection_config.DBConfiguration
-
- org.javalite.activejdbc.test.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 indatabase.propertiesfile. 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
- Author:
- igor on 12/2/16.
-
-
Constructor Summary
Constructors Constructor Description DBSpec()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcloseTestConnections()voidopenTestConnections()booleanrollback()Current state of 'rollback' flag.voidsetRollback(boolean rollback)Set to true in order to rollback a transaction at the end of the test.voidsuppressDb(boolean suppressDb)Call this method from a constructor of your spec in cases you do not need DB connections.booleansuppressedDb()-
Methods inherited from class org.javalite.activejdbc.connection_config.DBConfiguration
addConnectionConfig, addConnectionConfig, clearConnectionConfigs, clearConnectionConfigs, getConnectionConfigs, getConnectionConfigsExceptTesting, getConnectionConfigsForCurrentEnv, getTestConnectionConfigs, loadConfiguration, resetConnectionConfigs
-
-
-
-
Method Detail
-
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()
-
-