Cactus Task

The task cactus is an extension of the junit task that is included in Ant as an optional task. cactus extends junit to enable in-container tests. It features built-in support for a variety of containers, but also allows testing in custom containers.

Currently the following containers are supported out of the box:

  • Apache Tomcat 3.x
  • Apache Tomcat 4.x
  • Apache Tomcat 5.x
  • JBoss Application Server 3.x
  • Orion Application Server 1.x
  • Orion Application Server 2.x
  • Resin Server 2.x

Parameters

As this task is an extension of the junit task, it also supports all attributes that the junit task supports. In addition, the following parameters are supported:

Name Description Required
warfile The web application archive that should be tested. The archive must already contain everything needed for running Cactus tests (it must be cactified). Yes, unless the earfile attribute is specified
earfile The enterprise application archive that should be tested. The archive must contain a web module that already contains everything needed for running Cactus tests (it must be cactified). Yes, unless the warfile attribute is specified

Nested Elements

As this task is an extension of the junit task, it also supports all the nested elements supported by the junit task. In addition, the following nested elements are supported:

containerset

The containerset element lets you specify which containers the tests should run against. Every element nested inside this element corresponds to a container. See below for a list of container elements supported in this element.

Parameters

The containerset element supports the following parameters:
Name Description Required
timeout Specifies the timeout in milliseconds after which starting up a container should be given up. If the timeout is reached before the container starts responding with a successful HTTP status code, the build will fail. No, default is 3 minutes
proxyport By specifying this attribute it is possible to insert some application that acts as a local TCP/IP proxy between the test runner and the actual containers. Most importantly, that includes applications that record and display the HTTP transactions, which can be helpful in tracking down tricky problems. No

Supported Containers

All elements nested in the containerset element represent specific containers.

Specific container elements provide attributes and nested elements as appropriate.

generic

The generic container supports custom containers by allowing you to specify targets to be called, or tasks to executed, in order to start up and shut down the container.

Parameters

Name Description Required
name A name for the container that is displayed when the tests are run. No
port The TCP port that the container should listen to No, default is 8080
startuptarget The name of a target that should be called to perform the starting up of the container. Yes, unless there's a nested startup element
shutdowntarget The name of a target that should be called to perform the shutting down of the container. Yes, unless there's a nested shutdown element
if Tests will only be run in the container if a property of the given name exists in the current project No
unless Tests will only be run in the container if a property of the given name doesn't exist in the current project No

Nested Elements

The generic container supports the following nested elements:

exclude

Multiple exclude elements can be used as in standard Ant PatternSets or FileSets to exclude specific tests from running in the container.

startup

A single startup element can be nested inside a generic element. Using this element, you can implement the startup of the container, either by specifying a target name in the target attribute, or by directly embedding the required Ant tasks inside the startup element.

shutdown

A single shutdown element can be nested inside a generic element. Using this element, you can implement the shutdown of the container, either by specifying a target name in the target attribute, or by directly embedding the required Ant tasks inside the shutdown element.

jboss3x

The nested element orion1x allows running the tests against the JBoss 3.x application server.

Parameters

Name Description Required
dir The installation directory of the JBoss 3.x server Yes
config The name of the configuration to use No, the default is default
output Name of a file to write the output of the container to. If not specified, the standard output will be used No
append Whether output should be appended to or overwrite an existing file. No, default is false
if Tests will only be run in the container if a property of the given name exists in the current project No
unless Tests will only be run in the container if a property of the given name doesn't exist in the current project No

Nested Elements

The jboss3x container supports the following nested elements:

exclude

Multiple exclude elements can be used as in standard Ant PatternSets or FileSets to exclude specific tests from running in the container.

orion1x

The nested element orion1x allows running the tests against the Orion Application Server 1.x.

Parameters

Name Description Required
dir The installation directory of the Orion 1.x server Yes
port The TCP port that the container should listen to No, default is 8080
tmpdir The directory to which the container will be installed for the tests. No (by default the system temporary directory is used)
output Name of a file to write the output of the container to. If not specified, the standard output will be used No
append Whether output should be appended to or overwrite an existing file. No, default is false
if Tests will only be run in the container if a property of the given name exists in the current project No
unless Tests will only be run in the container if a property of the given name doesn't exist in the current project No

Nested Elements

The orion1x container supports the following nested elements:

exclude

Multiple exclude elements can be used as in standard Ant PatternSets or FileSets to exclude specific tests from running in the container.

orion2x

The nested element orion1x allows running the tests against the Orion Application Server 2.x.

Parameters

Name Description Required
dir The installation directory of the Orion 2.x server Yes
port The TCP port that the container should listen to No, default is 8080
tmpdir The directory to which the container will be installed for the tests. No (by default the system temporary directory is used)
output Name of a file to write the output of the container to. If not specified, the standard output will be used No
append Whether output should be appended to or overwrite an existing file. No, default is false
if Tests will only be run in the container if a property of the given name exists in the current project No
unless Tests will only be run in the container if a property of the given name doesn't exist in the current project No

Nested Elements

The orion2x container supports the following nested elements:

exclude

Multiple exclude elements can be used as in standard Ant PatternSets or FileSets to exclude specific tests from running in the container.

resin2x

The nested element orion1x allows running the tests against the Resin Server 2.x.

Parameters

Name Description Required
dir The installation directory of the Resin 2.x server Yes
resinconf The configuration file to use instead of the default one No
port The TCP port that the container should listen to No, default is 8080
tmpdir The directory to which the container will be installed for the tests. No (by default the system temporary directory is used)
output Name of a file to write the output of the container to. If not specified, the standard output will be used No
append Whether output should be appended to or overwrite an existing file. No, default is false
if Tests will only be run in the container if a property of the given name exists in the current project No
unless Tests will only be run in the container if a property of the given name doesn't exist in the current project No

Nested Elements

The resin2x container supports the following nested elements:

exclude

Multiple exclude elements can be used as in standard Ant PatternSets or FileSets to exclude specific tests from running in the container.

tomcat3x

The nested element tomcat3x allows running the tests against the Apache Tomcat 3.x servlet container.

Parameters

Name Description Required
dir The installation directory of the Tomcat 3.x server Yes
serverxml The server configuration file to use instead of the default one No
port The TCP port that the container should listen to No, default is 8080
tmpdir The directory to which the container will be installed for the tests. No (by default the system temporary directory is used)
output Name of a file to write the output of the container to. If not specified, the standard output will be used No
append Whether output should be appended to or overwrite an existing file. No, default is false
if Tests will only be run in the container if a property of the given name exists in the current project No
unless Tests will only be run in the container if a property of the given name doesn't exist in the current project No

Nested Elements

The tomcat3x container supports the following nested elements:

conf

A fileset that can be used to specify the set of files that should be placed into the conf directory of the installation directory. This fileset should not include the serverxml file.

exclude

Multiple exclude elements can be used as in standard Ant PatternSets or FileSets to exclude specific tests from running in the container.

tomcat4x

The nested element tomcat4x allows running the tests against the Apache Tomcat 4.x servlet container.

Parameters

Name Description Required
dir The installation directory of the Tomcat 4.x server Yes
serverxml The server configuration file to use instead of the default one No
port The TCP port that the container should listen to No, default is 8080
tmpdir The directory to which the container will be installed for the tests. No (by default the system temporary directory is used)
output Name of a file to write the output of the container to. If not specified, the standard output will be used No
append Whether output should be appended to or overwrite an existing file. No, default is false
if Tests will only be run in the container if a property of the given name exists in the current project No
unless Tests will only be run in the container if a property of the given name doesn't exist in the current project No

Nested Elements

The tomcat4x container supports the following nested elements:

conf

A fileset that can be used to specify the set of files that should be placed into the conf directory of the installation directory. This fileset should not include the serverxml file.

exclude

Multiple exclude elements can be used as in standard Ant PatternSets or FileSets to exclude specific tests from running in the container.

tomcat5x

The nested element tomcat5x allows running the tests against the Apache Tomcat 5.x servlet container.

Parameters

Name Description Required
dir The installation directory of the Tomcat 5.x server Yes
serverxml The server configuration file to use instead of the default one No
port The TCP port that the container should listen to No, default is 8080
tmpdir The directory to which the container will be installed for the tests. No (by default the system temporary directory is used)
output Name of a file to write the output of the container to. If not specified, the standard output will be used No
append Whether output should be appended to or overwrite an existing file. No, default is false
if Tests will only be run in the container if a property of the given name exists in the current project No
unless Tests will only be run in the container if a property of the given name doesn't exist in the current project No

Nested Elements

The tomcat5x container supports the following nested elements:

conf

A fileset that can be used to specify the set of files that should be placed into the conf directory of the installation directory. This fileset should not include the serverxml file.

exclude

Multiple exclude elements can be used as in standard Ant PatternSets or FileSets to exclude specific tests from running in the container.

Examples

The following example demonstrates how to run a suite of Cactus tests against three contains with builtin support (JBoss 3, Resin 2 and Tomcat 4).

<cactus warfile="${test.dir}/test.war"
    printsummary="yes" failureproperty="tests.failed">
  <classpath>
    <path refid="cactus.classpath"/>
    <pathelement location="${build.classes.dir}"/>
    <pathelement location="${test.classes.dir}"/>
  </classpath>
  <containerset>
    <jboss2x dir="${jboss3x.home}" config="default"
        todir="${test.reports.dir}/jboss3x"/>
    <resin2x dir="${resin2x.home}" port="8080"
        todir="${test.reports.dir}/resin2x"/>
    <tomcat4x dir="${tomcat4x.home}" port="8080"
        todir="${test.reports.dir}/tomcat4x"/>
  </containerset>
  <formatter type="xml"/>
  <batchtest>
    <fileset dir="${src.test.dir}">
      <include name="**/Test*.java"/>
      <exclude name="**/TestAll.java"/>
    </fileset>
  </batchtest>
</cactus>

The next example shows the use of the generic container element for starting/stopping a custom container. You need to define the two targets mycontainer.start and mycontainer.stop, so that the container is started up (on port 8080) before the tests are run, and shut down after the tests completed. How these targets are implemented is highly dependant on the container. Most likely you'll need to copy some files and use the <java> task to invoke a container-provided Java class that can start/stop the container.

<cactus warfile="${test.dir}/test.war"
    printsummary="yes" failureproperty="tests.failed">
  <classpath>
    <path refid="cactus.runtime.classpath"/>
    <pathelement location="${build.classes.dir}"/>
    <pathelement location="${test.classes.dir}"/>
  </classpath>
  <containerset>
    <generic name="My Container" port="8080">
      <startup target="mycontainer.start"/>
      <shutdown target="mycontainer.stop"/>
    </generic>
  </containerset>
  <formatter type="xml"/>
  <batchtest>
    <fileset dir="${src.test.dir}">
      <include name="**/Test*.java"/>
      <exclude name="**/TestAll.java"/>
    </fileset>
  </batchtest>
</cactus>