<!--
  JBoss, Home of Professional Open Source
  Copyright 2008, Red Hat Middleware LLC, and individual contributors
  as indicated by the @author tags.
  See the copyright.txt in the distribution for a
  full listing of individual contributors.
  This copyrighted material is made available to anyone wishing to use,
  modify, copy, or redistribute it subject to the terms and conditions
  of the GNU Lesser General Public License, v. 2.1.
  This program is distributed in the hope that it will be useful, but WITHOUT A
  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
  You should have received a copy of the GNU Lesser General Public License,
  v.2.1 along with this distribution; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  MA  02110-1301, USA.

  (C) 2008,
  @author JBoss Inc.
-->

<!--
  Ant build script for running DTF tests locally using the new lightweight test runner (JIRA DTF-4).
  Does not need tomcat, mysql or any DTF server processes running.

  For JBossTS JTS builds.

  1) Run the top level JBossTS ant build:  ant jts
  2) Run the qa build:  cd qa; ant
  2) Run the tests:  ant -f run-dtf-local.xml

  For general tests plus JDBC (e.g. use on hudson):
    cd qa
    ant get.drivers dist
    ant -f run-dtf-local.xml junit junit-jdbc

  Paths are relative to the JVM's working dir - don't expect to be able to execute this from anywhere but 'qa'.

-->
<project name="Local DTF Test for JBossTS" default="junit" basedir=".">

    <property name="working.dir" location="build"/>

	<path id="tests.classpath">
        <pathelement location="${working.dir}/qa/lib/TestingFramework.jar"/>
        <pathelement location="${working.dir}/lib/ext/junit.jar"/>
        <pathelement location="ext/jdom.jar"/>
    </path>

    <!-- a faster subset of the tests for smoke testing. aim to keep to under one hour total. -->
    <target name="express">

        <!-- currenttests01 : 36 tests, 3 minutes -->
        <antcall target="junit-tests"><param name="tests" value="currenttests01"/></antcall>
        <!-- jtatests01 : 6 tests, 1 minute -->
        <antcall target="junit-tests"><param name="tests" value="jtatests01"/></antcall>
        <!-- otsserver : 20 tests, 7 minutes -->
        <antcall target="junit-tests"><param name="tests" value="otsserver"/></antcall>

        <!-- rawresources01_1 : 6 tests, 1 minute -->
        <antcall target="junit-tests"><param name="tests" value="rawresources01_1"/></antcall>
        <!-- rawresources02_1 : 6 tests, 1 minute -->
        <antcall target="junit-tests"><param name="tests" value="rawresources02_1"/></antcall>
        <!-- rawsubtransactionawareresources01_1 : 6 tests, 1 minute -->
        <antcall target="junit-tests"><param name="tests" value="rawsubtransactionawareresources01_1"/></antcall>
        <!-- rawsubtransactionawareresources02_1 : 6 tests, 1 minute -->
        <antcall target="junit-tests"><param name="tests" value="rawsubtransactionawareresources02_1"/></antcall>

        <!-- crashrecovery01 : 24 tests, 6 minutes -->
        <antcall target="junit-tests"><param name="tests" value="crashrecovery01"/></antcall>
        <!-- crashrecovery02_1 : 5 tests, 6 minutes -->
        <antcall target="junit-tests"><param name="tests" value="crashrecovery02_1"/></antcall>
        <!-- crashrecovery03 : 1 tests, 1 minute -->
        <antcall target="junit-tests"><param name="tests" value="crashrecovery03"/></antcall>
        <!-- crashrecovery06 : 2 tests, 1 minute -->
        <antcall target="junit-tests"><param name="tests" value="crashrecovery06"/></antcall>
        <!-- crashrecovery12 : 7 tests, 5 minutes -->
        <antcall target="junit-tests"><param name="tests" value="crashrecovery12"/></antcall>

    </target>

    <!-- General tests.
        Some groups take a really long time and are disabled by default.
        The remaining tests should take a combined time of around 4hrs or so.
    -->
    <target name="junit">

        <!-- currenttests01 : 36 tests, 3 minutes -->
        <antcall target="junit-tests"><param name="tests" value="currenttests01"/></antcall>
        <!-- jtatests01 : 6 tests, 1 minute -->
        <antcall target="junit-tests"><param name="tests" value="jtatests01"/></antcall>
        <!-- otsserver : 20 tests, 7 minutes -->
        <antcall target="junit-tests"><param name="tests" value="otsserver"/></antcall>

        <!-- rawresources01_1 : 6 tests, 1 minute -->
        <antcall target="junit-tests"><param name="tests" value="rawresources01_1"/></antcall>
        <!-- rawresources01_2 : 294 tests, 30 minutes -->
        <antcall target="junit-tests"><param name="tests" value="rawresources01_2"/></antcall>
        <!-- rawresources01_3 : 150 tests, 15 minutes -->
        <antcall target="junit-tests"><param name="tests" value="rawresources01_3"/></antcall>
        <!-- rawresources02_1 : 6 tests, 1 minute -->
        <antcall target="junit-tests"><param name="tests" value="rawresources02_1"/></antcall>
        <!-- rawresources02_2 : 294 tests, 30 minutes -->
        <antcall target="junit-tests"><param name="tests" value="rawresources02_2"/></antcall>
        <!-- rawresources02_3 : 150 tests, 15 minutes -->
        <antcall target="junit-tests"><param name="tests" value="rawresources02_3"/></antcall>

        <!-- rawsubtransactionawareresources01_1 : 6 tests, 1 minute -->
        <antcall target="junit-tests"><param name="tests" value="rawsubtransactionawareresources01_1"/></antcall>
        <!-- rawsubtransactionawareresources01_2 : 10 tests, 1 minute -->
        <antcall target="junit-tests"><param name="tests" value="rawsubtransactionawareresources01_2"/></antcall>
        <!-- rawsubtransactionawareresources01_3 : 25 tests, 3 minutes -->
        <antcall target="junit-tests"><param name="tests" value="rawsubtransactionawareresources01_3"/></antcall>
        <!-- rawsubtransactionawareresources02_1 : 6 tests, 1 minute -->
        <antcall target="junit-tests"><param name="tests" value="rawsubtransactionawareresources02_1"/></antcall>
        <!-- rawsubtransactionawareresources02_2 : 10 tests, 1 minute -->
        <antcall target="junit-tests"><param name="tests" value="rawsubtransactionawareresources02_2"/></antcall>
        <!-- rawsubtransactionawareresources02_3 : 25 tests, 3 minutes -->
        <antcall target="junit-tests"><param name="tests" value="rawsubtransactionawareresources02_3"/></antcall>

        <!-- crashrecovery01 : 24 tests, 6 minutes -->
        <antcall target="junit-tests"><param name="tests" value="crashrecovery01"/></antcall>
        <!-- crashrecovery02_1 : 5 tests, 6 minutes -->
        <antcall target="junit-tests"><param name="tests" value="crashrecovery02_1"/></antcall>
        <!-- crashrecovery02_2 : 50 tests, 60 minutes -->
        <!-- <antcall target="junit-tests"><param name="tests" value="crashrecovery02_2"/></antcall> -->
        <!-- crashrecovery03 : 1 tests, 1 minute -->
        <antcall target="junit-tests"><param name="tests" value="crashrecovery03"/></antcall>
        <!-- crashrecovery04 : 48 tests, 11 minutes -->
        <antcall target="junit-tests"><param name="tests" value="crashrecovery04"/></antcall>
        <!-- crashrecovery05_1 : 10 tests, 12 minutes -->
        <antcall target="junit-tests"><param name="tests" value="crashrecovery05_1"/></antcall>
        <!-- crashrecovery05_2 : 100 tests, 122 minutes -->
        <!-- <antcall target="junit-tests"><param name="tests" value="crashrecovery05_2"/></antcall> -->
        <!-- crashrecovery06 : 2 tests, 1 minute -->
        <antcall target="junit-tests"><param name="tests" value="crashrecovery06"/></antcall>
        <!-- crashrecovery07 : 16 tests, 87 minutes -->
        <antcall target="junit-tests"><param name="tests" value="crashrecovery07"/></antcall>
        <!-- crashrecovery08 : 32 tests, 228 minutes -->
        <!-- <antcall target="junit-tests"><param name="tests" value="crashrecovery08"/></antcall> -->
        <!-- crashrecovery12 : 7 tests, 5 minutes -->
        <antcall target="junit-tests"><param name="tests" value="crashrecovery12"/></antcall>

    </target>

    <!-- long running crash rec test groups (the ones disabled in the 'junit' target) -->
    <target name="junit-longer">
        <antcall target="junit-tests"><param name="tests" value="crashrecovery02_2"/></antcall>
        <antcall target="junit-tests"><param name="tests" value="crashrecovery05_2"/></antcall>
        <antcall target="junit-tests"><param name="tests" value="crashrecovery08"/></antcall>
    </target>

    <!-- copy the selected db driver out of the available set into the classpath.
        Drivers are placed into the pool by build.xml and into the classpath by config/<product>.xml
     -->
    <target name="install-dbdriver">
        <delete dir="build/qa/lib/selected_dbdriver"/>
        <mkdir dir="build/qa/lib/selected_dbdriver"/>
        <copy todir="build/qa/lib/selected_dbdriver">
            <fileset dir="build/qa/lib/all_dbdrivers/" includes="${files}"/>
        </copy>
    </target>

    <!--  JDBC tests.
        You'll need a qa/config/jdbc_profiles/<hostname>/JDBCProfiles file for your machine to run these ones,
          although using the 'default' one is also an option.
        Plus copies of the db drivers of course (try 'ant get.drivers' if inside the redhat network).
        And a set of servers to run against. Did I mention it was complicated :-)
    -->
    <target  name="junit-jdbc">

        <antcall target="install-dbdriver"><param name="files" value="ojdbc14.jar"/></antcall>
        <antcall target="junit-tests"><param name="tests" value="jdbcresources01-oracle_thin_jndi"/></antcall>
        <antcall target="junit-tests"><param name="tests" value="jdbcresources02-oracle_thin_jndi"/></antcall>

        <!-- mssql needs different .jar for jdk 1.5 vs. 1.6 runtime -->
        <condition property="mssql.driver" value="sqljdbc4.jar">
            <equals arg1="${java.specification.version}" arg2="1.6"/>
        </condition>
        <property name="mssql.driver" value="sqljdbc.jar"/>
        <antcall target="install-dbdriver"><param name="files" value="${mssql.driver}"/></antcall>
        <antcall target="junit-tests"><param name="tests" value="jdbcresources01_mssqlserver_jndi"/></antcall>
        <antcall target="junit-tests"><param name="tests" value="jdbcresources02_mssqlserver_jndi"/></antcall>

        <antcall target="install-dbdriver"><param name="files" value="db2*"/></antcall>
        <antcall target="junit-tests"><param name="tests" value="jdbcresources01-ibmdb2_jndi"/></antcall>
        <antcall target="junit-tests"><param name="tests" value="jdbcresources02-ibmdb2_jndi"/></antcall>

        <antcall target="install-dbdriver"><param name="files" value="postgresql-8.3-603.jdbc3.jar"/></antcall>
        <antcall target="junit-tests"><param name="tests" value="jdbcresources01-pgsql_jndi"/></antcall>
        <antcall target="junit-tests"><param name="tests" value="jdbcresources02-pgsql_jndi"/></antcall>

        <antcall target="install-dbdriver"><param name="files" value="mysql-connector-java-5.1.7-bin.jar"/></antcall>
        <antcall target="junit-tests"><param name="tests" value="jdbcresources01-mysql_jndi"/></antcall>
        <antcall target="junit-tests"><param name="tests" value="jdbcresources02-mysql_jndi"/></antcall>

        <antcall target="install-dbdriver"><param name="files" value="jconn3.jar"/></antcall>
        <antcall target="junit-tests"><param name="tests" value="jdbcresources01-sybase_jndi"/></antcall>
        <antcall target="junit-tests"><param name="tests" value="jdbcresources02-sybase_jndi"/></antcall>

    </target>

    <target name="junit-tests">

        <echo message="Running test group ${tests} from basedir=${basedir}"/>


        <!-- this runs forked because the product config file it uses has relative paths in it, so we need to guarantee
            the working dir is the same as the location of this script.
		TODO: investigate why it needs such a large memory footprint. I suspect it's buffering
		the entire stdout, which is big for longer runs as DTF tends to be rather verbose.
		But with 10MB of stdout based on text file size, junit needs >128MB of memory???
		Stopping the buffering would be nice anyhow, as it stands we don't see any output in the file
		until the tests are all done, which makes following progress a bit of a problem. -->
        <junit printsummary="yes" haltonfailure="yes" fork="true" dir="${basedir}" maxmemory="192m">
            <classpath>
                <path refid="tests.classpath"/>
            </classpath>

            <formatter type="plain"/>

            <sysproperty key="testdefsFile" value="${basedir}/testdefs/jbossts-qa-${tests}-testdefs.xml"/>
            <sysproperty key="productConfigFile" value="${basedir}/config/JBossTS_JTS_JacORB_QA.xml"/>
            <sysproperty key="testnodeConfigFile" value="${basedir}/config/nodeconfig.xml"/>
            <sysproperty key="testnamePattern" value=".*"/>

            <test name="org.jboss.dtf.testframework.local.JUnitTestSuite" outfile="jbossts-qa-${tests}-output"/>

        </junit>

        <echo message="Done test group ${tests}"/>
    </target>


<!--
    unused examples of other approaches to running tests:

    <target name="run2">
        <java classname="org.jboss.dtf.testframework.local.JUnitTestSuite" fork="true">
            <classpath>
                <path refid="tests.classpath"/>
            </classpath>

            <arg value="./testdefs/jbossts-qa-crashrecovery12-testdefs.xml"/>
            <arg value="config/JBossTS_JTS_JacORB_QA.xml"/>
            <arg value="config/nodeconfig.xml"/>
            <arg value=".*"/>

            <jvmarg value="-Xdebug"/>
            <jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"/>

        </java>
    </target>

    <target name="run">
        <antcall target="run-tests"><param name="testdefs.filename" value="jbossts-qa-txcore-testdefs.xml"/></antcall>
    </target>

    <target name="run-tests">
        <java classname="org.jboss.dtf.testframework.local.LocalTestManager" fork="true">
            <classpath>
                <path refid="tests.classpath"/>
                <pathelement location="/usr/local/javastuff/jdom-1.1/lib/xerces.jar"/>
            </classpath>
            <arg value="file:///home/jhalli/IdeaProjects/jboss/jbossts_trunk/qa/testdefs/${testdefs.filename}"/>
            <arg value="/home/jhalli/IdeaProjects/jboss/jbossts_trunk/qa/config/JBossTS_JTS_JacORB_QA.xml"/>
            <arg value="file:///home/jhalli/IdeaProjects/jboss/jbossts_trunk/qa/config/nodeconfig.xml"/>

            <jvmarg value="-Xdebug"/>
            <jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"/>

        </java>
    </target>
-->
</project>
