when attempting combine spring test runner , powermock runner using powermockrule technique, exception thoughtworks xstream library whenever try inject entitymanager
using persistencecontext
annotation jpa. same test works fine when not using powermockrule
. ignore packages powermockloader @ start of test. tried various values @powermockignore
solves issues have powermock, however, error still happens when ignoring absolutely every package.
@powermockignore("*") @runwith(springjunit4classrunner.class) @contextconfiguration("/test-configuration.xml") public class springandpowermocktest { @rule public powermockrule rule = new powermockrule(); @persistencecontext private entitymanager manager; @test public void test() { } }
the exception follows -- links full backtrace on pastebin backtrace exceeded limit question length):
relevant persistence unit:
<persistence-unit name="inmemory"> <provider>org.hibernate.ejb.hibernatepersistence</provider> <properties> <property name="hibernate.connection.driver_class" value="org.h2.driver" /> <property name="hibernate.connection.url" value="jdbc:h2:mem:inmemoryunittests;mode=mysql;db_close_on_exit=false" /> <property name="hibernate.connection.username" value="sa" /> <property name="hibernate.connection.password" value="" /> <property name="hibernate.hbm2ddl.auto" value="create-drop" /> </properties> </persistence-unit>
maven dependencies:
<dependencies> <dependency> <groupid>org.powermock</groupid> <artifactid>powermock-module-junit4</artifactid> <version>1.5.1</version> <scope>test</scope> </dependency> <dependency> <groupid>org.powermock</groupid> <artifactid>powermock-api-mockito</artifactid> <version>1.5.1</version> <scope>test</scope> </dependency> <dependency> <groupid>org.mockito</groupid> <artifactid>mockito-core</artifactid> <version>1.9.5</version> <scope>test</scope> </dependency> <dependency> <groupid>org.powermock</groupid> <artifactid>powermock-api-easymock</artifactid> <version>1.5.1</version> <scope>test</scope> </dependency> <dependency> <groupid>org.powermock</groupid> <artifactid>powermock-module-junit4-rule</artifactid> <version>1.5.1</version> <scope>test</scope> </dependency> <dependency> <groupid>org.powermock</groupid> <artifactid>powermock-classloading-xstream</artifactid> <version>1.5.1</version> <scope>test</scope> </dependency> </dependencies>
testing using spring 3.2.3.release
. note have tested spring-test version 3.0.5.release
indeed resolve other errors spring/powermock combination, not one.
i had similar issue , suggested me create resources.java class produced entity manager.
@stateful public class resources implements serializable { @persistencecontext (type = persistencecontexttype.transaction) private entitymanager entitymanager; @produces public entitymanager getentitymanager() { return entitymanager; } }
i'm still not sure why solution worked me... did.
v/r ace
Comments
Post a Comment