Using Multiple TomEE with Arquillian

Arquillian is a really good framework for integration tests and it eases a lot the testing of your application. But what can it do when you need several containers (let say you have 2 different containers)?

Aslak Knutsen pointed me out arquillian was already supported it! It was so good i had to test.

The result is a very simple sample which shows how to make it work with TomEE: multiple-tomee-arquillian

The idea is to define a group of tomees (let’s say a cluster ;)). Then to add in your test class the name of the container to use to deploy the application defined by the archive the method returns (the next sample will make everything clear).

Then the question is how to get the url of the application (for a webapp)? Here again arquillian manages it: @ArquillianResource can inject the url corresponding to the webapp. There are two ways: either injecting it as a field, here it needs the container qualifier (a bit complicated for nothing) or to inject it as a method parameter (easy since it needs nothing more).

So let’s see a sample. Here web archives are really simple since they only contain an index.html (but it proves it works ;)):

In the java test class important points are:

  • don’t forget the (now classical) Arquillian runner
  • give a name to your deployment (@Deployment)
  • if you want to inject the url add testable=false to deployment annotation
  • specify the container where to deploy the archive using @TargetsContainer
  • on test method specify which deployment it targets with @OperateOnDeployment
public class MultipleTomEETest {
  @Deployment(name = "war1", testable = false)
  public static WebArchive createDep1() {
    return ShrinkWrap.create(WebArchive.class, "application1.war")
      .addAsWebResource(new StringAsset("Hello from TomEE 1"), "index.html");

  @Deployment(name = "war2", testable = false)
  public static WebArchive createDep2() {
    return ShrinkWrap.create(WebArchive.class, "application2.war")
      .addAsWebResource(new StringAsset("Hello from TomEE 2"), "index.html");

  public void testRunningInDep1(@ArquillianResource final URL url) throws IOException {
    final String content = IO.slurp(url);
    assertEquals("Hello from TomEE 1", content);

  public void testRunningInDep2(@ArquillianResource final URL url) throws IOException {
    final String content = IO.slurp(url);
    assertEquals("Hello from TomEE 2", content);

In arquillian.xml simply define a group of classical container configurations.

<arquillian xmlns:xsi=""   xsi:schemaLocation="">
  <group qualifier="tomee-cluster">
    <container qualifier="tomee-1">
        <property name="httpPort">-1</property>
        <property name="stopPort">-1</property>
        <property name="ajpPort">-1</property>
        <property name="version">1.0.0-beta-3-SNAPSHOT</property>
        <property name="dir">target/apache-tomee-remote-1</property>
        <property name="appWorkingDir">target/arquillian-test-working-dir-1</property>
    <container qualifier="tomee-2">
        <property name="httpPort">-1</property>
        <property name="stopPort">-1</property>
        <property name="ajpPort">-1</property>
        <property name="version">1.0.0-beta-3-SNAPSHOT</property>
        <property name="dir">target/apache-tomee-remote-2</property>
        <property name="appWorkingDir">target/arquillian-test-working-dir-2</property>

So now you can test in TomEE your application even if it needs several instances :).
To conclude i would like to thank Aslask Knutsen for his help regarding this topic.


1 thought on “Using Multiple TomEE with Arquillian

  1. Magic Mesh

    Excellent items from you, man. I’ve keep in mind your stuff prior to and you are just too excellent. I really like what you’ve received here, really like what you’re saying and the way in which by which you assert it. You make it enjoyable and you still care for to keep it wise. I cant wait to learn far more from you. This is actually a wonderful site.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s