Class AbstractPdoTest

java.lang.Object
org.tentackle.pdo.junit.AbstractPdoTest
All Implemented Interfaces:
DomainContextProvider

public abstract class AbstractPdoTest extends Object implements DomainContextProvider
Base class for Junit5 tests on PDO level.
Author:
harald
  • Constructor Details

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

    • openSessionsAndStartModificationTracker

      public boolean openSessionsAndStartModificationTracker()
      Opens the sessions and starts the modification tracker exactly once.
      If the database is in-memory, it will be populated before the tracker is started.
      See Also:
    • closeSessionsAndTerminateModificationTracker

      @AfterAll public static void closeSessionsAndTerminateModificationTracker()
      Terminates the modification tracker and closes the sessions.
    • beforeMethod

      @BeforeEach public void beforeMethod() throws Exception
      Begins the transaction if type is AbstractPdoTest.TransactionType.METHOD.
      Throws:
      Exception - if failed
    • afterMethod

      @AfterEach public void afterMethod() throws Exception
      Ends the transaction if type is AbstractPdoTest.TransactionType.METHOD.
      Throws:
      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 committed or rolled back.
      Returns:
      true if commit, false if rollback (default for regular tests)
    • getDomainContext

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

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

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

      protected void createDatabaseTables(org.tentackle.dbms.Db db)
      Creates the database tables.
      The default implementation loads the model from the classpath. Override this method to provide additional model sources.
      Parameters:
      db - the low-level database session
      See Also:
    • populateDatabase

      protected void populateDatabase()
      Populates the database with test data.
    • createDomainContext

      protected 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 Process runClass(Class<?> testClass, String... args) throws IOException
      Runs the given class in another JVM and waits for termination.
      The test class must have a main method.
      Parameters:
      testClass - the test class
      args - optional arguments
      Returns:
      the process object
      Throws:
      IOException - if some IO operation failed
    • waitForProcess

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