JBoss.orgCommunity Documentation
This guide documents Arquillian's architecture, how to get started using it and how to extend it. If you have questions, please use the discussion forum in the top-level Arquillian space on JBoss.org. We also provide a JIRA issue tracking system for bug reports and feature requests. If you are interested in the development of Arquillian, or want to translate this documentation into your language, we welcome you to join us in the Arquillian Development subspace on JBoss.org.
We believe that integration testing should be no more complex than writing a basic unit test. We created Arquillian to realize that goal. One of the major complaints we've heard about Seam 2 testing (i.e., SeamTest) was, not that it isn't possible, but that it isn't flexible and it's difficult to setup. We wanted to correct those shortcomings with Arquillian.
Testing needs vary greatly, which is why it's so vital that, with Arquillian (and ShrinkWrap), we have decomposed the problem into its essential elements. The result is a completely flexible and portable integration testing framework.
Instead of bringing your runtime to the test, Arquillian brings your test to the runtime.
Integration testing is very important in Java EE. The reason is two-fold:
Let's move on and consider some typical usage scenarios for Arquillian.
The following examples demonstrate the use of Arquillian. Currently Arquillian is distributed as a Maven only project, so you'll need to grab the examples from Git. You can choose between a JUnit example and a TestNG example. In this tutorial we show you how to use both.
git clone git://github.com/arquillian/arquillian.git arquillian cd arquillian git checkout 1.0.0.Alpha5If you want to try the JUnit examples do:
cd examples/junitOr if you want to try the TestNG examples do:
cd examples/testng
Running these tests from the command line is easy. The examples run against all the servers supported
by Arquillian (of course, you must choose a container that is capable of deploying EJBs for these tests).
To run the test, we'll use Maven. For this tutorial, we'll use JBoss AS 6 (currently at Milestone 3), for
which we use the jbossas-remote-6
profile.
First, make sure you have a copy of JBoss AS; you can download it from jboss.org.
We strongly recommend you use a clean copy of JBoss AS. Unzip JBoss AS to a directory of your choice and start it; we'll
use $JBOSS_HOME
to refer to this location throughout the tutorial.
$ unzip jboss-6.0.0.Final.zip && mv jboss-6.0.0.Final $JBOSS_HOME && $JBOSS_HOME/bin/run.sh
Now, we tell Maven to run the tests, for both JUnit and TestNG:
$ mvn test -Pjbossas-remote-6 $ cd ../arquillian-example-junit/ $ mvn test -Pjbossas-remote-6
You can also run the tests in an IDE. We'll show you how to run the tests in Eclipse, with m2eclipse installed, next.
Before running an Arquillian test in Eclipse, you must have the plugin for the unit testing framework you are using installed. Eclipse ships with the JUnit plugin, so you are already setup if you selected JUnit. If you are writing your tests with TestNG, you need the Eclipse TestNG plugin.
Since the examples in this guide are based on a Maven 2 project, you will also need the m2eclipse plugin. Instructions for using the m2eclipse update site to add the m2eclipse plugin to Eclipse are provided on the m2eclipse home page. For more, read the m2eclipse reference guide.
Once the plugins are installed, import your Maven project into the Eclipse workspace. Before executing the
test, you need to enable the profile for the target container, as we did on the command line. We'll
go ahead and activate the profile globally for the project (we also need the default
profile, read the note above for more). Right click on the project and select Properties.
Select the Maven property sheet and in the first form field, enter jbossas-remote-6
; you also need
to tell Maven to not resolve dependencies from the workspace (this interferes with resource loading):
Maven settings for project
Click OK and accept the project changes. Before we execute tests, make sure that Eclipse has properly processed all the resource files by running a full build on the project by selecting Clean from Project menu. Now you are ready to execute tests.
Assuming you have JBoss AS started from running the tests on the command line, you can now execute the tests. Right click on the InjectionTestCase.java file in the Package Explorer and select Run As... > JUnit Test or Run As... > TestNG Test depending on which unit testing framework the test is using.
Running the test from Eclipse using TestNG
You can now execute all the tests from Eclipse!
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.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_1_0.xsd">
<persistence-unit name="users" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/DefaultDS</jta-data-source>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
</properties>
</persistence-unit>
</persistence>
public @Stateless class UserRepositoryBean implements UserRepository {
@PersistenceContext EntityManager em;
public void storeAndFlush(User u) {
em.persist(u);
em.flush();
}
public List<User> findByLastName(String lastName) {
return em.createQuery("select u from User u where u.lastName = :lastName")
.setParameter("lastName", lastName)
.getResultList();
}
}
public class UserRepositoryTest extends Arquillian {
@Deployment
public static JavaArchive createTestArchive() {
return ShrinkWrap.create(JavaArchive.class, "test.jar")
.addClasses(User.class, UserRepository.class, UserRepositoryBean.class)
.addAsManifestResource(
"test-persistence.xml",
ArchivePaths.create("persistence.xml"));
}
private static final String FIRST_NAME = "Agent";
private static final String LAST_NAME = "Kay";
@EJB
private UserRepository userRepository;
@Test
public void testCanPersistUserObject() {
User u = new User(FIRST_NAME, LAST_NAME);
userRepository.storeAndFlush(u);
List<User> users = userRepository.findByLastName(LAST_NAME);
Assert.assertNotNull(users);
Assert.assertTrue(users.size() == 1);
Assert.assertEquals(users.get(0).getLastName(), LAST_NAME);
Assert.assertEquals(users.get(0).getFirstName(), FIRST_NAME);
}
}
That should give you a taste of what Arquillian tests look like. To learn how to setup Arquillian in your application and start developing tests with it, refer to the Chapter 3, Getting started chapter.
We've promised you that integration testing with Arquillian is no more complicated than writing a unit test. Now it's time to prove it to you. In this chapter, we'll look at what is required to setup Arquillian in your project, how to write an Arquillian test case, how to execute the test case and how the test results are displayed. That sounds like a lot, but you'll be writing your own Arquillian tests in no time. (You'll also learn about Chapter 7, Debugging remote tests in Chapter 7).
<properties>
<arquillian.version>1.0.0.Alpha5</arquillian.version>
</properties>
Make sure you have the correct APIs available for your test. In this test we are going to use CDI:
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.0-SP1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-junit</artifactId>
<version>${arquillian.version}</version>
<scope>test</scope>
</dependency>
If you plan to use TestNG, then add these two test-scoped dependencies instead:
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>5.12.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-testng</artifactId>
<version>${arquillian.version}</version>
<scope>test</scope>
</dependency>
Here's our TemperatureConverter
:
public class TemperatureConverter {
public double convertToCelsius(double f) {
return ((f - 32) * 5 / 9);
}
public double convertToFarenheit(double c) {
return ((c * 9 / 5) + 32);
}
}
public static Archive<?> methodName();
@Deployment
public static JavaArchive createTestArchive() {
return ShrinkWrap.create(JavaArchive.class, "test.jar")
.addClasses(TemperatureConverter.class)
.addAsManifestResource(
new ByteArrayAsset("<beans/>".getBytes()),
ArchivePaths.create("beans.xml"));
}
Here's the JUnit version of our test class:
@RunWith(Arquillian.class)
public class TemperatureConverterTest {
@Inject
private TemperatureConverter converter;
@Deployment
public static JavaArchive createTestArchive() {
return ShrinkWrap.create(JavaArchive.class, "test.jar")
.addClasses(TemperatureConverter.class)
.addAsManifestResource(
EmptyAsset.INSTANCE,
ArchivePaths.create("beans.xml"));
}
@Test
public void testConvertToCelsius() {
Assert.assertEquals(converter.convertToCelsius(32d), 0d);
Assert.assertEquals(converter.convertToCelsius(212d), 100d);
}
@Test
public void testConvertToFarenheit() {
Assert.assertEquals(converter.convertToFarenheit(0d), 32d);
Assert.assertEquals(converter.convertToFarenheit(100d), 212d);
}
}
public class TemperatureConverterTest extends Arquillian {
@Inject
private TemperatureConverter converter;
@Deployment
public static JavaArchive createTestArchive() {
return ShrinkWrap.create(JavaArchive.class, "test.jar")
.addClasses(TemperatureConverter.class)
.addAsManifestResource(
EmptyAsset.INSTANCE,,
ArchivePaths.create("beans.xml"));
}
@Test
public void testConvertToCelsius() {
Assert.assertEquals(converter.convertToCelsius(32d), 0d);
Assert.assertEquals(converter.convertToCelsius(212d), 100d);
}
@Test
public void testConvertToFarenheit() {
Assert.assertEquals(converter.convertToFarenheit(0d), 32d);
Assert.assertEquals(converter.convertToFarenheit(100d), 212d);
}
}
If you haven't already, download the latest version of JBoss AS 6.0 from the JBoss AS download page, extract the distribution and start the container.
Since Arquillian needs to perform JNDI lookups to get references to the components under test, we need to
include a jndi.properties
file on the test classpath. Create the file
src/test/resources/jndi.properties
and populate it with the following contents:
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces java.naming.provider.url=jnp://localhost:1099
Next, we're going to return to pom.xml to add another dependency. Arquillian picks which container it's going
to use to deploy the test archive and negotiate test execution using the service provider mechanism, meaning
which implementation of the DeployableContainer
SPI is on the classpath. We'll control
that through the use of Maven profiles. Add the following profiles to pom.xml:
<profiles>
<profile>
<id>jbossas-remote-6</id>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-jbossas-remote-6</artifactId>
<version>${arquillian.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.jbossas</groupId>
<artifactId>jboss-as-client</artifactId>
<version>6.0.0.Final</version>
<type>pom</type>
</dependency>
</dependencies>
</profile>
</profiles>
You would setup a similar profile for each Arquillian-supported container in which you want your tests executed.
All that's left is to execute the tests. In Maven, that's easy. Simply run the Maven test goal with the
jbossas-remote-6
profile activated:
mvn test -Pjbossas-remote-6
You should see that the two tests pass.
------------------------------------------------------- T E S T S ------------------------------------------------------- Running TemperatureConverterTest Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.964 sec Results : Tests run: 2, Failures: 0, Errors: 0, Skipped: 0 [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------
The tests are passing, but we don't see a green bar. To get that visual, we need to run the tests in the IDE. Arquillian tests can be executed using existing IDE plugins for JUnit and TestNG, respectively, or so you've been told. It's once again time to prove it.
Before running an Arquillian test in Eclipse, you must have the plugin for the unit testing framework you are using installed. Eclipse ships with the JUnit plugin, so you are already setup if you selected JUnit. If you are writing your tests with TestNG, you need the Eclipse TestNG plugin.
Since the example in this guide is based on a Maven 2 project, you will also need the m2eclipse plugin. Instructions for using the m2eclipse update site to add the m2eclipse plugin to Eclipse are provided on the m2eclipse home page. For more, read the m2eclipse reference guide.
Once the plugins are installed, import your Maven project into the Eclipse workspace. Before executing the
test, you need to enable the profile for the target container, as you did in the previous section. We'll
go ahead and activate the profile globally for the project. Right click on the project and select Properties.
Select the Maven property sheet and in the first form field, enter jbossas-remote-6
; you also need
to tell Maven to not resolve depedencies from the workspace (this interferes with resource loading):
Maven settings for project
Click OK and accept the project changes. Before we execute tests, make sure that Eclipse has properly processed all the resource files by running a full build on the project by selecting Clean from Project menu. Now you are ready to execute tests.
Right click on the TemperatureConverterTest.java file in the Package Explorer and select Run As... > JUnit Test or Run As... > TestNG Test depending on which unit testing framework the test is using.
Running the the JUnit test in Eclipse
Arquillian's forte is not only in its ease of use, but also in its flexibility. Good integration testing is not just about testing in any container, but rather testing in the container you are targeting. It's all too easy to kid ourselves by validating components in a specialized testing container, only to realize that the small variations causes the components fail when it comes time to deploy to the application for real. To make tests count, you want to execute them in the real container.
Arquillian supports a variety of target containers out of the box, which will be covered in this chapter. If the container you are using isn't supported, Arquillian makes it very easy to plug in your own implementation.
Arquillian recognizes three container interaction styles:
Containers can be further classified by their capabilities. There are three common catagories:
The implementations provided so far are shown in the table below. Also listed is the artifactId of the JAR that provides the implementation. To execute your tests against a container, you must include the artifactId that corresponds to that container on the classpath. Use the following Maven profile definition as a template to add support for a container to your Maven build, replacing %artifactId% with the artifactId from the table. You then activate the profile when executing the tests just as you did in the Chapter 3, Getting started chapter.
<profile>
<id>%artifactId%</id>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>%artifactId%</artifactId>
<version>${arquillian.version}</version>
</dependency>
</dependencies>
</profile>
Table 4.1. Target containers supported by Arquillian
Container name | Container type | Spec compliance | artifactId |
---|---|---|---|
JBoss AS 5 | remote | Java EE 5 | arquillian-jbossas-remote-5 |
JBoss AS 5.1 | remote | Java EE 5 | arquillian-jbossas-remote-5.1 |
JBoss AS 5.1 | managed | Java EE 5 | arquillian-jbossas-managed-5.1 |
JBoss AS 6.0 | remote | Java EE 6 | arquillian-jbossas-remote-6 |
JBoss AS 6.0 | managed | Java EE 6 | arquillian-jbossas-managed-6 |
JBoss AS 6.0 | embedded | Java EE 6 | arquillian-jbossas-embedded-6 |
JBoss Reloaded 1.0 | embedded | JBoss MC | arquillian-reloaded-embedded-1 |
GlassFish 3.1 | remote | Java EE 6 | arquillian-glassfish-remote-3.1 |
GlassFish 3.1 | embedded | Java EE 6 | arquillian-glassfish-embedded-3.1 |
Tomcat 6.0 | embedded | Servlet 2.5 | arquillian-tomcat-embedded-6 |
Jetty 6.1 | embedded | Servlet 2.5 | arquillian-jetty-embedded-6.1 |
Jetty 7.0 | embedded | Servlet ~3.0 | arquillian-jetty-embedded-7 |
Weld SE 1.0 | embedded | CDI | arquillian-weld-se-embedded-1 |
Weld SE 1.1 | embedded | CDI | arquillian-weld-se-embedded-1.1 |
Weld EE 1.1 | embedded | CDI | arquillian-weld-ee-embedded-1.1 |
Apache OpenWebBeans 1.0 | embedded | CDI | arquillian-openwebbeans-embedded-1 |
Apache OpenEJB 3.1 | embedded | EJB 3.0 | arquillian-openejb-embedded-3.1 |
Support for other containers is planned, including Weblogic (remote), WebSphere (remote) and Hibernate.
When you use a unit testing framework like JUnit or TestNG, your test case lives in a world on its own. That makes integration testing pretty difficult because it means the environment in which the business logic executes must be self-contained within the scope of the test case (whether at the suite, class or method level). The bonus of setting up this environment in the test falls on the developer's shoulders.
With Arquillian, you no longer have to worry about setting up the execution environment because that is all handled for you. The test will either be running in a container or a local CDI environment. But you still need some way to hook your test into this environment.
A key part of in-container integration testing is getting access the container-managed components that you plan to test. Using the Java new operator to instantiate the business class is not suitable in this testing scenario because it leaves out the declaratives services that get applied to the component at runtime. We want the real deal. Arquillian uses test enrichment to give us access to the real deal. The visible result of test enrichment is injection of container resources and beans directly into the test class.
"java:global/test.ear/test/" + fieldType.getSimpleName() + "Bean", "java:global/test.ear/test/" + fieldType.getSimpleName(), "java:global/test/" + fieldType.getSimpleName(), "java:global/test/" + fieldType.getSimpleName() + "Bean", "java:global/test/" + fieldType.getSimpleName() + "/no-interface", "test/" + unqualified interface name + "Bean/local", "test/" + unqualified interface name + "Bean/remote", "test/" + unqualified interface name + "/no-interface", unqualified interface name + "Bean/local", unqualified interface name + "Bean/remote", unqualified interface name + "/no-interface"
If no matching beans were found in those locations the injection will fail.
@Deployment
public static JavaArchive createTestArchive() {
return ShrinkWrap.create("test.jar", JavaArchive.class)
.addClass(NameOfClassUnderTest.class)
.addAsManifestResource(new ByteArrayAsset(new byte[0]), Paths.create("beans.xml"))
This chapter walks through the details of test execution, covering both the remote and local container cases.
Whilst it's not necessary to understand the details of how Arquillian works, it is often useful to have some insight. This chapter gives you an overview of how Arquillian executes your test for you in your chosen container.
You can add the following artifacts to the test archive:
Consult the ShrinkWrap API to discover all the options you have available for constructing the test archive.
The last operation that Arquillian performs before executing the individual test methods is "enriching" the
test class instance. This means hooking the test class to the container environment by satisfying its injection
points. The enrichment is provided by any implementation of the
org.jboss.arquillian.spi.TestEnricher
SPI on the classpath. Chapter 5, Test enrichment
details the injection points that Arquillian supports.
@Deployment(testable = true)
See the Complete Protocol Reference for an overview of the expected output of the packaging process when you provide a @Deployment
.
@Deployment(testable = false)
Here is an example calling a Servlet using the as client
mode.
@RunWith(Arquillian.class)
public class LocalRunServletTestCase
{
@Deployment(testable = false)
public static WebArchive createDeployment()
{
return ShrinkWrap.create("test.war", WebArchive.class)
.addClass(TestServlet.class);
}
@Test
public void shouldBeAbleToCallServlet(@ArquillianResource(TestServlet.class) URL baseUrl) throws Exception
{
// http://localhost:8080/test/
String body = readAllAndClose(new URL(baseUrl, "/Test").openStream());
Assert.assertEquals(
"Verify that the servlet was deployed and returns the expected result",
"hello",
body);
}
}
While Arquillian tests can be easily executing using existing IDE, Ant and Maven test plugins, debugging tests are not as straightforward (but by no means difficult). The extra steps documented in this chapter are only relevant for tests which are not executed in the same JVM as the test runner. These steps to not apply to tests that are run in a local bean container (e.g., Weld SE), which can be debugged just like any other unit test.
We'll assume in this chapter that you are already using Eclipse and you already have the test plugin installed for the testing framework you are using (JUnit or TestNG).
The Eclipse Server Tools, a subproject of the Eclipse Web Tools Project (WTP), has support for launching most major application servers, including JBoss AS 5. However, if you are using JBoss AS, you should consider using JBoss Tools instead, which offers tighter integration with JBoss technologies. See either the Server Tools documentation or the JBoss Tools documentation for instructions on how to setup a container and start it in debug mode.
See this blog entry to learn how to start JBoss AS with JPDA enabled and how to get the Eclipse debugger to connect to the remote process.
Just because the Arquillian project uses Maven doesn't mean you have to use it to run your Arquillian tests. Arquillian is designed to have seamless integration with JUnit and TestNG without any necessary test framework configuration. That means you can use any build system that has a JUnit or TestNG task to execute your Arquillian test cases. Since most of this guide focuses on using Arquillian in a Maven build, this chapter is going to be about alternative build systems, namely Gradle and Ant.
Gradle is a build tool that allows you to create declarative, maintainable, concise and highly-performing builds. More importantly, in this context, Gradle gives you all the freedom you need instead of imposing a rigid build lifecycle on you. You'll get a glimpse of just how flexible Gradle can be by learning how to integrate Arquillian into a Gradle build.
We'll be contrasting two strategies for running Arquillian tests from Gradle:
Container-specific test tasks
Test "profiles" via build fragment imports
The first strategy is the recommended one since it gives you the benefit of being able to run your tests on multiple containers in the same build. However, the second approach is less esoteric and will be more familiar to Maven users. Of course, Gradle is so flexible that there are likely other solutions for this problem. We invite you to give us feedback if you find a better way (or another way worth documenting).
Let's get the common build stuff out of the way, then dive into the two strategies listed above.
The simplest Gradle build for a Java project is a sparse one line.
apply plugin: JavaPlugin
apply plugin: JavaPlugin repositories { mavenCentral() mavenRepo urls: 'http://repository.jboss.org/nexus/content/groups/public' }
apply plugin: JavaPlugin buildDir = 'target/gradle-build' repositories { mavenCentral() mavenRepo urls: 'http://repository.jboss.org/nexus/content/groups/public' }
apply plugin: JavaPlugin buildDir = 'target/gradle-build' libraryVersions = [ junit: '4.8.1', arquillian: '1.0.0.Alpha4', jbossJavaeeSpec: '1.0.0.Beta7', weld: '1.0.1-Final', slf4j: '1.5.8', log4j: '1.2.14', jbossas: '6.0.0.Final', glassfish: '3.0.1-b20', cdi: '1.0-SP1' ] ...
dependencies { testCompile group: 'junit', name: 'junit', version: libraryVersions.junit testCompile group: 'org.jboss.arquillian', name: 'arquillian-junit', version: libraryVersions.arquillian }
configurations { compileOnly }
sourceSets { main { compileClasspath = configurations.compile + configurations.compileOnly } test { compileClasspath = compileClasspath + configurations.compileOnly } }
Here's the Gradle build all together now:
apply plugin: JavaPlugin buildDir = 'target/gradle-build' libraryVersions = [ junit: '4.8.1', arquillian: '1.0.0.Alpha3', jbossJavaeeSpec: '1.0.0.Beta7', weld: '1.0.1-Final', slf4j: '1.5.8', log4j: '1.2.14', jbossas: '6.0.0.Final', glassfish: '3.0.1-b20', cdi: '1.0-SP1' ] repositories { mavenCentral() mavenRepo urls: 'http://repository.jboss.org/nexus/content/groups/public' } configurations { compileOnly } sourceSets { main { compileClasspath = configurations.compile + configurations.compileOnly } test { compileClasspath = compileClasspath + configurations.compileOnly } }
We'll need three components for each container:
configurations { compileOnly weldEmbeddedTestRuntime { extendsFrom testRuntime } }
dependencies { compileOnly group: 'javax.enterprise', name: 'cdi-api', version: libraryVersions.cdi testCompile group: 'junit', name: 'junit', version: libraryVersions.junit testCompile group: 'org.jboss.arquillian', name: 'arquillian-junit', version: libraryVersions.arquillian // temporarily downgrade the weld-ee-embedded-1.1 container weldEmbeddedTestRuntime group: 'org.jboss.arquillian.container', name: 'arquillian-weld-ee-embedded-1.1', version: '1.0.0.Alpha3' weldEmbeddedTestRuntime group: 'org.jboss.spec', name: 'jboss-javaee-6.0', version: libraryVersions.jbossJavaeeSpec weldEmbeddedTestRuntime group: 'org.jboss.weld', name: 'weld-core', version: libraryVersions.weld weldEmbeddedTestRuntime group: 'org.slf4j', name: 'slf4j-log4j12', version: libraryVersions.slf4j weldEmbeddedTestRuntime group: 'log4j', name: 'log4j', version: libraryVersions.log4j }
Finally, we define the test task:
task weldEmbeddedTest(type: Test) { testClassesDir = sourceSets.test.classesDir classpath = sourceSets.test.classes + sourceSets.main.classes + configurations.weldEmbeddedTestRuntime }
gradle weldEmbeddedTest
gradle wET
Now we just repeat this setup for the other containers.
Here's the full build file with the tasks for our three target containers:
apply plugin: JavaPlugin buildDir = 'target/gradle-build' libraryVersions = [ junit: '4.8.1', arquillian: '1.0.0.Alpha4', jbossJavaeeSpec: '1.0.0.Beta7', weld: '1.0.1-Final', slf4j: '1.5.8', log4j: '1.2.14', jbossas: '6.0.0.Final', glassfish: '3.0.1-b20', cdi: '1.0-SP1' ] repositories { mavenCentral() mavenRepo urls: 'http://repository.jboss.org/nexus/content/groups/public' mavenRepo urls: 'http://repository.jboss.org/nexus/content/repositories/deprecated' } configurations { compileOnly weldEmbeddedTestRuntime { extendsFrom testRuntime } jbossasRemoteTestRuntime { extendsFrom testRuntime, compileOnly } glassfishEmbeddedTestRuntime { extendsFrom testRuntime } } dependencies { compileOnly group: 'javax.enterprise', name: 'cdi-api', version: libraryVersions.cdi testCompile group: 'junit', name: 'junit', version: libraryVersions.junit testCompile group: 'org.jboss.arquillian', name: 'arquillian-junit', version: libraryVersions.arquillian // temporarily downgrade the weld-ee-embedded-1.1 container weldEmbeddedTestRuntime group: 'org.jboss.arquillian.container', name: 'arquillian-weld-ee-embedded-1.1', version: '1.0.0.Alpha3' weldEmbeddedTestRuntime group: 'org.jboss.spec', name: 'jboss-javaee-6.0', version: libraryVersions.jbossJavaeeSpec weldEmbeddedTestRuntime group: 'org.jboss.weld', name: 'weld-core', version: libraryVersions.weld weldEmbeddedTestRuntime group: 'org.slf4j', name: 'slf4j-log4j12', version: libraryVersions.slf4j weldEmbeddedTestRuntime group: 'log4j', name: 'log4j', version: libraryVersions.log4j jbossasRemoteTestRuntime group: 'org.jboss.arquillian.container', name: 'arquillian-jbossas-remote-6', version: libraryVersions.arquillian jbossasRemoteTestRuntime group: 'org.jboss.jbossas', name: 'jboss-as-server', classifier: 'client', version: libraryVersions.jbossas, transitive: false jbossasRemoteTestRuntime group: 'org.jboss.jbossas', name: 'jboss-as-profileservice', classifier: 'client', version: libraryVersions.jbossas glassfishEmbeddedTestRuntime group: 'org.jboss.arquillian.container', name: 'arquillian-glassfish-embedded-3', version: libraryVersions.arquillian glassfishEmbeddedTestRuntime group: 'org.glassfish.extras', name: 'glassfish-embedded-all', version: libraryVersions.glassfish } sourceSets { main { compileClasspath = configurations.compile + configurations.compileOnly } test { compileClasspath = compileClasspath + configurations.compileOnly } } task weldEmbeddedTest(type: Test) { testClassesDir = sourceSets.test.classesDir classpath = sourceSets.test.classes + sourceSets.main.classes + configurations.weldEmbeddedTestRuntime } task jbossasRemoteTest(type: Test) { testClassesDir = sourceSets.test.classesDir classpath = sourceSets.test.classes + sourceSets.main.classes + files('src/test/resources-jbossas') + configurations.jbossasRemoteTestRuntime } task glassfishEmbeddedTest(type: Test) { testClassesDir = sourceSets.test.classesDir classpath = sourceSets.test.classes + sourceSets.main.classes + configurations.glassfishEmbeddedTestRuntime }
gradle weldEmbeddedTest jbossasRemoteTest glassfishEmbeddedTest
apply plugin: JavaPlugin buildDir = 'target/gradle-build' libraryVersions = [ junit: '4.8.1', arquillian: '1.0.0.Alpha3', jbossJavaeeSpec: '1.0.0.Beta7', weld: '1.0.1-Final', slf4j: '1.5.8', log4j: '1.2.14', jbossas: '6.0.0.Final', glassfish: '3.0.1-b20', cdi: '1.0-SP1' ] repositories { mavenCentral() mavenRepo urls: 'http://repository.jboss.org/nexus/content/groups/public' } configurations { compileOnly } dependencies { group: 'org.jboss.spec', name: 'jboss-javaee-6.0', version: libraryVersions.jbossJavaeeSpec } sourceSets { main { compileClasspath = configurations.compile + configurations.compileOnly } test { compileClasspath = compileClasspath + configurations.compileOnly } }
Create a file named weld-ee-embedded-profile.gradle and populate it with the following contents:
dependencies { // temporarily downgrade the weld-ee-embedded-1.1 container testRuntime group: 'org.jboss.arquillian.container', name: 'arquillian-weld-ee-embedded-1.1', version: '1.0.0.Alpha3' testRuntime group: 'org.jboss.spec', name: 'jboss-javaee-6.0', version: libraryVersions.jbossJavaeeSpec testRuntime group: 'org.jboss.weld', name: 'weld-core', version: libraryVersions.weld testRuntime group: 'org.slf4j', name: 'slf4j-log4j12', version: libraryVersions.slf4j testRuntime group: 'log4j', name: 'log4j', version: libraryVersions.log4j }
Here's the partial build file for Remote JBoss AS, named jbossas-remote-profile.gradle:
dependencies { testRuntime group: 'javax.enterprise', name: 'cdi-api', version: libraryVersions.cdi testRuntime group: 'org.jboss.arquillian.container', name: 'arquillian-jbossas-remote-6', version: libraryVersions.arquillian testRuntime group: 'org.jboss.jbossas', name: 'jboss-as-server', classifier: 'client', version: libraryVersions.jbossas, transitive: false testRuntime group: 'org.jboss.jbossas', name: 'jboss-as-profileservice', classifier: 'client', version: libraryVersions.jbossas } test { classpath = sourceSets.test.classes + sourceSets.main.classes + files('src/test/resources-jbossas') + configurations.testRuntime }And finally the one for Embedded GlassFish, named glassfish-embedded-profile.gradle:
dependencies { testRuntime group: 'org.jboss.arquillian.container', name: 'arquillian-glassfish-embedded-3', version: libraryVersions.arquillian testRuntime group: 'org.glassfish.extras', name: 'glassfish-embedded-all', version: libraryVersions.glassfish }
Now we need to import the appropriate partial Gradle build into the main build. The file will be selected based on the value of the project property named profile.
apply plugin: JavaPlugin buildDir = 'target/gradle-build' libraryVersions = [ junit: '4.8.1', arquillian: '1.0.0.Alpha4', jbossJavaeeSpec: '1.0.0.Beta7', weld: '1.0.1-Final', slf4j: '1.5.8', log4j: '1.2.14', jbossas: '6.0.0.Final', glassfish: '3.0.1-b20', cdi: '1.0-SP1' ] apply from: profile + '-profile.gradle' repositories { mavenCentral() mavenRepo urls: 'http://repository.jboss.org/nexus/content/groups/public' } configurations { compileOnly } dependencies { compileOnly group: 'javax.enterprise', name: 'cdi-api', version: libraryVersions.cdi testCompile group: 'junit', name: 'junit', version: libraryVersions.junit testCompile group: 'org.jboss.arquillian', name: 'arquillian-junit', version: libraryVersions.arquillian } sourceSets { main { compileClasspath = configurations.compile + configurations.compileOnly } test { compileClasspath = compileClasspath + configurations.compileOnly } }
Tests are run in the Weld EE Embedded runtime using this command:
gradle test -Pprofile=weld-ee-embedded
That's pretty much the same experience you get when you use Maven (and a whole heck of a lot simpler).
If you have a better idea of how to integrate an Arquillian test suite into a Gradle build, we'd love to hear it on the Arquillian discussion forums.
See the CDI subproject of the Arquillian showcase for an Ant+Ivy build example until this section is written.
This chapter walks through some more advanced features and use cases you can have Arquillian do for you.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<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">
<group qualifier="tomcat-cluster">
<container qualifier="container-1" default="true">
<configuration>
<property name="tomcatHome">target/tomcat-embedded-6-standby</property>
<property name="workDir">work</property>
<property name="bindHttpPort">8880</property>
<property name="unpackArchive">true</property>
</configuration>
<dependencies>
<dependency>org.jboss.arquillian.container:arquillian-tomcat-embedded-6:1.0.0.Alpha5</dependency>
<dependency>org.apache.tomcat:catalina:6.0.29</dependency>
<dependency>org.apache.tomcat:coyote:6.0.29</dependency>
<dependency>org.apache.tomcat:jasper:6.0.29</dependency>
</dependencies>
</container>
<container qualifier="container-2">
<configuration>
<property name="tomcatHome">target/tomcat-embedded-6-active-1</property>
<property name="workDir">work</property>
<property name="bindHttpPort">8881</property>
<property name="unpackArchive">true</property>
</configuration>
<dependencies>
<dependency>org.jboss.arquillian.container:arquillian-tomcat-embedded-6:1.0.0.Alpha5</dependency>
<dependency>org.apache.tomcat:catalina:6.0.29</dependency>
<dependency>org.apache.tomcat:coyote:6.0.29</dependency>
<dependency>org.apache.tomcat:jasper:6.0.29</dependency>
</dependencies>
</container>
</group>
</arquillian>
@Deployment(name = "dep1") @TargetsContainer("container-1")
public static WebArchive createDep1() {}
@Deployment(name = "dep2") @TargetsContainer("container-2")
public static WebArchive createDep2() {}
@Test @OperateOnDeployment("dep1")
public void testRunningInDep1() {}
@Test @OperateOnDeployment("dep2")
public void testRunningInDep2() {}
// include other arquillian imports here...
import org.jboss.arquillian.performance.annotation.Performance;
import org.jboss.arquillian.performance.annotation.PerformanceTest;
@PerformanceTest(resultsThreshold=2)
@RunWith(Arquillian.class)
public class WorkHardCdiTestCase
{
@Deployment
public static JavaArchive createDeployment() {
return ShrinkWrap.create(JavaArchive.class ,"test.jar")
.addPackage( WorkHard.class.getPackage())
.addAsManifestResource(
EmptyAsset.INSTANCE,
ArchivePaths.create("beans.xml"));
}
@Inject HardWorker worker;
@Test
@Performance(time=20)
public void doHardWork() throws Exception
{
Assert.assertEquals(21, worker.workingHard(), 0d);
}
}
How threshold is calculated: resultsThreshold * newTime < oldTime
.
The only extra dependency needed is to add arquillian-performance
to your pom.xml. Take a look at the Chapter 3, Getting started to see how you set up arquillian using maven.
<dependency>
<groupId>org.jboss.arquillian.extension</groupId>
<artifactId>arquillian-performance</artifactId>
<version>${arquillian.version}</version>
<scope>test</scope>
</dependency>
The JSFUnit integration to Arquillian is a simpler way of using JSFUnit.
The only dependencies needed is to add org.jboss.arquillian.framework:arquillian-framework-jsfunit
and org.jboss.jsfunit:jboss-jsfunit-core
to your pom.xml.
The rest is handled by Arquillian in the background.
Take a look at the Chapter 3, Getting started to see how you set up arquillian using maven.
<dependency>
<groupId>org.jboss.arquillian.framework</groupId>
<artifactId>arquillian-framework-jsfunit</artifactId>
<version>1.0.0.Alpha5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.jsfunit</groupId>
<artifactId>jboss-jsfunit-core</artifactId>
<version>1.3.0.Final</version>
<scope>test</scope>
</dependency>
To use JSFUnit with Arquillian, JSFUnit 1.3.0.Final is required.
package org.jboss.arquillian.drone.example;
import static org.jboss.arquillian.ajocado.Ajocado.elementPresent;
import static org.jboss.arquillian.ajocado.Ajocado.waitModel;
import static org.jboss.arquillian.ajocado.guard.request.RequestTypeGuardFactory.waitHttp;
import static org.jboss.arquillian.ajocado.locator.LocatorFactory.id;
import static org.jboss.arquillian.ajocado.locator.LocatorFactory.xp;
import java.net.URL;
import org.jboss.arquillian.ajocado.framework.AjaxSelenium;
import org.jboss.arquillian.ajocado.locator.IdLocator;
import org.jboss.arquillian.ajocado.locator.XpathLocator;
import org.jboss.arquillian.api.Run;
import org.jboss.arquillian.drone.annotation.ContextPath;
import org.jboss.arquillian.drone.annotation.Drone;
import org.jboss.arquillian.junit.Arquillian;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Tests Arquillian Drone extension against Weld Login example. *
* Uses Ajocado driver bound to Firefox browser.
*
*/
@RunWith(Arquillian.class)
public class AjocadoTestCase extends AbstractTestCase
{
// load ajocado driver
@Drone
AjaxSelenium driver;
// Load context path to the test
@ContextPath
URL contextPath;
protected XpathLocator LOGGED_IN = xp("//li[contains(text(),'Welcome')]");
protected XpathLocator LOGGED_OUT = xp("//li[contains(text(),'Goodbye')]");
protected IdLocator USERNAME_FIELD = id("loginForm:username");
protected IdLocator PASSWORD_FIELD = id("loginForm:password");
protected IdLocator LOGIN_BUTTON = id("loginForm:login");
protected IdLocator LOGOUT_BUTTON = id("loginForm:logout");
@Deployment(testable=false)
public static WebArchive createDeployment()
{
return ShrinkWrap.create(WebArchive.class, "weld-login.war")
.addClasses(Credentials.class, LoggedIn.class, Login.class, User.class, Users.class)
.addAsWebInfResource(new File("src/test/webapp/WEB-INF/beans.xml"))
.addAsWebInfResource(new File("src/test/webapp/WEB-INF/faces-config.xml"))
.addAsWebInfResource(new File("src/test/resources/import.sql"))
.addAsWebResource(new File("src/test/webapp/index.html"))
.addAsWebResource(new File("src/test/webapp/home.xhtml"))
.addAsWebResource(new File("src/test/webapp/template.xhtml"))
.addAsWebResource(new File("src/test/webapp/users.xhtml"))
.addAsResource(new File("src/test/resources/META-INF/persistence.xml"), ArchivePaths.create("META-INF/persistence.xml"))
.setWebXML(new File("src/test/webapp/WEB-INF/web.xml"));
}
@Test
public void testLoginAndLogout()
{
driver.open(contextPath);
waitModel.until(elementPresent.locator(USERNAME_FIELD));
Assert.assertFalse("User should not be logged in!", driver.isElementPresent(LOGOUT_BUTTON));
driver.type(USERNAME_FIELD, "demo");
driver.type(PASSWORD_FIELD, "demo");
waitHttp(driver).click(LOGIN_BUTTON);
Assert.assertTrue("User should be logged in!", driver.isElementPresent(LOGGED_IN));
waitHttp(driver).click(LOGOUT_BUTTON);
Assert.assertTrue("User should not be logged in!", driver.isElementPresent(LOGGED_OUT));
}
}
As you can see, execution does not differ from common Arquillian test much. The only
requirement is actually running Arquillian in client mode, which is enforced by marking
deployment as utestable = false
or alternatively by
@RunAsClient
annotation. The other annotations present in the test are used
to inject web test framework instance (@Drone
) and context path
(@ContextPath
) for deployed archive into your test. Their life cycle is
completely managed by Arquillian Drone, as described in Section 11.3.3, “Life cycle of @Drone objects”. The instance is used in test method to traverse UI of
application via Firefox browser, fill user credentials and signing up and out. Test is based
on JUnit, but Arquillian Drone, as well as the rest of Arquillian supports TestNG as
well.
This combination matrix is tested and known to work. However, we expect that all
WebDriver
interface based browsers will work. Arquillian Drone does not
force you to use a specific version of web framework test implementation, so feel free to
experiment with it.
package org.jboss.arquillian.drone.factory;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.jboss.arquillian.drone.spi.Qualifier;
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.FIELD, ElementType.PARAMETER })
@Qualifier
public @interface Different
{
}
@RunWith(Arquillian.class)
@RunAs(AS_CLIENT)
public class EnrichedClass
{
@Drone DefaultSelenium foo;
@Drone @Different DefaultSelenium bar;
public void testWithBothFooAndBar()
{
...
}
}
Arquillian Ajocado uses ajacodo
namespace. This means, you can define
properties either in arquillian.xml
<extension qualifier="ajocado">
<configuration>
<property name="seleniumHost">myhost.org</property>
</configuration>
</extension>
Or you can convert property name to name of system property, using following formula
arqullian. + (namespace) + . + (property name converted to dotted
lowercase)
. For instance, seleniumNetworkTrafficEnabled
will be
converted to arquillian.ajocado.selenium.network.traffic.enabled
System
property name.
Table 11.3. Selenium configuration
Property name | Default value | Description |
---|---|---|
serverPort | 14444 | Port on machine where Selenium server is running |
serverHost | localhost | Name of the machine where Selenium server is running |
url | http://localhost:8080 | Web Server URL |
timeout | 60000 | Default timeout in ms |
speed | 0 | Delay in ms before each command is sent |
browser | *firefox | Browser type, following Selenium conventions |
Selenium uses selenium
namespace.
Table 11.4. WebDriver configuration
Property name | Default value | Description |
---|---|---|
implementationClass | org.openqa.selenium.htmlunit.HtmlUnitDriver | Determines which browser instance is created for WebDriver testing |
WebDriver uses webdriver
namespace.
Table 11.5. Selenium Server configuration
Property name | Default value | Description |
---|---|---|
port | 14444 | Port on machine where to start Selenium Server |
host | localhost | Name of the machine where to start Selenium Server |
output | target/selenium-server-output.log | Name of file where to redirrect Selenium Server logger |
enable | false | Enable Arquillian to start Selenium Server |
Selenium Server uses selenium-server
namespace.
Please note that
non-letter characters are converted to dots, so for instance to enable Selenium via System
property, you have to set arquillian.selenium.server.enable
to
true
.
Selenium Server has different life cycle than @Drone instance, it is created and started before test suite and disposed after test suite. If you have your own Selenium Server instance running, you simply omit its configuration, however specifying it is the simplest way how to start it and have it managed by Arquillian.
If you are wondering how to define configuration for @Qualifier
@Drone
instance, it's very easy. Only modification you have to do is to
change namespace to include - (@Qualifier
annotation name converted to
lowercase). Please note, that for System properties are all non-letter characters converted to
dots. For instance, if you qualified Arquillian Ajocado instance with @MyExtraBrowser, its
namespace will become ajocado-myextrabrowser.
The namespace resolution is a bit more complex. Arquillian Drone will search for configuration in following order:
Search for the exact match of namespace (e.g.
ajocado-myextrabrowser
) in arqullian.xml, if found, step 2 is not
performed
Search for a match of base namespace, without qualifier (e.g.
ajocado
) in arqullian.xml
Then System property overriddes are applied in the same fashion.
Provides a way how to configure configurations of type C for
object of type T@Drone
Provides a way how to instantiate @Drone
object of type T
with configuration C
fully.quallified.name.of.my.implementation.Foo
Your class Foo
must implement
Instantiator<DefaultSelenium,SeleniumConfiguration>
interface.
Example of Maven profile setup
<profile>
<id>jbossas-remote-5</id>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-jbossas-remote-5</artifactId>
<version>1.0.0.Alpha5</version>
</dependency>
<dependency>
<groupId>org.jboss.jbossas</groupId>
<artifactId>jboss-as-client</artifactId>
<version>5.0.1.GA</version>
<type>pom</type>
</dependency>
</dependencies>
</profile>
Example of Maven profile setup
<profile>
<id>jbossas-remote-5.1</id>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-jbossas-remote-5.1</artifactId>
<version>1.0.0.Alpha5</version>
</dependency>
<dependency>
<groupId>org.jboss.jbossas</groupId>
<artifactId>jboss-as-client</artifactId>
<version>5.1.0.GA</version>
<type>pom</type>
</dependency>
</dependencies>
</profile>
Example of Maven profile setup
<profile>
<id>jbossas-managed-5.1</id>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-jbossas-managed-5.1</artifactId>
<version>1.0.0.Alpha5</version>
</dependency>
<dependency>
<groupId>org.jboss.jbossas</groupId>
<artifactId>jboss-server-manager</artifactId>
<version>1.0.3.GA</version>
</dependency>
<dependency>
<groupId>org.jboss.jbossas</groupId>
<artifactId>jboss-as-client</artifactId>
<version>5.1.0.GA</version>
<type>pom</type>
</dependency>
</dependencies>
</profile>
Example of Maven profile setup
<profile>
<id>jbossas-remote-6</id>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-jbossas-remote-6</artifactId>
<version>1.0.0.Alpha5</version>
</dependency>
<dependency>
<groupId>org.jboss.jbossas</groupId>
<artifactId>jboss-as-client</artifactId>
<version>6.0.0.Final</version>
<type>pom</type>
</dependency>
</dependencies>
</profile>
Example of Maven profile setup
<profile>
<id>jbossas-managed-6</id>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-jbossas-managed-6</artifactId>
<version>1.0.0.Alpha5</version>
</dependency>
<dependency>
<groupId>org.jboss.jbossas</groupId>
<artifactId>jboss-server-manager</artifactId>
<version>1.0.3.GA</version>
</dependency>
<dependency>
<groupId>org.jboss.jbossas</groupId>
<artifactId>jboss-as-client</artifactId>
<version>6.0.0.Final</version>
<type>pom</type>
</dependency>
</dependencies>
</profile>
Example of Maven profile setup
<profile>
<id>jbossas-embedded-6</id>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-jbossas-embedded-6</artifactId>
<version>1.0.0.Alpha5</version>
</dependency>
<dependency>
<groupId>org.jboss.jbossas</groupId>
<artifactId>jboss-as-depchain</artifactId>
<version>6.0.0.Final</version>
<type>pom</type>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.jbossas</groupId>
<artifactId>jboss-as-depchain</artifactId>
<version>6.0.0.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>${env.JBOSS_HOME}/client/jbossws-native-client.jar</additionalClasspathElement>
<!--
Because jbossweb.sar contains shared web.xml, which must be
visible from same CL as TomcatDeployer.class.getClassLoader
-->
<additionalClasspathElement>${env.JBOSS_HOME}/server/default/deploy/jbossweb.sar</additionalClasspathElement>
</additionalClasspathElements>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<trimStackTrace>false</trimStackTrace>
<printSummary>true</printSummary>
<forkMode>once</forkMode>
<!--
MaxPermSize Required to bump the space for relective data like
classes, methods, etc. EMB-41. Endorsed required for things like
WS support (EMB-61)
-->
<argLine>-Xmx512m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true -Djava.util.logging.manager=org.jboss.logmanager.LogManager -Djava.endorsed.dirs=${env.JBOSS_HOME}/lib/endorsed -Djboss.home=${env.JBOSS_HOME} -Djboss.boot.server.log.dir=${env.JBOSS_HOME}</argLine>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Example of Maven profile setup
<profile>
<id>glassfish-embedded-3.1</id>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-glassfish-embedded-3</artifactId>
<version>1.0.0.Alpha5</version>
</dependency>
<dependency>
<groupId>org.glassfish.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>3.1</version>
</dependency>
</dependencies>
</profile>
Example of Maven profile setup
<profile>
<id>glassfish-remote-3.1</id>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-glassfish-remote-3</artifactId>
<version>1.0.0.Alpha5</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
<?xml version="1.0" encoding="UTF-8"?> <arquillian xmlns="http://jboss.com/arquillian" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tomcat6="urn:arq:org.jboss.arquillian.container.tomcat.embedded_6"> <tomcat6:container> <!-- unpackArchive must be true if using the Weld Servlet module --> <tomcat6:unpackArchive>true</tomcat6:unpackArchive> </tomcat6:container> </arquillian>
Running an in-container test on Tomcat 6 currently requires that you add the Arquillian Protocol Servlet to the test archive's web.xml, a temporary measure until ARQ-217 is resolved. The listing below shows a minimum web.xml containing the required Servlet mapping:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>ServletTestRunner</servlet-name>
<servlet-class>org.jboss.arquillian.protocol.servlet_3.ServletTestRunner</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServletTestRunner</servlet-name>
<url-pattern>/ArquillianServletRunner</url-pattern>
</servlet-mapping>
</web-app>
If you forget to add this Servlet mapping for a test using the in-container run mode, you will get a failure with the message "Kept getting 404s" because Arquillian can't communicate with the deployed application.
Example of Maven profile setup
<profile>
<id>tomcat-embedded</id>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-tomcat-embedded-6</artifactId>
<version>1.0.0.Alpha5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>catalina</artifactId>
<version>6.0.29</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>coyote</artifactId>
<version>6.0.29</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>jasper</artifactId>
<version>6.0.29</version>
<scope>provided</scope>
</dependency>
<!-- Weld servlet, EL and JSP required for testing CDI injections -->
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet</artifactId>
<version>1.0.1-Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>el-impl</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
Example of Maven profile setup
<profile>
<id>jetty-embedded</id>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-jetty-embedded-6.1</artifactId>
<version>1.0.0.Alpha5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
<version>6.1.12</version>
<scope>test</scope>
</dependency>
<!-- plus and naming requires for using JNDI -->
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-plus</artifactId>
<version>6.1.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-naming</artifactId>
<version>6.1.12</version>
<scope>test</scope>
</dependency>
<!-- Weld servlet, EL and JSP required for testing CDI injections -->
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet</artifactId>
<version>1.0.1-Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>el-impl</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
Example of Maven profile setup
<profile>
<id>jetty-embedded</id>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-jetty-embedded-7</artifactId>
<version>1.0.0.Alpha5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>7.0.2.v20100331</version>
<scope>test</scope>
</dependency>
<!-- plus and naming requires for using JNDI -->
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-plus</artifactId>
<version>7.0.2.v20100331</version>
<scope>test</scope>
</dependency>
<!-- Weld servlet, EL and JSP required for testing CDI injections -->
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet</artifactId>
<version>1.0.1-Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>el-impl</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
Example of Maven profile setup
<profile>
<id>weld-se-embedded-1</id>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-weld-se-embedded-1</artifactId>
<version>1.0.0.Alpha5</version>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-core</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-core-bom</artifactId>
<version>1.0.1-SP1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</profile>
Example of Maven profile setup
<profile>
<id>weld-se-embedded-11</id>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-weld-se-embedded-1</artifactId>
<version>1.0.0.Alpha5</version>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-core</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-core-bom</artifactId>
<version>1.1.0.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</profile>
Example of Maven profile setup
<profile>
<id>weld-ee-embedded-1.1</id>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-weld-ee-embedded-1.1</artifactId>
<version>1.0.0.Alpha5</version>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-core</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-core-bom</artifactId>
<version>1.1.0.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</profile>
<dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>el-impl</artifactId>
<version>2.1.2-b04</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.servlet</groupId>
<artifactId>jboss-servlet-api_3.0_spec</artifactId>
<version>1.0.0.Beta2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.ejb3</groupId>
<artifactId>jboss-ejb3-api</artifactId>
<version>3.1.0</version>
<scope>test</scope>
</dependency>
Example of Maven profile setup
<profile>
<id>openwebbeans-embedded-1</id>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-openwebbeans-embedded-1</artifactId>
<version>1.0.0.Alpha5</version>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-spi</artifactId>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-impl</artifactId>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-el_2.2_spec</artifactId>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jta_1.1_spec</artifactId>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-validation_1.0_spec</artifactId>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-interceptor_1.1_spec</artifactId>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jcdi_1.0_spec</artifactId>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-atinject_1.0_spec</artifactId>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_2.5_spec</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans</artifactId>
<version>1.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</profile>
Example of Maven profile setup
<profile>
<id>openejb-embedded-3.1</id>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-openejb-3.1</artifactId>
<version>1.0.0.Alpha5</version>
</dependency>
<dependency>
<groupId>org.apache.openejb</groupId>
<artifactId>openejb-core</artifactId>
<version>3.1.4</version>
</dependency>
</dependencies>
</profile>