Class AbstractPdoTest

  • All Implemented Interfaces:
    org.tentackle.pdo.DomainContextProvider

    public abstract class AbstractPdoTest
    extends java.lang.Object
    implements org.tentackle.pdo.DomainContextProvider
    Base class for tests on PDO level.
    Author:
    harald
    • Constructor Detail

      • AbstractPdoTest

        public AbstractPdoTest​(AbstractPdoTest.TransactionType txType,
                               boolean commit)
        Creates a test.
        Parameters:
        txType - the transaction type
        commit - true if commit transaction, else rollback (default for regular tests)
      • AbstractPdoTest

        public AbstractPdoTest​(AbstractPdoTest.TransactionType txType)
        Creates a test with rollback.
        Parameters:
        txType - the transaction type
      • AbstractPdoTest

        public AbstractPdoTest()
        Creates a test with rollback and one transaction per class.
    • Method Detail

      • openSessionsAndStartModificationTracker

        @BeforeSuite(alwaysRun=true)
        public void openSessionsAndStartModificationTracker()
                                                     throws java.lang.Exception
        Opens the sessions and starts the modification tracker.
        Throws:
        java.lang.Exception - if failed
      • closeSessionsAndTerminateModificationTracker

        @AfterSuite(alwaysRun=true)
        public void closeSessionsAndTerminateModificationTracker()
                                                          throws java.lang.Exception
        Terminates the modification tracker and closes the sessions.
        Throws:
        java.lang.Exception - if failed
      • beforeClass

        @BeforeClass(alwaysRun=true)
        public void beforeClass()
                         throws java.lang.Exception
        Begins the transaction if type is AbstractPdoTest.TransactionType.CLASS.
        Throws:
        java.lang.Exception - if failed
      • afterClass

        @AfterClass(alwaysRun=true)
        public void afterClass()
                        throws java.lang.Exception
        Ends the transaction if type is AbstractPdoTest.TransactionType.CLASS.
        Throws:
        java.lang.Exception - if failed
      • beforeMethod

        @BeforeMethod(alwaysRun=true)
        public void beforeMethod()
                          throws java.lang.Exception
        Begins the transaction if type is AbstractPdoTest.TransactionType.METHOD.
        Throws:
        java.lang.Exception - if failed
      • afterMethod

        @AfterMethod(alwaysRun=true)
        public void afterMethod()
                         throws java.lang.Exception
        Ends the transaction if type is AbstractPdoTest.TransactionType.METHOD.
        Throws:
        java.lang.Exception - if failed
      • getSession

        public org.tentackle.session.Session getSession()
        Gets the session.
        Returns:
        the session
      • isCommit

        public boolean isCommit()
        Returns whether the transaction should be commit or rolled back.
        Returns:
        true if commit, false if rollback (default for regular tests)
      • getDomainContext

        public org.tentackle.pdo.DomainContext getDomainContext()
        Gets the domain context.
        Specified by:
        getDomainContext in interface org.tentackle.pdo.DomainContextProvider
        Returns:
        the domain context
      • runInOtherJVM

        public int runInOtherJVM​(java.lang.Class<?> testClass)
                          throws java.io.IOException
        Runs the given class in another JVM.
        The testclass must have a main method.
        Parameters:
        testClass - the test class
        Returns:
        the exit value
        Throws:
        java.io.IOException - if some IO operation failed
      • openSession

        protected org.tentackle.session.Session openSession()
        Opens the session.
        Returns:
        the thread-local session
      • createDomainContext

        protected org.tentackle.pdo.DomainContext createDomainContext()
        Creates the domain context.
        Returns:
        the context (usually thread-local)
      • beginTransaction

        protected void beginTransaction()
        Begins a transaction.
      • endTransaction

        protected void endTransaction()
        Commits or rolls back a transaction.
      • runClass

        public static java.lang.Process runClass​(java.lang.Class<?> testClass,
                                                 java.lang.String... args)
                                          throws java.io.IOException
        Runs the given class in another JVM and waits for termination.
        The testclass must have a main method.
        Parameters:
        testClass - the test class
        args - optional arguments
        Returns:
        the process object
        Throws:
        java.io.IOException - if some IO operation failed
      • waitForProcess

        public static void waitForProcess​(java.lang.Process process)
                                   throws java.io.IOException
        Waits for process to terminate and write stdout and stderr to the reporter log.
        Parameters:
        process - the process
        Throws:
        java.io.IOException - if some IO failed