Package org.tentackle.test.pdo
Class AbstractPdoTest
- java.lang.Object
-
- org.tentackle.test.pdo.AbstractPdoTest
-
- All Implemented Interfaces:
org.tentackle.pdo.DomainContextProvider
public abstract class AbstractPdoTest extends java.lang.Object implements org.tentackle.pdo.DomainContextProviderBase class for tests on PDO level.- Author:
- harald
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAbstractPdoTest.TransactionTypeThe transaction handling for the test class.
-
Constructor Summary
Constructors Constructor Description AbstractPdoTest()Creates a test with rollback and one transaction per class.AbstractPdoTest(AbstractPdoTest.TransactionType txType)Creates a test with rollback.AbstractPdoTest(AbstractPdoTest.TransactionType txType, boolean commit)Creates a test.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterClass()Ends the transaction if type isAbstractPdoTest.TransactionType.CLASS.voidafterMethod()Ends the transaction if type isAbstractPdoTest.TransactionType.METHOD.voidbeforeClass()Begins the transaction if type isAbstractPdoTest.TransactionType.CLASS.voidbeforeMethod()Begins the transaction if type isAbstractPdoTest.TransactionType.METHOD.protected voidbeginTransaction()Begins a transaction.voidcloseSessionsAndTerminateModificationTracker()Terminates the modification tracker and closes the sessions.protected org.tentackle.pdo.DomainContextcreateDomainContext()Creates the domain context.protected voidendTransaction()Commits or rolls back a transaction.org.tentackle.pdo.DomainContextgetDomainContext()Gets the domain context.org.tentackle.session.SessiongetSession()Gets the session.booleanisCommit()Returns whether the transaction should be commit or rolled back.protected org.tentackle.session.SessionopenSession()Opens the session.voidopenSessionsAndStartModificationTracker()Opens the sessions and starts the modification tracker.static java.lang.ProcessrunClass(java.lang.Class<?> testClass, java.lang.String... args)Runs the given class in another JVM and waits for termination.
The testclass must have a main method.intrunInOtherJVM(java.lang.Class<?> testClass)Runs the given class in another JVM.
The testclass must have a main method.static voidwaitForProcess(java.lang.Process process)Waits for process to terminate and write stdout and stderr to the reporter log.
-
-
-
Constructor Detail
-
AbstractPdoTest
public AbstractPdoTest(AbstractPdoTest.TransactionType txType, boolean commit)
Creates a test.- Parameters:
txType- the transaction typecommit- 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.ExceptionOpens the sessions and starts the modification tracker.- Throws:
java.lang.Exception- if failed
-
closeSessionsAndTerminateModificationTracker
@AfterSuite(alwaysRun=true) public void closeSessionsAndTerminateModificationTracker() throws java.lang.ExceptionTerminates the modification tracker and closes the sessions.- Throws:
java.lang.Exception- if failed
-
beforeClass
@BeforeClass(alwaysRun=true) public void beforeClass() throws java.lang.ExceptionBegins the transaction if type isAbstractPdoTest.TransactionType.CLASS.- Throws:
java.lang.Exception- if failed
-
afterClass
@AfterClass(alwaysRun=true) public void afterClass() throws java.lang.ExceptionEnds the transaction if type isAbstractPdoTest.TransactionType.CLASS.- Throws:
java.lang.Exception- if failed
-
beforeMethod
@BeforeMethod(alwaysRun=true) public void beforeMethod() throws java.lang.ExceptionBegins the transaction if type isAbstractPdoTest.TransactionType.METHOD.- Throws:
java.lang.Exception- if failed
-
afterMethod
@AfterMethod(alwaysRun=true) public void afterMethod() throws java.lang.ExceptionEnds the transaction if type isAbstractPdoTest.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:
getDomainContextin interfaceorg.tentackle.pdo.DomainContextProvider- Returns:
- the domain context
-
runInOtherJVM
public int runInOtherJVM(java.lang.Class<?> testClass) throws java.io.IOExceptionRuns 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.IOExceptionRuns the given class in another JVM and waits for termination.
The testclass must have a main method.- Parameters:
testClass- the test classargs- 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.IOExceptionWaits 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
-
-