java.lang.Object
io.ebean.test.ForTests
Helper methods for testing.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA wrapping transaction used in test code to rollback all changes. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ForTests.RollbackAllCreate and return a RollbackAll which should be closed at the end of the test(s).static voidenableTransactional(boolean enable) Enable or disable@Transactionalmethods.static voidnoTransactional(Runnable run) Run the closure with@Transactionalmethods effectively disabled (they won't create/commit transactions).static voidrollbackAll(Runnable run) All transactions started in the closure are effectively rolled back.
-
Constructor Details
-
ForTests
public ForTests()
-
-
Method Details
-
enableTransactional
public static void enableTransactional(boolean enable) Enable or disable@Transactionalmethods.This is intended for testing purposes such that tests on code with
@Transactionalmethods don't actually start or complete transactions.- Parameters:
enable- Set false to disable@Transactionalmethods
-
noTransactional
Run the closure with@Transactionalmethods effectively disabled (they won't create/commit transactions). -
rollbackAll
All transactions started in the closure are effectively rolled back.This creates a wrapping transaction that uses
Transaction.setNestedUseSavepoint(). All nested transactions are created as savepoints. On completion the wrapping transaction is rolled back.- Parameters:
run- Closure that runs such that all the transactions are rolled back.
-
createRollbackAll
Create and return a RollbackAll which should be closed at the end of the test(s).In tests for
@Beforewe create the rollbackAll and on@Afterweclose()it effectively rolling back all changes made during test execution.private ForTests.RollbackAll rollbackAll; @Before public void before() { rollbackAll = ForTests.createRollbackAll(); } @After public void after() { rollbackAll.close(); } ... tests execute and everything is rolled back
-