-
1. Re: SeamTest with transactional roll back
pmuir Jul 11, 2008 5:12 PM (in response to johnnyren)Take a look at SeamTest with DBUnit
-
2. Re: SeamTest with transactional roll back
skallio Jan 29, 2009 12:55 PM (in response to johnnyren)I have been trying to find information for the same question. Can somebody give more specific instruction what to do?
The difference in my case is that I don't have session beans but I would like to run SeamTests in transaction and rollback after each test. (I wonder if this is not what everybody wants?)
-
3. Re: SeamTest with transactional roll back
davidmiller Jan 11, 2012 6:43 AM (in response to johnnyren)I wouldn't mind an answer to this problem as well... The SeamTest and DBUNit docs tell me nothing....and if they do, what am I missing?
-
4. Re: SeamTest with transactional roll back
davidmiller Jan 26, 2012 7:13 AM (in response to johnnyren)Bump bump
-
5. Re: SeamTest with transactional roll back
javacoryd Feb 7, 2012 4:21 PM (in response to johnnyren)We have been doing this for quite some time now. We converted our base seam test over to JUnit because we like JUnit. You can do this with TestNG as well. Note: this is of course using a ComponentTest. Here is what we do:
@Before ( before the test starts )
a) Get the entityManager
b) Start the transaction
EntityTransaction transaction = entityManager.getTransaction();
if ( !transaction.isActive() ) {
transaction.begin();
}
c) Put the tranasaction into ThreadLocal
@After ( upon test completion )
a) Get the transaction off of ThreadLocal
b) Rollback the transaction
if ( trans != null && trans.isActive() ) {
trans.rollback();
}
c) Remove transaction from ThreadLocal
Cory.
-
6. Re: SeamTest with transactional roll back
davidmiller Feb 9, 2012 8:34 AM (in response to javacoryd)Thanks Cory, I'll give that a go.
-
7. Re: SeamTest with transactional roll back
javacoryd Feb 9, 2012 1:20 PM (in response to davidmiller)If you are willing to change the method you override in the ComponentTest to something else, this is easier:
public abstract class BaseTransactionalTest extends SeamTest {
protected abstract class TransactionalComponentTest extends ComponentTest {
protected void testComponents() throws Exception {
Transaction.instance().begin();
try {
doTestComponents();
} finally {
Transaction.instance().rollback();
}
}
protected abstract void doTestComponents() throws Exception;
}
}