<?xml version="1.0"?>

<!--
   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.
-->

<!--
Before you can run these subtargets directly, you need
to call at top-level: ant deploy-contrib compile-core-test
-->
<project name="vertica" default="jar">

  <import file="../build-contrib.xml"/>
  <property environment="env"/>

  <!-- ================================================================== -->
  <!-- Run unit tests                                                     -->
  <!-- Override with our own version so we can set hadoop.alt.classpath   -->
  <!-- and Hadoop logger properties                                       -->
  <!-- ================================================================== -->
  <target name="test" depends="compile-test, compile" if="test.available">
    <echo message="contrib: ${name}"/>
    <delete dir="${hadoop.log.dir}"/>
    <mkdir dir="${hadoop.log.dir}"/>
    <delete dir="${build.test}/data"/>
    <mkdir dir="${build.test}/data" />
    <junit
      printsummary="yes" showoutput="${test.output}"
      haltonfailure="no" fork="yes" maxmemory="256m"
      errorProperty="tests.failed" failureProperty="tests.failed"
      timeout="${test.timeout}"
      dir="${build.test}/data">

      <!-- uncomment this if you want to attach a debugger -->
      <!--
      <jvmarg line="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=2601" />
      -->

      <sysproperty key="test.build.data" value="${build.test}/data"/>
      <sysproperty key="build.test" value="${build.test}"/>
      <sysproperty key="contrib.name" value="${name}"/>

      <!--
           Added property needed to use the .class files for compilation
           instead of depending on hadoop-*-core.jar
      -->
      <sysproperty key="hadoop.alt.classpath"
        value="${hadoop.root}/build/classes" />

      <!-- we want more log4j output when running unit tests -->
      <sysproperty key="hadoop.root.logger"
        value="DEBUG,console" />

      <!-- requires fork=yes for:
        relative File paths to use the specified user.dir
        classpath to use build/contrib/*.jar
      -->
      <sysproperty key="user.dir" value="${build.test}/data"/>

      <sysproperty key="fs.default.name" value="${fs.default.name}"/>
      <sysproperty key="hadoop.test.localoutputfile" value="${hadoop.test.localoutputfile}"/>
      <sysproperty key="hadoop.log.dir" value="${hadoop.log.dir}"/>

      <!-- Path to SQL setup script. -->
      <sysproperty key="vertica.test_setup" value="${basedir}/testdata/vertica_test.sql" />

      <!-- Vertica database parameters -->
      <sysproperty key="vertica.hostname" value="localhost" />
      <sysproperty key="vertica.database" value="db" />
      <sysproperty key="vertica.username" value="dbadmin" />
      <sysproperty key="vertica.password" value="" />
	
      <!-- tools.jar from Sun JDK also required to invoke javac. -->
      <classpath>
        <path refid="test.classpath"/>
        <path refid="contrib-classpath"/>
        <pathelement path="${env.JAVA_HOME}/lib/tools.jar" />
      </classpath>
      <formatter type="${test.junit.output.format}" />
      <batchtest todir="${build.test}" unless="testcase">
        <fileset dir="${src.test}"
                 includes="**/Test*.java" excludes="**/${test.exclude}.java" />
      </batchtest>
      <batchtest todir="${build.test}" if="testcase">
        <fileset dir="${src.test}" includes="**/${testcase}.java"/>
      </batchtest>
    </junit>
    <fail if="tests.failed">Tests failed!</fail>
  </target>

</project>
