jeudi 18 août 2016

Use different persistence.xml for testing in arquillian

Env: Java EE 7 - Wildfly 10 - Arquillian

The persistence.xml file resides in src/main/resources/META-INF/persistence.xml and looks like this:

<persistence-unit name="primary" transaction-type="JTA">
    <jta-data-source>java:jboss/datasources/test</jta-data-source>
    <class>com.model.MyEntity1</class>
    <properties>
        <property name="javax.persistence.schema-generation.database.action" value="drop-and-create" />
        <property name="javax.persistence.schema-generation.create-source" value="script"/>
        <property name="javax.persistence.schema-generation.drop-source" value="script"/>
        <property name="javax.persistence.schema-generation.create-script-source" value="META-INF/sql/create.sql" />
        <property name="javax.persistence.schema-generation.drop-script-source" value="META-INF/sql/drop.sql" />
    </properties>
</persistence-unit>

For testing reasons i would like to use a different persistence.xml. My test persistence resides in src/test/resources/test-persistence.xml and looks like this (it does not execute any sql scripts upon deployment)

<persistence-unit name="primary" transaction-type="JTA">
    <jta-data-source>java:jboss/datasources/test</jta-data-source>
    <class>com.model.MyEntity1</class>
    <properties>
        <property name="javax.persistence.schema-generation.database.action" value="drop-and-create" />
    </properties>
</persistence-unit>

My arquillian deployment test:

@Deployment
public static Archive<?> createTestArchive() {
    return ShrinkWrap.create(WebArchive.class)
            .addPackage(MyEntity1.class.getPackage())
            .addPackage(EntityManagerProducer.class.getPackage())
            .addAsResource("test-persistence.xml", "META-INF/persistence.xml")
            .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
}

Running the arquillian test it seems that during deployment the server tries to execute the create and drop sql scripts as they are defined in the persistence.xml! I.e. it seems that my test-persistence.xml is ignored and instead the main persistence.xml is loaded.

Any help?

Aucun commentaire:

Enregistrer un commentaire