package org.jpwh.env; import org.testng.annotations.AfterSuite; import org.testng.annotations.BeforeSuite; import org.testng.annotations.Optional; import org.testng.annotations.Parameters; import java.util.Locale; /** * Starts and stops the transaction manager/database pool before/after a test suite. *

* All tests in a suite execute with a single {@link TransactionManagerSetup}, call * the static {@link TransactionManagerTest#TM} in your test to access the JTA * transaction manager and database connections. *

*

* The test parameters database (specifying a supported * {@link DatabaseProduct}) and a connectionURL are optional. * The default is an in-memory H2 database instance, created and destroyed * automatically for each test suite. *

*/ public class TransactionManagerTest { // Static single database connection manager per test suite static public TransactionManagerSetup TM; @Parameters({"database", "connectionURL"}) @BeforeSuite() public void beforeSuite(@Optional String database, @Optional String connectionURL) throws Exception { TM = new TransactionManagerSetup( database != null ? DatabaseProduct.valueOf(database.toUpperCase(Locale.US)) : DatabaseProduct.H2, connectionURL ); } @AfterSuite(alwaysRun = true) public void afterSuite() throws Exception { if (TM != null) TM.stop(); } }