<project name="Struts-EL Unit Tests" default="test.tomcat.40" basedir=".">

<!--
        This is a generic build.xml file for Ant that is used to run the
        Struts-EL 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.home                   The home directory of your Cactus
                                      installation (version 1.3+ required)
                                      
        cactus.contextURL             The URL used for testing
                                      

        aspectjrt.jar                 The AspectJ runtime jar that is
                                      included with Cactus 1.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

        httpunit.jar                  The HTTPUnit jar

        xalanj.jar                    The Xalan-J jar

        jtidy.jar                     The JTidy jar

        struts.jar                    The path to the base Struts jar file.

        jstl.jar                      The path to the JSTL 1.0 jar file.

        jstl-standard.jar             The path to the JSTL 1.0 "standard" jar
                                      file.

        tomcat.home.40                The home directory of where Tomcat 4.0
                                      is installed

        tomcat.home.41                The home directory of where Tomcat 4.1
                                      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-EL 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="${build.home}/test/classes"/>
      <pathelement location="${commons-beanutils.jar}"/>
      <pathelement location="${commons-collections.jar}"/>
      <pathelement location="${commons-digester.jar}"/>
      <pathelement location="${commons-httpclient.jar}"/>
      <pathelement location="${commons-logging.jar}"/>
      <pathelement location="${commons-validator.jar}"/>
      <pathelement location="${aspectjrt.jar}"/>
      <pathelement location="${cactus.jar}"/>
      <pathelement location="${junit.jar}"/>
      <pathelement location="${httpunit.jar}"/>
      <pathelement location="${xalanj.jar}"/>
      <pathelement location="${jtidy.jar}"/>
      <pathelement location="${servlet.jar}"/>
      <pathelement location="${struts.jar}"/>
      <pathelement location="${jstl.jar}"/>
	  <pathelement location="${jstl-standard.jar}"/>
    </path>

<!-- ========== Executable Targets ======================================== -->


<!--
        Initialization of custom Ant tasks
-->
    <target name="init">

        <taskdef name="runservertests"
            classname="org.apache.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}" excludes="**/*.java"/>
        </copy>
        <copy todir="${out.test.dir}/classes">
            <fileset dir="${conf.test.dir}" includes="**/*.properties"/>
        </copy>

    </target>

<!--
        Prepare test war (for all servlet engines)
-->
    <target name="prepare.test.war" depends="compile.test">

        <!-- Copy needed libs in /lib -->
        <copy file="${build.home}/library/${app.name}.jar"
            todir="${out.test.dir}/lib"/>
        <copy file="${aspectjrt.jar}" todir="${out.test.dir}/lib"/>
        <copy file="${junit.jar}"     todir="${out.test.dir}/lib"/>
        <copy file="${httpunit.jar}"     todir="${out.test.dir}/lib"/>
        <copy file="${xalanj.jar}"     todir="${out.test.dir}/lib"/>
        <copy file="${jtidy.jar}"     todir="${out.test.dir}/lib"/>
        <copy file="${log4j.jar}"     todir="${out.test.dir}/lib"/>
        <copy file="${cactus.jar}"    todir="${out.test.dir}/lib"/>
        <copy file="${struts.jar}"    todir="${out.test.dir}/lib"/>
        <copy file="${jstl.jar}"    todir="${out.test.dir}/lib"/>
        <copy file="${jstl-standard.jar}"    todir="${out.test.dir}/lib"/>
        <copy file="${commons-beanutils.jar}"
                                      todir="${out.test.dir}/lib"/>
        <copy file="${commons-collections.jar}"
                                      todir="${out.test.dir}/lib"/>
        <copy file="${commons-digester.jar}"
                                      todir="${out.test.dir}/lib"/>
        <copy file="${commons-logging.jar}"
                                      todir="${out.test.dir}/lib"/>
        <copy file="${commons-validator.jar}"
                                      todir="${out.test.dir}/lib"/>

        <war warfile="${out.test.dir}/test.war"
             webxml="${conf.test.dir}/web.xml">
	    
	    <fileset dir="${web.dir}/test"/>
 
            <classes dir="${out.test.dir}/classes"/>

            <!-- We need to copy the Cactus, JUnit, HTTPUnit, JTidy, 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.
-->
<!--
For JDK 1.4 logging, add the following properties with "jvmarg" elements:
"-Djava.util.logging.config.file=log.config"
"-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Jdk14Logger"
-->
    <target name="run.test">

        <junit printsummary="yes" haltonfailure="yes" haltonerror="yes" fork="yes">

            <jvmarg value="-Djava.util.logging.config.file=log.config"/>
            <jvmarg value="-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Jdk14Logger"/>

            <classpath>
                <pathelement path="${java.class.path}"/>
                <pathelement location="${commons-httpclient.jar}"/>
                <pathelement location="${out.test.dir}/classes"/>
                <!-- For cactus.properties -->
                <pathelement location="${conf.test.dir}"/>
            </classpath>
            <classpath refid="compile.classpath"/>

            <formatter type="plain" usefile="false"/>

            <!-- Logic Taglib Tests -->
            <batchtest fork="yes">
              <fileset dir="${out.test.dir}/classes">
                <include name="org/apache/strutsel/taglib/logic/Test*.class" />
              </fileset>
            </batchtest>

            <!-- HTML Taglib Tests -->
            <batchtest fork="yes">
              <fileset dir="${out.test.dir}/classes">
                <include name="org/apache/strutsel/taglib/html/Test*.class" />
              </fileset>
            </batchtest>

        </junit>

    </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="${out.tomcat.40.dir}"/>

        <mkdir dir="${out.tomcat.40.dir}/webapps"/>
        <mkdir dir="${out.tomcat.40.dir}/conf"/>

	<!-- Delete old directory so new war is unzipped -->
        <delete dir="${out.tomcat.40.dir}/webapps/test"/>

        <!-- 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="${cactus.contextURL}"
            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}"/>
            <jvmarg value="-Dcatalina.base=${tomcat.home.40}"/>
            <jvmarg value="-Djava.util.logging.config.file=log.config"/>
            <jvmarg value="-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Jdk14Logger"/>
            <arg value="-config"/>
            <arg value="${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}"/>
            <jvmarg value="-Dcatalina.base=${tomcat.home.40}"/>
            <arg value="-config"/>
            <arg value="${out.tomcat.40.dir}/conf/server.xml"/>
            <arg value="stop"/>
            <classpath>
              <fileset dir="${tomcat.home.40}">
                  <include name="bin/bootstrap.jar"/>
<!--                  <include name="server/catalina.jar"/> -->
              </fileset>
            </classpath>
        </java>

    </target>

<!--
        Prepare test directory structure for Tomcat 4.1 servlet engine
-->
    <target name="prepare.test.tomcat.41" depends="prepare.test.war" if="tomcat.home.41">

        <property name="out.tomcat.41.dir" value="${out.test.dir}/servers/tomcat41"/>
        <filter token="out.tomcat.41.full.dir" value="${out.tomcat.41.dir}"/>

        <mkdir dir="${out.tomcat.41.dir}/webapps"/>
        <mkdir dir="${out.tomcat.41.dir}/conf"/>

	<!-- Delete old directory so new war is unzipped -->
        <delete dir="${out.tomcat.41.dir}/webapps/test"/>

        <!-- Copy war file -->
        <copy file="${out.test.dir}/test.war" todir="${out.tomcat.41.dir}/webapps"/>
    
        <!-- Copy configuration files -->
        <copy file="${conf.test.dir}/tomcat41/server.xml"
            todir="${out.tomcat.41.dir}/conf" filtering="on"/>

    </target>

<!--
        Run unit tests on Tomcat 4.1 servlet engine
-->
    <target name="test.tomcat.41" depends="prepare.test.tomcat.41">

        <!-- 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="${cactus.contextURL}"
            startTarget="start.tomcat.41"
            stopTarget="stop.tomcat.41"
            testTarget="run.test"/>

    </target>

<!--
        Start Tomcat 4.1 servlet engine
-->
    <target name="start.tomcat.41">

        <java classname="org.apache.catalina.startup.Bootstrap" fork="yes">
            <jvmarg value="-Dcatalina.home=${tomcat.home.41}"/>
            <jvmarg value="-Dcatalina.base=${tomcat.home.41}"/>
            <arg value="-config"/>
            <arg value="${out.tomcat.41.dir}/conf/server.xml"/>
            <arg value="start"/>
            <classpath>
              <pathelement location="${java.home}/../lib/tools.jar"/>
              <fileset dir="${tomcat.home.41}">
                  <include name="bin/bootstrap.jar"/>
<!--                  <include name="server/catalina.jar"/> -->
              </fileset>
            </classpath>
        </java>

    </target>

<!--
        Stop Tomcat 4.1 servlet engine
-->
    <target name="stop.tomcat.41">

        <java classname="org.apache.catalina.startup.Bootstrap" fork="yes">
            <jvmarg value="-Dcatalina.home=${tomcat.home.41}"/>
            <jvmarg value="-Dcatalina.base=${tomcat.home.41}"/>
            <arg value="-config"/>
            <arg value="${out.tomcat.41.dir}/conf/server.xml"/>
            <arg value="stop"/>
            <classpath>
              <fileset dir="${tomcat.home.41}">
                  <include name="bin/bootstrap.jar"/>
<!--                  <include name="server/catalina.jar"/> -->
              </fileset>
            </classpath>
        </java>

    </target>


<!-- ================ Non-Cactus JUnit Based Tests ======================== -->


    <target name="test.junit" depends="compile.test"
     description="Run all non-Cactus based JUnit tests">

      <junit printsummary="yes" haltonfailure="no" haltonerror="no" fork="yes">

        <!-- JUnit Configuration Options -->
        <classpath refid="compile.classpath"/>
        <formatter  type="plain" usefile="false"/>

        <!-- Tests for org.apache.struts.action -->
        <!--
        <test       name="org.apache.struts.action.XXXX"/>
        -->

        <!-- Tests for org.apache.struts.util -->
        <batchtest fork="yes">
          <fileset dir="${out.test.dir}/classes">
            <include name="org/apache/struts/util/Test*.class"/>
          </fileset>
        </batchtest>

      </junit>

    </target>


</project>

