0 Replies Latest reply on Oct 27, 2016 6:11 AM by Julien Lebrun

    Arquillian wildfly embedded with JPA MySQL

    Julien Lebrun Newbie

      Hello Arquillian community,

       

      I've been trying to set up Arquillian integration tests with Wildfly embedded.

      It works well until I wanted to integrate JPA (via persistence.xml / JTA) via MySQL driver.

       

      Here is my configuration :

       

      arquillian.xml

      <arquillian>

          <container qualifier="wildfly10" default="true">

              <configuration>

                  <property name="jbossHome">target/wildfly-10.0.0.Final/</property>

                  <property name="modulePath">target/wildfly-10.0.0.Final/modules</property>

              </configuration>

          </container>

      </arquillian>

       

      Maven pom.xml

      I use this dependency (last version) : wildfly-arquillian-container-embedded

      Then I use maven-dependency-plugin to unpack wildfly to my target directory.

      I also use a copy goal to set the MySQL driver and module.xml in target/wildfly-10.0.0.Final/modules/system/layers/base/com/mysql/main

       

      module.xml (the file I copy in wildfly module directory)

      <module xmlns="urn:jboss:module:1.1" name="com.mysql">

          <resources>

              <resource-root path="mysql-connector-java-5.1.6.jar"/>

          </resources>

          <dependencies>

              <module name="javax.api"/>

              <module name="javax.transaction.api"/>

              <module name="javax.servlet.api" optional="true"/>

          </dependencies>

      </module>

       

      wildfly-ds.xml

      <datasources>

          <drivers>

              <driver name="mysql" module="com.mysql">

                  <driver-class>com.mysql.jdbc.Driver</driver-class>

              </driver>

          </drivers>

          <datasource jta="true" jndi-name="mysql/calendar" pool-name="proj" enabled="true"

                      use-java-context="true" use-ccm="true">

              <connection-url>jdbc:mysql://localhost:3306/calendar</connection-url>

              <driver>mysql</driver>

              <security>

                  <user-name>xxxxxx</user-name>

                  <password>xxxxxx</password>

              </security>

              <statement>

                  <prepared-statement-cache-size>32</prepared-statement-cache-size>

                  <share-prepared-statements>true</share-prepared-statements>

              </statement>

          </datasource>

      </datasources>

       

      persistence.xml

      <persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" version="2.1">

          <persistence-unit name="calendar-data" transaction-type="JTA">

              <jta-data-source>mysql/calendar</jta-data-source>

              <properties>

                  <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />

              </properties>

          </persistence-unit>

      </persistence>

       

      Java tests

      @Deployment

      public static Archive<?> createDeploymentPackage() throws IOException {

       

          File[] files = Maven.resolver().loadPomFromFile("pom.xml")

                              .importRuntimeDependencies()

                              .resolve()

                              .withTransitivity().asFile();

          return ShrinkWrap.create(WebArchive.class)

                           .addPackages(true, "xxx.core")

                           .addPackages(true, "xxx.ejb")

                           .addAsLibraries(files)

                           .addAsWebInfResource("wildfly-ds.xml")

                           .addAsWebInfResource("test-beans.xml", "beans.xml")

                           .addAsResource("test-persistence.xml", "persistence.xml");

      }

       

      @Test

      public void inContainerTest() {

          // tests

      }

       

      The problem is when I run my test, it could not deploy the test archive.

      It seems all goes well until it try to find the mysql driver :

      WFLYJPA0033: Can't find a persistence unit named calendar-data in deployment \"f97662f5-7680-42dd-89a0-7f2dcdd9b982.war\""},

          "WFLYCTL0180: Services with missing/unavailable dependencies" => [

              "jboss.deployment.unit.\"f97662f5-7680-42dd-89a0-7f2dcdd9b982.war\".batch.environment is missing [jboss.deployment.unit.\"f97662f5-7680-42dd-89a0-7f2dcdd9b982.war\".beanmanager]",

              "jboss.data-source.\"jboss.naming.context.java.mysql.calendar\" is missing [jboss.jdbc-driver.mysql]"

          ]

       

      My application works well if I deploy to a Wildfly instance (without Arquillian) : the persistance.xml with the datasource works well.

       

      But with Arquillian in an embedded Wildfly container it seems it could not find the MySQL driver despite I deploy it in module directory with the module.xml.

       

      Anybody know if I did something wrong ?

      Thank you