JBoss, Arquillian and TestNG, EJB is deployed in integration test but throws exception
lazar.tsarev Dec 1, 2014 5:00 AMI have a parent project and 3 modules to it - ejb, api, ear. In the api module are located the interfaces and the objects for communication. In the ejb I got implementation of the api. My test is located in ejb module. Here are the contents of the pom files from parent, api and ejb projects.
parent :
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>bg.bulsi.modules</groupId>
<artifactId>DocRegistry</artifactId>
<version>0.0.1</version>
<packaging>pom</packaging>
<name>DocRegistry Parent</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<javaee6.web.spec.version>2.0.0.Final</javaee6.web.spec.version>
<hibernate.jpamodelgen.version>1.2.0.CR1</hibernate.jpamodelgen.version>
<jboss.version>6.3</jboss.version>
<version.jboss.bom>1.0.4.Final-redhat-4</version.jboss.bom>
<java.version>1.7</java.version>
</properties>
<repositories>
<repository>
<id>redhat-techpreview-all-repository</id>
<name>Red Hat Tech Preview repository (all)</name>
<url>http://maven.repository.redhat.com/techpreview/all/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>redhat-techpreview-all-repository</id>
<name>Red Hat Tech Preview repository (all)</name>
<url>http://maven.repository.redhat.com/techpreview/all/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.bom</groupId>
<artifactId>jboss-javaee-6.0-with-tools</artifactId>
<version>${version.jboss.bom}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.1.5.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>bg.bulsi.modules</groupId>
<artifactId>DocRegistry-api</artifactId>
<version>0.0.1</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>bg.bulsi.modules</groupId>
<artifactId>DocRegistry-api</artifactId>
<version>0.0.1</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>bg.bulsi.modules</groupId>
<artifactId>DocRegistry-ejb</artifactId>
<version>0.0.1</version>
<type>ejb</type>
</dependency>
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-web-6.0</artifactId>
<version>${javaee6.web.spec.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.1.0.Final</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jasypt</groupId>
<artifactId>jasypt</artifactId>
<version>1.9.0</version>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.servlet</groupId>
<artifactId>jboss-servlet-api_3.0_spec</artifactId>
<version>1.0.0.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>${hibernate.jpamodelgen.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.1.6.Final</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.182</version>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.2.8</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- Test dependencies -->
<dependency>
<!-- Needed for ArquillianTest -->
<groupId>org.jboss.arquillian.protocol</groupId>
<artifactId>arquillian-protocol-servlet</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.testng</groupId>
<artifactId>arquillian-testng-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>3.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.akquinet.jbosscc</groupId>
<artifactId>jbosscc-needle</artifactId>
<version>2.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<!-- source output directory -->
<outputDirectory>target/metamodel</outputDirectory>
<processors>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
</processors>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>${hibernate.jpamodelgen.version}</version>
<scope>compile</scope>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/metamodel</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.3</version>
<configuration>
<ejbVersion>3.1</ejbVersion>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
<!-- The JBoss AS plugin deploys your ear to a local JBoss AS container -->
<!-- Due to Maven's lack of intelligence with EARs we need to configure the jboss-as maven plugin to skip deployment
for all modules. We then enable it specifically in the ear module. -->
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.1.0.Beta1b</version>
<inherited>true</inherited>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>2.0.5</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
<modules>
<module>DocRegistry-ejb</module>
<module>DocRegistry-ear</module>
<module>DocRegistry-api</module>
</modules>
</project>
api:
<?xml version="1.0" encoding="UTF-8"?> <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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <artifactId>DocRegistry</artifactId> <groupId>bg.bulsi.modules</groupId> <version>0.0.1</version> </parent> <artifactId>DocRegistry-api</artifactId> <packaging>jar</packaging> <name>DocRegistry API</name> <dependencies> <dependency> <groupId>org.jasypt</groupId> <artifactId>jasypt</artifactId> </dependency> <dependency> <groupId>org.jboss.spec.javax.ejb</groupId> <artifactId>jboss-ejb-api_3.1_spec</artifactId> <scope>provided</scope> </dependency> </dependencies> <build> </build> </project>
ejb :
<?xml version="1.0" encoding="UTF-8"?> <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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <artifactId>DocRegistry</artifactId> <groupId>bg.bulsi.modules</groupId> <version>0.0.1</version> </parent> <artifactId>DocRegistry-ejb</artifactId> <packaging>ejb</packaging> <name>DocRegistry EJB module</name> <build> </build> <dependencies> <dependency> <groupId>bg.bulsi.modules</groupId> <artifactId>DocRegistry-api</artifactId> </dependency> <dependency> <groupId>org.jboss.spec.javax.ejb</groupId> <artifactId>jboss-ejb-api_3.1_spec</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>javax.enterprise</groupId> <artifactId>cdi-api</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.hibernate.javax.persistence</groupId> <artifactId>hibernate-jpa-2.0-api</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.hibernate.javax.persistence</groupId> <artifactId>hibernate-jpa-2.0-api</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> </dependency> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> </dependency> <!-- Test scope dependencies --> <dependency> <groupId>bg.bulsi.modules</groupId> <artifactId>DocRegistry-api</artifactId> <type>test-jar</type> <scope>test</scope> </dependency> <dependency> <!-- Needed for ArquillianTest --> <groupId>org.jboss.arquillian.protocol</groupId> <artifactId>arquillian-protocol-servlet</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.jboss.arquillian.testng</groupId> <artifactId>arquillian-testng-container</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> </dependency> <dependency> <groupId>org.jboss.shrinkwrap.resolver</groupId> <artifactId>shrinkwrap-resolver-api-maven</artifactId> </dependency> <!-- <dependency> <groupId>org.jboss.shrinkwrap.resolver</groupId> <artifactId>shrinkwrap-resolver-depchain</artifactId> <version>2.1.1</version> </dependency> --> <dependency> <groupId>org.jboss.shrinkwrap.resolver</groupId> <artifactId>shrinkwrap-resolver-impl-maven</artifactId> </dependency> <!--shrinkwrap-resolver-depchain:pom --> <!--shrinkwrap-resolver-impl-maven:jar --> <dependency> <groupId>org.jboss.arquillian.container</groupId> <artifactId>arquillian-container-test-impl-base</artifactId> </dependency> </dependencies> <profiles> <profile> <id>default</id> <activation> <activeByDefault>true</activeByDefault> </activation> <dependencies> <dependency> <!-- Needed for ArquillianTest --> <!-- Requires a running JBoss AS7 with camunda BPM change to other artifact for embedded start or different server --> <!-- Included here for convenience when running the test in Eclipse --> <groupId>org.jboss.as</groupId> <artifactId>jboss-as-arquillian-container-remote</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.17</version> <configuration> <groups>integration,arquillian</groups> <excludes> <!-- Exclusion for Arquillian test cases to avoid dependency on infrastructure for Maven build. Feel free to adjust to your testing requirements. --> <!-- <exclude>**/Arquillian*.java</exclude> --> </excludes> </configuration> </plugin> </plugins> </build> </profile> </profiles> </project>
Here is the actual source of the test :
package bg.bulsi.modules.docregistry.dao;
import bg.bulsi.modules.docregistry.api.DocType;
import bg.bulsi.modules.docregistry.api.Document;
import bg.bulsi.modules.docregistry.api.IDocRegistry;
import bg.bulsi.modules.docregistry.api.User;
import java.io.File;
import java.util.Arrays;
import javax.ejb.EJB;
import javax.inject.Inject;
import javax.inject.Named;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.testng.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.shrinkwrap.resolver.api.maven.Maven;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
/**
*
* @author kaloyan
*
*/
@Test(groups = "integration")
public class DocRegistryTest extends Arquillian {
private static final Logger log = LoggerFactory.getLogger(DocRegistryTest.class);
@EJB
IDocRegistry docRegistry;
/* @BeforeSuite
public void deba() {
}*/
@Deployment
public static WebArchive createDeployment() {
log.info("\n\n&&&&&&&&&&&&&&&&&&&&&&&&&&&&&golqm si maina\n\n");
// resolve given dependencies from Maven POM
File[] libs = Maven.configureResolver().loadPomFromFile("pom.xml")
.importRuntimeAndTestDependencies().resolve()
.withTransitivity().asFile();
WebArchive wrap = ShrinkWrap
.create(WebArchive.class, "lazonepich.war")
// add needed dependencies
.addAsLibraries(libs)
// enable CDI
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
// boot JPA persistence unit
.addAsResource("META-INF/persistence.xml")
// add your own classes (could be done one by one as well)
.addPackage("bg.bulsi.modules.docregistry.ejb")
.addPackage("bg.bulsi.modules.docregistry.logging")
.addPackage("bg.bulsi.modules.docregistry.model")
;
System.out.println("THE WRAPPER---------------" + wrap);
return wrap;
}
@BeforeMethod
public void some() {
log.info("@BeforeMethod is the fun");
}
@Test
public void createCorrespondenceTest() throws Exception {
log.info("###############" + docRegistry);
User user = new User("Mihail", "Ivanov", "shopcho", "shopcho@soaid.bg");
byte[] file = new byte[] {0x31, 0x3D, 0x61, 0x3A};
Document doc = new Document(file, "firstfile", DocType.INITIAL);
String correspondenceId = docRegistry.addDocumentAndCreateCorrespondence(user, doc);
Document initDoc = docRegistry.findCorrespondence(correspondenceId);
Assert.assertEquals(doc.getFilename(), initDoc.getFilename());
Assert.assertEquals(doc.getType(), initDoc.getType());
Assert.assertTrue(Arrays.equals(doc.getFile(), initDoc.getFile()));
}
}
And here is the exception that I get :
11:33:27,060 INFO [bg.bulsi.modules.docregistry.dao.DocRegistryTest] (http-/0.0.0.0:8080-2) @BeforeMethod is the fun
11:33:27,063 INFO [bg.bulsi.modules.docregistry.dao.DocRegistryTest] (http-/0.0.0.0:8080-2) ###############Proxy for remote EJB StatelessEJBLocator{appName='', moduleName='lazonepich', distinctName='', beanName='DocRegistry', view='interface bg.bulsi.modules.docregistry.api.IDocRegistry'}
11:33:27,067 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/lazonepich].[ArquillianServletRunner]] (http-/0.0.0.0:8080-2) JBWEB000236: Servlet.service() for servlet ArquillianServletRunner threw exception: java.lang.NoSuchMethodError: org.jboss.arquillian.test.spi.TestResult.failed(Ljava/lang/Throwable;)Lorg/jboss/arquillian/test/spi/TestResult;
at org.jboss.arquillian.testng.container.TestListener.getTestResult(TestListener.java:73) [arquillian-testng-container-1.1.5.Final.jar:1.1.5.Final]
at org.jboss.arquillian.testng.container.TestNGTestRunner.execute(TestNGTestRunner.java:55) [arquillian-testng-container-1.1.5.Final.jar:1.1.5.Final]
at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.executeTest(ServletTestRunner.java:160) [arquillian-protocol-servlet-1.0.3.Final.jar:1.0.3.Final]
at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.execute(ServletTestRunner.java:126) [arquillian-protocol-servlet-1.0.3.Final.jar:1.0.3.Final]
at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.doGet(ServletTestRunner.java:90) [arquillian-protocol-servlet-1.0.3.Final.jar:1.0.3.Final]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:734) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:231) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.4.0.Final-redhat-19.jar:7.4.0.Final-redhat-19]
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.4.0.Final-redhat-19.jar:7.4.0.Final-redhat-19]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169) [jboss-as-web-7.4.0.Final-redhat-19.jar:7.4.0.Final-redhat-19]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:145) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:653) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:926) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at java.lang.Thread.run(Thread.java:724) [rt.jar:1.7.0_40]
Does anyone have an idea how to solve this problem ?