<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <parent>
        <artifactId>alfresco-share-parent</artifactId>
        <groupId>org.alfresco</groupId>
        <version>6.0.1-RC2</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>alfresco-cmm-qa</artifactId>
    <name>Alfresco CMM Automation QA</name>
    <properties>
        <!-- Skip Tests by default - use -Ptest to run them -->
        <skipTests>true</skipTests>
        <selenium.version>2.39.1</selenium.version>
        <spring.version>5.0.4.RELEASE</spring.version>
        <alfresco.api.utils.version>1.2</alfresco.api.utils.version>
		<remote.api.version>${dependency.alfresco-remote-api.version}</remote.api.version>
        <enterprise.installer.path>/data/bamboo/artifacts/${enterprise.build.plan}/ALL/alfresco-*-linux-x64.???</enterprise.installer.path>
        <testng.sanity.xml>src/test/resources/cmm-sanity-testng.xml</testng.sanity.xml>
        <testng.xml>src/test/resources/cmm-complete-e2e-testng.xml</testng.xml>
        <testngUnit.xml>src/test/resources/testngUnitTests.xml</testngUnit.xml>
    </properties>
    <build>
        <directory>target/${uniqueTestRunName}</directory>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        <testResources>
            <testResource>
                <directory>src/test/resources</directory>
                 <filtering>true</filtering>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>${testng.sanity.xml}</suiteXmlFile>
                        <suiteXmlFile>${testng.xml}</suiteXmlFile>
                    </suiteXmlFiles>
                    <runOrder>alphabetical</runOrder>
                    <workingDirectory>${basedir}</workingDirectory>
                    <redirectTestOutputToFile>false</redirectTestOutputToFile>
                    <parallel>classes</parallel>
                </configuration>
            </plugin>
            <plugin>            
                <!-- Configuration triggered by mvn antrun:run, used by Bamboo to stop 
                    server -->
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>default-cli</id>
                        <configuration>
                            <target>
                                <echo>Stopping Alfresco...</echo>
                                <exec executable="${basedir}/target/alf-installation/alfresco.sh" dir="target/alf-installation" failonerror="true">
                                    <arg value="stop" />
                                </exec>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.alfresco</groupId>
            <artifactId>selenium-grid</artifactId>
            <version>1.8</version>
        </dependency>
        <dependency>
            <groupId>org.alfresco</groupId>
            <artifactId>share-po</artifactId>
            <version>${project.version}</version>
            <type>test-jar</type>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.chemistry.opencmis</groupId>
                    <artifactId>chemistry-opencmis-commons-api</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.chemistry.opencmis</groupId>
                    <artifactId>chemistry-opencmis-client-bindings</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.chemistry.opencmis</groupId>
                    <artifactId>chemistry-opencmis-client-api</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.chemistry.opencmis</groupId>
                    <artifactId>chemistry-opencmis-commons-impl</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.alfresco</groupId>
            <artifactId>share-po</artifactId>
            <version>${project.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.social</groupId>
                    <artifactId>spring-social-alfresco-bm</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.alfresco.test</groupId>
            <artifactId>alfresco-api-test-utils</artifactId>
            <version>${alfresco.api.utils.version}</version>
        </dependency>
		<dependency>
			<groupId>org.alfresco</groupId>
			<artifactId>alfresco-remote-api</artifactId>
			<version>6.6</version>
		</dependency>
		<dependency>
			<groupId>org.alfresco</groupId>
			<artifactId>alfresco-remote-api</artifactId>
			<version>6.6</version>
			<classifier>tests</classifier>
		</dependency>
        <dependency>
            <groupId>org.alfresco.test</groupId>
            <artifactId>alfresco-testng</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>xml-apis</groupId>
            <artifactId>xml-apis</artifactId>
            <version>1.4.01</version>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>18.0</version>
        </dependency>
        <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-test</artifactId>
             <version>${spring.version}</version>
        </dependency>
        <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-core</artifactId>
             <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${spring.version}</version>
        </dependency>
  		<dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
           <version>3.1.0</version>
        </dependency>      
    </dependencies>
    <profiles>
        <profile>
            <id>install-alfresco</id>
            <build>
                <plugins>
                    <!-- Download and install the latest enterprise alfresco installer -->
                    <plugin>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>fetch-installer</id>
                                <phase>generate-test-resources</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <target>
                                        <echo>Recreating database...</echo>
                                        <sql driver="org.postgresql.Driver" url="jdbc:postgresql:template1" userid="alfresco" password="alfresco" autocommit="true">drop
                                            database if exists alfresco; create database alfresco</sql>
                                        <echo>Downloading Alfresco installer...</echo>
                                        <sshexec username="tomcat" host="pbam01.alfresco.com" keyfile="${user.home}/.ssh/id_rsa" outputproperty="installerPath" command="ls -rt ${enterprise.installer.path} | tail -1 | tr ' ' '?' " />
                                        <scp remoteFile="tomcat@pbam01.alfresco.com:${installerPath}" localTofile="target/alf-installer.bin" keyfile="${user.home}/.ssh/id_rsa" />
                                        <chmod file="target/alf-installer.bin" perm="a+x" verbose="true" />
                                        <echo>Installing Alfresco...</echo>
                                        <exec executable="${basedir}/target/alf-installer.bin" dir="target" failonerror="true">
                                            <arg line="--mode unattended --alfresco_admin_password admin --disable-components postgres,alfrescowcmqs --jdbc_username alfresco --jdbc_password alfresco --prefix ${basedir}/target/alf-installation" />
                                        </exec>
                                    </target>
                                </configuration>
                            </execution>
                        </executions>
                        <dependencies>
                            <dependency>
                                <groupId>org.apache.ant</groupId>
                                <artifactId>ant-jsch</artifactId>
                                <version>1.8.2</version>
                            </dependency>
                            <dependency>
                                <groupId>postgresql</groupId>
                                <artifactId>postgresql</artifactId>
                                <version>9.1-901-1.jdbc4</version>
                            </dependency>
                        </dependencies>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>run-alfresco</id>
            <build>
                <plugins>
                    <!-- Fetch JaCoCo agent and set the argLine property accordingly -->
                    <plugin>
                        <groupId>org.jacoco</groupId>
                        <artifactId>jacoco-maven-plugin</artifactId>
                        <version>0.7.6.201602180812</version>
                        <executions>
                            <execution>
                                <id>prepare-jacoco</id>
                                <goals>
                                    <goal>prepare-agent</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <includes>
                                <include>org.alfresco.*</include>
                            </includes>
                        </configuration>
                    </plugin>
                    <!-- Starts/stop the installed Alfresco -->
                    <plugin>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>start-alfresco</id>
                                <phase>process-test-classes</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <target>
                                        <echo>Starting Alfresco...</echo>
                                        <exec executable="${basedir}/target/alf-installation/alfresco.sh" dir="target/alf-installation" failonerror="true">
                                            <arg value="start" />
                                            <env key="CATALINA_OPTS" value="${argLine}" />
                                        </exec>
                                        <sleep minutes="5" />
                                    </target>
                                </configuration>
                            </execution>
                            <execution>
                                <id>stop-alfresco</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <target>
                                        <echo>Stopping Alfresco...</echo>
                                        <exec executable="${basedir}/target/alf-installation/alfresco.sh" dir="target/alf-installation" failonerror="true">
                                            <arg value="stop" />
                                        </exec>
                                    </target>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>test</id>
            <properties>
                <skipTests>false</skipTests>
            </properties>
        </profile>
    </profiles>
</project>
