<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.bamboo</groupId>
    <artifactId>atlassian-bamboo</artifactId>
    <version>7.2.0-m337</version>
  </parent>

  <artifactId>atlassian-acceptance-test</artifactId>

  <packaging>jar</packaging>

  <name>Atlassian Bamboo Acceptance Test Module</name>

  <properties>
    <clover.distributed.coverage>OFF</clover.distributed.coverage>
    <installDir>${java.io.tmpdir}/cargo/installs</installDir>
    <serverPort>9087</serverPort>
    <brokerUri>nio://localhost:61610</brokerUri>
    <acceptanceTestSettings />
    <jdbc.databaseUrl />
    <bamboo.allowMutativeGetInStrictXsrfMode />
    <serverJvmArgs>
      ${bambooServerJvmArgs}
      ${addopens.spring}
      ${addopens.xstream}
      ${addopens.felix}
      -Dbamboo.allowMutativeGetInStrictXsrfMode=${bamboo.allowMutativeGetInStrictXsrfMode}
      -Dbamboo.request.profiling=true
      -DacceptanceTestSettings=${acceptanceTestSettings}
      -Dacceptance.test.db.connection.type=${acceptance.test.db.connection.type}
      -Dbamboo.darkfeature.triggers.on.environment.pages=true
      -Datlassian.darkfeature.bamboo.experimental.rest.admin.enabled=true
      -Datlassian.darkfeature.bamboo.sox.compliance.configurable=true
      -Datlassian.darkfeature.bamboo.improved.admin.panel.nav=true
      -Dbamboo.darkfeature.repository.dashboard=true
      -Dbamboo.test.performance.data.gathering.enabled=true
      ${profileServerJvmArgs}
    </serverJvmArgs>
    <surefireArgs>-Xmx512m -XX:+HeapDumpOnOutOfMemoryError -Dremote.agent.logs.directory=${project.build.directory}/RemoteAgentLogs</surefireArgs>

    <test.host>localhost</test.host>

    <db.host>${test.host}</db.host>
    <db.username>bamboo</db.username>
    <db.password>bamboo</db.password>
    <bamboo.builders.enabled>true</bamboo.builders.enabled>

    <jdbc.dataSourceName>jdbc/bambooDS</jdbc.dataSourceName>
    <acceptance.test.db.connection.type>JDBC</acceptance.test.db.connection.type>

    <license.scope>test</license.scope>

    <!--To keep IDEA happy, these will be overridden in specific profiles-->
    <profileServerJvmArgs />
    <jdbc.artifactGroup />
    <jdbc.artifactId />
    <jdbc.artifactVersion />
    <jdbc.driver />
    <jdbc.url />
    <db.admin.username />
    <db.admin.password />
    <bamboo.war.override />
    <maven.test.failure.ignore />
    <!-- otherwise TestNG runner will ignore exclude settings in suite XML files -->
    <maven.test.excludedGroups />
  </properties>

  <profiles>
    <profile>
      <id>functest</id>
      <properties>
        <testClassName>BambooAcceptanceTestHarness</testClassName>
        <artifactToDeploy>atlassian-bamboo-web-app</artifactToDeploy>
        <containerId>tomcat8x</containerId> <!-- This has to be a cargo profile, amps profiles won't work. -->
        <containerVersion>${tomcat8x.zip.version}</containerVersion>
        <brokerUri>nio://localhost:61620</brokerUri>

        <jdbc.artifactGroup>com.h2database</jdbc.artifactGroup>
        <jdbc.artifactId>h2</jdbc.artifactId>
        <jdbc.artifactVersion>${h2.version}</jdbc.artifactVersion>

        <testng.setup>testng-setup.xml</testng.setup>
        <testng.suites>testng-requires-clean.xml,testng-sequential.xml,testng-permissions.xml,testng-notification.xml,testng-notification2.xml,testng-svn.xml,testng-svn-noncore.xml,testng-svn-noncore2.xml,testng-repository.xml,testng-branches-and-multirepository.xml,testng-misc.xml,testng-config.xml,testng-dependencies.xml,testng-dependencies2.xml,testng-deployments.xml</testng.suites>

        <jdbc.url.xmlEscaped>${jdbc.url}</jdbc.url.xmlEscaped>
      </properties>

      <build>
        <testResources>
          <testResource>
            <directory>src/it/resources</directory>
          </testResource>
        </testResources>
        <plugins>

          <!-- Make sure that the /it/resources is picked up in the resources phase -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <executions>
              <execution>
                <goals>
                  <goal>testResources</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

          <plugin>
            <inherited>false</inherited>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
              <execution>
                <phase>post-integration-test</phase>
                <configuration>
                  <tasks>
                    <exec executable="wget" os="Linux">
                      <arg value="-p" />
                      <arg value="-k" />
                      <arg value="--quiet" />
                      <arg value="--no-host-directories" />
                      <arg value="--directory-prefix=target/PerformanceStats" />
                      <arg value="http://localhost:${serverPort}/bamboo/rest/backdoor/1.0/stats" />
                    </exec>
                    <move failonerror="false" file="target/PerformanceStats/bamboo/rest/backdoor/1.0/stats" tofile="target/PerformanceStats/stats.json" />
                  </tasks>
                </configuration>
                <goals>
                  <goal>run</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

          <!-- Cargo plugin definition-->
          <plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven2-plugin</artifactId>

            <!-- Default plugin definition for cargo maven plugin-->
            <configuration>
              <!-- Config the server to be started -->
              <container>
                <timeout>360000</timeout>
                <containerId>${containerId}</containerId>
                <output>output.log</output>
                <log>cargo-log.log</log>
                <systemProperties>
                  <bamboo.home>${project.build.directory}/bamboo-home</bamboo.home>
                  <bamboo.jms.broker.uri>${brokerUri}</bamboo.jms.broker.uri>
                  <clover.distributed.coverage>${clover.distributed.coverage}</clover.distributed.coverage>
                  <bamboo.builders.enabled>${bamboo.builders.enabled}</bamboo.builders.enabled>
                  <atlassian.bamboo.plugin.scan.directory>${project.build.directory}/additional-plugins</atlassian.bamboo.plugin.scan.directory>
                </systemProperties>
                <!--<home>${containerHome}</home>-->
                <artifactInstaller>
                  <groupId>org.apache.tomcat</groupId>
                  <artifactId>apache-tomcat</artifactId>
                  <version>${containerVersion}</version>
                  <extractDir>${installDir}</extractDir>
                </artifactInstaller>

                <dependencies>
                  <dependency>
                    <groupId>${jdbc.artifactGroup}</groupId>
                    <artifactId>${jdbc.artifactId}</artifactId>
                  </dependency>
                </dependencies>
              </container>

              <!-- Cargo config element -->
              <configuration>
                <home>${project.build.directory}/${containerId}/container</home>
                <properties>
                  <cargo.servlet.port>${serverPort}</cargo.servlet.port>
                  <cargo.tomcat.uriencoding>UTF-8</cargo.tomcat.uriencoding>
                  <cargo.rmi.port>10546</cargo.rmi.port>
                  <cargo.jvmargs>${serverJvmArgs}</cargo.jvmargs>
                  <cargo.logging>medium</cargo.logging>
                  <cargo.start.jvmargs>
                    -Xdebug
                    -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005
                    -Xnoagent
                  </cargo.start.jvmargs>

                  <cargo.datasource.datasource.bamboo>
                    cargo.datasource.driver=${jdbc.driver}|
                    cargo.datasource.url=${jdbc.url.xmlEscaped}|
                    cargo.datasource.jndi=${jdbc.dataSourceName}|
                    cargo.datasource.username=${db.username}|
                    cargo.datasource.password=${db.password}
                  </cargo.datasource.datasource.bamboo>

                </properties>
              </configuration>

              <deployables>
                <deployable>
                  <groupId>com.atlassian.bamboo</groupId>
                  <artifactId>${artifactToDeploy}</artifactId>
                  <location>${bamboo.war.override}</location>
                  <type>war</type>
                  <pingURL>http://localhost:${serverPort}/bamboo</pingURL>
                  <pingTimeout>360000</pingTimeout>
                  <properties>
                    <context>bamboo</context>
                  </properties>
                </deployable>
              </deployables>

            </configuration>
            <!-- END maven config element -->

            <executions>
              <execution>
                <id>start-container</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>start</goal>
                </goals>
              </execution>

              <execution>
                <id>stop-container</id>
                <phase>post-integration-test</phase>
                <goals>
                  <goal>stop</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

          <!-- Run the ${testClassName} as part of the test-->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <!--Those 2 executions will be run in order by maven so the same phase can be used-->
            <executions>
              <execution>
                <id>bambooSetupForFunctionalTests</id>
                <phase>integration-test</phase>
                <goals>
                  <goal>test</goal>
                </goals>
                <configuration>
                  <suiteXmlFiles>
                    <suiteXmlFile>${testng.setup}</suiteXmlFile>
                  </suiteXmlFiles>
                  <skip>false</skip>
                  <argLine>${surefireArgs}</argLine>
                  <systemPropertyVariables>
                    <acceptanceTestSettings>${acceptanceTestSettings}</acceptanceTestSettings>
                    <acceptance.test.db.jdbc.databaseUrl>${jdbc.databaseUrl}</acceptance.test.db.jdbc.databaseUrl>
                  </systemPropertyVariables>
                </configuration>
              </execution>
              <execution>
                <id>bambooFunctionalTests</id>
                <phase>integration-test</phase>
                <goals>
                  <goal>test</goal>
                </goals>
                <configuration>
                  <suiteXmlFiles>
                    <suiteXmlFile>${testng.suites}</suiteXmlFile>
                  </suiteXmlFiles>
                  <skip>false</skip>
                  <testFailureIgnore>${maven.test.failure.ignore}</testFailureIgnore>
                  <argLine>${surefireArgs}</argLine>
                  <systemPropertyVariables>
                    <clover.distributed.coverage>${clover.distributed.coverage}</clover.distributed.coverage>
                    <clover.server>true</clover.server>
                    <acceptance.test.webapp.port>${serverPort}</acceptance.test.webapp.port>
                    <acceptance.test.webapp.context>/bamboo</acceptance.test.webapp.context>
                    <acceptance.test.version>${project.version}</acceptance.test.version>
                    <bamboo.jms.broker.uri>${brokerUri}</bamboo.jms.broker.uri>
                  </systemPropertyVariables>
                </configuration>
              </execution>
            </executions>
            <configuration>
              <argLine>${surefireArgs}</argLine>
            </configuration>
          </plugin>

          <plugin>
            <artifactId>maven-clean-plugin</artifactId>
            <executions>
              <execution>
                <id>auto-clean</id>
                <phase>validate</phase>
                <goals>
                  <goal>clean</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          <!-- Copy the test-utils plugin jar to a known location -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
              <execution>
                <id>copy</id>
                <phase>package</phase>
                <goals>
                  <goal>copy</goal>
                </goals>
                <configuration>
                  <artifactItems>
                    <artifactItem>
                      <groupId>com.atlassian.bamboo.plugins</groupId>
                      <artifactId>atlassian-bamboo-plugin-test-utils</artifactId>
                      <version>${project.version}</version>
                      <type>jar</type>
                      <overWrite>true</overWrite>
                      <outputDirectory>${project.build.directory}/additional-plugins</outputDirectory>
                    </artifactItem>
                  </artifactItems>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>

      <dependencies>
        <dependency>
          <groupId>com.atlassian.bamboo.plugins</groupId>
          <artifactId>atlassian-bamboo-plugin-test-utils</artifactId>
          <scope>test</scope>
        </dependency>
        <dependency>
          <groupId>${jdbc.artifactGroup}</groupId>
          <artifactId>${jdbc.artifactId}</artifactId>
          <version>${jdbc.artifactVersion}</version>
          <scope>test</scope>
        </dependency>
      </dependencies>
    </profile>

    <profile>
      <id>remoteAgentFuncTest</id>
      <properties>
        <testng.suites>testng-remote.xml</testng.suites>
      </properties>

      <dependencies>
        <dependency>
          <groupId>com.atlassian.bamboo</groupId>
          <artifactId>bamboo-agent</artifactId>
          <version>${project.version}</version>
          <scope>test</scope>
        </dependency>
      </dependencies>
    </profile>

    <profile>
      <id>salIntegrationTest</id>
      <properties>
        <testng.suites>testng-sal.xml</testng.suites>
        <profileServerJvmArgs>-Datlassian.darkfeature.foo=true</profileServerJvmArgs>
      </properties>

      <dependencies>
        <dependency>
          <groupId>com.atlassian.bamboo</groupId>
          <artifactId>atlassian-bamboo-plugin-salintegrationtest</artifactId>
          <version>${project.version}</version>
          <scope>test</scope>
        </dependency>
      </dependencies>

      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
              <execution>
                <id>copy</id>
                <!--
                Couldn't use pre-integration-test phase as cargo:start/cargo:deploy is bound to the same phase and maven can decide
                to run cargo:deploy before copying these JARs. Reordering profiles in POM and in command line didn't help
                -->
                <phase>process-test-resources</phase>
                <goals>
                  <goal>copy</goal>
                </goals>
                <configuration>
                  <artifactItems>
                    <artifactItem>
                      <groupId>com.atlassian.bamboo</groupId>
                      <artifactId>atlassian-bamboo-plugin-salintegrationtest</artifactId>
                      <version>${project.version}</version>
                      <type>jar</type>
                      <overWrite>true</overWrite>
                      <outputDirectory>${project.build.directory}/bamboo-home/plugins/</outputDirectory>
                    </artifactItem>
                    <artifactItem>
                      <groupId>com.atlassian.platform</groupId>
                      <artifactId>ctk-plugin</artifactId>
                      <type>jar</type>
                      <overWrite>true</overWrite>
                      <outputDirectory>${project.build.directory}/bamboo-home/plugins/</outputDirectory>
                    </artifactItem>
                    <artifactItem>
                      <groupId>com.atlassian.functest</groupId>
                      <artifactId>functest-plugin</artifactId>
                      <version>${atlassian.functest.version}</version>
                      <type>jar</type>
                      <overWrite>true</overWrite>
                      <outputDirectory>${project.build.directory}/bamboo-home/plugins/</outputDirectory>
                    </artifactItem>
                    <artifactItem>
                      <groupId>com.atlassian.bamboo.plugins</groupId>
                      <artifactId>atlassian-bamboo-plugin-test-utils</artifactId>
                      <version>${project.version}</version>
                      <type>jar</type>
                      <overWrite>true</overWrite>
                      <outputDirectory>${project.build.directory}/additional-plugins</outputDirectory>
                    </artifactItem>
                  </artifactItems>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>


    <!-- Database profiles -->
    <profile>
      <id>mysql</id>

      <properties>
        <db.name>MySQL</db.name>
        <db.provider>${db.name}</db.provider>
        <db.host>mysql</db.host>
        <db.port>3306</db.port>
        <db.admin.username>root</db.admin.username>
        <db.admin.password>root</db.admin.password>
        <db.instance>bamboo_functest</db.instance>

        <jdbc.driver>com.mysql.jdbc.Driver</jdbc.driver>
        <dbms.url>jdbc:mysql://${db.host}:${db.port}</dbms.url>
        <jdbc.databaseUrl>${dbms.url}/${db.instance}?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=utf8&amp;useSSL=false&amp;allowPublicKeyRetrieval=true</jdbc.databaseUrl>
        <!-- double XML encoding... so awesome...-->
        <jdbc.url.xmlEscaped>${dbms.url}/${db.instance}?autoReconnect=true&amp;amp;useUnicode=true&amp;amp;characterEncoding=utf8&amp;amp;useSSL=false&amp;amp;allowPublicKeyRetrieval=true</jdbc.url.xmlEscaped>

        <db.dialect>org.hibernate.dialect.MySQL5InnoDBDialect</db.dialect>

        <jdbc.artifactGroup>mysql</jdbc.artifactGroup>
        <jdbc.artifactId>mysql-connector-java</jdbc.artifactId>
        <jdbc.artifactVersion>${mysql.driver.version}</jdbc.artifactVersion>

        <acceptanceTestSettings>db-mysql.properties</acceptanceTestSettings>
      </properties>

      <build>
        <plugins>
          <!-- Drop and recreate database -->
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>sql-maven-plugin</artifactId>

            <configuration>
              <username>${db.admin.username}</username>
              <password>${db.admin.password}</password>
              <url>${dbms.url}</url>
              <driver>${jdbc.driver}</driver>
            </configuration>

            <executions>
              <execution>
                <id>drop-database</id>
                <phase>process-test-resources</phase>

                <goals>
                  <goal>execute</goal>
                </goals>

                <configuration>
                  <autocommit>true</autocommit>
                  <sqlCommand>
                    DROP DATABASE `${db.instance}`;
                    DROP USER '${db.username}'@'${db.host}';
                  </sqlCommand>
                  <onError>continue</onError>
                </configuration>
              </execution>

              <execution>
                <id>create-database</id>
                <phase>process-test-resources</phase>

                <goals>
                  <goal>execute</goal>
                </goals>

                <configuration>
                  <autocommit>true</autocommit>
                  <sqlCommand>
                    CREATE DATABASE `${db.instance}` CHARACTER SET UTF8 COLLATE utf8_bin;
                    CREATE USER '${db.username}'@'${db.host}' IDENTIFIED BY '${db.password}';
                    GRANT ALL ON `${db.instance}`.* TO '${db.username}'@'${db.host}';
                  </sqlCommand>
                  <onError>abort</onError>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <id>mysql-ec2</id>
      <properties>
        <db.admin.username>root</db.admin.username>
        <db.admin.password />
      </properties>
    </profile>

    <profile>
      <id>pgsql</id>

      <properties>
        <db.name>PostgreSQL</db.name>
        <db.host>postgres</db.host>
        <db.port>5432</db.port>
        <db.instance>bamboo_functest</db.instance>
        <db.admin.username>postgres</db.admin.username>
        <db.admin.password>postgres</db.admin.password>

        <!-- used by maven-sql-plugin -->
        <dbms.url>jdbc:postgresql://${db.host}:${db.port}/postgres</dbms.url>
        <!-- used by Bamboo -->
        <jdbc.databaseUrl>jdbc:postgresql://${db.host}:${db.port}/${db.instance}</jdbc.databaseUrl>

        <db.dialect>org.hibernate.dialect.PostgreSQL82Dialect</db.dialect>

        <jdbc.artifactGroup>org.postgresql</jdbc.artifactGroup>
        <jdbc.artifactId>postgresql</jdbc.artifactId>
        <jdbc.artifactVersion>${postgresql.driver.version}</jdbc.artifactVersion>
        <jdbc.driver>org.postgresql.Driver</jdbc.driver>

        <acceptanceTestSettings>db-postgresql.properties</acceptanceTestSettings>
      </properties>

      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <executions>
              <execution>
                <id>integration-test</id>
                <phase>integration-test</phase>
                <goals>
                  <goal>integration-test</goal>
                </goals>
              </execution>
              <execution>
                <id>integration-test-verify</id>
                <phase>verify</phase>
                <goals>
                  <goal>verify</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

          <!-- Drop and recreate database -->
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>sql-maven-plugin</artifactId>

            <configuration>
              <username>${db.admin.username}</username>
              <password>${db.admin.password}</password>
              <url>${dbms.url}</url>
              <driver>${jdbc.driver}</driver>
            </configuration>

            <executions>
              <execution>
                <id>drop-database</id>
                <phase>process-test-resources</phase>

                <goals>
                  <goal>execute</goal>
                </goals>

                <configuration>
                  <autocommit>true</autocommit>
                  <sqlCommand>
                    DROP DATABASE IF EXISTS "${db.instance}";
                    DROP ROLE IF EXISTS "${db.username}";
                    CREATE ROLE "${db.username}" NOSUPERUSER NOCREATEDB NOCREATEROLE LOGIN ENCRYPTED PASSWORD '${db.password}';
                  </sqlCommand>
                  <onError>continue</onError>
                </configuration>
              </execution>

              <execution>
                <id>create-database</id>
                <phase>process-test-resources</phase>

                <goals>
                  <goal>execute</goal>
                </goals>

                <configuration>
                  <autocommit>true</autocommit>
                  <sqlCommand>
                    UPDATE pg_database SET datistemplate = FALSE WHERE datname = 'template1';
                    DROP DATABASE template1;
                    CREATE DATABASE template1 WITH template = template0 encoding = 'UTF8';
                    CREATE DATABASE "${db.instance}" WITH OWNER "${db.username}" ENCODING 'UTF8';
                  </sqlCommand>
                  <onError>abort</onError>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <id>pgsql-ec2</id>
      <properties>
        <db.admin.username>postgres</db.admin.username>
        <db.admin.password />
      </properties>
    </profile>

    <profile>
      <id>oracle</id>

      <properties>
        <db.name>Oracle</db.name>
        <db.port>1521</db.port>
        <db.instance>JIRADB</db.instance>
        <db.host>oracle</db.host>
        <db.admin.username>sys</db.admin.username>
        <db.admin.password>oracle</db.admin.password>

        <jdbc.databaseUrl>jdbc:oracle:thin:@${db.host}:${db.port}:${db.instance}</jdbc.databaseUrl>
        <dbms.url>${jdbc.databaseUrl}</dbms.url>

        <db.dialect>org.hibernate.dialect.Oracle12cDialect</db.dialect>

        <jdbc.artifactGroup>com.oracle</jdbc.artifactGroup>
        <jdbc.artifactId>ojdbc8-atlassian-hosted</jdbc.artifactId>
        <jdbc.artifactVersion>${oracle.driver.version}</jdbc.artifactVersion>
        <jdbc.driver>oracle.jdbc.OracleDriver</jdbc.driver>

        <acceptanceTestSettings>db-oracle12c.properties</acceptanceTestSettings>
      </properties>
    </profile>

    <profile>
      <id>mssql</id>
      <properties>
        <db.password>Ighu0jie</db.password> <!-- Windows policy requirements  -->
        <db.admin.username>sa</db.admin.username>
        <db.port>1433</db.port>

        <dbms.url>jdbc:sqlserver://${db.host}:${db.port}</dbms.url>
        <jdbc.databaseUrl>${dbms.url};databaseName=${db.instance}</jdbc.databaseUrl>

        <jdbc.artifactGroup>com.microsoft.sqlserver</jdbc.artifactGroup>
        <jdbc.artifactId>mssql-jdbc</jdbc.artifactId>
        <jdbc.artifactVersion>${sqlServer.driver.version}</jdbc.artifactVersion>
        <jdbc.driver>com.microsoft.sqlserver.jdbc.SQLServerDriver</jdbc.driver>

        <acceptanceTestSettings>db-mssql.properties</acceptanceTestSettings>
      </properties>
    </profile>

    <profile>
      <!--Generic Microsoft SQL Server-->
      <!--Used for DB started at separate EC2 instance-->
      <id>mssql-remote</id>

      <properties>
        <db.port>1433</db.port>

        <db.instance>${mssql.db.instance}</db.instance>

        <db.admin.username>sa</db.admin.username>
        <db.admin.password>sa</db.admin.password>
        <db.password>Ighu0jie</db.password> <!-- Windows policy requirements  -->

        <db.host>${mssql.db.host}</db.host>

        <sqlCreateDb>SELECT @@version; CREATE DATABASE "${db.instance}" CONTAINMENT = PARTIAL COLLATE Latin1_General_CS_AS;</sqlCreateDb>
        <sqlCreateUser>CREATE USER ${db.username} WITH PASSWORD = '${db.password}';</sqlCreateUser>
        <sqlDropUser />

        <dbms.url>jdbc:sqlserver://${db.host}:${db.port}</dbms.url>
        <jdbc.databaseUrl>${dbms.url};databaseName=${db.instance}</jdbc.databaseUrl>

        <jdbc.artifactGroup>com.microsoft.sqlserver</jdbc.artifactGroup>
        <jdbc.artifactId>mssql-jdbc</jdbc.artifactId>
        <jdbc.artifactVersion>${sqlServer.driver.version}</jdbc.artifactVersion>
        <jdbc.driver>com.microsoft.sqlserver.jdbc.SQLServerDriver</jdbc.driver>
      </properties>

      <build>
        <plugins>
          <!-- Drop and recreate database -->
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>sql-maven-plugin</artifactId>

            <dependencies>
              <dependency>
                <groupId>${jdbc.artifactGroup}</groupId>
                <artifactId>${jdbc.artifactId}</artifactId>
                <version>${jdbc.artifactVersion}</version>
                <scope>runtime</scope>
              </dependency>
            </dependencies>

            <configuration>
              <username>${db.admin.username}</username>
              <password>${db.admin.password}</password>
              <url>${dbms.url}</url>
              <driver>${jdbc.driver}</driver>
              <printResultSet>true</printResultSet>
            </configuration>

            <executions>
              <execution>
                <id>drop-database</id>
                <phase>clean</phase>
                <goals>
                  <goal>execute</goal>
                </goals>
                <configuration>
                  <sqlCommand>DROP DATABASE "${db.instance}"; ${sqlDropUser}</sqlCommand>
                  <onError>continue</onError>
                </configuration>
              </execution>

              <execution>
                <id>create-database</id>
                <!--<phase>process-test-resources</phase>-->
                <phase>clean</phase>
                <goals>
                  <goal>execute</goal>
                </goals>
                <configuration>
                  <sqlCommand>${sqlCreateDb}</sqlCommand>
                  <onError>abort</onError>
                </configuration>
              </execution>
              <execution>
                <id>post-create-database</id>
                <phase>clean</phase>
                <goals>
                  <goal>execute</goal>
                </goals>
                <configuration>
                  <sqlCommand>
                    ALTER DATABASE "${db.instance}" SET READ_COMMITTED_SNAPSHOT ON WITH ROLLBACK IMMEDIATE;
                    USE "${db.instance}";
                    ${sqlCreateUser}
                    EXEC sp_addrolemember 'db_owner', '${db.username}';
                  </sqlCommand>
                  <onError>abort</onError>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
    <!--used for DB started at Docker-->
    <!--see https://stash.atlassian.com/projects/JIRASERVER/repos/docker-files/browse/mssql2017 for credentials details-->
      <id>mssql-docker</id>
      <properties>
        <db.instance>bamboo</db.instance>
        <db.admin.password>Passw0rd</db.admin.password>

        <sqlCreateDb>SELECT @@version; CREATE DATABASE "${db.instance}" COLLATE Latin1_General_CS_AS;</sqlCreateDb>
        <sqlCreateUser>CREATE LOGIN ${db.username} WITH PASSWORD = '${db.password}', DEFAULT_DATABASE=master, CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF;</sqlCreateUser>
        <sqlDropUser />
      </properties>
      <build>
        <plugins>
          <!-- Drop and recreate database -->
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>sql-maven-plugin</artifactId>

            <configuration>
              <username>${db.admin.username}</username>
              <password>${db.admin.password}</password>
              <url>${dbms.url}</url>
              <driver>${jdbc.driver}</driver>
              <printResultSet>true</printResultSet>
            </configuration>
            <executions>
              <execution>
                <id>create-database</id>
                <phase>clean</phase>
                <goals>
                  <goal>execute</goal>
                </goals>
                <configuration>
                  <sqlCommand>${sqlCreateDb}</sqlCommand>
                  <onError>abort</onError>
                </configuration>
              </execution>
              <execution>
                <id>post-create-database</id>
                <phase>clean</phase>
                <goals>
                  <goal>execute</goal>
                </goals>
                <configuration>
                  <sqlCommand>
                    ALTER DATABASE "${db.instance}" SET READ_COMMITTED_SNAPSHOT ON WITH ROLLBACK IMMEDIATE;
                    ${sqlCreateUser}
                    USE "${db.instance}";
                    ALTER AUTHORIZATION ON DATABASE::${db.instance} TO ${db.username};
                  </sqlCommand>
                  <onError>abort</onError>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <id>resolveDeps</id>
      <dependencies>

        <!-- Module dependencies -->
        <dependency>
          <groupId>com.atlassian.bamboo</groupId>
          <artifactId>atlassian-bamboo-web-app</artifactId>
          <type>war</type>
        </dependency>

        <dependency>
          <groupId>com.atlassian.bamboo.plugins</groupId>
          <artifactId>atlassian-bamboo-plugin-clover</artifactId>
        </dependency>

        <dependency>
          <groupId>com.atlassian.bamboo.plugins</groupId>
          <artifactId>bamboo-plugin-oauth-service-provider-spi</artifactId>
        </dependency>

        <dependency>
          <groupId>com.atlassian.bamboo.plugins.maven</groupId>
          <artifactId>atlassian-bamboo-plugin-maven</artifactId>
        </dependency>

        <dependency>
          <groupId>com.atlassian.bamboo.plugins.ant</groupId>
          <artifactId>atlassian-bamboo-plugin-ant</artifactId>
        </dependency>

        <dependency>
          <groupId>com.atlassian.bamboo.plugins.testresultparser</groupId>
          <artifactId>atlassian-bamboo-plugin-testresultparser</artifactId>
        </dependency>

        <dependency>
          <groupId>com.atlassian.bamboo.plugins.scripttask</groupId>
          <artifactId>atlassian-bamboo-plugin-scripttask</artifactId>
        </dependency>

        <dependency>
          <groupId>com.atlassian.bamboo.plugins.php</groupId>
          <artifactId>atlassian-bamboo-plugin-php</artifactId>
        </dependency>

        <dependency>
          <groupId>com.atlassian.bamboo.plugins</groupId>
          <artifactId>atlassian-bamboo-plugin-rest</artifactId>
        </dependency>

        <dependency>
          <groupId>com.atlassian.bamboo.plugins.vcs</groupId>
          <artifactId>atlassian-bamboo-plugin-vcs</artifactId>
        </dependency>

        <dependency>
          <groupId>com.atlassian.bamboo.plugins</groupId>
          <artifactId>atlassian-bamboo-plugin-git</artifactId>
        </dependency>

        <!-- To hit the right URLs-->
        <dependency>
          <groupId>com.atlassian.bamboo</groupId>
          <artifactId>atlassian-bamboo-api</artifactId>
        </dependency>

        <!-- To reach default image AmiId -->
        <dependency>
          <groupId>com.atlassian.bamboo</groupId>
          <artifactId>atlassian-bamboo-agent-elastic-server</artifactId>
        </dependency>

      </dependencies>
    </profile>

    <profile>
      <id>tomcat8x</id>
      <properties>
        <containerId>tomcat8x</containerId>
        <containerVersion>${tomcat8x.zip.version}</containerVersion>
      </properties>
    </profile>

  </profiles>

  <dependencies>

    <!-- For the tests to be able to assert resource keys-->
    <dependency>
      <groupId>com.atlassian.bamboo</groupId>
      <artifactId>atlassian-bamboo-language</artifactId>
    </dependency>


    <!-- Atlassian dependencies -->
    <!-- To hit the right URLs-->
    <dependency>
      <groupId>com.atlassian.bamboo</groupId>
      <artifactId>atlassian-bamboo-api</artifactId>
    </dependency>
    <dependency>
      <groupId>com.atlassian.bamboo</groupId>
      <artifactId>atlassian-bamboo-core</artifactId>
    </dependency>
    <dependency>
      <groupId>com.atlassian.bamboo</groupId>
      <artifactId>atlassian-bamboo-maven-embedder</artifactId>
    </dependency>
    <dependency>
      <groupId>com.atlassian.bamboo</groupId>
      <artifactId>bamboo-specs-api</artifactId>
    </dependency>
    <dependency>
      <groupId>com.atlassian.bamboo</groupId>
      <artifactId>bamboo-specs</artifactId>
    </dependency>

    <dependency>
      <groupId>com.atlassian.bamboo</groupId>
      <artifactId>atlassian-bamboo-test-utils</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>com.atlassian.bamboo.plugins</groupId>
      <artifactId>atlassian-bamboo-plugin-git</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>com.atlassian.bamboo.plugins</groupId>
      <artifactId>atlassian-bamboo-plugin-mercurial</artifactId>
      <scope>test</scope>
      <exclusions>
        <!-- Embedded scanner 1.x libs erroneously violate enforce_spring_scanner_scope because they
             get dependency managed up to 2.x: shouldn't really be in test jar's transitives -->
        <exclusion>
          <groupId>com.atlassian.plugin</groupId>
          <artifactId>atlassian-spring-scanner-annotation</artifactId>
        </exclusion>
        <exclusion>
          <groupId>com.atlassian.plugin</groupId>
          <artifactId>atlassian-spring-scanner-runtime</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <!-- Other dependencies -->
    <dependency>
      <groupId>net.sourceforge.jwebunit</groupId>
      <artifactId>jwebunit-htmlunit-plugin</artifactId>
    </dependency>

    <dependency>
      <groupId>net.sourceforge.htmlunit</groupId>
      <artifactId>htmlunit</artifactId>
      <version>1.11-atlassian-13</version>
      <exclusions>
        <exclusion>
          <groupId>commons-logging</groupId>
          <artifactId>commons-logging</artifactId>
        </exclusion>
        <exclusion>
          <groupId>xalan</groupId>
          <artifactId>xalan</artifactId>
        </exclusion>
        <exclusion>
          <!-- renamed to org.mozilla:rhino-->
          <groupId>rhino</groupId>
          <artifactId>js</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <dependency>
      <groupId>com.atlassian.fusion</groupId>
      <artifactId>ctk-test-resources</artifactId>
    </dependency>

    <dependency>
      <!-- needed while htmlunit uses old name - rhino:js -->
      <groupId>org.mozilla</groupId>
      <artifactId>rhino</artifactId>
    </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
    </dependency>

    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>com.icegreen</groupId>
      <artifactId>greenmail</artifactId>
    </dependency>

    <dependency>
      <groupId>org.testng</groupId>
      <artifactId>testng</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.hamcrest</groupId>
      <artifactId>hamcrest-all</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>exml</groupId>
      <artifactId>exml</artifactId>
    </dependency>

    <dependency>
      <groupId>com.sun.jersey</groupId>
      <artifactId>jersey-client</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>com.google.code.gson</groupId>
      <artifactId>gson</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>com.atlassian.functest</groupId>
      <artifactId>functest-plugin</artifactId>
      <scope>provided</scope>
      <exclusions>
        <exclusion>
          <groupId>com.atlassian.selenium</groupId>
          <artifactId>atlassian-webdriver-core</artifactId>
        </exclusion>
        <exclusion>
          <groupId>org.seleniumhq.selenium</groupId>
          <artifactId>selenium</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <dependency>
      <groupId>com.atlassian.testtools</groupId>
      <artifactId>atlassian-testtools</artifactId>
      <scope>compile</scope>
      <exclusions>
        <exclusion>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>com.atlassian.platform</groupId>
      <artifactId>ctk-plugin</artifactId>
      <!-- This dependency offers a convenient way for developers to put a breakpoint.
           It is not directly used by the test classes, but this plugin is installed in Bamboo and
           CtkIntegrationTest calls it. It is not technically required here, this is just to
           be developer friendly. -->
    </dependency>

    <dependency>
      <groupId>com.atlassian.bamboo</groupId>
      <artifactId>atlassian-bamboo-rest-model</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>com.atlassian.bamboo</groupId>
      <artifactId>atlassian-bamboo-rest-common</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>io.rest-assured</groupId>
      <artifactId>rest-assured</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>com.atlassian.analytics</groupId>
      <artifactId>analytics-client-lib</artifactId>
      <version>${atlassian.analytics.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.atlassian.analytics</groupId>
      <artifactId>analytics-client-s3</artifactId>
      <version>${atlassian.analytics.version}</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.yaml</groupId>
      <artifactId>snakeyaml</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>

    <testResources>
      <testResource>
        <directory>src/it/resources</directory>
      </testResource>
      <testResource>
        <directory>src/test/resources</directory>
      </testResource>
    </testResources>

    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <skip>true</skip>
          <!-- If no profile specified, run no tests-->
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <executions>
          <execution>
            <id>test-compile</id>
            <phase>compile</phase>
            <goals>
              <goal>testCompile</goal>
            </goals>
            <configuration>
              <skip>false</skip>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <executions>
          <execution>
            <id>package-test-jar</id>
            <phase>package</phase>
            <goals>
              <goal>test-jar</goal>
            </goals>
            <configuration>
              <excludes>
                <exclude>**/*.key</exclude>
                <exclude>**/*.pub</exclude>
              </excludes>
              <skip>false</skip>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>sql-maven-plugin</artifactId>
      </plugin>
    </plugins>
    <testSourceDirectory>src/it/java</testSourceDirectory>
  </build>
</project>
