Cannot make sequent calls in functional test if JPA is involved

Bug #490897 reported by tomas
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
play framework
Status tracked in 1.0
1.0
Fix Released
Undecided
Unassigned
1.1
Fix Committed
Undecided
Unassigned

Bug Description

If I try to make more than one request during a functional test, I get an JPAException. Using 1.0-r715.

create new application, configure db for memory usage (tested for mysql also)
add an entity
to Application.index, add something to touch the database
to ApplicationTest, add another request to "/" in the same method.
Result - exception on the second request:
play.exceptions.JPAException: The JPA context is not initialized. JPA Entity Manager automatically start when one or more classes annotated with the @javax.persistence.Entity annotation are found in the application.
 at play.db.jpa.JPA.get(JPA.java:19)
 at play.db.jpa.JPA.em(JPA.java:52)
 at play.db.jpa.JPASupport.em(JPASupport.java:447)
 at models.Person.findAll(Person.java)
 at controllers.Application.index(Application.java:9)
 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:597)
 at play.utils.Java.invokeStatic(Java.java:129)
 at play.mvc.ActionInvoker.invoke(ActionInvoker.java:128)
 at play.test.FunctionalTest.makeRequest(FunctionalTest.java:149)
 at play.test.FunctionalTest.GET(FunctionalTest.java:55)
 at ApplicationTest.testThatIndexPageWorks(ApplicationTest.java:13)
 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:597)
 at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
 at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
 at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
 at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
 at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
 at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
 at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
 at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
 at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
 at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
 at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
 at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
 at org.junit.internal.runners.CompositeRunner.runChildren(CompositeRunner.java:33)
 at org.junit.internal.runners.CompositeRunner.run(CompositeRunner.java:28)
 at org.junit.runner.JUnitCore.run(JUnitCore.java:130)
 at org.junit.runner.JUnitCore.run(JUnitCore.java:109)
 at org.junit.runner.JUnitCore.run(JUnitCore.java:100)
 at play.test.TestEngine$1.call(TestEngine.java:84)
 at play.test.TestEngine$1.call(TestEngine.java:80)
 at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
 at java.util.concurrent.FutureTask.run(FutureTask.java:138)
 at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
 at java.lang.Thread.run(Thread.java:619)

Revision history for this message
tomas (gugljafa) wrote :
Changed in play:
status: New → Confirmed
status: Confirmed → Fix Committed
Revision history for this message
Guillaume Bort (guillaume-bort) wrote :

Thank you.

Revision history for this message
tomas (gugljafa) wrote :

I get almost same exception when I copy the GET method from FunctionalTest into a UnitTest and use Fixtures.deleteAll in @Before method. It is strange that the test fails on the second test, and the TestRunner marks the whole test case as green

Changed in play:
status: Fix Committed → Incomplete
Revision history for this message
Guillaume Bort (guillaume-bort) wrote :

You can't do that since it totally breaks the test execution model.

Changed in play:
status: Incomplete → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.