Configurando Arquillian no Wildfly 8

Segue a baixo configuração do Arquillian para Wildfly 8.0.0.Final :

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
      http://maven.apache.org/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>
  <groupId>br.com.emmanuelneri.blog</groupId>
  <artifactId>cdi</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>CDI</name>

    <properties>
        <version.wildfly>8.0.0.Final</version.wildfly>
        <version.arquillian>1.1.4.Final</version.arquillian>
    </properties>

    <repositories>
        <repository>
            <id>JBoss Repository</id>
            <url>https://repository.jboss.org/nexus/content/groups/public/</url>
        </repository>
    </repositories>
  <dependencies>

      <dependency>
          <groupId>javax.enterprise</groupId>
          <artifactId>cdi-api</artifactId>
          <version>1.1</version>
          <scope>provided</scope>
      </dependency>

      <dependency>
          <groupId>org.hibernate.javax.persistence</groupId>
          <artifactId>hibernate-jpa-2.1-api</artifactId>
      </dependency>
      <dependency>
          <groupId>org.hibernate</groupId>
          <artifactId>hibernate-entitymanager</artifactId>
          <version>4.3.5.Final</version>
      </dependency>

      <dependency>
          <groupId>org.hibernate</groupId>
          <artifactId>hibernate-core</artifactId>
          <version>4.3.5.Final</version>
      </dependency>

      <dependency>
          <groupId>postgresql</groupId>
          <artifactId>postgresql</artifactId>
          <version>9.1-901.jdbc4</version>
      </dependency>

      <!-- Test-->
      <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>4.10</version>
          <scope>test</scope>
      </dependency>
      <dependency>
          <groupId>org.jboss.arquillian.junit</groupId>
          <artifactId>arquillian-junit-container</artifactId>
          <scope>test</scope>
      </dependency>
      <dependency>
          <groupId>org.wildfly</groupId>
          <artifactId>wildfly-arquillian-container-embedded</artifactId>
          <version>${version.wildfly}</version>
          <scope>test</scope>
      </dependency>
      <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-simple</artifactId>
          <scope>test</scope>
      </dependency>
      <dependency>
          <groupId>org.wildfly</groupId>
          <artifactId>wildfly-embedded</artifactId>
          <version>${version.wildfly}</version>
          <scope>test</scope>
      </dependency>
  </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.jboss.shrinkwrap.resolver</groupId>
                <artifactId>shrinkwrap-resolver-bom</artifactId>
                <version>2.1.0</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.wildfly.bom</groupId>
                <artifactId>jboss-javaee-7.0-with-all</artifactId>
                <version>${version.wildfly}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.jboss.arquillian</groupId>
                <artifactId>arquillian-bom</artifactId>
                <version>${version.arquillian}</version>
                <scope>import</scope>
                <type>pom</type>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <finalName>cdi</finalName>

        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.17</version>
                <configuration>
                    <systemPropertyVariables>
                        <java.util.logging.manager>
                             org.jboss.logmanager.LogManager
                        </java.util.logging.manager>
                    </systemPropertyVariables>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

arquillian.xml

<arquillian xmlns="http://jboss.org/schema/arquillian" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="
        http://jboss.org/schema/arquillian
        http://jboss.org/schema/arquillian/arquillian_1_0.xsd>
    <container qualifier="wildfly" default="true>
        <configuration>
            <property name="jbossHome>
                /Applications/wildfly-8.0.0.Final
            </property>
            <property name="modulePath>
                /Applications/wildfly-8.0.0.Final/modules
            </property>
        </configuration>
    </container>
</arquillian>

O caminho “/Applications/wildfly-8.0.0.Final” é o local do Wildfly na sua maquina.

Observação
O arquivo arquillian.xml deve ficar no seguinte diretório: src/test/resources/arquillian.xml.

Abaixo segue um teste persistindo o objeto pessoa, apenas para validação da configuração do Arquillian.

DbTest.java

@RunWith(Arquillian.class)
public class DbTest {

    @Deployment
    public static Archive<?> createDeployment() {
        return ShrinkWrap.create(WebArchive.class, "cdi.war")
                .addPackage(Pessoa.class.getPackage())
                .addAsResource("META-INF/persistence.xml")
                .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
    }

    @PersistenceContext(unitName = "cdiPU")
    private EntityManager entityManager;

    @Inject
    UserTransaction utx;

    @Test
    public void persistTest() throws SystemException, NotSupportedException, 
        HeuristicRollbackException, HeuristicMixedException, RollbackException {
        
        Pessoa pessoa = new Pessoa("Pessoa 1");

        utx.begin();
        entityManager.joinTransaction();
        entityManager.persist(pessoa);
        utx.commit();
        entityManager.clear();

        assertNotNull(pessoa.getId());
    }

}
Anúncios

Deixe um comentário

Preencha os seus dados abaixo ou clique em um ícone para log in:

Logotipo do WordPress.com

Você está comentando utilizando sua conta WordPress.com. Sair /  Alterar )

Foto do Google+

Você está comentando utilizando sua conta Google+. Sair /  Alterar )

Imagem do Twitter

Você está comentando utilizando sua conta Twitter. Sair /  Alterar )

Foto do Facebook

Você está comentando utilizando sua conta Facebook. Sair /  Alterar )

Conectando a %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.