Package io.ebean.test

Class ForTests

    • Method Detail

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

        {@code
        
           private ForTests.RollbackAll rollbackAll;