<?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/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>jira-greenhopper-parent-pom</artifactId>
        <groupId>com.atlassian.jira.plugins</groupId>
        <version>1000.455.0</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>greenhopper-wired-integration-test</artifactId>
    <packaging>atlassian-plugin</packaging>

    <name>GreenHopper Wired Tests</name>

    <!--
          Test plugin which executes it.com.atlassian.greenhopper tests in this module.
          Disabled for most builds.
          Invoke it by activating the profile i.e.
              mvn clean install -DskipTests
              cd greenhopper-wired-integration-test
              mvn verify -Pwired-integration-tests
          The JIRA version tested against may be overridden via the jira.version maven property e.g.
              mvn verify -Pwired-integration-tests -Djira.version=1001.0.0-SNAPSHOT
      -->

    <properties>
        <atlassian.plugin.key.tests>com.atlassian.jira.plugins.greenhopper-wired-integration-test</atlassian.plugin.key.tests>
        <jira.integration.version>${jira.version}</jira.integration.version>
        <datasource.jndi>jdbc/JiraDS</datasource.jndi>
    </properties>

    <dependencies>

        <!-- test dependencies -->
        <dependency>
            <groupId>com.atlassian.jira</groupId>
            <artifactId>jira-core</artifactId>
            <version>${jira.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.jira.plugins</groupId>
            <artifactId>jira-greenhopper-plugin</artifactId>
            <version>${project.version}</version>
            <scope>provided</scope>
        </dependency>

        <!-- descope transitives from above provided, managed to compile
                TODO: remove scopes from dependencyManagement -->
        <dependency>
            <groupId>com.atlassian.cache</groupId>
            <artifactId>atlassian-cache-compat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.jira.plugins</groupId>
            <artifactId>jira-mobile-api</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian.workcontext</groupId>
            <artifactId>atlassian-work-context-doorway</artifactId>
            <version>1.2.1</version>
            <scope>provided</scope>
        </dependency>

        <!-- current version of junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- WIRED TEST RUNNER DEPENDENCIES -->
        <dependency>
            <groupId>com.atlassian.plugins</groupId>
            <artifactId>atlassian-plugins-osgi-testrunner</artifactId>
            <version>${plugin.testrunner.version}</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <artifactId>junit</artifactId>
                    <groupId>junit</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>junit</artifactId>
                    <groupId>junit-dep</groupId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>com.atlassian.maven.plugins</groupId>
                <artifactId>maven-jira-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <enableQuickReload>false</enableQuickReload>
                    <enableFastdev>false</enableFastdev>

                    <productVersion>${jira.version}</productVersion>
                    <productDataVersion>${jira.version}</productDataVersion>

                    <log4jProperties>../greenhopper/src/test/resources/log4j.properties</log4jProperties>

                    <!-- Skip wired integration tests by default - override in it wired-integration-tests profile -->
                    <skipTests>true</skipTests>

                    <skipManifestValidation>true</skipManifestValidation> <!-- these validations are misleading and have been removed in later versions of AMPS -->

                    <pluginArtifacts>
                        <pluginArtifact>
                            <groupId>com.atlassian.jira.plugins</groupId>
                            <artifactId>jira-greenhopper-plugin</artifactId>
                            <version>${project.version}</version>
                        </pluginArtifact>
                        <pluginArtifact>
                            <groupId>com.atlassian.qunit</groupId>
                            <artifactId>atlassian-qunit-plugin</artifactId>
                            <version>${atlassian.qunit.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-importers-plugin</artifactId>
                            <version>${jim.version}</version>
                        </pluginArtifact>
                    </pluginArtifacts>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>wired-integration-tests</id>
            <properties>
                <product>jira</product>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>org.postgresql</groupId>
                    <artifactId>postgresql</artifactId>
                    <version>${database.driver.version.postgres}</version>
                </dependency>
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.atlassian.maven.plugins</groupId>
                        <artifactId>maven-jira-plugin</artifactId>
                        <version>${amps.version}</version>
                        <extensions>true</extensions>
                        <configuration>
                            <skipTests>false</skipTests>
                            <libArtifacts>
                                <libArtifact>
                                    <groupId>org.postgresql</groupId>
                                    <artifactId>postgresql</artifactId>
                                    <version>${database.driver.version.postgres}</version>
                                </libArtifact>
                            </libArtifacts>
                            <server>localhost</server>
                            <jvmArgs>-Xmx2048m -XX:MaxPermSize=386m -Dgreenhopper.force.collation.functions.always=true -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005</jvmArgs>
                            <products>
                                <product>
                                    <instanceId>jira</instanceId>
                                    <version>${jira.integration.version}</version>
                                    <output>${project.build.directory}/jira-postgres-${jira.integration.version}.log</output>
                                    <dataSources>
                                        <dataSource>
                                            <jndi>${datasource.jndi}</jndi>
                                            <url>jdbc:postgresql://localhost:${datasource.port}/jiradb</url>
                                            <driver>org.postgresql.Driver</driver>
                                            <username>${datasource.username}</username>
                                            <password>${datasource.password}</password>
                                            <schema>public</schema>
                                            <defaultDatabase>jdbc:postgresql://localhost:${datasource.port}/postgres</defaultDatabase>
                                            <systemUsername>postgres</systemUsername>
                                            <systemPassword>postgres</systemPassword>
                                            <dumpFilePath>${project.build.directory}/classes/test-data.pgsql</dumpFilePath>
                                            <importMethod>Sql</importMethod>
                                            <type>postgres72</type>
                                        </dataSource>
                                    </dataSources>
                                </product>
                            </products>
                        </configuration>
                        <executions>
                            <execution>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>prepare-database</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>default-integration-tests</id>
                                <phase>integration-test</phase>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <!--
                Release profile should exclude running integration tests,
                since when releasing we've already tested the code elsewhere (in CI)
             -->
            <id>release-profile</id>
            <properties>
                <skipTests>true</skipTests>
            </properties>
        </profile>
    </profiles>

</project>
