<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>atlassian-crowd</artifactId>
        <version>2.2.0-m7</version>
        <relativePath>../..</relativePath>
    </parent>

    <artifactId>crowd-bamboo-test-runner</artifactId>
    <name>Atlassian Crowd-Bamboo Test Runner Module</name>
    <packaging>pom</packaging>

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

        <dependency>
            <groupId>com.atlassian.crowd</groupId>
            <artifactId>crowdified-bamboo-webapp</artifactId>
            <version>${project.version}</version>
            <type>war</type>
        </dependency>

        <dependency>
            <groupId>com.atlassian.crowd</groupId>
            <artifactId>crowd-acceptance-test</artifactId>
            <version>${project.version}</version>
            <scope>compile</scope>
        </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>
        </dependency>

        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
        </dependency>

        <dependency>
            <groupId>net.sourceforge.jwebunit</groupId>
            <artifactId>jwebunit-core</artifactId>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>compile</scope>
        </dependency>

    </dependencies>

    <properties>
        <crowd.home>${project.build.directory}/crowd-home</crowd.home>
        <bamboo.home>${project.build.directory}/bamboo-home</bamboo.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>

        <!-- We are skipping by deault and explicitly setting this to true when we want to run this runner -->
        <maven.test.skip>true</maven.test.skip>

        <!-- please list ALL port configurations here -->
        <crowd.cargo.servlet.port>8095</crowd.cargo.servlet.port>
        <crowd.cargo.rmi.port>8195</crowd.cargo.rmi.port>
        <bamboo.cargo.servlet.port>8085</bamboo.cargo.servlet.port>
        <bamboo.cargo.rmi.port>8185</bamboo.cargo.rmi.port>

    </properties>


    <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>crowd-acceptance-test</artifactId>
                                    <version>${project.version}</version>
                                </artifactItem>
                            </artifactItems>

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

            <plugin>
                <groupId>org.codehaus.cargo</groupId>
                <artifactId>cargo-maven2-plugin</artifactId>
                <executions>
                    <!--Crowd Container (crowd web-app)-->
                    <execution>
                        <id>start-crowd-container</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                        <configuration>
                            <skip>${maven.test.skip}</skip>
                            <wait>false</wait>
                            <container>
                                <containerId>tomcat6x</containerId>
                                <zipUrlInstaller>
                                    <url>
                                        https://m2proxy.atlassian.com/repository/public/org/apache/tomcat/apache-tomcat/${tomcat.version}/apache-tomcat-${tomcat.version}.zip
                                    </url>
                                </zipUrlInstaller>
                                <timeout>120000</timeout>
                                <output>${project.build.directory}/output-crowd.log</output>
                                <log>${project.build.directory}/cargo-crowd.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}/tomcat6x-crowd/container</home>
                                <properties>
                                    <cargo.servlet.port>${crowd.cargo.servlet.port}</cargo.servlet.port>
                                    <cargo.rmi.port>${crowd.cargo.rmi.port}</cargo.rmi.port>
                                    <cargo.logging>high</cargo.logging>
                                    <cargo.jvmargs>-Xms128m -Xmx512m -XX:MaxPermSize=256m -Dcrowd.home=${crowd.home}</cargo.jvmargs>
                                </properties>
                                <deployables>
                                    <deployable>
                                        <groupId>com.atlassian.crowd</groupId>
                                        <artifactId>crowd-web-app</artifactId>
                                        <type>war</type>
                                        <properties>
                                            <context>crowd</context>
                                        </properties>
                                        <pingURL>http://localhost:${crowd.cargo.servlet.port}/crowd</pingURL>
                                        <pingTimeout>240000</pingTimeout>
                                    </deployable>
                                </deployables>
                            </configuration>
                        </configuration>
                    </execution>

                    <!-- Bamboo Container (bamboo web-app) -->
                    <execution>
                        <id>start-bamboo-container</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                        <configuration>
                            <skip>${maven.test.skip}</skip>
                            <wait>${cargo.wait}</wait>
                            <container>
                                <containerId>tomcat6x</containerId>
                                <zipUrlInstaller>
                                    <url>
                                        https://m2proxy.atlassian.com/repository/public/org/apache/tomcat/apache-tomcat/${tomcat.version}/apache-tomcat-${tomcat.version}.zip
                                    </url>
                                </zipUrlInstaller>
                                <timeout>120000</timeout>
                                <output>${project.build.directory}/output-bamboo.log</output>
                                <log>${project.build.directory}/cargo-bamboo.log</log>
                                <dependencies>
                                    <dependency>
                                        <groupId>hsqldb</groupId>
                                        <artifactId>hsqldb</artifactId>
                                    </dependency>
                                    <dependency>
                                        <groupId>javax.transaction</groupId>
                                        <artifactId>jta</artifactId>
                                    </dependency>
                                </dependencies>
                            </container>
                            <configuration>
                                <home>${project.build.directory}/tomcat6x-bamboo/container</home>
                                <properties>
                                    <cargo.servlet.port>${bamboo.cargo.servlet.port}</cargo.servlet.port>
                                    <cargo.rmi.port>${bamboo.cargo.rmi.port}</cargo.rmi.port>
                                    <cargo.logging>high</cargo.logging>
                                    <cargo.jvmargs>-Xms128m -Xmx512m -XX:MaxPermSize=256m -Dcrowd.properties=${acceptanceTestClassDirectory}/localtest.bamboo.properties -Dbamboo.home=${bamboo.home}</cargo.jvmargs>
                                    <!--<cargo.datasource.datasource>-->
                                        <!--cargo.datasource.url=jdbc:hsqldb:mem:bamboo_cargo|-->
                                        <!--cargo.datasource.driver=org.hsqldb.jdbcDriver|-->
                                        <!--cargo.datasource.username=sa|cargo.datasource.password=|-->
                                        <!--cargo.datasource.type=javax.sql.DataSource|-->
                                        <!--cargo.datasource.jndi=jdbc/BambooDS-->
                                    <!--</cargo.datasource.datasource>-->
                                </properties>
                                <deployables>
                                    <deployable>
                                        <groupId>com.atlassian.crowd</groupId>
                                        <artifactId>crowdified-bamboo-webapp</artifactId>
                                        <type>war</type>
                                        <properties>
                                            <context>bamboo</context>
                                        </properties>
                                        <pingURL>http://localhost:${bamboo.cargo.servlet.port}/bamboo</pingURL>
                                        <pingTimeout>240000</pingTimeout>
                                    </deployable>
                                </deployables>
                            </configuration>
                        </configuration>
                    </execution>

                </executions>

            </plugin>

        </plugins>

        <pluginManagement>
            <plugins>
                <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>

                        <argLine>-Xmx128m</argLine>

                        <systemProperties>
                            <property>
                                <name>crowd.home</name>
                                <value>${crowd.home}</value>
                            </property>
                        </systemProperties>

                    </configuration>

                    <executions>
                        <!-- first setup Crowd -->
                        <execution>
                            <id>setup-crowd</id>
                            <goals>
                                <goal>test</goal>
                            </goals>
                            <phase>integration-test</phase>
                            <configuration>
                                <includes>
                                    <include>**/SetupCrowdTest.java</include>
                                </includes>
                                <skip>${maven.test.skip}</skip>
                                <testClassesDirectory>${acceptanceTestClassDirectory}</testClassesDirectory>
                            </configuration>
                        </execution>

                        <!-- then setup bamboo -->
                        <execution>
                            <id>setup-bamboo</id>
                            <goals>
                                <goal>test</goal>
                            </goals>
                            <phase>integration-test</phase>
                            <configuration>
                                <includes>
                                    <include>**/SetupBambooTest.java</include>
                                </includes>
                                <skip>${maven.test.skip}</skip>
                                <testClassesDirectory>${acceptanceTestClassDirectory}</testClassesDirectory>
                            </configuration>
                        </execution>

                        <!-- then run the bamboo test suite -->
                        <execution>
                            <id>run-crowd-bamboo-tests</id>
                            <goals>
                                <goal>test</goal>
                            </goals>
                            <phase>integration-test</phase>
                            <configuration>
                                <includes>
                                    <include>**/BambooCrowdAcceptanceTestHarness.java</include>
                                </includes>
                                <skip>${maven.test.skip}</skip>
                                <testClassesDirectory>${acceptanceTestClassDirectory}</testClassesDirectory>
                            </configuration>
                        </execution>

                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>

