<?xml version="1.0" encoding="UTF-8"?>
<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">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.atlassian.jira.plugins</groupId>
        <artifactId>jira-greenhopper-parent-pom</artifactId>
        <version>8.10.1</version>
    </parent>

    <artifactId>greenhopper-ha-test</artifactId>

    <packaging>atlassian-plugin</packaging>
    <name>Jira Agile Clustered Test Plugin</name>
    <description>Clustered Jira tests for Jira Agile.</description>

    <dependencies>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
        </dependency>
    	<dependency>
    		<groupId>com.atlassian.jira.plugins</groupId>
    		<artifactId>jira-ha-test-api</artifactId>
    		<version>${jira.version}</version>
            <scope>test</scope>
    	</dependency>

        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-core-asl</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-jaxrs</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-xc</artifactId>
            <scope>test</scope>
        </dependency>


        <dependency>
            <groupId>com.atlassian.jira</groupId>
            <artifactId>jira-api</artifactId>
            <version>${jira.version}</version>
            <scope>provided</scope>
        </dependency>
        <!-- REST module dependencies -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>jsr311-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.plugins.rest</groupId>
            <artifactId>atlassian-rest-common</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.sal</groupId>
            <artifactId>sal-api</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- Unit test dependencies -->
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-core</artifactId>
            <version>${hamcrest.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>${mockito.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.jira</groupId>
            <artifactId>jira-tests</artifactId>
            <version>${jira.version}</version>
            <scope>test</scope>
        </dependency>

        <!-- Func test dependencies -->
        <dependency>
            <groupId>com.atlassian.jira</groupId>
            <artifactId>jira-func-tests</artifactId>
            <version>${jira.version}</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <!-- Already have the log4j binding -->
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-simple</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.mortbay.jetty</groupId>
                    <artifactId>servlet-api-2.5</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.atlassian.jira.plugins</groupId>
            <artifactId>jira-greenhopper-integration-test</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.atlassian.jira.plugins</groupId>
            <artifactId>jira-soapclient</artifactId>
            <version>6.0.4</version>
        </dependency>

         <dependency>
            <groupId>${hadb.groupId}</groupId>
            <artifactId>${hadb.artifactId}</artifactId>
            <version>${hadb.version}</version>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <profiles>
        <profile>
            <id>setup-db</id>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <!-- Inherited version is 1.6 -->
                        <version>1.7</version>
                        <executions>
                            <execution>
                                <id>drop-database</id>
                                <phase>pre-integration-test</phase>
                                <configuration>
                                    <target>
                                        <!-- Postgres client utility -->
                                        <exec executable="dropdb" failonerror="false">
                                            <arg value="--echo" />
                                            <arg value="--username=${hadb.username}" />
                                            <arg value="--no-password" />
                                            <arg value="--if-exists" />
                                            <arg value="${hadb.instance}" />
                                        </exec>
                                    </target>
                                </configuration>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>create-database</id>
                                <phase>pre-integration-test</phase>
                                <configuration>
                                    <target>
                                        <!-- Postgres client utility -->
                                        <exec executable="createdb" failonerror="true">
                                            <arg value="--echo" />
                                            <arg value="--username=${hadb.username}" />
                                            <arg value="--no-password" />
                                            <arg value="--encoding=UTF8" />
                                            <arg value="${hadb.instance}" />
                                        </exec>
                                        <!-- Postgres client utility -->
                                        <exec executable="psql" failonerror="true">
                                            <arg value="--dbname=${hadb.instance}" />
                                            <arg value="--file=${project.build.directory}/database-dump/jira-ha-empty-db.dmp" />
                                            <arg value="--username=${hadb.username}" />
                                            <arg value="--no-password" />
                                        </exec>

                                        <!-- Additional script for putting in greenhopper license -->
                                        <exec executable="psql" failonerror="true">
                                            <arg value="--dbname=${hadb.instance}" />
                                            <arg value="--file=${project.basedir}/src/dbscript/agile-license.sql" />
                                            <arg value="--username=${hadb.username}" />
                                            <arg value="--no-password" />
                                        </exec>

                                        <mkdir dir="/tmp/jiraha_shared/data/attachments" />
                                    </target>
                                </configuration>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>docker</id>
            <properties>
                <hadb.port>5433</hadb.port>
                <db.dumpLogsOnError>ALL</db.dumpLogsOnError>
                <boxdb.startupTimeout>1800</boxdb.startupTimeout>
                <db.type>postgres</db.type>
                <db.version>11</db.version>
                <db.containerName>ha-agile-test-postgres</db.containerName>
                <db.dump>${project.build.directory}/database-dump/jira-ha-empty-db.dmp</db.dump>
                <db.user>${hadb.username}</db.user>
                <db.password>${hadb.password}</db.password>
                <db.name>${hadb.instance}</db.name>
                <db.deleteOnStop>true</db.deleteOnStop>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.atlassian.maven.plugins</groupId>
                        <artifactId>jiradb-maven-plugin</artifactId>
                        <configuration>
                            <jiraHome>${project.build.directory}</jiraHome>
                            <boxSettingsFile>${project.build.directory}/boxdb.properties</boxSettingsFile>
                        </configuration>
                        <executions>
                            <execution>
                                <id>start-db</id>
                                <goals>
                                    <goal>start</goal>
                                </goals>
                                <phase>pre-integration-test</phase>
                            </execution>
                            <execution>
                                <id>stop-db</id>
                                <goals>
                                    <goal>stop</goal>
                                </goals>
                                <phase>post-integration-test</phase>
                            </execution>
                            <execution>
                                <id>stop-on-clean</id>
                                <goals>
                                    <goal>stop</goal>
                                </goals>
                                <phase>clean</phase>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
                <pluginManagement>
                    <plugins>
                        <plugin>
                            <groupId>au.net.causal.maven.plugins</groupId>
                            <artifactId>boxdb-maven-plugin</artifactId>
                            <configuration>
                                <box>
                                    <scriptExecutions>
                                        <scriptExecution>
                                            <directory>${project.basedir}/src/dbscript</directory>
                                            <stage>POST_RESTORE</stage>
                                            <scripts>
                                                <script>agile-license.sql</script>
                                            </scripts>
                                        </scriptExecution>
                                    </scriptExecutions>
                                </box>
                            </configuration>
                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
        </profile>
        <profile>
            <id>skippingTests</id>
            <activation>
                <property>
                    <name>skipTests</name>
                </property>
            </activation>
            <properties>
                <skip.extract.dependencies>false</skip.extract.dependencies>
            </properties>
        </profile>
        <profile>
            <id>skip-unit-tests</id>
            <activation>
                <property>
                    <name>skipUTs</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <skipTests>true</skipTests>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.8</version>
                <executions>
                    <execution>
                        <id>extract-database-dump</id>
                        <phase>generate-test-resources</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>com.atlassian.jira.plugins</groupId>
                                    <artifactId>jira-ha-tests</artifactId>
                                    <version>${jira.version}</version>
                                    <classifier>tests</classifier>
                                    <includes>jira-ha-empty-db.dmp</includes>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>${project.build.directory}/database-dump</outputDirectory>
                        </configuration>
                    </execution>
                    <execution>
                        <id>extract-node-resources</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>com.atlassian.jira.plugins</groupId>
                                    <artifactId>jira-ha-tests</artifactId>
                                    <version>${jira.version}</version>
                                    <classifier>tests</classifier>
                                    <includes>node*.zip</includes>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>${project.build.directory}/node-resources</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>com.atlassian.maven.plugins</groupId>
                <artifactId>jira-maven-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <buildTestPlugin>false</buildTestPlugin>
                    <installPlugin>false</installPlugin>
                    <extractDependencies>${skip.extract.dependencies}</extractDependencies>
                    <pluginArtifacts combine.children="append">
                        <pluginArtifact>
                            <groupId>com.atlassian.jira.tests</groupId>
                            <artifactId>jira-testkit-plugin</artifactId>
                            <version>${testkit.version}</version>
                        </pluginArtifact>
                        <pluginArtifact>
                            <groupId>com.atlassian.jira</groupId>
                            <artifactId>jira-func-test-plugin</artifactId>
                            <version>${jira.version}</version>
                        </pluginArtifact>
                        <pluginArtifact>
                            <groupId>com.atlassian.jira.plugins</groupId>
                            <artifactId>greenhopper-client-plugin</artifactId>
                            <version>${project.version}</version>
                        </pluginArtifact>
                        <pluginArtifact>
                            <groupId>com.atlassian.jira.plugins</groupId>
                            <artifactId>greenhopper-dev-extensions</artifactId>
                            <version>${project.version}</version>
                        </pluginArtifact>
                        <pluginArtifact>
                            <groupId>com.atlassian.jira.plugins</groupId>
                            <artifactId>jira-greenhopper-plugin</artifactId>
                            <version>${project.version}</version>
                        </pluginArtifact>
                        <pluginArtifact>
                            <groupId>com.atlassian.jira.plugins</groupId>
                            <artifactId>jira-ha-plugin</artifactId>
                            <version>${jira.version}</version>
                        </pluginArtifact>
                    </pluginArtifacts>
                    <parallel>false</parallel>
                    <systemPropertyVariables>
                        <xvfb.enable>true</xvfb.enable>
                        <jira.test.version>${jira.version}</jira.test.version>
                    </systemPropertyVariables>
                    <jvmArgs>-Xmx1g ${jacocoArgLine}</jvmArgs>
                    <productVersion>${jira.version}</productVersion>
                    <productDataVersion>${jira.version}</productDataVersion>
                    <applications>
                        <application>
                            <applicationKey>jira-software</applicationKey>
                            <version>${jira.software.application.version}</version>
                        </application>
                    </applications>
                    <products>
                        <product>
                            <id>jira</id>
                            <instanceId>node1</instanceId>
                            <httpPort>5991</httpPort>
                            <server>${test.host}</server>
                            <ajpPort>8010</ajpPort>
                            <contextPath>/node1</contextPath>
                            <productDataPath>${project.build.directory}/node-resources/node1.zip</productDataPath>
                            <systemPropertyVariables>
                                <jira.ha.webfilter.disabled>true</jira.ha.webfilter.disabled>
                                <atlassian.ehcache.config>${project.build.directory}/node1/webapp/WEB-INF/classes/ehcache.xml</atlassian.ehcache.config>
                                <atlassian.cache.jmx>true</atlassian.cache.jmx>
                                <atlassian.cluster.scale>true</atlassian.cluster.scale>
                                <atlassian.darkfeature.com.atlassian.jira.config.CoreFeatures.LICENSE_ROLES_ENABLED>true</atlassian.darkfeature.com.atlassian.jira.config.CoreFeatures.LICENSE_ROLES_ENABLED>
                            </systemPropertyVariables>
                            <dataSources>
                                <dataSource>
                                    <jndi>jdbc/JiraDS</jndi>
                                    <url>${jdbc.url}</url>
                                    <username>${hadb.username}</username>
                                    <password>${hadb.password}</password>
                                    <driver>${jdbc.driver}</driver>
                                    <schema>public</schema>
                                    <libArtifacts>
                                        <libArtifact>
                                            <groupId>${hadb.groupId}</groupId>
                                            <artifactId>${hadb.artifactId}</artifactId>
                                            <version>${hadb.version}</version>
                                        </libArtifact>
                                    </libArtifacts>
                                </dataSource>
                            </dataSources>
                            <sharedHome>${shared.home}</sharedHome>
                        </product>
                        <product>
                            <id>jira</id>
                            <instanceId>node2</instanceId>
                            <httpPort>5992</httpPort>
                            <server>${test.host}</server>
                            <ajpPort>8011</ajpPort>
                            <contextPath>/node2</contextPath>
                            <productDataPath>${project.build.directory}/node-resources/node2.zip</productDataPath>
                            <systemPropertyVariables>
                                <jira.ha.webfilter.disabled>true</jira.ha.webfilter.disabled>
                                <atlassian.ehcache.config>${project.build.directory}/node2/webapp/WEB-INF/classes/ehcache.xml</atlassian.ehcache.config>
                                <atlassian.cache.jmx>true</atlassian.cache.jmx>
                                <atlassian.cluster.scale>true</atlassian.cluster.scale>
                                <atlassian.darkfeature.com.atlassian.jira.config.CoreFeatures.LICENSE_ROLES_ENABLED>true</atlassian.darkfeature.com.atlassian.jira.config.CoreFeatures.LICENSE_ROLES_ENABLED>
                            </systemPropertyVariables>
                            <dataSources>
                                <dataSource>
                                    <jndi>jdbc/JiraDS</jndi>
                                    <url>${jdbc.url}</url>
                                    <username>${hadb.username}</username>
                                    <password>${hadb.password}</password>
                                    <driver>${jdbc.driver}</driver>
                                    <schema>public</schema>
                                    <libArtifacts>
                                        <libArtifact>
                                            <groupId>${hadb.groupId}</groupId>
                                            <artifactId>${hadb.artifactId}</artifactId>
                                            <version>${hadb.version}</version>
                                        </libArtifact>
                                    </libArtifacts>
                                </dataSource>
                            </dataSources>
                            <sharedHome>/tmp/jiraha_shared</sharedHome>
                        </product>
                    </products>
                    <testGroups>
                        <testGroup>
                            <id>ha</id>
                            <productIds>
                                <productId>node1</productId>
                                <productId>node2</productId>
                            </productIds>
                            <includes>
                                <include>it/com/atlassian/jira/plugins/greenhopper/ha/*Test.java</include>
                            </includes>
                        </testGroup>
                    </testGroups>
                 </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-clean-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <filesets>
                        <fileset>
                            <directory>${shared.home}</directory>
                        </fileset>
                    </filesets>
                </configuration>
            </plugin>
        </plugins>

        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>com.atlassian.maven.plugins</groupId>
                    <artifactId>amps-maven-plugin</artifactId>
                </plugin>
                <plugin>
                    <groupId>com.atlassian.maven.plugins</groupId>
                    <artifactId>jira-maven-plugin</artifactId>
                </plugin>
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.12.2</version>
                    <configuration>
                        <excludes>
                            <exclude>**/*$*</exclude>
                            <exclude>it/**</exclude>
                        </excludes>
                    </configuration>
                </plugin>
                <plugin>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>2.12.4</version>
                    <configuration>
                        <argLine>-Xmx1500m ${jacocoArgLine}</argLine>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>com.atlassian.maven.plugins</groupId>
                    <artifactId>amps-dispatcher-maven-plugin</artifactId>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.cargo</groupId>
                    <artifactId>cargo-maven2-plugin</artifactId>
                    <version>1.1.3</version>
                    <!-- We want to be able to start the cargo container even if we skip the tests (so that atlas-run works) -->
                    <configuration>
                        <skip>false</skip>
                        <!--<cargo.jvmargs>-Xmx1g</cargo.jvmargs>-->
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>com.atlassian.maven.plugins</groupId>
                    <artifactId>jiradb-maven-plugin</artifactId>
                    <version>${jiradb.version}</version>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <properties>
        <shared.home>/tmp/jiraha_shared</shared.home>
        <testkit.version>7.2.13</testkit.version>
        <xvfb.enable>false</xvfb.enable>
        <jira.software.application.version>${project.version}</jira.software.application.version>
        <test.host>localhost</test.host>
        <license.scope>test</license.scope>

        <appServer.install.directory>atlassian-jira-${jira.version}-standalone</appServer.install.directory>

        <hadb.host>${test.host}</hadb.host>
        <hadb.groupId>org.postgresql</hadb.groupId>
        <hadb.artifactId>postgresql</hadb.artifactId>
        <hadb.version>${database.driver.version.postgres}</hadb.version>

        <hadb.instance>jiraha</hadb.instance>
        <hadb.username>postgres</hadb.username>
        <hadb.password>postgresbox</hadb.password>
        <hadb.port>5432</hadb.port>
        <jdbc.url>jdbc:postgresql://${hadb.host}:${hadb.port}/${hadb.instance}</jdbc.url>
        <jdbc.driver>org.postgresql.Driver</jdbc.driver>
        <hadb.schema>public</hadb.schema>

        <hadb.url>${jdbc.url}</hadb.url>
        <skip.extract.dependencies>true</skip.extract.dependencies>

        <hadb.jar>${hadb.artifactId}.${hadb.version}.jar</hadb.jar>
        <hadb.testTableName>SQL SELECT 1 FROM DUAL</hadb.testTableName>
    </properties>
</project>
