<?xml version="1.0"?>

<project name="interop-doclit" default="main" basedir=".">
    <description>
        Interop tests for doc-lit, code generated samples
    </description>
    <property name="dir.doclit" value="doclit-interop"/>
    <property name="dir.wsdl" value="./itest-resources/WSDLs"/>
    <property name="dir.temp" value="${dir.doclit}/temp"/>
    <property name="dir.clients" value="${dir.doclit}/clients"/>
    <property environment="env"/>
    <property name="dir.src" value="${dir.doclit}/src"/>
    <property name="dir.classes" value="${dir.doclit}/classes"/>
    <property name="dir.home" value="${user.home}"/>

    <!-- Allthe required jars here -->
    <path id="jarpath.axis2">
        <fileset dir="../../target/lib">
            <include name="*.jar"/>
        </fileset>
<!--        <fileset dir="${dir.home}/.maven/repository">-->
<!--            <include name="**/**/*.jar"/>-->
<!--        </fileset>-->
    </path>

    <!-- preparing paths -->

    <target name="prepare">

        <mkdir dir="${dir.classes}"/>
        <mkdir dir="${dir.src}"/>
        <mkdir dir="${dir.src}/test"/>
        <mkdir dir="${dir.temp}"/>
    </target>

    <!-- This is where the classes are located for run-1-->
    <path id="interop.path">
        <path refid="classpath.interop"/>
        <path refid="jarpath.axis2"/>
    </path>

    <!-- This is where the classes are located for run-2>-->


    <path id="classpath.interop">
        <pathelement path="${dir.classes}"/>
        <fileset dir="${dir.classes}">
            <include name="**/*.*"/>
        </fileset>
    </path>

    <path id="classpath.interop2">
        <!--        <pathelement path="${dir.classes}"/>-->
        <fileset dir="${dir.classes}">
            <include name="**/*.*"/>
        </fileset>
    </path>


    <target name="clean">
        <delete dir="${dir.classes}"/>
        <delete dir="${dir.classes}"/>
        <delete dir="${dir.classes}"/>
        <delete dir="${dir.src}"/>
        <delete dir="${dir.src}"/>
        <delete dir="${dir.src}"/>
    </target>

    <target name="temp-clean">
        <delete dir="${dir.src}/test"/>
        <delete dir="${dir.classes}/schema**/*"/>
        <delete dir="${dir.classes}/test"/>
    </target>

    <description>
    ////////////////////////////////// CodeGen with WSDL2Java /////////////////////////////////////////////////////////////////////////
    </description>

    <!-- generating the first file src files-->
    <target name="gen" depends="prepare">
        <java classname="org.apache.axis2.wsdl.WSDL2Java" fork="true">
            <classpath refid="jarpath.axis2"/>
            <arg value="-uri"/>
            <arg file="./${dir.temp}/current.wsdl"/>
            <arg value="-sd"/>
            <arg value="-o"/>
            <arg file="${dir.src}"/>
            <arg value="-p"/>
            <arg value="test.stub"/>
        </java>
        <move todir="${dir.classes}">
            <fileset dir="${dir.src}">
                <include name="**/schema**/**/*.class"/>
            </fileset>
            <fileset dir="${dir.src}/resources">
                <include name="**/schema**/**/*.xsb"/>
            </fileset>
        </move>
        <delete includeemptydirs="true">
           <!-- <fileset dir="${dir.src}/schema**/*" includes="**/*"/>
            <fileset dir="${dir.src}" includes="**/schema**/*.xsb"/> -->
          <fileset dir="${dir.src}">
                <include name="**/schema**/*.class"/>
                <include name="**/schema**/*.xsb"/>
            </fileset>
        </delete>
        <delete file="${dir.temp}/current.wsdl"/>
    </target>


    <description>
    /////////////////////////////////// Compiling the generated codes ////////////////////////////////////////////////////////////////////////
    </description>

    <!-- compiling the first source generated from gen-1 to be used in run-1-->
    <target name="compile" depends="gen">
        <javac srcdir="${dir.src}" destdir="${dir.classes}">
            <include name="**/*.*"/>
            <classpath refid="interop.path"/>
        </javac>
    </target>


    <description>
    ////////////////////////////////////// Compiling the testcases /////////////////////////////////////////////////////////////////////
    </description>

    <!-- compiling the test case1 to be used in run-1-->
    <target name="compile-client1">
        <javac srcdir="${dir.clients}" destdir="${dir.classes}">
            <include name="**/**/WMRound3Compound1InteropTest.java"/>
            <classpath refid="interop.path1"/>
        </javac>
    </target>


    <description>
    /////////////////////////////////// Running Tests ////////////////////////////////////////////////////////////////////////
    </description>

    <!-- runing first test case -->
    <target name="run-test" depends="compile">
        <junit fork="true" printsummary="false" haltonfailure="false"
            failureproperty="tests.failed" showoutput="true">
            <classpath>
                <pathelement path="${dir.classes}"/>
                <path>
                   <fileset dir="../../target/lib">
                     <include name="*.jar"/>
                    </fileset>
                </path>
            </classpath>
            <formatter type="brief" usefile="false"/>
            <batchtest>
                <fileset dir="${dir.src}">
                    <include name="**/**/*Test.java"/>
                </fileset>
            </batchtest>
        </junit>
        <fail if="tests.failed"/>
        <antcall target="temp-clean"/>
    </target>


    <target name="run" depends="run-test"/>

    <target name="main">
        <antcall target="clean"></antcall>
        <!-- Server Whitemesa -->
                <copy file="${dir.wsdl}/compound1.wsdl" tofile="${dir.temp}/current.wsdl"/>
                <copy file="${dir.clients}/test/WMRound3Compound1InteropTest.java" todir="${dir.src}/test"  />
                <antcall target="run"/>
                <copy file="${dir.wsdl}/compound2.wsdl" tofile="${dir.temp}/current.wsdl"/>
                <copy file="${dir.clients}/test/WMRound3Compound2InteropTest.java" todir="${dir.src}/test"  />
                <antcall target="run"/>
                <copy file="${dir.wsdl}/interoptestheaders.wsdl" tofile="${dir.temp}/current.wsdl"/>
                <copy file="${dir.clients}/test/Round3DoclitHeadersInteropTest.java" todir="${dir.src}/test"  />
                <antcall target="run"/>

        <!-- Server MS stk v3.0-->
                <copy file="${dir.wsdl}/stkv3Compound1.wsdl" tofile="${dir.temp}/current.wsdl"/>
                <copy file="${dir.clients}/test/MsStkv3Round3Compound1InteropTest.java" todir="${dir.src}/test"  />
                <antcall target="run"/>
                <copy file="${dir.wsdl}/stkv3Compound2.wsdl" tofile="${dir.temp}/current.wsdl"/>
                <copy file="${dir.clients}/test/MsStkv3Round3Compound2InteropTest.java" todir="${dir.src}/test"  />
                <antcall target="run"/>

        <!-- Test Failed, JIRA 238 -->
        <!--        <copy file="${dir.wsdl}/stkv3interopTestDocLit.wsdl" tofile="${dir.temp}/current.wsdl"/>-->
        <!--        <copy file="${dir.clients}/test/WMRound3DoclitInteropTest.java" todir="${dir.src}/test"  />-->
        <!--        <antcall target="run"/>-->

        <!-- Test Failed, JIRA 233 -->
        <!--        <copy file="${dir.wsdl}/stkv3interopTestDocLitParameters.wsdl" tofile="${dir.temp}/current.wsdl"/>-->
        <!--        <copy file="${dir.clients}/test/Round3DoclitparamInteropTest.java" todir="${dir.src}/test"  />-->
        <!--        <antcall target="run"/>-->

        <!-- Server ASP.NET -->
                <copy file="${dir.wsdl}/aspnetcompound1.wsdl" tofile="${dir.temp}/current.wsdl"/>
                <copy file="${dir.clients}/test/ASPNetRound3Compound1InteropTest.java" todir="${dir.src}/test"  />
                <antcall target="run"/>
                <copy file="${dir.wsdl}/aspnetcompound2.wsdl" tofile="${dir.temp}/current.wsdl"/>
                <copy file="${dir.clients}/test/AspNetRound3Compound2InteropTest.java" todir="${dir.src}/test"  />
                <antcall target="run"/>
                <copy file="${dir.wsdl}/aspnetInteropTestDocLit.wsdl" tofile="${dir.temp}/current.wsdl"/>
                <copy file="${dir.clients}/test/AspNetRound3DoclitInteropTest.java" todir="${dir.src}/test"  />
                <antcall target="run"/>
        <!-- this test failed, JIRA 233 -->
<!--                <copy file="${dir.wsdl}/aspnetInteropTestDocLitParameters.wsdl" tofile="${dir.temp}/current.wsdl"/>-->
<!--                <copy file="${dir.clients}/test/AspNetRound3DoclitparamInteropTest.java" todir="${dir.src}/test"  />-->
<!--                <antcall target="run"/>-->

        <!-- Sun Server -->
                <copy file="${dir.wsdl}/suncompound1.wsdl" tofile="${dir.temp}/current.wsdl"/>
                <copy file="${dir.clients}/test/SunRound3Compound1InteropTest.java" todir="${dir.src}/test"  />
                <antcall target="run"/>
                <copy file="${dir.wsdl}/suncompound2.wsdl" tofile="${dir.temp}/current.wsdl"/>
                <copy file="${dir.clients}/test/SunRound3Compound2InteropTest.java" todir="${dir.src}/test"  />
                <antcall target="run"/>
        <!-- Test failed, JIRA 238 -->
        <!--        <copy file="${dir.wsdl}/sundoclit.wsdl" tofile="${dir.temp}/current.wsdl"/>-->
        <!--        <copy file="${dir.clients}/test/WMRound3DoclitInteropTest.java" todir="${dir.src}/test"  />-->
        <!--        <antcall target="run"/>-->
        <!-- Test Failed, JIRA 233 -->
<!--        <copy file="${dir.wsdl}/sundoclitparams.wsdl" tofile="${dir.temp}/current.wsdl"/>-->
<!--        <copy file="${dir.clients}/test/SunRound3DoclitparamInteropTest.java" todir="${dir.src}/test"/>-->
<!--        <antcall target="run"/>-->


    </target>


</project>
