Generating the cactus.properties File Automatically
Problem
You want to
automatically
generate the cactus.properties
file to match the
current environment.
Solution
Create a target within your Ant buildfile to generate the
cactus.properties
file each time Cactus tests
are run.
Discussion
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:[37]
<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}"/> ...
Get Java Extreme Programming Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.