<?xml version="1.0" encoding="ISO-8859-1"?>

<!--
 Licensed to the Apache Software Foundation (ASF) under one
 or more contributor license agreements.  See the NOTICE file
 distributed with this work for additional information
 regarding copyright ownership.  The ASF licenses this file
 to you under the Apache License, Version 2.0 (the
 "License"); you may not use this file except in compliance
 with the License.  You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing,
 software distributed under the License is distributed on an
 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.    
-->

<!-- Legacy Testcases for Velocity. See notes at the top
     of the main build file
-->

<project name="main" default="test-all" basedir="..">
  <property file="${user.home}/.ant.properties" />
  <property file="${user.home}/build.properties" />
  <property file=".ant.properties" />

  <!-- This file contains all the defaults for building Velocity -->
  <property file="build/build.properties" />

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

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

  <!-- =================================================================== -->
  <!-- JUnit Test Cases                                                    -->
  <!-- =================================================================== -->
  <target name="test-clean">
    <!-- Delete the results directories -->
    <delete dir="${build.test}/anakia" quiet="true"/>
    <delete dir="${build.test}/cpload" quiet="true"/>
    <delete dir="${build.test}/multiloader" quiet="true"/>
    <delete dir="${build.test}/texen" quiet="true"/>
  </target>

  <target name="test-all"
          depends="test-cpload,test-anakia,test-texen,
                   test-texen-classpath,test-multiloader"/>

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

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

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

    <taskdef name="anakia" classname="org.apache.velocity.anakia.AnakiaTask"
             classpathref="velocity.test.classpath"/>

    <anakia basedir="${test.dir}/anakia/xdocs" destdir="${build.test}/anakia"
            extension=".html" style="./site.vsl"
            projectFile="./stylesheets/project.xml"
            excludes="**/stylesheets/**"
            includes="**/*.xml"
            templatePath="${test.dir}/anakia/xdocs/stylesheets"
            velocityPropertiesFile="${test.dir}/anakia/velocity.properties"
            lastModifiedCheck="false">
    </anakia>

    <anakia basedir="${test.dir}/anakia/xdocs"
            destdir="${build.test}/anakia"
        extension=".context.html" style="./site_contexts.vsl"
        projectFile="./stylesheets/project.xml"
        excludes="**/stylesheets/**"
        includes="**/*.xml"
        templatePath="${test.dir}/anakia/xdocs/stylesheets"
        lastModifiedCheck="false">

        <context name="customContext" file="./stylesheets/customContext.xml"/>
    </anakia>

    <java classname="${test.runner}" fork="yes" dir="${velocity.dir}" failonerror="${test.haltonerror}"
          classpathref="velocity.test.classpath">
      <arg value="org.apache.velocity.test.AnakiaTestCase"/>
    </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"
             classpathref="velocity.test.classpath"/>

    <texen
      contextProperties="${test.dir}/texen/service.props,${test.dir}/texen/additional.props"
      controlTemplate="Control.vm"
      outputDirectory="${build.test}/texen"
      templatePath="${test.dir}/texen/templates"
      outputFile="report"
    />

    <java classname="${test.runner}" fork="yes" dir="${velocity.dir}" failonerror="${test.haltonerror}"
          classpathref="velocity.test.classpath">
      <arg value="org.apache.velocity.test.TexenTestCase"/>
    </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">
      <classpath>
        <pathelement location="${test.dir}/texen-classpath/test.jar"/>
        <path refid="velocity.test.classpath"/>
      </classpath>
    </taskdef>

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

    <java classname="${test.runner}" fork="yes" dir="${velocity.dir}" failonerror="${test.haltonerror}"
          classpathref="velocity.test.classpath">
      <arg value="org.apache.velocity.test.TexenClasspathTestCase"/>
    </java>

  </target>

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

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

  <!-- use this test to directly test all the templates for a quick test cycle -->
  <target name="test-templates">
    <echo message="Running Template tests..."/>

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

</project>
