SeamTest and transactions
taccart.thierry.accart.name Jun 26, 2008 4:36 PMHi
I'm trying to implement some tests on for my code.
All my CRUD interface is based on SEAM and works fine.
In addition, I've build an API to offer ability to manage data outside seam UI.
For my tests, I'm facing the following problem : my API is a singleton that stores current entityManager and persits transcientInstance via
getEntityManager().joinTransaction(); getEntityManager().persist(transientInstance); getEntityManager().flush();
I've tried to build test on this and fail to make anything with transactions.
I finally tried the following dummy test :
public class MyApiTest extends SeamTest { @Test public void testLM0001() { try { UserTransaction uTx = super.getUserTransaction(); uTx.begin(); uTx.commit(); } catch (Exception e) { e.printStackTrace(); } } @Test public void testLM0002() { try { Transaction.instance().begin(); Transaction.instance().commit(); } catch (Exception e) { e.printStackTrace(); } }
and both tests are failing with error No event context active
java.lang.IllegalStateException: No event context active at org.jboss.seam.ScopeType.getContext(ScopeType.java:114) at org.jboss.seam.Component.getInstance(Component.java:1851) at org.jboss.seam.Component.getInstance(Component.java:1829) at org.jboss.seam.Component.getInstance(Component.java:1824) at org.jboss.seam.transaction.Transaction.instance(Transaction.java:36) at org.jboss.seam.mock.BaseSeamTest.getUserTransaction(BaseSeamTest.java:1010) at MyApiTest.testLM0001(LogManagerTest.java:20) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:604) at org.testng.internal.Invoker.invokeMethod(Invoker.java:470) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:564) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:830) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109) at org.testng.TestRunner.runWorkers(TestRunner.java:678) at org.testng.TestRunner.privateRun(TestRunner.java:624) at org.testng.TestRunner.run(TestRunner.java:495) at org.testng.SuiteRunner.runTest(SuiteRunner.java:300) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:295) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:275) at org.testng.SuiteRunner.run(SuiteRunner.java:190) at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:792) at org.testng.TestNG.runSuitesLocally(TestNG.java:765) at org.testng.TestNG.run(TestNG.java:699) at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:73) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:122)
How can I get transaction working with SeamTest ?
Am I wrong when I'm planning to manually manage transactions with MyApi ?
Thanks for your support :)