|
|
Tests rolling back on initial connection vs after test transaction
mons.dbcp.PoolingDataSource@1ff6de1] to thread [main]
2008-05-01 15:53:20,848 [main] DEBUG org..transaction.support.TransactionSynchronizationManager - Bound value [org..jdbc.datasource.ConnectionHolder@159d87f] for key [com.foo.database.ProxyDataSource@176de14] to thread [main]
2008-05-01 15:53:20,851 [main] DEBUG org..jdbc.datasource.DataSourceTransactionManager - Initiating transaction rollback
2008-05-01 15:53:20,936 [main] DEBUG org..jdbc.datasource.DataSourceTransactionManager - Rolling back JDBC transaction on Connection [jdbc:sybase:Tds:..., UserName=dbo, jConnect (TM) for JDBC (TM)]
I am not sure how to solve this one. Any assistance is greatly appreciated
In case anyone encounters the same problem, what eventually worked for me was this:Code:
@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({TransactionalTestExecutionListener.class})
@ContextConfiguration(locations = {quot;classpath:applicationContext-acegi-security.xmlquot;, quot;classpath:applicationContext.xmlquot;, quot;classpath:applicationServices.xmlquot;, quot;classpath:dataAccessContext-web.xmlquot;, quot;classpath:daoConfig.xmlquot;, quot;classpath:messaging.xmlquot;})
@TransactionConfiguration(transactionManager = quot;transactionManagerquot;, defaultRollback = true)
public class TransactionalTestSuite extends AbstractTransactionalJUnit4SpringContextTests {
...
}
then I created a testSuiteAuthenticator object that handles junit and security setup and login. In the test I used the static @BeforeClass, @AfterClass annotations on methods doing class-based setup, then @BeforeTransaction for immediate test method setup. From this I extend any test classes needing this rollback functionality and it works like a charm.
In your child test classes simply
Code:
@Resource(name = quot;myTransactionalServicequot;)private IMyTransactionalService service;
@BeforeTransaction
public void doSomePreWork{}
@Test
public void rollbackMethod{}
no test method naming convention required |
|