Child pages
  • Tomcat Container
Skip to end of metadata
Go to start of metadata

Pax Exam's Tomcat container is a web plus CDI container, without any OSGi or full Java EE support. It is intended for testing plain old web applications and can be used with OpenWebBeans or Weld as CDI providers.

If your web application does not use CDI itself, just add a CDI provider for testing so that injection into test cases will work.

This container launches Tomcat 7.x embedded in the same VM and deploys a WAR test probe built on the fly from the classpath contents.

pax-exam-container-tomcat depends on Embedded Tomcat Maven artifacts. There is no need for a separate Tomcat installation.

This is the standard lifecycle of the Tomcat container:

  1. Tomcat is started via org.apache.catalina.startup.Tomcat. A temporary directory is used as catalina.base.
  2. Any WAR modules configured by the user are deployed.
  3. A WAR probe is built and deployed.
  4. All tests contained in the probe are executed within the container.
  5. All WAR modules (including the WAR probe, if any) are undeployed.
  6. Tomcat is stopped.
  7. The catalina.base temporary directory is deleted (depending on the configuration options).

A context.xml configuration file can be placed in one of the following locations:

  • src/test/resources/META-INF/context.xml
  • src/main/webapp/META-INF/context.xml

Pax Exam automatically configures a CDI servlet context listener, depending on the CDI provider. The CDI provider is defined by a configuration property in exam.properties:

pax.exam.system = javaee
pax.exam.tomcat.listener = openwebbeans     # or weld

Current restrictions:

  • Tomcat JULI logging is not yet redirected to SLF4J, the preferred logging solution in Pax Exam.
  • No labels