3 Replies Latest reply on Feb 18, 2012 4:39 AM by Bartosz Majsak

    Arquillian Embedded glassfish + EJB + JPA

    vicente san silvestre chacon Newbie

      Hi arquillian team Im new to the framework and Im having troubles setting my first project, I'm trying to run a test of a EJB that inserts a user in to a Database

       

      and I want to use Derby inmemory database in order to run my tests on any computer  please help I went through all the examples I could find and no luck

      Im getting the following error:

       

      error:

      Invalid resource : { ResourceInfo : (jndiName=java:app/jdbc/arquillian__pm), (applicationName=test) }

       

      My userBean:

       

       

      @Entity

      @Table(name = "WebUser")

      public class WebUser implements Serializable {

          private static final long serialVersionUID = 1L;

          @Id

          @GeneratedValue(strategy = GenerationType.IDENTITY)

          @Basic(optional = false)

          @Column(name = "id")

          private Integer id;

          @Basic(optional = false)

          @Column(name = "name")

          private String name;

          @Basic(optional = false)

          @Column(name = "lastname")

          private String lastname;

          @Column(name = "email")

          private String email;

      ......

       

      My EJB:

       

       

      @Named

      @Stateless

      public class WebUserService {

          @PersistenceContext

          private EntityManager em;

       

       

          public void insert(WebUser webUser) {

            em.persist(webUser)

          }    

       

      }

       

      my Pom.xml

       

       

      ...

          <!--REPOSITORIES-->

          <repositories>

              <repository>

                  <id>java.net2</id>

                  <name>Repository hosting the jee6 artifacts</name>

                  <url>http://download.java.net/maven/2</url>

              </repository>

              <repository>

                  <url>http://download.java.net/maven/2/</url>

                  <id>jsf20</id>

                  <layout>default</layout>

              </repository>

              <repository>

                  <id>JBoss</id>

                  <name>JBoss Repository</name>

                  <url>https://repository.jboss.org/nexus/content/groups/public/</url>

              </repository>

              <repository>

                  <id>Glassfish</id>

                  <name>Glassfish Repository</name>

                  <url>http://download.java.net/maven/glassfish</url>

              </repository>

          </repositories>

       

       

          <dependencyManagement>

              <dependencies>

                  <dependency>

                      <groupId>org.jboss.arquillian</groupId>

                      <artifactId>arquillian-bom</artifactId>

                      <version>1.0.0.Final-SNAPSHOT</version>

                      <scope>import</scope>

                      <type>pom</type>

                  </dependency>

              </dependencies>

          </dependencyManagement>

       

       

          <dependencies>

       

              <dependency>

                  <groupId>org.hibernate</groupId>

                  <artifactId>hibernate-entitymanager</artifactId>

                  <version>3.6.5.Final</version>

              </dependency>

       

              <dependency>

                  <groupId>org.hibernate</groupId>

                  <artifactId>hibernate-validator</artifactId>

                  <version>4.2.0.Final</version>

              </dependency>

       

              <dependency>

                  <groupId>org.hibernate.javax.persistence</groupId>

                  <artifactId>hibernate-jpa-2.0-api</artifactId>

                  <version>1.0.0.Final</version>

              </dependency>

       

              <dependency>

                  <groupId>hsqldb</groupId>

                  <artifactId>hsqldb</artifactId>

                  <version>1.8.0.7</version>

                  <scope>test</scope>

              </dependency>

       

              <dependency>

              <groupId>org.hibernate</groupId>

              <artifactId>hibernate-jpamodelgen</artifactId>

              <version>1.1.1.Final</version>

              <scope>provided</scope>

              </dependency>

       

       

              <dependency>

                  <groupId>org.slf4j</groupId>

                  <artifactId>slf4j-log4j12</artifactId>

                  <version>1.6.1</version>

              </dependency>

       

       

              <!--ARQUILLIAN-->

              <dependency>

                  <groupId>junit</groupId>

                  <artifactId>junit</artifactId>

                  <version>4.8.2</version>

                  <scope>test</scope>

              </dependency>

       

              <dependency>

                  <groupId>org.jboss.arquillian.container</groupId>

                  <artifactId>arquillian-glassfish-embedded-3.1</artifactId>

                  <scope>test</scope>

              </dependency>

       

              <dependency>

                  <groupId>org.jboss.arquillian.junit</groupId>

                  <artifactId>arquillian-junit-container</artifactId>

                  <scope>test</scope>

              </dependency>

       

          </dependencies>

       

          <profiles>

              <profile>

                  <id>glassfish-embedded</id>

                  <activation>

                      <activeByDefault>true</activeByDefault>

                  </activation>

       

                  <dependencies>

                      <dependency>

                          <groupId>org.jboss.arquillian.container</groupId>

                          <artifactId>arquillian-glassfish-embedded-3.1</artifactId>

                          <version>1.0.0.Final-SNAPSHOT</version>

                      </dependency>

                      <dependency>

                          <groupId>org.glassfish.extras</groupId>

                          <artifactId>glassfish-embedded-all</artifactId>

                          <version>3.2-b06</version>

                      </dependency>

                  </dependencies>

                  <build>

                      <testResources>

                          <testResource>

                              <directory>src/test/resources</directory>

                          </testResource>

                          <testResource>

                              <directory>src/test/resources-glassfish-embedded</directory>

                          </testResource>

                      </testResources>

                  </build>

              </profile>

          </profiles>

       

       

      my  sun-resources.xml file

      <?xml version="1.0" encoding="UTF-8"?>

      <!DOCTYPE resources PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Resource Definitions //EN"

              "http://www.sun.com/software/appserver/dtds/sun-resources_1_4.dtd">

      <resources>

       

          <jdbc-resource pool-name="ArquillianEmbeddedDerbyPool"

                         jndi-name="jdbc/arquillian"/>

          <jdbc-connection-pool name="ArquillianEmbeddedDerbyPool"

                                res-type="javax.sql.DataSource"

                                datasource-classname="org.apache.derby.jdbc.EmbeddedDataSource"

                                is-isolation-level-guaranteed="false">

              <property name="databaseName" value="target/databases/derby"/>

              <property name="createDatabase" value="create"/>

          </jdbc-connection-pool>

       

      </resources>

       

       

      my test-persistence.xml

       

       

      <?xml version="1.0" encoding="UTF-8"?>

      <persistence version="2.0" 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_2_0.xsd">

         <persistence-unit name="test" transaction-type="JTA">

            <provider>org.hibernate.ejb.HibernatePersistence</provider>

            <jta-data-source>java:app/jdbc/arquillian</jta-data-source>

              <properties>

                  <property name="hibernate.archive.autodetection" value="class" />

                  <property name="hibernate.format_sql" value="true"/>

                  <property name="hibernate.hbm2ddl.auto" value="create"/>

              </properties>

         </persistence-unit>

      </persistence>

       

       

      my arquillian.xml

       

       

      <?xml version="1.0" encoding="UTF-8"?>

      <arquillian xmlns="http://jboss.com/arquillian"

         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

         xmlns:glassfish-embedded="urn:arq:org.jboss.arquillian.container.glassfish.embedded_3">

       

         <glassfish-embedded:container>

             <glassfish-embedded:sunResourcesXml>src/test/resources-glassfish-embedded/sun-resources.xml</glassfish-embedded:sunResourcesXml>

         </glassfish-embedded:container>

       

      </arquillian>

       

       

      My test:

       

       

      @RunWith(Arquillian.class)

      public class WebUserServiceTest {

       

          @Inject

          private WebUserService webUserService;

       

          @Deployment

          public static JavaArchive createTestArchive() {

              return ShrinkWrap.create(JavaArchive.class, "test.jar")

                      .addClasses(WebUserService.class)

                      .addAsManifestResource("test-persistence.xml", "persistence.xml")

                      .addAsManifestResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"));

          }

       

          @Test

          public void testCanPersistUserObject() {

              Assert.assertTrue(true);   

          }

       

       

      this is my email address lema017@gmail.com

      this is my skype_id : vicente.san.silvestre

       

      I attached my project is really small I created only to test arquillian and contains only one entity and one ejb and one test

       

      pls help