1 Reply Latest reply on Feb 5, 2013 1:29 PM by Diego Gusava

    Arquillian Seam 2 test database

    Diego Gusava Newbie

      Hi guys,

      i am trying to use Arquillian with the seam-2 extension and h2 database, but seems that i can´t inject a EntityManager, always return null

       

      my components

       

       

      <?xml version="1.0" encoding="UTF-8"?>
      <components xmlns="http://jboss.com/products/seam/components"
                xmlns:core="http://jboss.com/products/seam/core"
                xmlns:document="http://jboss.com/products/seam/document"
                xmlns:pdf="http://jboss.com/products/seam/pdf"
          xmlns:persistence="http://jboss.com/products/seam/persistence"
          xmlns:transaction="http://jboss.com/products/seam/transaction"
          xmlns:drools="http://jboss.com/products/seam/drools"
          xmlns:bpm="http://jboss.com/products/seam/bpm"
          xmlns:security="http://jboss.com/products/seam/security"
          xmlns:mail="http://jboss.com/products/seam/mail"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:web="http://jboss.com/products/seam/web"
          xsi:schemaLocation=
                    "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.1.xsd
                    http://jboss.com/products/seam/document http://jboss.com/products/seam/document-2.1.xsd
              http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.1.xsd
              http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.1.xsd
              http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.1.xsd
              http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.1.xsd
              http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.1.xsd
              http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.1.xsd
              http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.1.xsd
              http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.1.xsd">
      
      
                   <persistence:managed-persistence-context name="entityManager" auto-create="true" 
                             entity-manager-factory="#{arquillianEntityManagerFactory}"/>
      
      
                   <persistence:entity-manager-factory name="arquillianEntityManagerFactory" persistence-unit-name="arquillian"/>
      
      
      </components>
      
      

       

      some dependencies of my  pom.xml

       

      <dependency>
                                    <groupId>junit</groupId>
                                    <artifactId>junit</artifactId>
                                    <version>${version.junit}</version>
                                    <scope>test</scope>
                          </dependency>
      
      
                          <dependency>
                                    <groupId>org.jboss.arquillian</groupId>
                                    <artifactId>arquillian-bom</artifactId>
                                    <version>${version.arquillian_core}</version>
                                    <type>pom</type>
                                    <scope>import</scope>
                          </dependency>
      
      
                          <dependency>
                                    <groupId>org.jboss.arquillian.junit</groupId>
                                    <artifactId>arquillian-junit-container</artifactId>
                                    <version>${version.arquillian_core}</version>
                                    <scope>test</scope>
                          </dependency>
      
      
                          <dependency>
                                    <groupId>org.jboss.arquillian.extension</groupId>
                                    <artifactId>arquillian-seam2</artifactId>
                                    <version>${version.arquillian.seam2}</version>
                                    <scope>test</scope>
                          </dependency>
      
      
                          <dependency>
                                    <groupId>org.easytesting</groupId>
                                    <artifactId>fest-assert</artifactId>
                                    <version>${version.fest.assert}</version>
                                    <scope>test</scope>
                          </dependency>
      
      
                          <dependency>
                                    <groupId>org.jboss.jbossas</groupId>
                                    <artifactId>jboss-server-manager</artifactId>
                                    <version>${version.org.jboss.jbossas_server-manager}</version>
                                    <scope>test</scope>
                          </dependency>
      
      
                          <dependency>
                                    <groupId>org.jboss.client</groupId>
                                    <artifactId>jbossall-client</artifactId>
                                    <version>${version.org.jboss.jbossas}</version>
                                    <scope>test</scope>
                          </dependency>
                          <dependency>
                                    <groupId>org.jboss.arquillian.container</groupId>
                                    <artifactId>arquillian-jbossas-managed-4.2</artifactId>
                                    <version>1.0.0.CR3</version>
                                    <scope>test</scope>
                          </dependency>
                          <dependency>
                                    <groupId>dom4j</groupId>
                                    <artifactId>dom4j</artifactId>
                                    <version>1.6.1</version>
                                    <scope>provided</scope>
                          </dependency>
      
      
                          <dependency>
                                    <groupId>com.h2database</groupId>
                                    <artifactId>h2</artifactId>
                                    <version>1.3.166</version>
                                    <scope>test</scope>
                          </dependency>
      
      

       

      my class

       

      package com.saudesuplementar.qualirede.helpers.test;
      
      
      import javax.persistence.EntityManager;
      
      
      import org.jboss.arquillian.container.test.api.Deployment;
      import org.jboss.arquillian.junit.Arquillian;
      import org.jboss.seam.annotations.In;
      import org.jboss.shrinkwrap.api.Archive;
      import org.jboss.shrinkwrap.api.ShrinkWrap;
      import org.jboss.shrinkwrap.api.asset.EmptyAsset;
      import org.jboss.shrinkwrap.api.spec.WebArchive;
      import org.junit.Test;
      import org.junit.runner.RunWith;
      
      
      import com.saudesuplementar.qualirede.model.Uf;
      
      
      @RunWith(Arquillian.class)
      public class UfTest {
      
      
          /**
           * EntityManager injetado pelo JBoss Seam.
           */
          @In("#{entityManager}")
          EntityManager entityManager;
      
      
          @Deployment
          public static Archive<?> createDeployment() {
              return ShrinkWrap
                      .create(WebArchive.class, "qualirede.war")
                      .addPackages(true, "com.saudesuplementar.qualirede.model")
                      .addPackages(true, "org.fest")
                      .addAsResource(EmptyAsset.INSTANCE, "seam.properties")
                      .addAsResource("test-persistence.xml",
                              "classes/META-INF/persistence.xml")
                      .addAsWebInfResource("jbossas-ds.xml")
                      .setWebXML("web.xml");
          }
      
      
          @Test
          public void testeUf() throws Exception {
              // utx.begin();
              // em.joinTransaction();
              System.out.println("Inserting ufs...");
              Uf uf = new Uf();
              uf.setDescricao("Santa Catarina");
              uf.setSigla("SC");
              entityManager.persist(uf);
              // utx.commit();
              // em.clear();
          }
      
      
      }
      
      

       

      my jboss-ds.xml

       

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE datasources
          PUBLIC "-//JBoss//DTD JBOSS JCA Config 1.5//EN"
          "http://www.jboss.org/j2ee/dtd/jboss-ds_1_5.dtd">
      <datasources>
                <local-tx-datasource>
                          <jndi-name>arquillian</jndi-name>
                          <connection-url>jdbc:h2:mem:arquillian;DB_CLOSE_DELAY=-1</connection-url>
                          <driver-class>h2</driver-class>
                </local-tx-datasource>
      </datasources>
      

       

      my persistence.xml

       

      <?xml version="1.0" encoding="UTF-8"?>
      <persistence xmlns="http://java.sun.com/xml/ns/persistence"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
                version="1.0">
                <persistence-unit name="test">
                          <jta-data-source>java:/test</jta-data-source>
                          <properties>
                                    <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
                                    <property name="hibernate.hbm2ddl.auto" value="create-drop" />
                                    <property name="hibernate.show_sql" value="true" />
                                    <property name="hibernate.format_sql" value="true" />
                          </properties>
                </persistence-unit>                               
      </persistence>
      
      

       

      is there any example to help me here?

       

      Thanks