wangscript / warp-persist

Automatically exported from code.google.com/p/warp-persist
0 stars 0 forks source link

Class-level @Transactional does not work with JUnit #27

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
My Setup: Guice 1.0, Warp-persist 2.0-20081028, JUnit 4.3.1, Hibernate 3

injector = Guice.createInjector(new ReportProModule(p),PersistenceService
   .usingHibernate()
   .across(UnitOfWork.TRANSACTION)
   .buildModule()
);

I wrote my own TestSuite that can Guice inject my JUnit classes. Although 
using JUnit 4, I did not use the JUnit annotations, just the old 
reflection way of JUnit 3. And I was using the plain old Transaction unit 
of work (so each test method gets its own transaction).

What I found was that if I put @Transactional on my test* methods, 
everything works fine.

But if I put @Transactional at the class level, Hibernate does not find 
its transaction and throws "saveOrUpdate is not valid without active 
transaction". 

Furthermore, if I then add ".forAll(Matchers.annotatedWith
(Transactional.class), Matchers.any())" to the PersistenceService, I 
get  "com.google.inject.cglib.core.CodeGenerationException: 
java.lang.reflect.InvocationTargetException-->null", with the underlying 
exception:  

java.lang.SecurityException: 
class "junit.framework.TestCase$$FastClassByCGLIB$$39a925f2"'s signer 
information does not match signer information of other classes in the same 
package

Original issue reported on code.google.com by doug.sat...@ymail.com on 1 Jan 2009 at 12:00

GoogleCodeExporter commented 9 years ago
Thanks for reporting this. It's normal that you need the additional 
configuration for
class level @Transactional. Other than that, this is an issue on the Guice side:
http://code.google.com/p/google-guice/issues/detail?id=149. Please comment on 
that
issue so that they are aware of your problem.

Your JUnit jar is probably signed, so then you have some options:
- Remove the signing information from junit.jar (or build from src)
- Sign the Guice jar with the same key JUnit uses.
- Patch Guice so that its Enhancer uses a custom namingpolicy that puts all 
generated
classes in a different package.

You could also have a look at the various testing frameworks that come with 
Guice
integration like GuiceBerry or AtUnit. Maybe that's what you're looking for?

Original comment by robbie.v...@gmail.com on 1 Jan 2009 at 7:08