Question

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)

My test looks like this:

@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
    }
}

My pom.xml looks like this:

...
<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>
...

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).

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

Was it helpful?

Solution

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

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

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

OTHER TIPS

If you are using eclipse add -javaagent:{your java agent path} to the VM arguments for the test.

In my case I took the java agent directly from a TomEE installation.

Run configuration

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top