<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.crowd</groupId>
        <artifactId>crowd-user-management</artifactId>
        <version>2.0</version>
    </parent>

    <artifactId>horde-user-management-test-runner</artifactId>
    <name>Atlassian Horde User Management Acceptance Test Runner Module</name>
    <packaging>pom</packaging>

    <dependencies>
        <dependency>
            <groupId>com.atlassian.crowd</groupId>
            <artifactId>horde-user-management-web-app</artifactId>
            <type>war</type>
        </dependency>

        <dependency>
            <groupId>com.atlassian.crowd</groupId>
            <artifactId>hsqldb-web-app</artifactId>
            <type>war</type>
        </dependency>

        <dependency>
            <groupId>com.atlassian.crowd</groupId>
            <artifactId>crowd-user-management-test-rest</artifactId>
            <version>${project.version}</version>
            <type>test-jar</type>
        </dependency>

        <dependency>
            <groupId>com.atlassian.crowd</groupId>
            <artifactId>horde-user-management-acceptance-tests</artifactId>
            <version>${project.version}</version>
        </dependency>

        <dependency>
            <groupId>hsqldb</groupId>
            <artifactId>hsqldb</artifactId>
            <!-- Needs to be compile at this point so cargo can access it, scope:test will not work -->
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>javax.transaction</groupId>
            <artifactId>jta</artifactId>
            <!-- Needs to be compile at this point so cargo can access it, scope:test will not work -->
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <!-- Needs to be compile at this point so cargo can access it, scope:test will not work -->
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>xml-apis</groupId>
            <artifactId>xml-apis</artifactId>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>com.atlassian.crowd</groupId>
            <artifactId>horde-acceptance-test</artifactId>
            <version>${crowd.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>com.atlassian.crowd</groupId>
                    <artifactId>crowd-rest-plugin</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.atlassian.crowd</groupId>
                    <artifactId>crowd-rest-application-management</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>com.atlassian.crowd</groupId>
            <artifactId>crowd-rest-plugin</artifactId>
            <version>${crowd.version}</version>
            <type>jar</type>
        </dependency>

        <dependency>
            <groupId>com.atlassian.crowd</groupId>
            <artifactId>crowd-rest-application-management</artifactId>
            <version>${crowd.version}</version>
            <type>jar</type>
        </dependency>


    </dependencies>

    <properties>
        <horde.home>${project.build.directory}/horde-home</horde.home>
        <acceptanceTestClassDirectory>${project.build.directory}/it-classes</acceptanceTestClassDirectory>

        <!-- Set to true (-Dcargo.wait=true) to make Cargo bring up the Crowd container and pause so you can figure
         out what you did wrong. -->
        <cargo.wait>false</cargo.wait>
        <cargo.pingTimeout>${cargo.timeout}</cargo.pingTimeout>

        <!-- please list ALL port configurations here -->
        <horde.cargo.servlet.port>8095</horde.cargo.servlet.port>
        <horde.cargo.rmi.port>8195</horde.cargo.rmi.port>
        <horde.cargo.debug /> <!-- set in the debug profile if activated -->
        <horde.local.environment /> <!-- set in the local-horde profile if activated -->
        <hsqldb.cargo.servlet.port>8096</hsqldb.cargo.servlet.port>
        <hsqldb.cargo.rmi.port>8196</hsqldb.cargo.rmi.port>
        <hsqldb.cargo.tomcat.ajp.port>8296</hsqldb.cargo.tomcat.ajp.port>  <!-- to avoid conflict for 8009 -->

        <horde.license.directory>${project.basedir}/src/test/resources</horde.license.directory>
        <horde.jdbc.username>sa</horde.jdbc.username>
        <horde.jdbc.password />
        <horde.jdbc.driver>org.hsqldb.jdbcDriver</horde.jdbc.driver>
        <horde.jdbc.url>jdbc:hsqldb:http://localhost:${hsqldb.cargo.servlet.port}/hsqldb/</horde.jdbc.url>
        <horde.hibernate.dialect>org.hibernate.dialect.HSQLDialect</horde.hibernate.dialect>
        <horde.hibernate.hbm2ddl.auto>validate</horde.hibernate.hbm2ddl.auto>
        <horde.product.application.password>qybhDMZh</horde.product.application.password>

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

    <profiles>
        <profile>
            <id>debug</id>
            <properties>
                <horde.cargo.debug>-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005</horde.cargo.debug>
            </properties>
        </profile>

        <profile>
            <id>local-horde</id>
            <properties>
                <horde.local.environment>
                    -Dhamlet.base.url=http://hamlet.dev6.intsys.atlassian.com
                    -Dhams.pricing.service.base.url=http://hams-pricing.dev6.intsys.atlassian.com
                    -Dadminchrome.servlet.path=/plugins/servlet/um
                    -Dadminchrome.context.path=/crowd
                    -Dhams.credentialsfile=${project.basedir}/tmp/hams-credentials.properties
                </horde.local.environment>
            </properties>
        </profile>

        <!-- Don't re-run the acceptance tests in release:perform -->
        <profile>
            <id>release</id>
            <properties>
                <skipTests>true</skipTests>
            </properties>
        </profile>
    </profiles>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unpack-func-tests</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>

                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>com.atlassian.crowd</groupId>
                                    <artifactId>horde-user-management-acceptance-tests</artifactId>
                                    <version>${project.version}</version>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>com.atlassian.crowd</groupId>
                                    <artifactId>horde-acceptance-test</artifactId>
                                    <version>${crowd.version}</version>
                                </artifactItem>
                            </artifactItems>

                            <outputDirectory>${acceptanceTestClassDirectory}</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.codehaus.cargo</groupId>
                <artifactId>cargo-maven2-plugin</artifactId>
                <executions>
                    <execution>
                        <id>start-hsql</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                        <configuration>
                            <container>
                                <output>${project.build.directory}/output-hsqldb.log</output>
                                <log>${project.build.directory}/cargo-hsqldb.log</log>
                                <dependencies>
                                    <dependency>
                                        <groupId>hsqldb</groupId>
                                        <artifactId>hsqldb</artifactId>
                                    </dependency>
                                </dependencies>
                            </container>
                            <configuration>
                                <home>${project.build.directory}/${cargo.containerid}-hsqldb/container</home>
                                <properties>
                                    <cargo.servlet.port>${hsqldb.cargo.servlet.port}</cargo.servlet.port>
                                    <cargo.rmi.port>${hsqldb.cargo.rmi.port}</cargo.rmi.port>
                                    <cargo.tomcat.ajp.port>${hsqldb.cargo.tomcat.ajp.port}</cargo.tomcat.ajp.port>
                                    <cargo.servlet.uriencoding>UTF-8</cargo.servlet.uriencoding>
                                    <cargo.jvmargs>
                                        -Djava.awt.headless=true
                                        <!-- For the initial population of the database. Will run HTI with this config -->
                                        -Dhorde.jdbc.url=${horde.jdbc.url}
                                        -Dhorde.jdbc.username=${horde.jdbc.username}
                                        -Dhorde.jdbc.password=${horde.jdbc.password}
                                        -Dhorde.jdbc.driver=${horde.jdbc.driver}
                                        -Dhorde.product.application.password=${horde.product.application.password}
                                        -Dhorde.init.xml=${acceptanceTestClassDirectory}/test-init.xml
                                    </cargo.jvmargs>
                                </properties>
                            </configuration>
                            <deployables>
                                <deployable>
                                    <groupId>com.atlassian.crowd</groupId>
                                    <artifactId>hsqldb-web-app</artifactId>
                                    <type>war</type>
                                    <properties>
                                        <context>hsqldb</context>
                                    </properties>
                                    <!-- This runs the horde tenant initialiser to put the db in correct state for schema
                                         validation by horde -->
                                    <pingURL>http://localhost:${hsqldb.cargo.servlet.port}/hsqldb/run-hti</pingURL>
                                </deployable>
                            </deployables>
                        </configuration>
                    </execution>

                    <execution>
                        <id>start-horde-container</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                        <configuration>
                            <wait>${cargo.wait}</wait>
                            <container>
                                <output>${project.build.directory}/output-horde.log</output>
                                <log>${project.build.directory}/cargo-horde.log</log>
                                <dependencies>
                                    <dependency>
                                        <groupId>hsqldb</groupId>
                                        <artifactId>hsqldb</artifactId>
                                    </dependency>
                                    <dependency>
                                        <groupId>javax.transaction</groupId>
                                        <artifactId>jta</artifactId>
                                    </dependency>
                                    <dependency>
                                        <groupId>javax.mail</groupId>
                                        <artifactId>mail</artifactId>
                                    </dependency>
                                </dependencies>
                            </container>
                            <configuration>
                                <home>${project.build.directory}/${cargo.containerid}-horde/container</home>
                                <properties>
                                    <cargo.servlet.port>${horde.cargo.servlet.port}</cargo.servlet.port>
                                    <cargo.rmi.port>${horde.cargo.rmi.port}</cargo.rmi.port>
                                    <cargo.servlet.uriencoding>UTF-8</cargo.servlet.uriencoding>
                                    <!-- keep the options as similar as possible to the ones of OD -->
                                    <cargo.jvmargs>
                                        ${horde.cargo.debug}
                                        ${horde.local.environment}
                                        -client
                                        -Xms2m
                                        -Xmx64m
                                        -XX:MaxPermSize=256m
                                        -Djava.awt.headless=true
                                        -Dhorde.jdbc.url=${horde.jdbc.url}
                                        -Dhorde.jdbc.username=${horde.jdbc.username}
                                        -Dhorde.jdbc.password=${horde.jdbc.password}
                                        -Dhorde.jdbc.driver=${horde.jdbc.driver}
                                        -Dhorde.hibernate.dialect=${horde.hibernate.dialect}
                                        -Dhorde.hibernate.hbm2ddl.auto=${horde.hibernate.hbm2ddl.auto}
                                        -Dhorde.ondemand.sysadmin.username=secondadmin
                                        -Dhorde.ondemand.directory.name="Directory One"
                                        -Dhorde.product.application.password=${horde.product.application.password}
                                        -Dhorde.client.base.url=http://localhost:${horde.cargo.servlet.port}
                                        -Dhorde.license.directory=${horde.license.directory}
                                        -Dappid=horde <!-- This is a dummy sysprop that is used by collectd to differentiate this process from the hsqldb web app -->
                                        -Danalytics.server=localhost:29876
                                    </cargo.jvmargs>
                                </properties>
                            </configuration>
                            <deployables>
                                <deployable>
                                    <groupId>com.atlassian.crowd</groupId>
                                    <artifactId>horde-user-management-web-app</artifactId>
                                    <type>war</type>
                                    <properties>
                                        <context>crowd</context>
                                    </properties>
                                    <pingURL>http://localhost:${horde.cargo.servlet.port}/crowd/?skipHealthCheck=true</pingURL>
                                    <pingTimeout>${cargo.pingTimeout}</pingTimeout>
                                </deployable>
                            </deployables>
                        </configuration>
                    </execution>

                    <execution>
                        <id>stop-horde-container</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                        <configuration>
                            <configuration>
                                <home>${project.build.directory}/${cargo.containerid}-horde/container</home>
                                <properties>
                                    <cargo.servlet.port>${horde.cargo.servlet.port}</cargo.servlet.port>
                                    <cargo.jvmargs>-Djava.awt.headless=true</cargo.jvmargs>
                                </properties>
                            </configuration>
                        </configuration>
                    </execution>

                    <execution>
                        <id>stop-hsqldb</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                        <configuration>
                            <configuration>
                                <home>${project.build.directory}/${cargo.containerid}-hsqldb/container</home>
                                <properties>
                                    <cargo.servlet.port>${hsqldb.cargo.servlet.port}</cargo.servlet.port>
                                    <cargo.jvmargs>-Djava.awt.headless=true</cargo.jvmargs>
                                </properties>
                            </configuration>
                        </configuration>
                    </execution>
                </executions>

            </plugin>

            <plugin>
                <!--
                Configure Surefire to run in the integration-test phase, but not in the
                 normal test phase.
                -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>

                <configuration>
                    <!-- skip unit tests -->
                    <skipTests>true</skipTests>
                    <systemProperties>
                        <property>
                            <name>acceptance.test.crowd.port</name>
                            <value>${horde.cargo.servlet.port}</value>
                        </property>
                        <property>
                            <name>horde.property.crowd.server.url</name>
                            <value>http://localhost:${horde.cargo.servlet.port}/crowd</value>
                        </property>
                        <property>
                            <name>horde.jdbc.url</name>
                            <value>${horde.jdbc.url}</value>
                        </property>
                        <property>
                            <name>horde.jdbc.username</name>
                            <value>${horde.jdbc.username}</value>
                        </property>
                        <property>
                            <name>horde.jdbc.password</name>
                            <value>${horde.jdbc.password}</value>
                        </property>
                        <property>
                            <name>horde.jdbc.driver</name>
                            <value>${horde.jdbc.driver}</value>
                        </property>
                        <property>
                            <name>horde.product.application.password</name>
                            <value>${horde.product.application.password}</value>
                        </property>
                        <property>
                            <name>horde.init.xml</name>
                            <value>${acceptanceTestClassDirectory}/test-init.xml</value>
                        </property>
                    </systemProperties>

                    <testClassesDirectory>${acceptanceTestClassDirectory}</testClassesDirectory>
                </configuration>

                <executions>

                    <!-- run Horde User Management REST API functional tests -->
                    <execution>
                        <id>test-horde</id>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <phase>integration-test</phase>
                        <configuration>
                            <includes>
                                <include>**/HordeUserManagementRestAcceptanceTestHarness.java</include>
                                <include>**/HordeUserManagementWebAcceptanceTestHarness.java</include>
                                <include>**/HordeRestAcceptanceTestHarness.java</include>

                            </includes>
                            <argLine>-Xmx256m</argLine>
                            <skipTests>${skipTests}</skipTests>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
