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

<project name="itest" default="build-repos" basedir=".">

	<target name="generate-test-sources" unless="test.skip">
		<!-- Set a property that can be picked up from the ant build.xml's -->

		<echo>${maven.test.path}</echo>

		<property name="axis2.home" value="${basedir}/target" />
		<property name="maven.junit.jvmargs" value="" />
		<path id="maven.dependency.classpath">
			<path refid="maven.runtime.classpath" />
		</path>
		<!-- compiling some custom wsdl files -->
		<property name="wsdl.source.dir" value="test-resources/wsdl" />
		<property name="wsdl.output.base.dir" value="target/wsdl" />
		<!-- make the dirs -->
		<mkdir dir="${wsdl.output.base.dir}" />

		<echo>Compiling ComplexDataTypes.wsdl</echo>
		<mkdir dir="${wsdl.output.base.dir}/complexdatatype" />

		<java classname="org.apache.axis2.wsdl.WSDL2Java" fork="true">
			<classpath refid="maven.runtime.classpath" />
			<classpath location="${compiled.classes.dir}" />
			<arg line="-ap -o target/wsdl/complexdatatype -s -u -uw -uri test-resources/ComplexDataTypes/ComplexDataTypes.wsdl" />
		</java>

		<echo>Compiling DocumentUnwrappingTest.wsdl</echo>
		<mkdir dir="${wsdl.output.base.dir}/documentunwrapping" />

		<java classname="org.apache.axis2.wsdl.WSDL2Java" fork="true">
			<classpath refid="maven.runtime.classpath" />
			<classpath location="${compiled.classes.dir}" />
			<arg line="-ap -o target/wsdl/documentunwrapping -ss -sd -ssi -u  -g -uw -uri test-resources/wsdl/DocumentUnwrappingTest.wsdl" />
		</java>
		<ant antfile="build.xml" inheritall="true" inheritrefs="true" dir="target/wsdl/documentunwrapping" />

		<echo>Compiling RPCUnwrappingTest.wsdl</echo>
		<mkdir dir="${wsdl.output.base.dir}/rpcunwrapping" />
		<java classname="org.apache.axis2.wsdl.WSDL2Java" fork="true">

			<classpath refid="maven.runtime.classpath" />
			<classpath location="${compiled.classes.dir}" />
			<arg line="-ap -o target/wsdl/rpcunwrapping -ss -sd -ssi -u  -g -uw -uri test-resources/wsdl/RPCUnwrappingTest.wsdl" />
		</java>
		<ant antfile="build.xml" inheritall="true" inheritrefs="true" dir="target/wsdl/rpcunwrapping" />

		<echo>Compiling ComplexDataTypesDocLitBare.wsdl</echo>
		<mkdir dir="${wsdl.output.base.dir}/complexdatatypebare" />
		<java classname="org.apache.axis2.wsdl.WSDL2Java" fork="true">
			<classpath refid="maven.runtime.classpath" />
			<classpath location="${compiled.classes.dir}" />
			<arg line="-o target/wsdl/complexdatatypebare -s -uri test-resources/ComplexDataTypesDocLitBare/ComplexDataTypesDocLitBare.wsdl" />
		</java>
		<ant antfile="build.xml" inheritall="true" inheritrefs="true" dir="target/wsdl/complexdatatypebare" />

		<ant antfile="itest-build.xml" inheritall="true" inheritrefs="true" dir="." target="rpc-wsdl-codegen" />
		<ant antfile="itest-build.xml" inheritall="true" inheritrefs="true" dir="." target="wsdl20-codegen" />
	</target>

	<target name="rpc-wsdl-codegen">
		<echo>Running codegen RPC WSDLs - take 1</echo>
		<java classname="org.apache.axis2.wsdl.WSDL2Java" fork="true">
			<classpath refid="maven.dependency.classpath" />
			<arg line="-ap -o target/rpc-test1 -uri test-resources/rpc/test-rpc-2.wsdl -uw" />
		</java>
		<ant antfile="build.xml" inheritall="true" inheritrefs="true" dir="target/rpc-test1" target="jar.client" />

		<echo>Running codegen RPC WSDLs - take 2</echo>
		<java classname="org.apache.axis2.wsdl.WSDL2Java" fork="true">
			<classpath refid="maven.dependency.classpath" />
			<arg line="-ap -o target/rpc-test2 -uri test-resources/rpc/test-rpc-3.wsdl -uw" />
		</java>
		<ant antfile="build.xml" inheritall="true" inheritrefs="true" dir="target/rpc-test2" target="jar.client" />


		<echo>Running codegen RPC WSDLs - take 3</echo>
		<java classname="org.apache.axis2.wsdl.WSDL2Java" fork="true">
			<classpath refid="maven.dependency.classpath" />
			<arg line="-ap -o target/rpc-test3 -uri test-resources/rpc/test-rpc-2.wsdl -uw" />
		</java>
		<ant antfile="build.xml" inheritall="true" inheritrefs="true" dir="target/rpc-test3" target="jar.client" />

		<echo>Running codegen RPC WSDLs - take 4</echo>
		<java classname="org.apache.axis2.wsdl.WSDL2Java" fork="true">
			<classpath refid="maven.dependency.classpath" />
			<arg line="-ap -o target/rpc-test4 -uri test-resources/rpc/test-rpc-2.wsdl -uw -ss -sd" />
		</java>
		<ant antfile="build.xml" inheritall="true" inheritrefs="true" dir="target/rpc-test4"
							 target="jar.server"/>

		<echo>Running codegen RPC WSDLs with helper mode -  take 1</echo>
		<java classname="org.apache.axis2.wsdl.WSDL2Java" fork="true">
			<classpath refid="maven.dependency.classpath"/>
			<arg line="-ap -o target/helper-test1 -uri test-resources/rpc/test-rpc-2.wsdl -u -Eh"/>
		</java>
		<ant antfile="build.xml" inheritall="true" inheritrefs="true" dir="target/helper-test1"
					 target="jar.client"/>

		<echo>Running codegen RPC WSDLs with helper mode -  take 2</echo>
		<java classname="org.apache.axis2.wsdl.WSDL2Java" fork="true">
			<classpath refid="maven.dependency.classpath"/>
			<arg line="-ap -o target/helper-test2 -uri test-resources/rpc/test-rpc-2.wsdl -u -Eh"/>
		</java>
		<ant antfile="build.xml" inheritall="true" inheritrefs="true" dir="target/helper-test2"
					 target="jar.client"/>
	</target>

	<target name="wsdl20-codegen">
		<echo>Running codegen for WSDL 2.0</echo>
		<java classname="org.apache.axis2.wsdl.WSDL2Java" fork="true">
			<classpath refid="maven.runtime.classpath"/>
			<arg line="-wv 2.0 -ap -o target/wsdl20-test -s -uri test-resources/wsdl20/HotelReservationService.wsdl"/>
		</java>
		<ant antfile="build.xml" inheritall="true" inheritrefs="true" dir="target/wsdl20-test"
									 target="jar.client"/>
    </target>

	<target name="enterprise-wsdl-codegen">
		<!-- codegen for the enterprise wsdl -->
		<echo>Running codegen for Enterprise WSDL - take 1</echo>
		<java classname="org.apache.axis2.wsdl.WSDL2Java" fork="true">
			<classpath refid="maven.dependency.classpath"/>
			<arg line="-ap -d xmlbeans -o target/enterprise-test1 -s -uri test-resources/enterprise.wsdl"/>
		</java>
		<ant antfile="build.xml" inheritall="true" inheritrefs="true" dir="target/enterprise-test1"
									 target="jar.client"/>

		<echo>Running codegen for Enterprise WSDL - take 2</echo>
		<java classname="org.apache.axis2.wsdl.WSDL2Java" fork="true">
			<classpath refid="maven.dependency.classpath"/>
			<arg line="-ap -o target/enterprise-test2 -s -uri test-resources/enterprise.wsdl"/>
		</java>
		<ant antfile="build.xml" inheritall="true" inheritrefs="true" dir="target/enterprise-test2"
									 target="jar.client"/>

		<echo>Running codegen for Enterprise WSDL - take 3</echo>
		<java classname="org.apache.axis2.wsdl.WSDL2Java" fork="true">
			<classpath refid="maven.dependency.classpath"/>
			<arg line="-ap -d xmlbeans -ss -sd -g -o target/enterprise-test3 -s -uri test-resources/enterprise.wsdl"/>
		</java>
		<ant antfile="build.xml" inheritall="true" inheritrefs="true" dir="target/enterprise-test3"
									 target="jar.server"/>

		<echo>Running codegen for Enterprise WSDL - take 4</echo>
		<java classname="org.apache.axis2.wsdl.WSDL2Java" fork="true">
			<classpath refid="maven.dependency.classpath"/>
			<arg line="-ap -ns2p urn:sobject.enterprise.soap.sforce.com=com.salesforce -d xmlbeans -ss -sd -g -o target/enterprise-test4 -s -uri test-resources/enterprise.wsdl"/>
		</java>
		<ant antfile="build.xml" inheritall="true" inheritrefs="true" dir="target/enterprise-test4"
									 target="jar.server"/>
	</target>

	<target name="build-repos" unless="test.skip">
		<mkdir dir="target/toWar/services/"/>

		<mkdir dir="target/test-resources/MessageContextInjectionRepo"/>

		<!-- Spring resources -->
		<mkdir dir="target/test-resources/spring"/>
		<copy file="../spring/test-resources/applicationContext.xml"
    	                  tofile="target/test-classes/spring/applicationContext.xml"/>

		<!-- Test with target resolver  -->
		<mkdir dir="target/test-resources/deployment"/>

		<copy file="test-resources/deployment/server-transport.xml"
    	            	  tofile="target/test-resources/deployment/server-transport.xml"/>

        <antcall target="build-jaxrs-services"/>
    </target>
	<target name="build-soap12-services">
		<ant antfile="build.xml" inheritall="true" inheritrefs="true"
		                         dir="test-resources/SOAP12Testing/SOAP12TestModuleB"/>
		<ant antfile="build.xml" inheritall="true" inheritrefs="true"
		                         dir="test-resources/SOAP12Testing/SOAP12TestModuleC"/>
		<ant antfile="build.xml" inheritall="true" inheritrefs="true"
		                         dir="test-resources/SOAP12Testing/SOAP12TestServiceB"/>
		<ant antfile="build.xml" inheritall="true" inheritrefs="true"
		                         dir="test-resources/SOAP12Testing/SOAP12TestServiceC"/>
	</target>

     <target name="build-jaxrs-services">
        <ant antfile="build.xml" inheritall="true" inheritrefs="true"
                                 dir="test-resources/jaxrs/archiveTestModule"/>
        <ant antfile="build.xml" inheritall="true" inheritrefs="true"
                                 dir="test-resources/jaxrs/pojoTestModule"/>
    </target>
</project>
