Persistence.xml overridden in Arquillian tests

965 views Asked by At

Arquillian examples mainly show how to construct WarArchive, JavaArchive, etc. I can't find any good example how to override one of jar files which exists in already compile war file.

The reason is that one of the jars contains persistence.xml which I wan't to override to defined for instance hbm2ddl.auto etc.

What is the proper way to do that?

1

There are 1 answers

1
jensp On BEST ANSWER

The problem might be that your using ShrinkWrap.createFromZipFile. From my experience with Arquillian it better to create a custom WAR/JAR for each test. The method which creates the deployment usually looks like this:

@Deployment
public static WebArchive createDeployment() {
    //Load dependencies from POM
    final PomEquippedResolveStage pom = Maven
        .resolver()
        .loadPomFromFile("pom.xml");
    final PomEquippedResolveStage dependencies = pom
        .importCompileAndRuntimeDependencies();
    final File[] libs =         
      dependencies.resolve().withTransitivity().asFile();

    return ShrinkWrap
      .create(WebArchive.class,
              "ExampleArchive.war")
      .addPackage(org.example.Example.class.getPackage())
      .addAsLibraries(files)
      .addAsResource("test-persistence.xml",
                    "META-INF/persistence.xml")
      .addAsWebInfResource(EmptyAsset.INSTANCE, "WEB-INF/beans.xml"); 

}

The test-persistence.xml goes into your test resources directory.