Arquillian集成测试和OpenJPA增强 [英] Arquillian integration tests and OpenJPA enhancement

查看:113
本文介绍了Arquillian集成测试和OpenJPA增强的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Arquillian和dbunit进行一组集成测试.我可以很好地运行某些测试,但不能运行涉及与数据具有oneToMany关系的实体的测试.在运行测试时,我会收到PersistenceException:

I'm working on a set of integration tests using arquillian and dbunit. I can run some of my tests just fine, but not the ones involving entities which have oneToMany relations with data in them. When running my tests I then get a 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来在构建时增强实体,但这会改变已编译的实体,随后将其部署到我们的生产环境中(使用部署时增强).

I did try the openjpa-maven-plugin to enhance the entities at build-time, but this will afaik alter the compiled entities which later will be deployed to our production environment (using deploy-time enhancement).

考虑到这一点,是否可以在我的Arquillian测试中启用部署时间增强功能?

With that in mind, is it possible to enable deploy-time enhancement in my arquillian tests?

推荐答案

在使用openJpa时,我发现此链接非常有用:

As I'm using openJpa, I found this link very helpful:

http://openejb.apache.org/javaagent.html

我只是向maven surefire插件提供了openejb java-agent.

I am simply providing the openejb java-agent to the maven surefire plugin.

这篇关于Arquillian集成测试和OpenJPA增强的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆