Check out the Getting started page if you are not familiar with Arquillian.

All the Arquillian Adapters for TomEE support the following configuration options in the arquillian.xml:

<container qualifier="tomee" default="true">
    <configuration>
        <property name="httpPort">-1</property>
        <property name="stopPort">-1</property>
    </configuration>
</container>

The above can also be set as system properties rather than via the arquillian.xml file.

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <configuration>
        <systemPropertyVariables>
          <tomee.httpPort>-1</tomee.httpPort>
          <tomee.stopPort>-1</tomee.stopPort>
        </systemPropertyVariables>
      </configuration>
    </plugin>
  </plugins>
</build>

When a port is set to -1, a random port will be chosen. This is key to avoiding port conflicts on CI systems or for just plain clean testing.

The TomEE Arquillian adapters will export the actual port chosen back as a system propert using the same name. The test case can use the property to retrieve the port and contact the server.

URL url = new URL("http://localhost:" + System.getProperty("tomee.httpPort");
// use the URL to connect to the server

When you are actually using a test on the client side, you can use instead

@Arquillian private URL url;

The url will get injected by Arquillian. Be careful, that injection only works if your are on the client side (it does not make sense in the server side). So, if for a specific need to need it, just use the system property.

TomEE Embedded Adapter

The TomEE Embedded Adapter will boot TomEE right inside the testcase itself resulting in one JVM running both the application and the test case. This is generally much faster than the TomEE Remote Adapter and great for development. That said, it is strongly recommended to also run all tests in a Continous Integration system using the TomEE Remote Adapter.

To use the TomEE Embedded Arquillian Adapter, simply add this Maven dependency to your Arquillian setup:

<dependency>
  <groupId>org.apache.openejb</groupId>
  <artifactId>arquillian-tomee-embedded</artifactId>
  <version>1.0.0</version>
</dependency>

As mentioned above the Embedded Adapter has the following properties which can be specified in the arquillian.xml file:

Or alternatively as System properties, possibly shared with other TomEE Arquillian Adapters:

Or more specifically as a System properties only applicable to the Embedded Adapter:

TomEE Remote Adapter

The TomEE Remote Adapter will unzip and setup a TomEE or TomEE Plus distribution. Once setup, the server will execute in a separate process. This will be slower, but with the added benefit it is 100% match with the production system.

The following shows a typical configuration for testing against TomEE (webprofile version). The same can be done against TomEE+ by changing <tomee.classifier>webprofile</tomee.classifier> to <tomee.classifier>plus</tomee.classifier>

<properties>
  <tomee.version>1.0.0</tomee.version>
  <tomee.classifier>webprofile</tomee.classifier>
</properties>
<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <configuration>
        <systemPropertyVariables>
          <tomee.classifier>${tomee.classifier}</tomee.classifier>
          <tomee.version>${tomee.version}</tomee.version>
        </systemPropertyVariables>
      </configuration>
    </plugin>
  </plugins>
</build>
<dependencies>
  <dependency>
    <groupId>org.apache.openejb</groupId>
    <artifactId>arquillian-tomee-remote</artifactId>
    <version>${tomee.version}</version>
  </dependency>
  <dependency>
    <groupId>org.apache.openejb</groupId>
    <artifactId>apache-tomee</artifactId>
    <version>${tomee.version}</version>
    <classifier>${tomee.classifier}</classifier>
    <type>zip</type>
  </dependency>
</dependencies>

The Remote Adapter has the following properties which can be specified in the arquillian.xml file:

Or alternatively as System properties, possibly shared with other TomEE Arquillian Adapters:

Or more specifically as a System properties only applicable to the Remote Adapter:

Maven Profiles

Setting up both adapters is quite easy via maven profiles. Here the default adapter is the Embedded Adapter, the Remote Adapter will run with -Ptomee-webprofile-remote specified as a mvn command argument.

<profiles>

  <profile>
    <id>tomee-embedded</id>
    <activation>
      <activeByDefault>true</activeByDefault>
    </activation>
    <dependencies>
      <dependency>
        <groupId>org.apache.openejb</groupId>
        <artifactId>arquillian-tomee-embedded</artifactId>
        <version>1.0.0</version>
      </dependency>
    </dependencies>
  </profile>

  <profile>
    <id>tomee-webprofile-remote</id>
    <properties>
      <tomee.version>1.0.0</tomee.version>
      <tomee.classifier>webprofile</tomee.classifier>
    </properties>
    <build>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <configuration>
            <systemPropertyVariables>
              <tomee.classifier>${tomee.classifier}</tomee.classifier>
              <tomee.version>${tomee.version}</tomee.version>
            </systemPropertyVariables>
          </configuration>
        </plugin>
      </plugins>
    </build>
    <dependencies>
      <dependency>
        <groupId>org.apache.openejb</groupId>
        <artifactId>arquillian-tomee-remote</artifactId>
        <version>${tomee.version}</version>
      </dependency>
      <dependency>
        <groupId>org.apache.openejb</groupId>
        <artifactId>apache-tomee</artifactId>
        <version>${tomee.version}</version>
        <classifier>${tomee.classifier}</classifier>
        <type>zip</type>
      </dependency>
    </dependencies>
  </profile>

  <profile>
    <id>tomee-plus-remote</id>
    <properties>
      <tomee.version>1.0.0</tomee.version>
      <tomee.classifier>plus</tomee.classifier>
    </properties>
    <build>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <configuration>
            <systemPropertyVariables>
              <tomee.classifier>${tomee.classifier}</tomee.classifier>
              <tomee.version>${tomee.version}</tomee.version>
            </systemPropertyVariables>
          </configuration>
        </plugin>
      </plugins>
    </build>
    <dependencies>
      <dependency>
        <groupId>org.apache.openejb</groupId>
        <artifactId>arquillian-tomee-remote</artifactId>
        <version>${tomee.version}</version>
      </dependency>
      <dependency>
        <groupId>org.apache.openejb</groupId>
        <artifactId>apache-tomee</artifactId>
        <version>${tomee.version}</version>
        <classifier>${tomee.classifier}</classifier>
        <type>zip</type>
      </dependency>
    </dependencies>
  </profile>

</profiles>