You want to automatically generate the cactus.properties file to match the current environment.
Create a target within your Ant buildfile to generate the cactus.properties file each time Cactus tests are run.
Writing Cactus tests is pretty straightforward, but configuring your environment can be cumbersome, especially if your environment changes over time. Automatically generating configuration files eases the burden of keeping your testing environment in sync with your development environment.
Ant is the obvious choice for generating the cactus.properties file. The first step is to ensure that the following Ant properties are defined in your buildfile:[7]
[7] Your test environment may require different property values for the host, port, web application context name, etc. than shown here.
<property name="dir.build" value="build"/> <property name="host" value="http://localhost"/> <property name="port" value="8080"/> <property name="webapp.context.name" value="xptest"/> <property name="servlet.redirector" value="ServletRedirector"/> <property name="jsp.redirector" value="JspRedirector"/> <property name="filter.redirector" value="FilterRedirector"/>
By setting up global properties, you ensure that a single change ripples through the rest of the buildfile. Next, your buildfile should execute the propertyfile task:
<target name="prepare"> <mkdir dir="${dir.build}"/> <propertyfile file="${dir.build}/cactus.properties"> <entry key="cactus.contextURL" value="${host}:${port}/${webapp.context.name}"/> <entry key="cactus.servletRedirectorName" value="${servlet.redirector}"/> <entry key="cactus.jspRedirectorName" value="${jsp.redirector}"/> <entry key="cactus.filterRedirectorName" value="${filter.redirector}"/> </propertyfile> </target>
|
The best place to generate the cactus.properties file is within a target that executes each time the Cactus test suite runs. In this recipe, the property file is generated within the prepare target, which is the first target executed when running the test suite. Each time you run the Cactus test suite the cactus.properties file is generated by Ant to reflect any changes to the host, port, web context name, or redirector values.
Recipe 7.4 describes the details of the cactus.properties file. Recipe 7.3 describes how to setup a stable build environment for server-side testing.