Reputation: 283
So, I have a project which uses persistence.xml in main, it is in src/main/resources/META-INF
Now i want to use an in-memory database (H2) in writing automated unit test so i need to have another persistence.xml, i have it in src/test/resouce/META-INF
So my question is how can i over-ride the first persistence,
I am also using shrikwrap resolver to resolve all dependencies from pom.xml, so it resolves it all and i add it to shrikwrap to return WebArchive, is there any way, i tried many such as creating profile or maven filetering but doesnt work with Arquillian as i resolve everything and add to deployment.
You can find my Arquillian deployment below :
WebArchive[] file = Maven.resolver().loadPomFromFile("pom.xml")
.resolve("G:A:V").withTransitivity().as(WebArchive.class);
WebArchive war = ShrinkWrap.create(WebArchive.class, "test.war")
.addAsResource("META-INF/persistence.xml")
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
war.addAsLibraries(file);
return war;
Upvotes: 2
Views: 1024
Reputation: 1064
You have at least two options here.
StringAsset
- addAsResource(new StringAsset("<xml content>"), "META-INF/persistence.xml")
h2-test-persistence.xml
, in src/test/resources/
and add it using addAsResource("h2-test-persistence.xml", "META-INF/persistence.xml")
Upvotes: 0
Reputation: 2017
Have you tried adding the new resource after addAsLibrary(file)
?
WebArchive war = ShrinkWrap.create(WebArchive.class, "test.war")
.addAsLibraries(file)
.addAsResource("META-INF/persistence.xml")
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
Upvotes: 0