Arquillian testing with JBoss
s3ppl Mar 12, 2012 3:57 PMHi everyone,
i've tried to put up a simple test-example using arquillian on an already installed jboss-as for quite some time now and read a lot of examples already, but i don't seem to get it somehow. My final target is to get an integration test on an JBoss 4.3 EAP server working, but i'm not sure if this is still supported.
Nevertheless, I tried to get tests working on JBoss 4.2 and JBoss 5.1. I guess the main problem is simply that i unsure which dependendies have to be in the pom.xml to get this started. But i really don't know, what I should try anymore..
I got different test-projects and most of them have nearly the same layout except for the pom.xml, consisting of just a container and a bean, all looking quite like this:
package importing.T1; import javax.ejb.Stateless; @Stateless public class App implements AppLocal { @Override public String sayHello() { return "Hello"; } }
package importing.T1; import javax.ejb.Local; @Local public interface AppLocal { public String sayHello(); }
The according test looks simply like this right now:
package importing.T1; import static org.junit.Assert.*; import javax.ejb.EJB; import org.jboss.arquillian.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Test; import org.junit.runner.RunWith; @RunWith(Arquillian.class) public class AppTest { @EJB AppLocal app; @Deployment public static JavaArchive createArchive() { return ShrinkWrap.create(JavaArchive.class); } @Test public void testSayHello() { assertTrue(true); } }
Since i just have this one project available right now, i can only post that right now, so i'm just putting the other files here.
That's my arquillian.xml, which just holds the path to my jboss-directory
<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-4-managed" default="true"> <configuration> <property name="jbossHome">Path\to\JBoss</property> </configuration> </container> </arquillian>
Here comes my pom.xml
<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> <groupId>importing</groupId> <artifactId>T1</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>T1</name> <url>http://maven.apache.org</url> <repositories> <repository> <id>jboss.public.repo</id> <url>https://repository.jboss.org/nexus/content/groups/public/</url> </repository> </repositories> <dependencyManagement> <dependencies> <dependency> <groupId>org.jboss.arquillian</groupId> <artifactId>arquillian-bom</artifactId> <version>1.0.0-SNAPSHOT</version> <scope>import</scope> <type>pom</type> </dependency> </dependencies> </dependencyManagement> <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> </configuration> </plugin> </plugins> </build> <dependencies> <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.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.arquillian.container</groupId> <artifactId>arquillian-jbossas-managed-4.2</artifactId> <version>1.0.0.CR3</version> <scope>test</scope> </dependency> </dependencies> </project>
The error that occurs in this project looks like this (surefire report):
------------------------------------------------------------------------------- Test set: importing.T1.AppTest ------------------------------------------------------------------------------- Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.125 sec <<< FAILURE! initializationError(importing.T1.AppTest) Time elapsed: 0 sec <<< ERROR! java.lang.RuntimeException: Could not create a new instance of class org.jboss.arquillian.test.impl.EventTestRunnerAdaptor see cause. at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:169) at org.jboss.arquillian.test.spi.TestRunnerAdaptorBuilder.build(TestRunnerAdaptorBuilder.java:40) at org.jboss.arquillian.junit.Arquillian.<init>(Arquillian.java:90) at org.jboss.arquillian.junit.Arquillian.<init>(Arquillian.java:71) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:31) at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:24) at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57) at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29) at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57) at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24) at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:33) at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:146) at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:97) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.maven.surefire.booter.ProviderFactory$ClassLoaderProxy.invoke(ProviderFactory.java:103) at $Proxy0.invoke(Unknown Source) at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:145) at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcess(SurefireStarter.java:87) at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:69) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:165) ... 25 more Caused by: java.lang.RuntimeException: Could not create a new instance of class org.jboss.arquillian.core.impl.ManagerImpl see cause. at org.jboss.arquillian.core.spi.SecurityActions.newInstance(SecurityActions.java:157) at org.jboss.arquillian.core.spi.ManagerBuilder.create(ManagerBuilder.java:77) at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.<init>(EventTestRunnerAdaptor.java:55) ... 30 more Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at org.jboss.arquillian.core.spi.SecurityActions.newInstance(SecurityActions.java:153) ... 32 more Caused by: java.lang.NoClassDefFoundError: org/jboss/arquillian/container/spi/client/container/DeployableContainer at org.jboss.arquillian.container.jbossas.managed_4_2.JBossASExtension.register(JBossASExtension.java:35) at org.jboss.arquillian.core.impl.loadable.LoadableExtensionLoader.load(LoadableExtensionLoader.java:78) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90) at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99) at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81) at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:134) at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:114) at org.jboss.arquillian.core.impl.ManagerImpl.fireProcessing(ManagerImpl.java:315) at org.jboss.arquillian.core.impl.ManagerImpl.<init>(ManagerImpl.java:97) ... 37 more Caused by: java.lang.ClassNotFoundException: org.jboss.arquillian.container.spi.client.container.DeployableContainer at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 50 more
I hope someone could explain me, what i'm doing wrong. Another project tells me btw, that the start of the server fails, if i try to do a maven test, using m2e.
Thanks 4 the help
Patrick