2

I try to make a test with Arquillian in a maven project however in every execution of the test that gives me the following exception:

Grave: Exception in command execution : java.lang.NoClassDefFoundError: javax/validation/ParameterNameProvider
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.855 sec <<< FAILURE!
Tests in error: 
es.costa.service.test.magali.PersonaFactorTest: Could not setup GlassFish Embedded Runtime
Caused by: org.glassfish.embeddable.GlassFishException: PlainTextActionReporterFAILUREjava.lang.NoClassDefFoundError: javax/validation/ParameterNameProviderjava.lang.NoClassDefFoundError: javax/validation/ParameterNameProvider
java.lang.RuntimeException: Could not setup GlassFish Embedded Runtime

This is the pom.xml:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.jboss.arquillian</groupId>
            <artifactId>arquillian-bom</artifactId>
            <version>1.0.3.Final</version>
            <scope>import</scope>
            <type>pom</type>
        </dependency>
    </dependencies>
</dependencyManagement>
<dependencies>
    <dependency>
        <groupId>org.jboss.ejb3</groupId>
        <artifactId>jboss-ejb3-ext-api</artifactId>
        <version>2.1.0</version>
    </dependency>
    <dependency>
        <groupId>es.costa</groupId>
        <artifactId>costa-interfaces</artifactId>
        <version>${project.version}</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.jboss.arquillian.junit</groupId>
        <artifactId>arquillian-junit-container</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>5.1.3.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator-annotation-processor</artifactId>
        <version>5.0.3.Final</version>
    </dependency>
</dependencies>
<build>
    <sourceDirectory>ejbModule/src/main/java</sourceDirectory>
    <testSourceDirectory>ejbModule/src/test/java</testSourceDirectory>
    <resources>
        <resource>
            <directory>ejbModule/src/main/resources</directory>
            <excludes>
                <exclude>**/*.java</exclude>
            </excludes>
        </resource>
    </resources>
    <testResources>
        <testResource>
            <directory>ejbModule/src/test/resources</directory>
        </testResource>
    </testResources>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${maven-compiler-plugin.version}</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
                <encoding>Cp1252</encoding>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.12</version>
        </plugin>
        <plugin>
            <artifactId>maven-ejb-plugin</artifactId>
            <version>${maven-ejb-plugin.version}</version>
            <configuration>
                <ejbVersion>${ejb.version}</ejbVersion>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <artifactSet>
                    <includes>
                        <include>es.costa</include>
                    </includes>
                </artifactSet>
                <finalName>${artifactId}-${project.version}</finalName>
            </configuration>
        </plugin>


        <plugin>
            <groupId>org.jboss.as.plugins</groupId>
            <artifactId>jboss-as-maven-plugin</artifactId>
            <configuration>
                <filename>${artifactId}-${project.version}.jar</filename>
            </configuration>
        </plugin>
    </plugins>
</build>
<profiles>
    <profile>
        <id>dev</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <dependencies>
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-entitymanager</artifactId>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>javax.persistence</groupId>
                <artifactId>persistence-api</artifactId>
                <version>${javax-persistance.version}</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </profile>
    <profile>
        <id>jenkins</id>
        <dependencies>
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-entitymanager</artifactId>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>javax.persistence</groupId>
                <artifactId>persistence-api</artifactId>
                <version>${javax-persistance.version}</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </profile>
    <profile>
        <id>arquillian-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.CR3</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.glassfish.main.extras</groupId>
                <artifactId>glassfish-embedded-all</artifactId>
                <version>3.1.2</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>com.h2database</groupId>
                <artifactId>h2</artifactId>
                <version>1.3.166</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
        <build>
            <testResources>
                <testResource>
                    <directory>ejbModule/src/test/resources</directory>
                </testResource>
                <testResource>
                    <directory>ejbModule/src/test/resources-glassfish-embedded</directory>
                </testResource>
            </testResources>
            <plugins>
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.12</version>
                    <configuration>
                        <systemPropertyVariables>
                           <arquillian.launch>glassfish-embedded</arquillian.launch>
                            <java.util.logging.config.file>
                                ${project.build.testOutputDirectory}/logging.properties
                            </java.util.logging.config.file>
                            <derby.stream.error.file>
                                ${project.build.directory}/derby.log
                            </derby.stream.error.file>
                        </systemPropertyVariables>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

this is the arquillian.xml

<?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-embedded" default="true">
    <configuration>
        <property name="resourcesXml">
            ejbModule/src/test/resources-glassfish-embedded/glassfish-resources.xml
        </property>
    </configuration>
</container>    

This is 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="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>    

Abder KRIMA
  • 3,418
  • 5
  • 31
  • 54

2 Answers2

0

There are many issues with your files that I can see without even trying your code. Many of the necessary steps and configurations are missing from your files.

  1. You do not have the the reference to the arquillian container from your pom.xml

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>                       
        <configuration>
            <systemPropertyVariables>                               
                <arquillian.launch>glassfish-embedded</arquillian.launch>
            </systemPropertyVariables>
        </configuration>
    </plugin>
    
  2. You should make sure that the glassfish container properties are correctly specified in the arquillian.xml. Example:

    <property name="resourcesXml">src/test/resources/domain.xml</property>
    <property name="glassFishHome">${glassfish.managed.home}</property>
    

    You can get the full list of properties at https://docs.jboss.org/author/display/ARQ/GlassFish+3.1+-+Embedded

  3. Pay particular attention to whether you specify glassfish-resources.xml or domain.xml in the resourcesXml attrbiute. Generally, you can have the glassfish-resources.xml bundled within the application war.

I suggest you refer to:

  1. https://github.com/arquillian/arquillian-examples
  2. http://arquillian.org/guides/getting_started/
Kalle Richter
  • 8,008
  • 26
  • 77
  • 177
KayDK
  • 134
  • 10
  • First thank you for having to answer my post: 1) I don't what do you mean by that? 2) The glassfish container properties are correctly specified int the arquillian.xml – Abder KRIMA Apr 29 '15 at 14:53
  • Explanation of Point 1: In pom.xml, the arquillian container needs to know what actual container to use i.e. glassfish, jboss etc. It needs to go to arquillian.xml and then read the container properties. This step enabled that link. – KayDK Apr 29 '15 at 15:09
  • i added the modifications as you said but it gives me the same error and i change de location of the files : `glassfish-resources.xml` and `test-persistence.xml` and `logging.properties` into ejbModule/src/test/resources-glassfish-embedded source folder – Abder KRIMA Apr 29 '15 at 15:28
  • Point 1 is optional because there’s only one container specified in `arquillian.xml` and, more specifically, because it is marked as the default: `default="true"`. – ᴠɪɴᴄᴇɴᴛ Jul 26 '16 at 12:59
0

i removed the block of code :

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-validator</artifactId>
    <version>5.1.3.Final</version>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-validator-annotation-processor</artifactId>
    <version>5.0.3.Final</version>
</dependency>

And i think that it solved the problem but now i have an other error message :

ArquillianServletRunner not found. Could not determine ContextRoot from ProtocolMetadata, please contact DeployableContainer developer.
Kalle Richter
  • 8,008
  • 26
  • 77
  • 177
Abder KRIMA
  • 3,418
  • 5
  • 31
  • 54
  • 1
    I made this : `.... JavaArchive jar = ShrinkWrap.create(JavaArchive.class,"es-costa-servi") .addPackage(PersonFactory.class.getPackage()) .addPackage(IPersonFactoryLocal.class.getPackage()) .addAsManifestResource("test-persistence.xml", "META-INF/persistence.xml") .addAsManifestResource("jbossas-ds.xml") .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); ...` – Abder KRIMA Apr 29 '15 at 17:02
  • and now i have the test passed with succes but when i try to inject my ejb by using in the test methode a systeme.out.println(IjectedEJB.getMessage); it gives me that : `shouldFindAllGamesUsingJpqlQuery(es.costa.service.all.test.opa.IjectedEJBTest)` – Abder KRIMA Apr 29 '15 at 17:03