<?xml version="1.0"?>

<!-- ===================================================================

   Build file for Axis functional test Ant task

Notes:
   This is a build file for use with the Jakarta Ant build tool.
   This build file builds an Ant task used to perform Axis functional tests.

Prerequisites:

   a successful Axis build configuration

Author:
  Rob Jellinghaus <robj@unrealities.com>

Copyright:
  Copyright (c) 2001 Apache Software Foundation.

==================================================================== -->

<project default="functional-tests" basedir=".">
  <property name="test.functional.usefile" value="true"/>
  <property name="test.functional.reportdir" value="test-reports"/>
  <!--The following is the port the service is listening on. -->
  <!--FYI to run tcpmon change this to another port and have tcpmon listen on 8080 -->
  <property name="test.functional.SimpleAxisPort" value="8080"/>
  <!--The IP port the service will be targeted at.-->
  <property name="test.functional.ServicePort" value="8080"/>
  <property name="test.functional.fail" value="yes"/>
  <property name="test.functional.testcase" value="**/FunctionalTests"/>

  <path id="test-classpath">
    <pathelement location="${xerces.jar}"/>
    <pathelement location="${junit.jar}"/>
    <pathelement location="${j2ee.jar}"/>
    <pathelement location="${jsse.jar}"/>
    <pathelement location="${tools.jar}"/>
    <fileset dir="${lib.dir}">
        <include name="*.jar"/>
    </fileset>
    <fileset dir="lib">
     <include name="*.jar"/>
    </fileset>
    <pathelement path="${java.class.path}" />
    <pathelement location="${build.dest}" />
  </path>

  <taskdef name="runaxisfunctionaltests"
           classname="test.functional.ant.RunAxisFunctionalTestsTask">
      <classpath refid="test-classpath" />
  </taskdef>

  <!-- =================================================================== -->
  <!-- Launches the functional test TCP server -->
  <!-- =================================================================== -->
  <target name="start-functional-test-tcp-server" if="junit.present">
    <echo message="Starting test tcp server."/>
    <java classname="samples.transport.tcp.TCPListener" fork="yes" dir="./build">
      <arg line="-p 8088" /> <!-- arbitrary port -->
      <classpath refid="test-classpath" />
    </java>
  </target>

  <!-- =================================================================== -->
  <!-- Launches the functional test HTTP server -->
  <!-- =================================================================== -->
  <target name="start-functional-test-http-server" if="junit.present">
    <echo message="Starting test http server."/>
    <java classname="org.apache.axis.transport.http.SimpleAxisServer" fork="yes" dir="./build">
        <!-- Uncomment this to use Jikes instead of Javac for compiling JWS Files
        <jvmarg value="-Daxis.Compiler=org.apache.axis.components.compiler.Jikes"/>
        -->
        <jvmarg value="-Daxis.wsdlgen.intfnamespace=http://localhost:${test.functional.ServicePort}"/>
        <jvmarg value="-Daxis.wsdlgen.serv.loc.url=http://localhost:${test.functional.ServicePort}"/>
        <arg line="-p ${test.functional.SimpleAxisPort}" />  <!-- arbitrary port -->
      <classpath refid="test-classpath" />
    </java>
  </target>

  <!-- =================================================================== -->
  <!-- Prepares the JUnit functional test -->
  <!-- =================================================================== -->
  <target name="junit-functional-prepare" if="junit.present">

    <!-- first, put the JWS where the functional test can see it -->
    <mkdir dir="build/jws" />
    <copy file="samples/stock/StockQuoteService.jws" todir="build/jws" />
    <copy file="test/functional/AltStockQuoteService.jws" todir="build/jws" />
    <copy file="test/functional/GlobalTypeTest.jws" todir="build/jws"/>

    <!--...not to mention the sample user list -->
    <copy file="samples/stock/users.lst" todir="build"/>
  </target>

  <!-- =================================================================== -->
  <!-- Runs the JUnit functional test  -->
  <!-- =================================================================== -->
  <target name="junit-functional" if="junit.present" depends="junit-functional-prepare">
    <mkdir dir="${test.functional.reportdir}" />
    <java classname="org.apache.axis.client.AdminClient" fork="yes">
      <classpath refid="test-classpath" />
      <arg line="${deploy.xml.property}"/>
    </java>

    <!-- now, run the actual test -->
    <junit dir="." printsummary="yes" haltonfailure="${test.functional.fail}" fork="yes">
      <!-- Pass through the proxy parameters -->
      <jvmarg value="-Dhttp.proxyHost=${http.proxyHost}"/>
      <jvmarg value="-Dhttp.proxyPort=${http.proxyPort}"/>
      <jvmarg value="-Dhttp.nonProxyHosts=${http.nonProxyHosts}"/>
      <jvmarg value="-Dhttp.proxyUser=${http.proxyUser}"/>
      <jvmarg value="-Dhttp.proxyPassword=${http.proxyPassword}"/>
      <!-- Pass the port for SimpleAxisServer -->
      <jvmarg value="-Dtest.functional.SimpleAxisPort=${test.functional.SimpleAxisPort}"/>
      <jvmarg value="-Dtest.functional.ServicePort=${test.functional.ServicePort}"/>
      <classpath refid="test-classpath" />
      <formatter type="xml" usefile="${test.functional.usefile}"/>
      <batchtest todir="${test.functional.reportdir}">
        <fileset dir="${build.dest}">
          <!-- Convention: each package that's being tested
                has its own test class collecting all the tests -->
              <include name="**/FunctionalTests.class" />
              <include name="**/*TestCase.class" />
              <exclude name="**/Interop3TestCase.class"/>
              <exclude name="**/test/wsdl/attachments/**/*.class" unless="attachments.present" />
        </fileset>
      </batchtest>
    </junit>

    <java classname="org.apache.axis.client.AdminClient" fork="yes">
      <classpath refid="test-classpath" />
      <arg line="${undeploy.xml.property}"/>
    </java>
  </target>

  <target name="junit-functional-secure" if="junit.present" depends="junit-functional-prepare,start-signature-signing-and-verification">
    <!-- now, run the actual test -->
    <junit dir="." printsummary="yes" haltonfailure="${test.functional.fail}" fork="yes">
      <classpath refid="test-classpath" />
      <formatter type="xml" usefile="${test.functional.usefile}"/>
      <batchtest todir="${test.functional.reportdir}">
        <fileset dir="${build.dest}">
          <!-- Convention: each package that's being tested
                has its own test class collecting all the tests -->
              <include name="**/TestBidBuySample.class" />
              <exclude name="**/Interop3TestCase.class"/>
        </fileset>
      </batchtest>
    </junit>
  </target>

  <!-- =================================================================== -->
  <!-- Start Signature Signing and Verification -->
  <!-- =================================================================== -->
  <target name="start-signature-signing-and-verification" if="security.present">
    <!-- Enable transparent Signing of SOAP Messages sent
        from the client and Server-side Signature Verification.
    -->
    <java classname="org.apache.axis.client.AdminClient" fork="yes">
      <classpath refid="test-classpath" />
      <arg line="samples/security/serversecuritydeploy.wsdd"/>
    </java>
    <java classname="org.apache.axis.utils.Admin" fork="yes">
      <classpath refid="test-classpath" />
      <arg value="client"/>
      <arg value="samples/security/clientsecuritydeploy.wsdd"/>
    </java>
  </target>

  <!-- =================================================================== -->
  <!-- Stop Signature Signing and Verification -->
  <!-- =================================================================== -->
  <target name="stop-signature-signing-and-verification" if="security.present">
    <!-- Disable transparent Signing of SOAP Messages sent
        from the client and Server-side Signature Verification.
    -->
    <java classname="org.apache.axis.client.AdminClient" fork="yes">
      <classpath refid="test-classpath" />
      <arg line="samples/security/serversecurityundeploy.wsdd"/>
    </java>
    <java classname="org.apache.axis.utils.Admin" fork="yes">
      <classpath refid="test-classpath" />
      <arg value="client"/>
      <arg value="samples/security/clientsecurityundeploy.wsdd"/>
    </java>
  </target>

  <!-- =================================================================== -->
  <!-- Stops the functional test HTTP server -->
  <!-- =================================================================== -->
  <target name="stop-functional-test-http-server" if="junit.present" >
    <echo message="Stopping test http server."/>
    <java classname="org.apache.axis.client.AdminClient" fork="yes">
      <classpath refid="test-classpath" />
      <arg line="quit"/>
    </java>
  </target>

  <!-- =================================================================== -->
  <!-- Stops the functional test HTTP server when testing digital signature -->
  <!-- =================================================================== -->
  <target name="stop-functional-test-http-server-secure" if="junit.present" depends="stop-signature-signing-and-verification">
    <echo message="Stopping test http server."/>
    <java classname="org.apache.axis.client.AdminClient" fork="yes">
      <classpath refid="test-classpath" />
      <arg line="quit"/>
    </java>
  </target>

  <!-- =================================================================== -->
  <!-- Generate code using Wsdl2java utility                               -->
  <!-- =================================================================== -->
  <target name="wsdl-setup" if="junit.present" >
    <copy file="${axis.home}/samples/stock/GetQuote.wsdl" todir="."/>
    <copy todir="${build.dir}/classes" overwrite="yes">
      <fileset dir="${test.dir}/wsdl/_import">
        <include name="NStoPkg.properties"/>
      </fileset>
    </copy>
    <copy todir="${build.dir}/work/samples" overwrite="yes">
      <fileset dir="${samples.dir}">
        <include name="**/userguide/example6/"/>
      </fileset>
    </copy>
    <ant inheritAll="${ant.inheritAll}" inheritRefs="${ant.inheritRefs}" dir="${axis.home}/test/wsdl" antfile="Wsdl2javaTestSuite.xml">
    </ant>
    <copy todir="${build.dir}/work/test" overwrite="yes">
      <fileset dir="${test.dir}">
        <include name="**/*Impl.java"/>
      </fileset>
      <fileset dir="${test.dir}">
        <include name="**/*TestCase.java"/>
        <exclude name="**/EmptySATestCase.java"/>
	<exclude name="**/SalesRankNPrice_ServiceTestCase.java"/>
      </fileset>
      <fileset dir="${test.dir}">
        <include name="**/Main.java"/>
      </fileset>
    </copy>
    <copy todir="${build.dir}/work/test/wsdl" overwrite="yes">
      <fileset dir="${test.dir}/wsdl">
        <include name="**/*Impl.java"/>
      </fileset>
      <fileset dir="${test.dir}/wsdl">
        <include name="**/*TestCase.java"/>
        <exclude name="**/EmptySATestCase.java"/>
	<exclude name="**/SalesRankNPrice_ServiceTestCase.java"/>
      </fileset>
      <fileset dir="${test.dir}/wsdl">
        <include name="**/Main.java"/>
      </fileset>
      <fileset dir="${test.dir}/wsdl">
        <include name="sequence/SequenceInfo.java"/>
      </fileset>
    </copy>

    <copy todir="${build.dir}/work/samples" overwrite="yes">
      <fileset dir="${samples.dir}">
        <include name="**/*BindingImpl.java"/>
      </fileset>
      <fileset dir="${samples.dir}">
        <include name="**/*TestCase.java"/>
      </fileset>
      <fileset dir="${samples.dir}">
        <include name="**/Main.java"/>
      </fileset>
    </copy>
    <path id="deploy.xml.files">
        <fileset dir="${build.dir}/work">
          <include name="**/deploy.wsdd"/>
        </fileset>
    </path>
    <path id="undeploy.xml.files">
        <fileset dir="${build.dir}/work">
          <include name="**/undeploy.wsdd"/>
        </fileset>
    </path>
    <property name="deploy.xml.property" refid="deploy.xml.files"/>
    <property name="undeploy.xml.property" refid="undeploy.xml.files"/>
    <javac srcdir="${build.dir}/work" destdir="${build.dest}"
           debug="${debug}">
      <classpath refid="test-classpath" />
      <include name="**/*.java" />
      <exclude name="test/wsdl/interop3/**/*.java" />
      <exclude name="test/wsdl/attachments/**/*.java" unless="attachments.present" />
    </javac>
  </target>

  <!-- =================================================================== -->
  <!-- Run functional tests                                                -->
  <!-- =================================================================== -->
  <target name="functional-tests" if="junit.present" depends="wsdl-setup">

    <!-- This uses a custom Ant task.  See test/functional/ant/RunAxisFunctionalTests.java -->
    <!-- This pattern taken from Cactus, http://jakarta.apache.org/commons/cactus -->
    <runaxisfunctionaltests
      url="http://localhost:8088"
      startTarget1="start-functional-test-tcp-server"
      startTarget2="start-functional-test-http-server"
      testTarget="junit-functional"
      stopTarget="stop-functional-test-http-server" />

    <!-- now run security test -->
    <runaxisfunctionaltests
      url="http://localhost:8088"
      startTarget1="start-functional-test-tcp-server"
      startTarget2="start-functional-test-http-server"
      testTarget="junit-functional-secure"
      stopTarget="stop-functional-test-http-server-secure" />

    <delete file="GetQuote.wsdl"/>
  </target>

  <!-- =================================================================== -->
  <!-- Run functional tests ONLY                                           -->
  <!-- =================================================================== -->
  <target name="functional-tests-only" if="junit.present">

    <!-- This uses a custom Ant task.  See test/functional/ant/RunAxisFunctionalTests.java -->
    <!-- This pattern taken from Cactus, http://jakarta.apache.org/commons/cactus -->
    <runaxisfunctionaltests
      url="http://localhost:8088"
      startTarget1="start-functional-test-tcp-server"
      startTarget2="start-functional-test-http-server"
      testTarget="junit-functional-tests-only"
      stopTarget="stop-functional-test-http-server" />
  </target>

  <!-- =================================================================== -->
  <!-- Run secure functional tests ONLY                                    -->
  <!-- =================================================================== -->
  <target name="functional-tests-secure-only" if="junit.present">

    <runaxisfunctionaltests
      url="http://localhost:8088"
      startTarget1="start-functional-test-tcp-server"
      startTarget2="start-functional-test-http-server"
      testTarget="junit-functional-secure"
      stopTarget="stop-functional-test-http-server-secure" />
  </target>

  <!-- =================================================================== -->
  <!-- Runs the JUnit functional tests ONLY -->
  <!-- =================================================================== -->
  <target name="junit-functional-tests-only" if="junit.present" depends="junit-functional-prepare">
    <java classname="org.apache.axis.client.AdminClient" fork="yes">
      <classpath refid="test-classpath" />
      <arg line="${deploy.xml.property}"/>
    </java>

    <!-- now, run the actual test -->
    <junit dir="." printsummary="yes" haltonfailure="${test.functional.fail}" fork="yes">
      <!-- Pass through the proxy parameters -->
      <jvmarg value="-Dhttp.proxyHost=${http.proxyHost}"/>
      <jvmarg value="-Dhttp.proxyPort=${http.proxyPort}"/>
      <jvmarg value="-Dhttp.nonProxyHosts=${http.nonProxyHosts}"/>
      <jvmarg value="-Dhttp.proxyUser=${http.proxyUser}"/>
      <jvmarg value="-Dhttp.proxyPassword=${http.proxyPassword}"/>
      <!-- Pass the port for SimpleAxisServer -->
      <jvmarg value="-Dtest.functional.SimpleAxisPort=${test.functional.SimpleAxisPort}"/>
      <jvmarg value="-Dtest.functional.ServicePort=${test.functional.ServicePort}"/>
      <classpath refid="test-classpath" />
      <formatter type="xml" usefile="${test.functional.usefile}"/>
      <batchtest todir="${test.functional.reportdir}">
        <fileset dir="${build.dest}">
          <!-- Convention: each package that's being tested
                has its own test class collecting all the tests -->
              <include name="**/${test.functional.testcase}.class" />
        </fileset>
      </batchtest>
    </junit>

    <java classname="org.apache.axis.client.AdminClient" fork="yes">
      <classpath refid="test-classpath" />
      <arg line="${undeploy.xml.property}"/>
    </java>
  </target>


  <!-- =================================================================== -->
  <!-- Runs the JUnit functional test, with special class parameter.       -->
  <!-- This is because RobJ's IDE can't build into multiple directories;   -->
  <!-- it builds all the tests & samples into build/classes.               -->
  <!-- If he wants to build & run the server under the debugger while      -->
  <!-- firing the client tests at it, he has to use this target so junit   -->
  <!-- will find the classes in the IDE's build location.                  -->
  <!-- =================================================================== -->
  <target name="junit-functional-noserver" if="junit.present">
    <junit printsummary="yes" haltonfailure="${test.functional.fail}" fork="yes">
      <classpath refid="test-classpath" />
      <formatter type="plain" />
      <batchtest>
        <fileset dir="${build.dest}">
          <!-- Convention: each package that's being tested
                has its own test class collecting all the tests -->
          <include name="**/FunctionalTests.class" />
        </fileset>
      </batchtest>
    </junit>
  </target>


</project>


