<?xml version="1.0"?>

<!-- Testcases for Velocity -->
<project name="main" default="test-all">

  <property name="build.dir" value="../bin"/>
  <property name="build.dest" value="${build.dir}/classes"/>
  <property name="ant.home" value="."/>
  <property name="test.home" value="../test"/>
  <property name="junit.jar" value="lib/junit-3.7.jar"/>

  <!-- JUnit Testbed properties -->
  <property name="velocity.test.runner" value="junit.textui.TestRunner"/>

  <!-- Turns on/off overall failure if one test fails -->
 <property name="testbed.failonerror" value="true"/>

  <!-- Build classpath -->
  <path id="classpath">
    <fileset dir="./lib">
      <include name="**/*.jar"/>
    </fileset>
    <pathelement location="${build.dest}"/>
  </path>

  <!-- =================================================================== -->
  <!-- JUnit Test Cases                                                    -->
  <!-- =================================================================== -->
  <target name="test-clean">
    <!--
         Hack to prevent Ant from complaining about missing directories.
         This is fixed in Ant >1.3, but we are using Ant 1.3 now.
    -->
    <mkdir dir="${test.home}/anakia/results"/>
    <mkdir dir="${test.home}/configuration/results"/>
    <mkdir dir="${test.home}/cpload/results"/>
    <mkdir dir="${test.home}/multi/results"/>
    <mkdir dir="${test.home}/multiloader/results"/>
    <mkdir dir="${test.home}/templates/results"/>
    <mkdir dir="${test.home}/texen/results"/>
    <!--
         Delete the results directories
    -->
    <delete dir="${test.home}/anakia/results" quiet="true"/>
    <delete dir="${test.home}/configuration/results" quiet="true"/>
    <delete dir="${test.home}/cpload/results" quiet="true"/>
    <delete dir="${test.home}/multi/results" quiet="true"/>
    <delete dir="${test.home}/multiloader/results" quiet="true"/>
    <delete dir="${test.home}/templates/results" quiet="true"/>
    <delete dir="${test.home}/texen/results" quiet="true"/>
  </target>

  <target name="test-all" depends="
                                   test-template,
                                   test-velocityapp,
                                   test-introspect,
                                   test-introspect2,
                                   test-classloaderchange,
                                   test-inlinevmscope,
                                   test-multi,
                                   test-cpload,
                                   test-contextsafety,
                                   test-configuration,
                                   test-commonsextprop,
                                   test-externallogger,
                                   test-methodinvocationexception,
                                   test-multiloader,
                                   test-encoding,
                                   test-eventhandling,
                                   test-velocimacro,
                                   test-anakia,
                                   test-texen,
                                   test-texen-classpath,
                                   test-misc,
                                   test-servlet,
                                   test-parser
                                   "/>

  <target name="test-template">
    <echo message="Running Template tests..."/>

    <java classname="${velocity.test.runner}" fork="yes"
          failonerror="${testbed.failonerror}">
      <arg value="org.apache.velocity.test.TemplateTestCase"/>
      <classpath refid="classpath"/>
    </java>
   </target>

 <target name="test-eventhandling">
    <echo message="Running Event Handler tests..."/>

    <java classname="${velocity.test.runner}" fork="yes" failonerror="${testbed.failonerror}">
      <arg value="org.apache.velocity.test.EventHandlingTestCase"/>
      <classpath>
        <path refid="classpath"/>
      </classpath>
    </java>
   </target>

  <target name="test-encoding">
    <echo message="Running Template encoding test..."/>

    <java classname="${velocity.test.runner}" fork="yes" failonerror="${testbed.failonerror}">
      <arg value="org.apache.velocity.test.EncodingTestCase"/>
      <classpath>
        <path refid="classpath"/>
      </classpath>
    </java>
   </target>

  <target name="test-velocityapp">
    <echo message="Running app.Velocity tests..."/>

    <java classname="${velocity.test.runner}" fork="yes" failonerror="${testbed.failonerror}">
      <arg value="org.apache.velocity.test.VelocityAppTestCase"/>
      <classpath>
        <path refid="classpath"/>
      </classpath>
    </java>
  </target>

  <target name="test-introspect">
    <echo message="Running Introspector tests..."/>

    <java classname="${velocity.test.runner}" fork="yes" failonerror="${testbed.failonerror}">
      <arg value="org.apache.velocity.test.IntrospectorTestCase"/>
      <classpath>
        <path refid="classpath"/>
      </classpath>
    </java>
  </target>

  <target name="test-introspect2">
    <echo message="Running Introspector2 tests..."/>

    <java classname="${velocity.test.runner}" fork="yes" failonerror="${testbed.failonerror}">
      <arg value="org.apache.velocity.test.IntrospectorTestCase2"/>
      <classpath>
        <path refid="classpath"/>
      </classpath>
    </java>
  </target>

  <target name="test-classloaderchange">
    <java classname="${velocity.test.runner}" fork="yes" failonerror="${testbed.failonerror}" >
      <arg value="org.apache.velocity.test.ClassloaderChangeTest"/>
      <classpath>
        <path refid="classpath"/>
      </classpath>
    </java>
  </target>

  <target name="test-inlinevmscope">
    <echo message="Running Inline VM Scope tests..."/>

    <java classname="${velocity.test.runner}" fork="yes" failonerror="${testbed.failonerror}" >
      <arg value="org.apache.velocity.test.InlineScopeVMTestCase"/>
      <classpath>
        <path refid="classpath"/>
      </classpath>
    </java>
  </target>

  <target name="test-multi">
    <echo message="Running Multiple File Resource Path tests..."/>

    <java classname="${velocity.test.runner}" fork="yes" failonerror="${testbed.failonerror}">
      <arg value="org.apache.velocity.test.MultipleFileResourcePathTest"/>
      <classpath>
        <path refid="classpath"/>
      </classpath>
    </java>
  </target>

  <target name="test-cpload">
    <echo message="Running Classpath Resource tests..."/>

    <java classname="${velocity.test.runner}" fork="yes" failonerror="${testbed.failonerror}">
      <arg value="org.apache.velocity.test.ClasspathResourceTest"/>
      <classpath>
        <path refid="classpath"/>
        <pathelement location="../test/cpload/test1.jar"/>
        <pathelement location="../test/cpload/test2.jar"/>
      </classpath>
    </java>
  </target>

  <target name="test-contextsafety">
    <echo message="Running Context Safety tests..."/>

    <java classname="${velocity.test.runner}" fork="yes" failonerror="${testbed.failonerror}">
      <arg value="org.apache.velocity.test.ContextSafetyTestCase"/>
      <classpath>
        <path refid="classpath"/>
      </classpath>
    </java>
  </target>

  <target name="test-anakia">
    <echo message="Running Anakia tests..."/>

    <taskdef name="anakia" classname="org.apache.velocity.anakia.AnakiaTask">
      <classpath>
        <path refid="classpath"/>
      </classpath>
    </taskdef>
    <anakia basedir="../test/anakia/xdocs" destdir="../test/anakia/results"
            extension=".html" style="./site.vsl"
            projectFile="./stylesheets/project.xml"
            excludes="**/stylesheets/**"
            includes="**/*.xml"
            templatePath="../test/anakia/xdocs/stylesheets"
            lastModifiedCheck="false">
    </anakia>

    <java classname="${velocity.test.runner}" fork="yes" failonerror="${testbed.failonerror}" >
      <arg value="org.apache.velocity.test.AnakiaTestCase"/>
      <classpath>
        <path refid="classpath"/>
      </classpath>
    </java>
  </target>

  <target name="test-configuration">
    <java classname="${velocity.test.runner}" fork="yes" failonerror="${testbed.failonerror}" >
      <arg value="org.apache.velocity.test.ConfigurationTestCase"/>
      <classpath>
        <path refid="classpath"/>
      </classpath>
    </java>
  </target>

 <target name="test-commonsextprop">
    <java classname="${velocity.test.runner}" fork="yes" failonerror="${testbed.failonerror}" >
      <arg value="org.apache.velocity.test.CommonsExtPropTestCase"/>
      <classpath>
        <path refid="classpath"/>
      </classpath>
    </java>
  </target>

  <target name="test-externallogger">
    <echo message="Running external logger tests..."/>

    <java classname="${velocity.test.runner}" fork="yes" failonerror="${testbed.failonerror}">
      <arg value="org.apache.velocity.test.ExternalLoggerTest"/>
      <classpath>
        <path refid="classpath"/>
      </classpath>
    </java>
   </target>


  <target name="test-methodinvocationexception">
    <echo message="Running MethodInvocationException tests..."/>

    <java classname="${velocity.test.runner}" fork="yes" failonerror="${testbed.failonerror}">
      <arg value="org.apache.velocity.test.MethodInvocationExceptionTest"/>
      <classpath>
        <path refid="classpath"/>
      </classpath>
    </java>
   </target>

   <target name="test-misc">
    <echo message="Running misc tests..."/>

    <java classname="${velocity.test.runner}" fork="yes" failonerror="${testbed.failonerror}">
      <arg value="org.apache.velocity.test.MiscTestCase"/>
      <classpath>
        <path refid="classpath"/>
      </classpath>
    </java>
  </target>

   <target name="test-parser">
    <echo message="Running special parser tests..."/>

    <java classname="${velocity.test.runner}" fork="yes" failonerror="${testbed.failonerror}">
      <arg value="org.apache.velocity.test.ParserTestCase"/>
      <classpath>
        <path refid="classpath"/>
      </classpath>
    </java>
  </target>

  <target name="test-servlet">
    <echo message="Running VelocityServlet tests..."/>

    <java classname="${velocity.test.runner}" fork="yes" failonerror="${testbed.failonerror}">
      <arg value="org.apache.velocity.test.VelocityServletTest"/>
      <classpath>
        <path refid="classpath"/>
      </classpath>
    </java>
   </target>

  <!-- ================================================================ -->
  <!-- T E X E N  T E S T                                               -->
  <!-- ================================================================ -->
  <!-- Generate turbine service code via Texen                          -->
  <!-- ================================================================ -->

  <target name="test-texen">

    <taskdef name="texen" classname="org.apache.velocity.texen.ant.TexenTask">
      <classpath>
        <path refid="classpath"/>
      </classpath>
    </taskdef>

    <texen
      contextProperties="../test/texen/service.props,../test/texen/additional.props"
      controlTemplate="Control.vm"
      outputDirectory="../test/texen/results"
      templatePath="../test/texen/templates"
      outputFile="report"
    />

    <java classname="${velocity.test.runner}" fork="yes" failonerror="${testbed.failonerror}">
      <arg value="org.apache.velocity.test.TexenTestCase"/>
      <classpath>
        <path refid="classpath"/>
      </classpath>
    </java>

  </target>

  <!-- ================================================================ -->
  <!-- T E X E N  C L A S S P A T H                                     -->
  <!-- ================================================================ -->
  <!-- Generate turbine service code via Texen with all the templates   -->
  <!-- and ancillary files in a JAR.                                    -->
  <!-- ================================================================ -->

  <target name="test-texen-classpath">

    <taskdef name="texen" classname="org.apache.velocity.texen.ant.TexenTask"
	reverseloader="true">
      <classpath>
        <pathelement location="../test/texen-classpath/test.jar"/>
        <path refid="classpath"/>
      </classpath>
    </taskdef>

    <texen
      useClassPath="true"
      contextProperties="service.props"
      controlTemplate="Control.vm"
      outputDirectory="../test/texen-classpath/results"
      outputFile="report"
    />

    <java classname="${velocity.test.runner}" fork="yes" failonerror="${testbed.failonerror}">
      <arg value="org.apache.velocity.test.TexenClasspathTestCase"/>
      <classpath>
        <path refid="classpath"/>
      </classpath>
    </java>

  </target>

  <target name="test-multiloader">
    <echo message="Running MultiLoader tests..."/>

    <java classname="${velocity.test.runner}" fork="yes" failonerror="${testbed.failonerror}">
      <arg value="org.apache.velocity.test.MultiLoaderTestCase"/>
      <classpath>
        <path refid="classpath"/>
        <pathelement location="../test/multiloader/test1.jar"/>
      </classpath>
    </java>
  </target>

 <target name="test-velocimacro">
    <echo message="Running Velocimacro tests..."/>
    <java classname="${velocity.test.runner}" fork="yes" failonerror="${testbed.failonerror}">
      <arg value="org.apache.velocity.test.VelocimacroTestCase"/>
      <classpath>
        <path refid="classpath"/>
      </classpath>
    </java>
  </target>

</project>

