<?xml version="1.0"?>

<project name="portal-test-db-upgrade" basedir="." default="test" xmlns:antelope="antlib:ise.antelope.tasks">
	<import file="build-test.xml" />

	<target name="prepare-db-common">
		<antcall target="prepare-portal-ext-properties" inheritAll="false" />

		<ant dir="portal-impl" target="deploy-properties" inheritAll="false" />

		<if>
			<isset property="sql.version" />
			<then>
				<property name="sql.dir" value="sql\legacy\${sql.version}\create\" />

				<if>
					<contains string="${db.type}" substring="db2" />
					<then>
						<property name="sql.file" value="create-db2.sql" />
					</then>
					<elseif>
						<contains string="${db.type}" substring="mysql" />
						<then>
							<property name="sql.file" value="create-mysql.sql" />
						</then>
					</elseif>
					<elseif>
						<contains string="${db.type}" substring="oracle" />
						<then>
							<property name="sql.file" value="create-oracle.sql" />
						</then>
					</elseif>
					<elseif>
						<contains string="${db.type}" substring="postgresql" />
						<then>
							<property name="sql.file" value="create-postgresql.sql" />
						</then>
					</elseif>
					<elseif>
						<contains string="${db.type}" substring="sql-server" />
						<then>
							<property name="sql.file" value="create-sql-server.sql" />
						</then>
					</elseif>
					<elseif>
						<contains string="${db.type}" substring="sybase" />
						<then>
							<property name="sql.file" value="create-sybase.sql" />
						</then>
					</elseif>
				</if>
			</then>
		</if>

		<antcall target="rebuild-database" inheritAll="false">
			<param name="sql.dir" value="${sql.dir}" />
			<param name="sql.file" value="${sql.file}" />
		</antcall>
	</target>

	<target name="prepare-db-db2-common">
		<echo file="test.${user.name}.properties">db.type=db2</echo>

		<antcall target="prepare-db-common" inheritAll="false" />
	</target>

	<target name="prepare-db-mysql-common">
		<echo file="test.${user.name}.properties">db.type=mysql</echo>

		<antcall target="prepare-db-common" inheritAll="false" />
	</target>

	<target name="prepare-db-oracle-10-common">
		<echo file="test.${user.name}.properties">db.type=oracle-10</echo>

		<antcall target="prepare-db-common" inheritAll="false" />
	</target>

	<target name="prepare-db-oracle-11-common">
		<echo file="test.${user.name}.properties">db.type=oracle-11</echo>

		<antcall target="prepare-db-common" inheritAll="false" />
	</target>

	<target name="prepare-db-postgresql-8.4-common">
		<echo file="test.${user.name}.properties">db.type=postgresql-8.4</echo>

		<antcall target="prepare-db-common" inheritAll="false" />
	</target>

	<target name="prepare-db-postgresql-9.0-common">
		<echo file="test.${user.name}.properties">db.type=postgresql-9.0</echo>

		<antcall target="prepare-db-common" inheritAll="false" />
	</target>

	<target name="prepare-db-sql-server-2005-common">
		<echo file="test.${user.name}.properties">db.type=sql-server-2005</echo>

		<antcall target="prepare-db-common" inheritAll="false" />
	</target>

	<target name="prepare-db-sql-server-2008-common">
		<echo file="test.${user.name}.properties">db.type=sql-server-2008</echo>

		<antcall target="prepare-db-common" inheritAll="false" />
	</target>

	<target name="prepare-db-sybase-common">
		<echo file="test.${user.name}.properties">db.type=sybase</echo>

		<antcall target="prepare-db-common" inheritAll="false" />
	</target>

	<target name="run-latest-upgrade-test">
		<echo file="app.server.${user.name}.properties">app.server.type=tomcat</echo>

		<ant antfile="build-test-tomcat.xml" target="run-selenium-tomcat" inheritAll="false">
			<property name="skip.rebuild-database" value="true" />
		</ant>
	</target>

	<target name="run-smoke-test">
		<ant antfile="build-test-tomcat.xml" target="run-selenium-tomcat" inheritAll="false">
			<property name="skip.rebuild-database" value="true" />
			<property name="test.name" value="DBUpgradeSmokeTestSuite" />
		</ant>
	</target>

	<target name="run-versioned-upgrade-test">
		<ant antfile="build-test-tomcat.xml" target="run-selenium-versioned-tomcat" inheritAll="false">
			<property name="skip.rebuild-database" value="true" />
		</ant>

		<antcall target="clean-up-bundles">
			<param name="skip.delete-liferay-home" value="true" />
		</antcall>
	</target>
</project>