javamavenjbossjboss-arquillian

Could not create new instance of class org.jboss.arquillian.test.impl.EventTestRunnerAdaptor


I have this pom.xml file

<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/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>company</groupId>
        <artifactId>trick-services-parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <artifactId>tricker-services-webapp</artifactId>
    <packaging>war</packaging>
    <name>trick-rest</name>
    <!-- <build> <finalName>trick</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-war-plugin</artifactId> <configuration> <outputDirectory>../vagrant/deployments</outputDirectory> 
        </configuration> </plugin> <plugin> <artifactId>maven-surefire-plugin</artifactId> 
        <version>2.17</version> </plugin> </plugins> <resources> <resource> <directory>src/main/resources</directory> 
        <filtering>true</filtering> </resource> </resources> <testResources> <testResource> 
        <directory>src/test/resources</directory> <filtering>true</filtering> </testResource> 
        </testResources> </build> -->

    <build>
        <defaultGoal>test</defaultGoal>
        <plugins>
            <!-- The compiler plugin enforces Java 1.6 compatibility and controls 
                execution of annotation processors -->
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.12</version>
            </plugin>
        </plugins>
    </build>



    <dependencyManagement>

        <dependencies>
            <!-- <dependency> <groupId>org.jboss.arquillian.extension</groupId> <artifactId>arquillian-rest-warp-bom</artifactId> 
                <version>1.0.0.Alpha2</version> <scope>import</scope> <type>pom</type> </dependency> -->
            <dependency>
                <groupId>org.jboss.shrinkwrap.resolver</groupId>
                <artifactId>shrinkwrap-resolver-bom</artifactId>
                <version>2.0.0-alpha-5</version>
                <scope>import</scope>
                <type>pom</type>
            </dependency>
            <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.arquillian.extension</groupId> <artifactId>arquillian-rest-warp-bom</artifactId> 
            <version>1.0.0.Alpha2</version> </dependency> -->
        <dependency>
            <groupId>org.jboss.shrinkwrap.resolver</groupId>
            <artifactId>shrinkwrap-resolver-api</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.shrinkwrap.resolver</groupId>
            <artifactId>shrinkwrap-resolver-impl-maven</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.jboss.arquillian.junit</groupId>
            <artifactId>arquillian-junit-container</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.jboss.arquillian</groupId>
            <artifactId>arquillian-junit</artifactId>
            <scope>test</scope>
            <version>1.0.0.Alpha5</version>
        </dependency>

        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
        </dependency>
        <!-- F -->

        <!-- Jax RS and REST API Related Dependencies -->
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jaxrs</artifactId>
        </dependency>

        <!-- Used by Jetty only. -->

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.jboss.spec</groupId>
            <artifactId>jboss-javaee-6.0</artifactId>
            <type>pom</type>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>company</groupId>
            <artifactId>tricking-service</artifactId>
            <version>${project.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.jboss.arquillian.container</groupId>
                    <artifactId>arquillian-weld-ee-embedded-1.1</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.jboss.weld</groupId>
                    <artifactId>weld-core</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- <dependency> <groupId>com.wordnik</groupId> <artifactId>swagger-jaxrs_2.9.1</artifactId> 
            </dependency> -->
        <dependency>
            <groupId>com.wordnik</groupId>
            <artifactId>swagger-annotations</artifactId>
        </dependency>
        <dependency>
            <groupId>com.wordnik</groupId>
            <artifactId>swagger-core_2.9.1</artifactId>
            <version>1.3.1</version>
        </dependency>
        <!-- <dependency> <groupId>org.jboss.arquillian.extension</groupId> <artifactId>arquillian-warp-impl</artifactId> 
            <scope>test</scope> </dependency> -->

        <!-- <dependency> <groupId>org.jboss.arquillian.extension</groupId> <artifactId>arquillian-rest-warp-impl-resteasy</artifactId> 
            <scope>test</scope> </dependency> -->
        <!-- <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>org.jboss.as</groupId> <artifactId>jboss-as-arquillian-container-managed</artifactId> 
            <version>7.1.1.Final</version> <scope>test</scope> </dependency> -->

    </dependencies>
    <profiles>
        <profile>
            <id>arquillian-glassfish-embedded</id>
            <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>
                <!-- Enable dependency if you want to use H2 -->
                <!-- Also update glassfish-resources.xml to use H2 connection information -->
                <!-- <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> 
                    <version>1.3.166</version> <scope>test</scope> </dependency> -->
            </dependencies>
            <build>
                <testResources>
                    <testResource>
                        <directory>src/test/resources</directory>
                    </testResource>
                    <testResource>
                        <directory>src/test/resources-glassfish-embedded</directory>
                    </testResource>
                </testResources>
                <plugins>
                    <!-- The surefire plugin is configured to pass a system property to 
                        GlassFish to retarget the derby log file -->
                    <plugin>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>2.12</version>
                        <configuration>
                            <systemPropertyVariables>
                                <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>
        <profile>
            <!-- Make sure that the default Derby database is started when you start 
                the GlassFish instance -->
            <!-- You can start the database using this command: asadmin start-database -->
            <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>
            </dependencies>
            <build>
                <testResources>
                    <testResource>
                        <directory>src/test/resources</directory>
                    </testResource>
                    <testResource>
                        <directory>src/test/resources-glassfish-remote</directory>
                    </testResource>
                </testResources>
            </build>
        </profile>
        <profile>
            <id>arquillian-jbossas-managed</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.as</groupId>
                    <artifactId>jboss-as-arquillian-container-managed</artifactId>
                    <version>7.1.1.Final</version>
                    <scope>test</scope>
                </dependency>
                <dependency>
                    <groupId>org.jboss.arquillian.protocol</groupId>
                    <artifactId>arquillian-protocol-servlet</artifactId>
                    <scope>test</scope>
                </dependency>
            </dependencies>
            <build>
                <testResources>
                    <testResource>
                        <directory>src/test/resources</directory>
                    </testResource>
                    <testResource>
                        <directory>src/test/resources-jbossas-managed</directory>
                    </testResource>
                </testResources>
                <plugins>
                    <plugin>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>unpack</id>
                                <phase>process-test-classes</phase>
                                <goals>
                                    <goal>unpack</goal>
                                </goals>
                                <configuration>
                                    <artifactItems>
                                        <artifactItem>
                                            <groupId>org.jboss.as</groupId>
                                            <artifactId>jboss-as-dist</artifactId>
                                            <version>7.1.1.Final</version>
                                            <type>zip</type>
                                            <overWrite>false</overWrite>
                                            <outputDirectory>target</outputDirectory>
                                        </artifactItem>
                                    </artifactItems>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>arquillian-jbossas-remote</id>
            <dependencies>
                <dependency>
                    <groupId>org.jboss.spec</groupId>
                    <artifactId>jboss-javaee-6.0</artifactId>
                    <version>1.0.0.Final</version>
                    <type>pom</type>
                    <scope>provided</scope>
                </dependency>
                <dependency>
                    <groupId>org.jboss.as</groupId>
                    <artifactId>jboss-as-arquillian-container-remote</artifactId>
                    <version>7.1.1.Final</version>
                    <scope>test</scope>
                </dependency>
                <dependency>
                    <groupId>org.jboss.arquillian.protocol</groupId>
                    <artifactId>arquillian-protocol-servlet</artifactId>
                    <scope>test</scope>
                </dependency>
            </dependencies>
            <build>
                <testResources>
                    <testResource>
                        <directory>src/test/resources</directory>
                    </testResource>
                    <testResource>
                        <directory>src/test/resources-jbossas-managed</directory>
                    </testResource>
                </testResources>
            </build>
        </profile>
    </profiles>
</project>

And this is a test class that I have:

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

     @Test
      public void getAllTrickers() throws Exception
      {
         Assert.assertTrue(true);
      }

}

This is my 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="jbossas-managed" default="true">
        <configuration>
            <property name="jbossHome">target/jboss-as-7.1.1.Final</property>
        </configuration>
    </container>
</arquillian>

and this is my test-persitence:

<?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">
        <!-- Use this jta-data-source if you're testing on JBoss AS 7.1 (setup by jbossas-ds.xml) -->
        <jta-data-source>jdbc/arquillian</jta-data-source>

        <!-- Use this jta-data-source if you're testing on JBoss AS 7.0 -->
        <!-- Optionally, you can setup a DataSource with this name in your JBoss AS 7.0 installation -->
        <!-- 
        <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>
        -->
        <properties>
            <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
            <property name="hibernate.show_sql" value="true"/>
        </properties>
    </persistence-unit>
</persistence>

This is my jbossas-ds.xml

<?xml version="1.0" encoding="UTF-8"?>
<datasources xmlns="http://www.jboss.org/ironjacamar/schema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://www.jboss.org/ironjacamar/schema
        http://docs.jboss.org/ironjacamar/schema/datasources_1_0.xsd">
    <datasource enabled="true"
        jndi-name="jdbc/arquillian"
        pool-name="ArquillianEmbeddedH2Pool">
        <connection-url>jdbc:h2:mem:arquillian;DB_CLOSE_DELAY=-1</connection-url>
        <driver>h2</driver>
    </datasource>
</datasources>

And I want to run it on JBoss so on cmd I am saying:

mvn test -Parquillian-jbossas-managed

And the error that I am getting is this:

Tests in error:
  com.company.Trickservice.webapp.api.test.TrickerResourceTest: Could not create new instance of class org.jboss.arquillian.test.impl.EventTestRunnerAdaptor

Full stacktrace on cmd:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.company.trickservice.webapp.api.test.TrickerResourceTest
12:36:29,500 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
12:36:29,500 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
12:36:29,500 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/C:/Users/Elban/Documents/trick-services/web/target/classes/logback.xml]
12:36:29,501 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback.xml] occurs multiple times on the classpath.
12:36:29,501 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback.xml] occurs at [file:/C:/Users/Elban/Documents/trick-services/web/target/classes/logback.xml]
12:36:29,501 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback.xml] occurs at [jar:file:/C:/Users/Elban/.m2/repository/company/tricking-core/0.0.1-SNAPSHOT/tricking-co
re-0.0.1-SNAPSHOT.jar!/logback.xml]
12:36:29,550 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
12:36:29,556 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
12:36:29,563 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
12:36:29,573 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
12:36:29,609 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to TRACE
12:36:29,609 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT]
12:36:29,610 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
12:36:29,610 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@74af72d8 - Registering current configuration as safe fallback point

12:36:29.617 [main] DEBUG org.jboss.logging - Logging Provider: org.jboss.logging.Slf4jLoggerProvider
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.354 sec <<< FAILURE!

Results :

Tests in error:
  com.company.trickservice.webapp.api.test.trickerResourceTest: Could not create new instance of class org.jboss.arquillian.test.impl.EventTestRunnerAdaptor

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

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 27.390s
[INFO] Finished at: Thu Jun 05 12:36:30 CEST 2014
[INFO] Final Memory: 47M/300M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project tricker-services-webapp: There are test failures.
[ERROR]
[ERROR] Please refer to C:\Users\Elban\Documents\trick-services\web\target\surefire-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
C:\Users\Elban\Documents\trick-services\web>

If you need any more information, just let me know.


Solution

  • I found the solution yesterday so I'll answer it here in case anyone else goes threw this error:

    The problem was that my Tricker class had a field of type TrickerType and I did not include it on the Depoyment. So, this solved my issue:

    @RunWith(Arquillian.class)
    @RunAsClient
    public class TrickerResourceTest {
        @Deployment
        public static Archive<?> createDeployment() {
            return ShrinkWrap.create(WebArchive.class, "test.war")
                .addPackage(Tricker.class.getPackage(), TrickerType.class.getPackage())
                .addAsResource("test-persistence.xml", "META-INF/persistence.xml")
                .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
        }
    
         @Test
          public void getAllTrickers() throws Exception
          {
             Assert.assertTrue(true);
          }
    
    }