2 Replies Latest reply on Feb 24, 2017 2:21 AM by mjobanek

    Guidance in using Arquillian with Wildfly9

    jvskriubakken

      Hi all!

       

      We are developing applications currently running on Wildfly 9 (9.0.1.Final). Our stack is typically (sub modules in maven):

      - rest layer in webapp (jaxrs)

      - service layer

      - dao layer (jpa)

      - domain objects (with jpa annotations)

      - and we use of course CDI

      .. and we are putting it all together using Maven3.

       

      So far we have been creating our dependencies and injected them into our services manually when "integration testing" our code.  So I am very eager to use Arquillian and let it do all the job.

       

      But, after days of googling and reading I feel a bit stuck. And I

       

      This is what I've figured out so far:

      - use: Maven.resolver().loadPomFromFile("pom.xml").importRuntimeDependencies().resolve().withTransitivity() and add the result to archive as libraries to avoid manually setting up every dependency.

      - use ShrinkWrap to create a WebArchive

       

      My biggest question is:

      How do I best setup (simplest way/best practise) the @Deployetment and Arquillian so that I can test my whole stack from webapp to database (with JPA and H2database in memory) against Wildfly 9?

      Preferably I would like it run as as embedded? as it then requires no preparment (of any Wildfly installation) before running the integration tests with maven. Is it possible at all?

       

      Thanks for any guidance or help!

       

      Jørund

        • 1. Re: Guidance in using Arquillian with Wildfly9
          jvskriubakken

          So, here is an update on my current approach

           

          1. I've minimised the @Deployment method with the use of the MavenImporter:

          @Deployment
          public static Archive createDeployment() {

           

             return ShrinkWrap

            .create(MavenImporter.class)

            .loadPomFromFile("pom.xml")

            .importBuildOutput()

            .as(WebArchive.class)

            .addAsWebInfResource("test-ds.xml", "test-ds.xml");
          }

           

          I'm pretty happy with firing up the whole application with such few lines. However, one obstacle is left: I would really like to avoid duplicating my persistence.xml which resides in my dao module (containing JPA entities and daos) as my persistence.xml list each entity. However I soon see this at the only solution as I do not figure out how to override the jpa property javax.persistence.schema-generation.database.action which in production i set to "none" and in test must be "drop-and-create". Is there any elegant solution to doing this without duplicating my persistence.xml?

           

          I've attached my pom and test-ds.xml.

           

          Am I on the right track here, when using MavenImporter instead of the Persistence Extension?

           

          Cheers,

           

           

          Jøund

          • 2. Re: Guidance in using Arquillian with Wildfly9
            mjobanek

            Hi,

            if you need somehow hack you persistence.xml, you can try using ShrinkWrap Descriptors project - an article about it:How do I create or copy and modify persistence.xml, beans.xml, etc?

             

            As for your question: "Am I on the right track here, when using MavenImporter instead of the Persistence Extension?"

            MavenImporter (provided by ShrinkWrap Resolver) solves a different problem than the Persistence Extension. ShrinkWrap Resolver is a tool for managing maven dependencies (it doesn't test anything), but Persistence Extension is a tool that helps you writing tests for persistence layer (focused on the tests). So you can use both tools in one tests, but for different purposes.