3 Replies Latest reply on Sep 24, 2012 8:53 AM by bmajsak

    Arquillian persistence with glassfish remote and postgresql

    milanche

      I've been trying to set up persistence testing as show in this guide. I am using glassfish remote, so I changed arquillian.xml file to suit my settings. And the tests work fine with Derby DB.

      However, I wanted to test persistence in my other (playground) project that runs with glassfish and postgrsql 9.2.1, but I ran into problems with configuring the testing environment.

      The problem is that GamePersistenceTest doesn't run.

      I have MVC configured project (CarApplication) and "entity" is a subproject.

       

      Here is the maven output for entity (sub)project

      -------------------------------------------------------

      T E S T S

      -------------------------------------------------------

      Running com.codenious.root.ejb.ejbentity.GamePersistenceTest

      Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNGMapConfigurator@6b125fac

      Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.278 sec

       

       

      Results :

       

       

      Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

       

       

      ------------------------------------------------------------------------

      BUILD SUCCESS

      ------------------------------------------------------------------------

      Total time: 2.773s

      Finished at: Mon Sep 24 13:45:12 CEST 2012

      Final Memory: 13M/214M

      ------------------------------------------------------------------------

       

      There is no output from the glassfish console. So I assume that testing had failed before even deployed to the server instance.

      I would appreciate, if anyone could help me with configuring arquillian framework.

       

      Here is my pom.xml (relevant part of it):

       

          <dependencyManagement>

              <dependencies>

                  <dependency>

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

                      <artifactId>arquillian-bom</artifactId>

                      <version>1.0.0.Final</version>

                      <scope>import</scope>

                      <type>pom</type>

                  </dependency>

              </dependencies>

          </dependencyManagement>

       

       

          <dependencies>

              <dependency>

                  <groupId>org.testng</groupId>

                  <artifactId>testng</artifactId>

                  <version>6.5.2</version>

                  <scope>test</scope>

              </dependency>

       

              <dependency>

                  <groupId>org.hibernate</groupId>

                  <artifactId>hibernate-jpamodelgen</artifactId>

                  <version>1.2.0.Final</version>

                  <scope>provided</scope>

              </dependency>

       

              <dependency>

                  <groupId>junit</groupId>

                  <artifactId>junit</artifactId>

                  <version>4.8.2</version>

                  <scope>test</scope>

              </dependency>

       

              <dependency>

                  <groupId>org.hibernate</groupId>

                  <artifactId>hibernate-core</artifactId>

                  <version>4.1.6.Final</version>

              </dependency>

       

              <dependency>

                  <groupId>org.slf4j</groupId>

                  <artifactId>slf4j-simple</artifactId>

                  <version>1.6.6</version>

              </dependency>

       

              <dependency>

                  <groupId>javassist</groupId>

                  <artifactId>javassist</artifactId>

                  <version>3.12.1.GA</version>

              </dependency>

       

              <dependency>

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

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

                  <scope>test</scope>

              </dependency>

       

          </dependencies>

       

      <build>

              <plugins>

                  <plugin>

                      <groupId>org.apache.maven.plugins</groupId>

                      <artifactId>maven-compiler-plugin</artifactId>

                      <version>2.3.2</version>

                      <configuration>

                          <source>1.6</source>

                          <target>1.6</target>

                          <compilerArguments>

                              <endorseddirs>${endorsed.dir}</endorseddirs>

                          </compilerArguments>

                      </configuration>

                  </plugin>

                  <plugin>

                      <groupId>org.apache.maven.plugins</groupId>

                      <artifactId>maven-ejb-plugin</artifactId>

                      <version>2.3</version>

                      <configuration>

                          <ejbVersion>3.1</ejbVersion>

                      </configuration>

                  </plugin>

                  <plugin>

                      <groupId>org.apache.maven.plugins</groupId>

                      <artifactId>maven-dependency-plugin</artifactId>

                      <version>2.1</version>

                      <executions>

                          <execution>

                              <phase>validate</phase>

                              <goals>

                                  <goal>copy</goal>

                              </goals>

                              <configuration>

                                  <outputDirectory>${endorsed.dir}</outputDirectory>

                                  <silent>true</silent>

                                  <artifactItems>

                                      <artifactItem>

                                          <groupId>javax</groupId>

                                          <artifactId>javaee-endorsed-api</artifactId>

                                          <version>6.0</version>

                                          <type>jar</type>

                                      </artifactItem>

                                  </artifactItems>

                              </configuration>

                          </execution>

                      </executions>

                  </plugin>

                  <plugin>

                      <artifactId>maven-surefire-plugin</artifactId>

                      <version>2.12</version>

                  </plugin>

              </plugins>

          </build>

       

      <profiles>

              <profile>          

                  <id>arquillian-glassfish-remote</id>

                  <dependencies>

                      <dependency>

                          <groupId>org.jboss.spec</groupId>

                          <artifactId>jboss-javaee-web-6.0</artifactId>

                          <version>3.0.0.Final</version>

                          <type>pom</type>

                          <scope>provided</scope>

                          <exclusions>

                              <exclusion>

                                  <groupId>xalan</groupId>

                                  <artifactId>xalan</artifactId>

                              </exclusion>

                          </exclusions>

                      </dependency>

                      <dependency>

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

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

                          <version>1.0.0.CR3</version>

                          <scope>test</scope>

                      </dependency>

                      <dependency>

                          <groupId>postgresql</groupId>

                          <artifactId>postgresql</artifactId>

                          <version>9.1-901.jdbc4</version>

                          <scope>test</scope>

                      </dependency>               

                  </dependencies>          

                  <build>

                      <testResources>

                          <testResource>

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

                          </testResource>

                          <testResource>

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

                          </testResource>

                      </testResources>

                  </build>

              </profile>

      </profiles>

       

      Here is test/resources-glassfish-remote/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>jdbc/rootApp</jta-data-source>

          <class>com.codenious.root.ejb.ejbentity.Car</class>

          <class>com.codenious.root.ejb.ejbentity.Renter</class>

          <class>com.codenious.root.ejb.ejbentity.UserGroup</class>

          <class>com.codenious.root.ejb.ejbentity.Game</class>

          <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>

          <validation-mode>CALLBACK</validation-mode>

          <properties>

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

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

          </properties>

        </persistence-unit>

      </persistence>

       

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

      <!DOCTYPE resources PUBLIC

          "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN"

          "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">

      <resources>

          <jdbc-resource pool-name="RootPool"

              jndi-name="jdbc/rootApp"/>

          <jdbc-connection-pool name="RootPool"

              res-type="javax.sql.DataSource"

              datasource-classname="org.postgresql.ds.PGSimpleDataSource"

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

              <property name="databaseName" value="m..."/>

              <property name="PortNumber" value="5..."/>

              <property name="ServerName" value="192..."/>

              <property name="User" value="..."/>

              <property name="password" value="..."/>

          </jdbc-connection-pool>

       

       

          <!--

          <jdbc-resource pool-name="ArquillianEmbeddedH2Pool"

              jndi-name="jdbc/arquillian"/>

          <jdbc-connection-pool name="ArquillianEmbeddedH2Pool"

              res-type="javax.sql.DataSource"

              datasource-classname="org.h2.jdbcx.JdbcDataSource">

              <property name="user" value="sa"/>

              <property name="password" value=""/>

              <property name="url" value="jdbc:h2:file:target/databases/h2/db"/>

          </jdbc-connection-pool>

          -->

      </resources>

       

       

      src/test/resources/arquillian.xml:

      (I tried to add glassfish-resources.xml with property "resourcesXml", but it doesn't work either.)

       

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

      <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="glassfish-remote" default="true" >

              <configuration>

                  <property name="glassFishHome">/opt/app/glassfish-3.1.2.2</property>

                  <property name="adminHost">localhost</property>

                  <property name="adminPort">4...</property>

                  <property name="resourcesXml">

                      src/test/resources-glassfish-remote/glassfish-resources.xml

                  </property>

              </configuration>

          </container>

      </arquillian>

       

      src/test/resources/resources-glassfish-remote/glassfish-resources.xml:

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

      <!DOCTYPE resources PUBLIC

          "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN"

          "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">

      <resources>

          <jdbc-resource pool-name="RootPool"

              jndi-name="jdbc/rootApp"/>

          <jdbc-connection-pool name="RootPool"

              res-type="javax.sql.DataSource"

              datasource-classname="org.postgresql.ds.PGSimpleDataSource"

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

              <property name="databaseName" value="db_name"/>

              <property name="PortNumber" value="5..."/>

              <property name="ServerName" value="192..."/>

              <property name="User" value="user"/>

              <property name="password" value="pass"/>

          </jdbc-connection-pool>

       

       

          <!--

          <jdbc-resource pool-name="ArquillianEmbeddedH2Pool"

              jndi-name="jdbc/arquillian"/>

          <jdbc-connection-pool name="ArquillianEmbeddedH2Pool"

              res-type="javax.sql.DataSource"

              datasource-classname="org.h2.jdbcx.JdbcDataSource">

              <property name="user" value="sa"/>

              <property name="password" value=""/>

              <property name="url" value="jdbc:h2:file:target/databases/h2/db"/>

          </jdbc-connection-pool>

          -->

      </resources>


      src/test/resources/resources-glassfish-remote/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>jdbc/rootApp</jta-data-source>

          <class>com.codenious.root.ejb.ejbentity.Car</class>

          <class>com.codenious.root.ejb.ejbentity.Renter</class>

          <class>com.codenious.root.ejb.ejbentity.UserGroup</class>

          <class>com.codenious.root.ejb.ejbentity.Game</class>

          <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>

          <validation-mode>CALLBACK</validation-mode>

          <properties>

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

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

          </properties>

        </persistence-unit>

      </persistence>