<!--
Build include file for the GridSphere Portal source code, see build.xml

 - $Id: build-unittests.xml 4496 2006-02-08 20:27:04Z wehrens $

-->


<project name="unittests">


    <!-- =================================================================== -->
    <!-- Run the client JUnit test cases                                     -->
    <!-- =================================================================== -->
    <target name="tests">

        <delete dir="${gridsphere.build}/reports"/>
        <mkdir dir="${gridsphere.build}/reports"/>

        <junit printsummary="yes" haltonfailure="yes" haltonerror="yes" fork="yes">
            <sysproperty key="cactus.contextURL" value="http://localhost:8080/gridsphere"/>
            <classpath>
                <path refid="classpath"/>
                <pathelement location="${gridsphere.appserver}/webapps/gridsphere"/>
            </classpath>
            <test name="org.gridlab.gridsphere.GridSphereTest" todir="${gridsphere.build}/reports">
                <formatter type="xml"/>
            </test>
        </junit>

    </target>


    <!-- =================================================================== -->
    <!-- Creates HTML reports from the test results                          -->
    <!-- =================================================================== -->
    <target name="test-reports" description="Create test reports from Junit results">
        <echo message="Making GridSphere Junit Test Reports"/>
        <mkdir dir="${gridsphere.build}/reports/html"/>
        <junitreport todir="${gridsphere.build}/reports">
            <fileset dir="${gridsphere.build}/reports">
                <include name="TEST-*.xml"/>
            </fileset>
            <report format="noframes" todir="${gridsphere.build}/reports/html" styledir="${env.ANT_HOME}/etc"/>
        </junitreport>
    </target>

    <!-- =================================================================== -->
    <!-- Mail the HTML reports of  the test results                          -->
    <!-- =================================================================== -->
    <target name="mail">
        <mail
            mailhost="${mail.junit.mailhost}"
            from="${mail.junit.from}"
            tolist="${mail.junit.tolist}"
            subject="GridSphere JUnit Test Results">
            <message mimetype="text/html" src="${gridsphere.build}/reports/html/junit-noframes.html"/>
            <fileset dir="${gridsphere.build}/reports">
                <include name="TESTS-*.xml"/>
            </fileset>
        </mail>
    </target>

       <!-- =================================================================== -->
    <!-- Run Tomcat tests                                                    -->
    <!-- =================================================================== -->
    <target name="run-tests" depends="deploy-test">
        <antcall target="run-test"/>
    </target>

    <target name="run-test" if="catalina.exists" description="Run Junit tests in running Tomcat container">

        <!-- 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 stopped if the tests fail for any reason -->

        <runservertests
            testURL="http://127.0.0.1:8080/gridsphere/ServletRedirector?Cactus_Service=RUN_TEST"
            startTarget="start-tomcat"
            stopTarget="stop-tomcat"
            testTarget="tests"/>
    </target>

        <!-- =================================================================== -->
    <!-- Deploys GridSphere to Tomcat                                        -->
    <!-- =================================================================== -->
    <target name="deploy-test" depends="jar, gridsphere-test-jar" description="Deploys GridSphere test to a local server">

        <antcall target="deploy-install"/>

        <antcall target="configure-test-database"/>

        <antcall target="create-database"/>

        <copy todir="${env.CATALINA_HOME}/webapps/gridsphere">
            <fileset dir="${build.webapps}/gridsphere"/>
        </copy>

        <!-- <copy overwrite="true" file="lib/gridsphere-test.jar" todir="${env.CATALINA_HOME}/webapps/gridsphere/WEB-INF/lib"/> -->
        <copy overwrite="true" file="${build.lib}/gridsphere-test.jar" todir="${env.CATALINA_HOME}/webapps/gridsphere/WEB-INF/lib"/>

    </target>
</project>
