Preloader image

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

All the Arquillian Adapters for TomEE support the following configuration options in the src/test/resources/arquillian.xml:

<container qualifier="tomee" default="true">
    <configuration>
        <property name="httpPort">-1</property>
        <property name="stopPort">-1</property>
        <!--Optional Container Properties-->
        <property name="properties">
            aproperty=something
        </property>
        <!--Optional Remote Adapter Deployer Properties
        <property name="deployerProperties">
            aproperty=something
        </property>
        -->
    </configuration>
</container>

The above can also be set as system properties rather than via the src/test/resources/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 property 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

If that property returns null

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

import org.jboss.arquillian.test.api.ArquillianResource;
...
@ArquillianResource 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 test case 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 Continuous Integration system using the TomEE Remote Adapter.

To use the TomEE Embedded Arquillian Adapter, simply add these Maven dependencies to your Maven pom.xml:

<dependency>
  <groupId>org.apache.tomee</groupId>
  <artifactId>arquillian-tomee-embedded</artifactId>
  <version>${TOMEE_VERSION}</version> <!--Current version-->
</dependency>
<dependency>
  <groupId>org.apache.tomee</groupId>
  <artifactId>tomee-embedded</artifactId>
  <version>${TOMEE_VERSION}</version>
</dependency>
<!--Required for WebServices and RESTful WebServices-->
<dependency>
  <groupId>org.apache.tomee</groupId>
  <artifactId>tomee-webservices</artifactId>
  <version>${TOMEE_VERSION}</version>
</dependency>
<dependency>
  <groupId>org.apache.tomee</groupId>
  <artifactId>tomee-jaxrs</artifactId>
  <version>${TOMEE_VERSION}</version>
</dependency>

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

  • httpPort

  • stopPort

  • properties (System properties for container)

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

  • tomee.httpPort

  • tomee.stopPort

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

  • tomee.embedded.httpPort

  • tomee.embedded.stopPort

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 environment.

On a local machine clients can get the remote server port using the following System property:

final String port = System.getProperty("server.http.port");

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>${TOMEE_VERSION}</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.tomee</groupId>
    <artifactId>arquillian-tomee-remote</artifactId>
    <version>${tomee.version}</version>
  </dependency>
  <dependency>
    <groupId>org.apache.tomee</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 src/test/resources/arquillian.xml file:

  • httpPort

  • stopPort

  • version

  • classifier (Must be either webprofile or plus)

  • properties (System properties for container)

  • deployerProperties (Sent to Deployer)

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

  • tomee.httpPort

  • tomee.stopPort

  • tomee.version

  • tomee.classifier

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

  • tomee.remote.httpPort

  • tomee.remote.stopPort

  • tomee.remote.version

  • tomee.remote.classifier

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.tomee</groupId>
        <artifactId>arquillian-tomee-embedded</artifactId>
        <version>${TOMEE_VERSION}</version>
      </dependency>
    </dependencies>
  </profile>

  <profile>
    <id>tomee-webprofile-remote</id>
    <properties>
      <tomee.version>${TOMEE_VERSION}</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.tomee</groupId>
        <artifactId>arquillian-tomee-remote</artifactId>
        <version>${tomee.version}</version>
      </dependency>
      <dependency>
        <groupId>org.apache.tomee</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>${TOMEE_VERSION}</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.tomee</groupId>
        <artifactId>arquillian-tomee-remote</artifactId>
        <version>${tomee.version}</version>
      </dependency>
      <dependency>
        <groupId>org.apache.tomee</groupId>
        <artifactId>apache-tomee</artifactId>
        <version>${tomee.version}</version>
        <classifier>${tomee.classifier}</classifier>
        <type>zip</type>
      </dependency>
    </dependencies>
  </profile>

</profiles>