Arquillian Container Tomcat project provides DeployableContainer
implementations for managing the lifecycle of Tomcat
instances within Arquillian tests.
It supports Jakarta EE features like JNDI and Servlet,
enabling seamless deployment and testing of web applications.
There three distinct operation modes:
-
Embedded: Runs within the same JVM as the test cases.
-
Managed: Operates in a separate JVM, with Arquillian managing its lifecycle.
-
Remote: Connects to an already running Tomcat instance.
Each configuration has its specific setup and considerations and are outlined below to help users integrate Tomcat into their testing workflows.
A DeployableContainer
implementation that manages the complete lifecycle of an embedded (same JVM) Tomcat Servlet Container.
Keep in mind that only select Jakarta EE APIs are available in Tomcat, such as JNDI and Servlet 3.0.
Test archives are adapted to Tomcat’s StandardContext
API by ShrinkWrap and deployed programmatically.
@Resource |
@EJB |
@EJB (no-interface) |
@Inject (CDI) |
@Inject (MC) |
@PersistenceContext / @PersistenceUnit |
✓ |
✓ |
WarningCDI support requires use of Weld Servlet and associated configuration. The WAR will have to be unpacked as well in order for Weld to locate the classes. See the following configuration example.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://jboss.org/schema/arquillian"
xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
<container qualifier="tomcat" default="true">
<configuration>
<property name="unpackArchive">true</property>
</configuration>
</container>
</arquillian>
Default Protocol: Servlet 6.0
Name | Type | Default | Description |
---|---|---|---|
|
|
|
The HTTP port the server should bind to. |
|
|
|
The host the server should be run on. |
|
|
Optional location of a Tomcat installation to link against. |
|
|
|
|
Optional name of the server. |
|
|
|
Optional relative or absolute path to the directory where applications are deployed (e.g., webapps). |
|
|
Optional relative or absolute path to the directory where applications are expanded and session serialization data is stored (e.g., work). |
|
|
|
|
Specify if the deployment should be deployed exploded or compressed. |
<profile>
<id>tomcat-embedded</id>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-tomcat-embedded-10</artifactId>
<version>${version.arquillian.container.tomcat}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>${version.tomcat}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>${version.tomcat}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-logging-juli</artifactId>
<version>${version.tomcat}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jdt.core.compiler</groupId>
<artifactId>ecj</artifactId>
<version>3.7</version>
<scope>test</scope>
</dependency>
<!-- Weld servlet for testing CDI injections -->
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet</artifactId>
<version>5.1.5.Final</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
A DeployableContainer
implementation that can run and connect to remote (different JVM, but same machine) Tomcat instances.
This implementation has lifecycle support, so the container will be started and stopped as part of the test run.
@Resource |
@EJB |
@EJB (no-interface) |
@Inject (CDI) |
@Inject (MC) |
@PersistenceContext @PersistenceUnit |
✓ |
Name | Type | Default | Description |
---|---|---|---|
|
|
|
The HTTP port the server will run on, has to be the same as in |
|
|
|
The host the server will run on, has to be the same as in |
|
|
|
The Tomcat configuration to start. |
|
|
|
The Java runtime to use to start the server. |
|
|
|
JVM arguments used to start the server. |
|
|
Username of the user who has |
|
|
|
Password of the user who has |
|
|
|
|
The JMX port used to connect to the running instance, needed for deployment introspection. |
|
|
|
Charset of URL used for deploy/undeploy operations. |
|
|
|
Should the server startup console log be piped to the console. |
|
|
|
Time to wait before throwing an exception on server startup. |
|
|
|
Which server configuration file to startup with. |
<profile>
<id>tomcat-managed</id>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-tomcat-managed-10</artifactId>
<version>${version.arquillian.container.tomcat}</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
A DeployableContainer
implementation that can connect to a remote Tomcat Servlet Container instance.
@Resource |
@EJB |
@EJB (no-interface) |
@Inject (CDI) |
@Inject (MC) |
@PersistenceContext @PersistenceUnit |
✓ |
✓ |
Warning
|
CDI support requires the use of Weld Servlet and associated configuration. |
Name | Type | Default | Description |
---|---|---|---|
|
|
|
The HTTP port the server is bound to. |
|
|
|
The host the server is running on. |
|
|
The user to authenticate as when using the Management console. |
|
|
|
The password to authenticate with when using the Management console. |
|
|
|
|
The JMX port used to connect to the running instance, needed for deployment introspection. |
<profile>
<id>tomcat-remote</id>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-tomcat-remote-10</artifactId>
<version>${version.arquillian.container.tomcat}</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
Warning
|
The remote Tomcat instance has to expose a remote JMX MBeanConnection .
This can be done by adding the following to the startup script.
|
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.port=8089"
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.ssl=false"
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.authenticate=false"
Note
|
This makes your Tomcat insecure! Use only for testing and development purposes. |