| <project name="Struts Unit Tests" default="test.tomcat.32" basedir="."> |
| |
| <!-- |
| This is a generic build.xml file for Ant that is used to run the |
| Struts unit tests. This build file *must* be called from the |
| build.xml file in order to inherit most of it's needed properties |
| (See below for the list of these properties). |
| --> |
| |
| <!-- ========== Prerequisite Properties =================================== --> |
| |
| |
| <!-- |
| These properties MUST be set on the "ant" command line, the "antrc" |
| properties file in your home directory, or from settings in a superior |
| build.xml script. |
| |
| build.home Base directory into which we are building |
| the Struts components. |
| |
| servlet.jar The servlet jar (either 2.2 or 2.3) |
| |
| cactus.jar The Cactus jar (either for Servlet API |
| 2.2 or 2.3) |
| |
| cactus.ant.jar The Cactus custom Ant tasks jar |
| |
| junit.jar The JUnit jar |
| |
| tomcat.home.32 The home directory of where Tomcat 3.2 |
| is installed |
| |
| tomcat.home.40 The home directory of where Tomcat 4.0 |
| is installed |
| |
| compile.debug The debug mode for compilation |
| |
| compile.deprecation The deprecation mode for compilation |
| |
| compile.optimize The optimization mode for compilation |
| |
| src.dir The location of the source directory |
| |
| app.name The name of the Struts jar (without the |
| '.jar' suffix |
| |
| --> |
| |
| <!-- ========== Initialization Properties ================================= --> |
| |
| <!-- |
| These property values may optionally be overridden with property |
| settings from an "ant" command line, the "build.properties" file |
| in this directory, the "build.properties" file in your home |
| directory, or from settings in a superior build.xml script. |
| --> |
| |
| |
| <!-- ========== Derived Properties ======================================== --> |
| |
| <!-- |
| These property values are derived from values defined above, and |
| generally should NOT be overridden by command line settings |
| --> |
| |
| <!-- Source directory for tests --> |
| <property name="src.test.dir" value="${src.dir}/test"/> |
| |
| <!-- Configuration directory for tests --> |
| <property name="conf.test.dir" value="conf/test"/> |
| |
| <!-- Output directory for tests --> |
| <property name="out.test.dir" value="${build.home}/test"/> |
| |
| <!-- Compilation Classpath --> |
| <path id="compile.classpath"> |
| <pathelement location="${build.home}/library/${app.name}.jar"/> |
| <pathelement location="${servlet.jar}"/> |
| <pathelement location="${cactus.jar}"/> |
| <pathelement location="${junit.jar}"/> |
| </path> |
| |
| <!-- ========== Executable Targets ======================================== --> |
| |
| |
| <!-- |
| Initialization of custom Ant tasks |
| --> |
| <target name="init"> |
| |
| <taskdef name="runservertests" |
| classname="org.apache.commons.cactus.ant.RunServerTestsTask"> |
| |
| <classpath> |
| <pathelement location="${cactus.ant.jar}"/> |
| <pathelement path="${java.class.path}"/> |
| </classpath> |
| </taskdef> |
| |
| </target> |
| |
| <!-- |
| Create directories and copy files for the struts tests |
| --> |
| <target name="prepare.test" depends="init"> |
| |
| <!-- Create target directories for classes --> |
| <mkdir dir="${out.test.dir}/classes"/> |
| |
| <!-- Create directory where servlet engines will run --> |
| <mkdir dir="${out.test.dir}/servers"/> |
| |
| <!-- Create a lib directory where needed libs for the test war will |
| be put --> |
| <mkdir dir="${out.test.dir}/lib"/> |
| |
| </target> |
| |
| <!-- |
| Compile unit tests |
| --> |
| <target name="compile.test" depends="prepare.test"> |
| |
| <javac srcdir="${src.test.dir}" |
| destdir="${out.test.dir}/classes" |
| debug="${compile.debug}" |
| optimize="${compile.optimize}" |
| deprecation="${compile.deprecation}"> |
| |
| <classpath refid="compile.classpath"/> |
| </javac> |
| <copy todir="${out.test.dir}/classes"> |
| <fileset dir="${src.test.dir}" includes="**/*.properties"/> |
| </copy> |
| |
| </target> |
| |
| <!-- |
| Prepare test war (for all servlet engines) |
| --> |
| <target name="prepare.test.war" depends="compile.test" if="tomcat.home.32"> |
| |
| <!-- Copy needed libs in /lib --> |
| <copy file="${build.home}/library/${app.name}.jar" |
| todir="${out.test.dir}/lib"/> |
| <copy file="${junit.jar}" todir="${out.test.dir}/lib"/> |
| <copy file="${cactus.jar}" todir="${out.test.dir}/lib"/> |
| |
| <war warfile="${out.test.dir}/test.war" |
| webxml="${conf.test.dir}/web.xml"> |
| |
| <classes dir="${out.test.dir}/classes"/> |
| |
| <!-- We need to copy the Cactus, JUnit and Struts jars in the war. |
| This is because if we just put these jars in the global |
| classpath for the Servlet engine, the Cactus jar might not be |
| able to load the test case class as the test classes are loaded |
| by the war classloader. This will depend on servlet engines --> |
| |
| <lib dir="${out.test.dir}/lib"/> |
| |
| <webinf dir="${conf.test.dir}"> |
| <include name="struts-config.xml"/> |
| </webinf> |
| |
| </war> |
| |
| </target> |
| |
| <!-- |
| Start the Cactus test using JUnit test runner. |
| --> |
| <target name="run.test"> |
| |
| <junit printsummary="yes" haltonfailure="yes" haltonerror="yes" fork="yes"> |
| |
| <classpath> |
| <pathelement path="${java.class.path}"/> |
| <pathelement location="${out.test.dir}/classes"/> |
| <!-- For cactus.properties --> |
| <pathelement location="${conf.test.dir}"/> |
| </classpath> |
| <classpath refid="compile.classpath"/> |
| |
| <formatter type="plain" usefile="false"/> |
| |
| <!-- Suite of tests --> |
| <test name="org.apache.struts.action.TestActionServlet"/> |
| |
| </junit> |
| |
| </target> |
| |
| <!-- |
| Prepare test directory structure for Tomcat 3.2 servlet engine |
| --> |
| <target name="prepare.test.tomcat.32" depends="prepare.test.war" if="tomcat.home.32"> |
| |
| <property name="out.tomcat.32.dir" value="${out.test.dir}/servers/tomcat32"/> |
| <filter token="out.tomcat.32.dir" value="${out.tomcat.32.dir}"/> |
| |
| <mkdir dir="${out.tomcat.32.dir}/webapps"/> |
| <mkdir dir="${out.tomcat.32.dir}/conf"/> |
| |
| <!-- Copy war file --> |
| <copy file="${out.test.dir}/test.war" todir="${out.tomcat.32.dir}/webapps"/> |
| |
| <!-- Copy configuration files --> |
| <copy file="${conf.test.dir}/tomcat32/server.xml" |
| todir="${out.tomcat.32.dir}/conf" filtering="on"/> |
| |
| </target> |
| |
| <!-- |
| Run unit tests on Tomcat 3.2 servlet engine |
| --> |
| <target name="test.tomcat.32" depends="prepare.test.tomcat.32"> |
| |
| <!-- Start the servlet engine, wait for it to be started, run the |
| unit tests, stop the servlet engine, wait for it to be stopped. |
| The servlet engine is automatically stopped if the tests fail for |
| any reason.--> |
| |
| <runservertests testURL="http://localhost:8080/test" |
| startTarget="start.tomcat.32" |
| stopTarget="stop.tomcat.32" |
| testTarget="run.test"/> |
| |
| </target> |
| |
| <!-- |
| Start Tomcat 3.2 servlet engine |
| --> |
| <target name="start.tomcat.32"> |
| |
| <java classname="org.apache.tomcat.startup.Tomcat" fork="yes"> |
| <arg value="-config"/> |
| <arg value="${out.tomcat.32.dir}/conf/server.xml"/> |
| <classpath> |
| <pathelement location="${java.home}/../lib/tools.jar"/> |
| <fileset dir="${tomcat.home.32}/lib"> |
| <include name="*.jar"/> |
| </fileset> |
| </classpath> |
| </java> |
| |
| </target> |
| |
| <!-- |
| Stop Tomcat 3.2 servlet engine |
| --> |
| <target name="stop.tomcat.32"> |
| |
| <java classname="org.apache.tomcat.startup.Tomcat" fork="yes"> |
| <jvmarg value="-Dtomcat.home=${tomcat.home.32}"/> |
| <arg value="-stop"/> |
| <classpath> |
| <pathelement location="${java.home}/../lib/tools.jar"/> |
| <fileset dir="${tomcat.home.32}/lib"> |
| <include name="*.jar"/> |
| </fileset> |
| </classpath> |
| </java> |
| |
| </target> |
| |
| <!-- |
| Prepare test directory structure for Tomcat 4.0 servlet engine |
| --> |
| <target name="prepare.test.tomcat.40" depends="prepare.test.war" if="tomcat.home.40"> |
| |
| <property name="out.tomcat.40.dir" value="${out.test.dir}/servers/tomcat40"/> |
| <filter token="out.tomcat.40.full.dir" value="${basedir}/${out.tomcat.40.dir}"/> |
| |
| <mkdir dir="${out.tomcat.40.dir}/webapps"/> |
| <mkdir dir="${out.tomcat.40.dir}/conf"/> |
| |
| <!-- Copy war file --> |
| <copy file="${out.test.dir}/test.war" todir="${out.tomcat.40.dir}/webapps"/> |
| |
| <!-- Copy configuration files --> |
| <copy file="${conf.test.dir}/tomcat40/server.xml" |
| todir="${out.tomcat.40.dir}/conf" filtering="on"/> |
| |
| </target> |
| |
| <!-- |
| Run unit tests on Tomcat 4.0 servlet engine |
| --> |
| <target name="test.tomcat.40" depends="prepare.test.tomcat.40"> |
| |
| <!-- Start the servlet engine, wait for it to be started, run the |
| unit tests, stop the servlet engine, wait for it to be stopped. |
| The servlet engine is automatically stopped if the tests fail for |
| any reason.--> |
| |
| <runservertests testURL="http://localhost:8080/test" |
| startTarget="start.tomcat.40" |
| stopTarget="stop.tomcat.40" |
| testTarget="run.test"/> |
| |
| </target> |
| |
| <!-- |
| Start Tomcat 4.0 servlet engine |
| --> |
| <target name="start.tomcat.40"> |
| |
| <java classname="org.apache.catalina.startup.Bootstrap" fork="yes"> |
| <jvmarg value="-Dcatalina.home=${tomcat.home.40}"/> |
| <arg value="-config"/> |
| <arg value="${basedir}/${out.tomcat.40.dir}/conf/server.xml"/> |
| <arg value="start"/> |
| <classpath> |
| <pathelement location="${java.home}/../lib/tools.jar"/> |
| <fileset dir="${tomcat.home.40}"> |
| <include name="bin/bootstrap.jar"/> |
| <include name="server/catalina.jar"/> |
| </fileset> |
| </classpath> |
| </java> |
| |
| </target> |
| |
| <!-- |
| Stop Tomcat 4.0 servlet engine |
| --> |
| <target name="stop.tomcat.40"> |
| |
| <java classname="org.apache.catalina.startup.Bootstrap" fork="yes"> |
| <jvmarg value="-Dcatalina.home=${tomcat.home.40}"/> |
| <arg value="stop"/> |
| <classpath> |
| <fileset dir="${tomcat.home.40}"> |
| <include name="bin/bootstrap.jar"/> |
| <include name="server/catalina.jar"/> |
| </fileset> |
| </classpath> |
| </java> |
| |
| </target> |
| |
| </project> |