我正在使用arquillian和dbunit进行一组集成测试。我可以很好地运行我的一些测试,但不能涉及与数据有oneToMany
关系的实体。运行我的测试时,我得到一个PersistenceException:
Caused by: java.lang.NullPointerException
at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.setInverseRelation(JDBCStoreManager.java:451)
我的测试看起来像这样:
@RunWith(Arquillian.class)
@CreateSchema("sql/masterplanCreateTables.sql")
public class MasterPlanManagerBeanDbIT {
@Rule
public PersistenceUnitRule rule = new PersistenceUnitRule();
@Inject
private MasterplanManager instance;
@PersistenceContext
EntityManager entityManager;
@Deployment
public static WebArchive createDeployment() throws Exception {
return ShrinkWrap
.create(WebArchive.class, .....
}
@Test
@UsingDataSet("/data/integration/uttrans/masterplan/validData_dbInput.xml")
public void updateTrip_givenValidInput_expectsTripToBeUpdated() {
Trip input = givenTrips().get(0);
input.setNote("updated value");
Trip updated = instance.updateTrip(input);
checkEquality(input, updated);//checks field by field for equality
}
}
我的pom.xml
看起来像这样:
...
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.0.1.Final</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
...
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.openejb</groupId>
<artifactId>arquillian-tomee-embedded</artifactId>
<version>${tomee.version}</version>
<scope>test</scope>
</dependency>
...
</dependencies>
...
我确实尝试openjpa-maven-plugin
在构建时增强实体,但这将改变已编译的实体,这些实体稍后将部署到我们的生产环境(使用部署时增强)。
考虑到这一点,是否可以在我的arquillian测试中启用部署时增强功能?
答案 0 :(得分:1)
当我使用openJpa时,我发现此链接非常有用:
http://openejb.apache.org/javaagent.html
我只是将openejb java-agent提供给maven surefire插件。
答案 1 :(得分:0)