Reputation: 4747
I am learning Arquillian to see if I can add to it project.
I was able to create a test and deploying a "static" test-persistence.xml, similar to this tutorial.
My problem is that my real persistence.xml has different mappings () and entities (). To get my tests to work I have to either:
Alternative 4 is not feasible, since it can't be maintained. Alternative 1 is feasible, but I would like to keep my builds smaller. I tried both 2 and 3, but I was not able to find any way (I am using JavaEE, JPA 2.0 and Hibernate) to make any of them. It seems that Hibernate does not support adding entities/mappings on-the-fly and that Archive.AddAsResource accepts just a path, not a "file content", or something like this.
I think this is a common issue when testing with Arquillian. How can I build my persistence.xml in a way that it has only the things required for my test?
Upvotes: 2
Views: 149
Reputation: 616
Create a test version of your persistence.xml stored as a separate file in your source tree, and have ShrinkWrap add it to your test archives as a file asset.
return ShrinkWrap.create(JavaArchive.class)
.addAsManifestResource(new FileAsset(new File("src/test/resources/META-INF/test-persistence.xml")), "persistence.xml");
Upvotes: 2