Package io.ebean.test

Class ForTests

java.lang.Object
io.ebean.test.ForTests

public class ForTests extends Object
Helper methods for testing.
  • Constructor Details

    • ForTests

      public ForTests()
  • Method Details

    • enableTransactional

      public static void enableTransactional(boolean enable)
      Enable or disable @Transactional methods.

      This is intended for testing purposes such that tests on code with @Transactional methods don't actually start or complete transactions.

      Parameters:
      enable - Set false to disable @Transactional methods
    • noTransactional

      public static void noTransactional(Runnable run)
      Run the closure with @Transactional methods effectively disabled (they won't create/commit transactions).
    • rollbackAll

      public static void rollbackAll(Runnable run)
      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

      public static ForTests.RollbackAll createRollbackAll()
      Create and return a RollbackAll which should be closed at the end of the test(s).

      In tests for @Before we create the rollbackAll and on @After we close() 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