<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.confluence.test</groupId>
        <artifactId>confluence-test-runner</artifactId>
        <version>6.14.0-m58</version>
    </parent>

    <artifactId>confluence-crowd-test</artifactId>
    <packaging>jar</packaging>

    <name>Confluence Crowd Acceptance Test Runner</name>
    <description>This module runs all acceptance tests against a Confluence instance configured with Crowd.
    </description>

    <build>
        <testSourceDirectory>src/it/java</testSourceDirectory>
        <testResources>
            <testResource>
                <directory>src/it/resources</directory>
                <filtering>true</filtering>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>com.atlassian.selenium</groupId>
            <artifactId>atlassian-webdriver-core</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian.selenium</groupId>
            <artifactId>atlassian-pageobjects-api</artifactId>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian.confluence</groupId>
            <artifactId>confluence-test-support</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.confluence</groupId>
            <artifactId>confluence-not-shippable</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <profiles>
        <profile>
            <id>crowd</id>
            <dependencies>
                <dependency>
                    <groupId>com.atlassian.confluence</groupId>
                    <artifactId>confluence-webapp</artifactId>
                    <version>${project.version}</version>
                    <type>war</type>
                </dependency>
                <dependency>
                    <groupId>com.atlassian.confluence</groupId>
                    <artifactId>confluence-acceptance-test</artifactId>
                    <scope>test</scope>
                </dependency>
                <dependency>
                    <groupId>com.atlassian.crowd</groupId>
                    <artifactId>crowd-web-app</artifactId>
                    <version>${crowd.webapp.version}</version>
                    <type>war</type>
                </dependency>
                <!-- These are runtime dependencies of crowd, so they aren't supplied automatically. -->
                <dependency>
                    <groupId>javax.transaction</groupId>
                    <artifactId>javax.transaction-api</artifactId>
                </dependency>
                <dependency>
                    <groupId>javax.mail</groupId>
                    <artifactId>mail</artifactId>
                </dependency>
                <dependency>
                    <groupId>org.hsqldb</groupId>
                    <artifactId>hsqldb</artifactId>
                    <!-- override the version of hsqldb supplied by confluence due
                         to this bug: https://jira.atlassian.com/browse/CWD-3769 -->
                    <version>1.8.0.10</version>
                </dependency>
            </dependencies>

            <build>
                <plugins>
                    <plugin>
                        <!--
                        Use the dependency plugin to
                         - extract the Confluence acceptance tests
                           into the test output directory for running with the Crowd-specific tests
                         - extract the Crowd web app so that its properties can be changed.
                        -->
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>unpack-crowd-war</id>
                                <phase>generate-test-resources</phase>
                                <goals>
                                    <goal>unpack</goal>
                                </goals>
                                <configuration>
                                    <artifactItems>
                                        <artifactItem>
                                            <groupId>com.atlassian.crowd</groupId>
                                            <artifactId>crowd-web-app</artifactId>
                                            <!-- hopefully figured out from dependency?  -->
                                            <type>war</type>
                                        </artifactItem>
                                    </artifactItems>
                                    <outputDirectory>${project.build.testOutputDirectory}/crowd-webapp-unpacked
                                    </outputDirectory>
                                </configuration>
                            </execution>
                            <execution>
                                <id>unpack-confluence-war</id>
                                <phase>generate-test-resources</phase>
                                <goals>
                                    <goal>unpack-dependencies</goal>
                                </goals>
                                <configuration>
                                    <includeArtifactIds>confluence-webapp</includeArtifactIds>
                                    <outputDirectory>${project.build.testOutputDirectory}/confluence-webapp-unpacked
                                    </outputDirectory>
                                </configuration>
                            </execution>
                         </executions>
                    </plugin>
                    <plugin>
                        <!--
                        Configure Failsafe to run in the integration-test phase, but not in the
                         normal test phase.
                        -->
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <configuration>
                            <!-- skip unit tests -->
                            <skip>true</skip>
                            <systemPropertyVariables combine.children="append">
                                <crowd.url>${crowd.url}</crowd.url>
                                <crowd.confluence.application.name>${crowd.confluence.application.name}</crowd.confluence.application.name>
                                <crowd.confluence.application.password>${crowd.confluence.application.password}</crowd.confluence.application.password>
                                <crowdMode>true</crowdMode>
                                <ldapMode>${ldapMode}</ldapMode>
                            </systemPropertyVariables>
                        </configuration>
                        <executions>
                            <execution>
                                <id>setup-crowd</id>
                                <phase>integration-test</phase>
                                <goals>
                                    <goal>integration-test</goal>
                                    <goal>verify</goal>
                                </goals>
                                <configuration>
                                    <includes>
                                        <include>**/SetupCrowdTest.java</include>
                                    </includes>
                                    <skip>false</skip>
                                </configuration>
                            </execution>
                            <execution>
                                <id>confluence-setup-inside-crowd</id>
                                <phase>integration-test</phase>
                                <goals>
                                    <goal>integration-test</goal>
                                    <goal>verify</goal>
                                </goals>
                                <configuration>
                                    <includes>
                                        <include>**/SetupConfluenceInsideCrowd.java</include>
                                    </includes>
                                    <skip>false</skip>
                                </configuration>
                            </execution>
                            <execution>
                                <id>confluence-setup-sso-inside-crowd</id>
                                <phase>integration-test</phase>
                                <goals>
                                    <goal>integration-test</goal>
                                    <goal>verify</goal>
                                </goals>
                                <configuration>
                                    <includes>
                                        <include>**/SetupConfluenceSSOInsideCrowd.java</include>
                                    </includes>
                                    <skip>false</skip>
                                </configuration>
                            </execution>
                            <!-- clone of 00_setup in confluence-test-runner, because we can't inject new tasks to run before those otherwise -->
                            <execution>
                                <id>setup-confluence</id>
                                <phase>integration-test</phase>
                                <goals>
                                    <goal>integration-test</goal>
                                    <goal>verify</goal>
                                </goals>
                                <configuration>
                                    <skip>false</skip>
                                    <includes>
                                        <include>com/atlassian/confluence/setup/SetupAcceptanceTest.java</include>
                                    </includes>
                                </configuration>
                            </execution>
                            <execution>
                                <id>run_startup_error_test</id>
                                <phase>integration-test</phase>
                                <goals>
                                    <goal>integration-test</goal>
                                    <goal>verify</goal>
                                </goals>
                                <configuration>
                                    <skip>true</skip>
                                    <argLine>${surefire.argLine}</argLine>
                                    <includes>
                                        <!-- We always want to run certain "integrity" tests in every job -->
                                        <include>com/atlassian/confluence/setup/StartupErrorTest.java</include>
                                    </includes>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.codehaus.cargo</groupId>
                        <artifactId>cargo-maven2-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>start-crowd-container</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>start</goal>
                                </goals>
                                <configuration>
                                    <container>
                                        <containerId>${crowd.cargo.containerId}</containerId>
                                        <artifactInstaller>
                                            <groupId>org.apache.tomcat</groupId>
                                            <artifactId>${crowd.tomcat.artifactId}</artifactId>
                                            <version>${crowd.tomcat.version}</version>
                                            <classifier>${crowd.tomcat.classifier}</classifier>
                                            <extractDir>${cargo.container.zipurlinstaller.installdir}</extractDir>
                                        </artifactInstaller>
                                        <timeout>${cargo.timeout}</timeout>
                                        <output>${project.build.directory}/output-crowd.log</output>
                                        <log>${project.build.directory}/cargo-crowd.log</log>
                                        <systemProperties>
                                            <crowd.home>${project.build.directory}/crowd-home</crowd.home>
                                        </systemProperties>
                                        <dependencies>
                                            <!-- These 4 are runtime dependencies of crowd,
                                                 so they aren't supplied automatically. -->
                                            <dependency>
                                                <groupId>org.hsqldb</groupId>
                                                <artifactId>hsqldb</artifactId>
                                            </dependency>
                                            <dependency>
                                                <groupId>javax.transaction</groupId>
                                                <artifactId>javax.transaction-api</artifactId>
                                            </dependency>
                                            <dependency>
                                                <groupId>javax.mail</groupId>
                                                <artifactId>mail</artifactId>
                                            </dependency>
                                        </dependencies>
                                    </container>
                                    <configuration>
                                        <home>${project.build.directory}/${crowd.cargo.containerId}-crowd/container</home>
                                        <properties>
                                            <cargo.servlet.port>${cargo.crowd.servlet.port}</cargo.servlet.port>
                                            <cargo.tomcat.uriencoding>UTF-8</cargo.tomcat.uriencoding>
                                            <cargo.rmi.port>${cargo.crowd.rmi.port}</cargo.rmi.port>
                                            <cargo.tomcat.ajp.port>${cargo.crowd.ajp.port}</cargo.tomcat.ajp.port>
                                            <cargo.jvmargs>-XX:MaxPermSize=128M -Djava.awt.headless=true -Xmx256m</cargo.jvmargs>
                                            <cargo.datasource.datasource>
                                                cargo.datasource.url=jdbc:hsqldb:${project.build.directory}/database/crowddb|
                                                cargo.datasource.driver=org.hsqldb.jdbcDriver|
                                                cargo.datasource.username=sa|
                                                cargo.datasource.password=|
                                                cargo.datasource.jndi=jdbc/CrowdDS
                                            </cargo.datasource.datasource>
                                        </properties>
                                    </configuration>
                                    <deployables>
                                        <deployable>
                                            <groupId>com.atlassian.crowd</groupId>
                                            <artifactId>crowd-web-app</artifactId>
                                            <type>war</type>
                                            <properties>
                                                <context>crowd</context>
                                            </properties>
                                            <location>${project.build.testOutputDirectory}/crowd-webapp-unpacked
                                            </location>
                                            <pingURL>http://localhost:${cargo.crowd.servlet.port}/crowd</pingURL>
                                            <pingTimeout>240000</pingTimeout>
                                        </deployable>
                                    </deployables>
                                </configuration>
                            </execution>
                            <execution>
                                <id>start-confluence-container</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>${cargo.goal}</goal>
                                </goals>
                                <configuration>
                                    <container>
                                        <containerId>${cargo.containerId}</containerId>
                                        <artifactInstaller>
                                            <groupId>org.apache.tomcat</groupId>
                                            <artifactId>${crowd.tomcat.artifactId}</artifactId>
                                            <version>${crowd.tomcat.version}</version>
                                            <classifier>${crowd.tomcat.classifier}</classifier>
                                            <extractDir>${cargo.container.zipurlinstaller.installdir}</extractDir>
                                        </artifactInstaller>
                                        <timeout>120000</timeout>
                                        <output>${project.build.directory}/output-confluence.log</output>
                                        <log>${project.build.directory}/cargo-confluence.log</log>
                                        <systemProperties>
                                            <confluence.home>${project.build.directory}/confluence-home</confluence.home>
                                            <upm.pac.disable>true</upm.pac.disable>
                                            <confluence.browser.language.enabled>${languageoverride}</confluence.browser.language.enabled>
                                            <LogMessageRecordingAppender.enabled>${record.startup.errors}</LogMessageRecordingAppender.enabled>
                                            <!--
                                            when running tests, we set the event dispatch thread size to 1, which can sometimes fail
                                            to handle the large number of events in tests. Set the queue size appropriately large to
                                            make sure events eventually finish
                                            -->
                                            <atlassian.event.thread_pool_configuration.queue_size>2048</atlassian.event.thread_pool_configuration.queue_size>
                                        </systemProperties>
                                    </container>
                                    <configuration>
                                        <home>${project.build.directory}/${cargo.containerId}-confluence/container</home>
                                        <properties>
                                            <cargo.servlet.port>${http.port}</cargo.servlet.port>
                                            <cargo.tomcat.uriencoding>UTF-8</cargo.tomcat.uriencoding>
                                            <cargo.rmi.port>${controller.port}</cargo.rmi.port>
                                            <cargo.tomcat.ajp.port>${ajp.port}</cargo.tomcat.ajp.port>
                                            <cargo.jvmargs>${jvm.args}</cargo.jvmargs>
                                        </properties>
                                    </configuration>
                                    <deployables>
                                        <deployable>
                                            <groupId>com.atlassian.confluence</groupId>
                                            <artifactId>confluence-webapp</artifactId>
                                            <type>war</type>
                                            <properties>
                                                <context>${webappContext}</context>
                                            </properties>
                                            <location>
                                                ${project.build.testOutputDirectory}/confluence-webapp-unpacked
                                            </location>
                                            <pingURL>http://localhost:${http.port}/${webappContext}</pingURL>
                                            <pingTimeout>240000</pingTimeout>
                                        </deployable>
                                    </deployables>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <!-- activates the maven clean plugin configuration from the parent -->
                        <artifactId>maven-clean-plugin</artifactId>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>crowd-standard-test</id>
            <build>
                <plugins>
                    <plugin>
                        <!--
                        Configure Failsafe to run in the integration-test phase, but not in the
                         normal test phase.
                        -->
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <executions>
                            <!-- clone of 50_acceptance_tests in confluence-test-runner, because we can't inject new tasks to run before those otherwise -->
                            <execution>
                                <id>test-confluence</id>
                                <phase>integration-test</phase>
                                <goals>
                                    <goal>integration-test</goal>
                                    <goal>verify</goal>
                                </goals>
                                <configuration>
                                    <skip>false</skip>
                                    <argLine>${surefire.argLine}</argLine>
                                    <includes>
                                        <include>com/atlassian/confluence/harnesses/StandardAcceptanceTestBatch.java</include>
                                        <include>com/atlassian/confluence/harnesses/PluginExportedRestTestBatch.java</include>
                                    </includes>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>crowd-sso</id>
            <properties>
                <ldapMode>CROWD_SSO</ldapMode>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-resources-plugin</artifactId>
                        <version>2.6</version>
                        <executions>
                            <execution>
                                <id>copy-crowd-sso-resources</id>
                                <phase>process-test-resources</phase>
                                <goals>
                                    <goal>copy-resources</goal>
                                </goals>
                                <configuration>
                                    <outputDirectory>${project.build.testOutputDirectory}/confluence-webapp-unpacked/WEB-INF/classes</outputDirectory>
                                    <resources>
                                        <resource>
                                            <directory>${project.basedir}/src/it/resources/</directory>
                                            <filtering>true</filtering>
                                            <includes>
                                                <include>seraph-config.xml</include>
                                                <include>crowd.properties</include>
                                            </includes>
                                        </resource>
                                    </resources>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <!--
                        Configure Failsafe to run in the integration-test phase, but not in the
                         normal test phase.
                        -->
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <executions>
                            <!-- clone of 50_acceptance_tests in confluence-test-runner, because we can't inject new tasks to run before those otherwise -->
                            <execution>
                                <id>test-confluence</id>
                                <phase>integration-test</phase>
                                <goals>
                                    <goal>integration-test</goal>
                                    <goal>verify</goal>
                                </goals>
                                <configuration>
                                    <skip>false</skip>
                                    <argLine>${surefire.argLine}</argLine>
                                    <includes>
                                        <include>**/TestConfluenceCrowdSSO.java</include>
                                    </includes>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>cargo-run</id>
            <properties>
                <cargo.goal>run</cargo.goal>
            </properties>
        </profile>
    </profiles>

    <properties>
        <!-- URLs & ports -->
        <cargo.crowd.servlet.port>${http.port2}</cargo.crowd.servlet.port>
        <cargo.crowd.rmi.port>${controller.port2}</cargo.crowd.rmi.port>
        <cargo.crowd.ajp.port>${ajp.port2}</cargo.crowd.ajp.port>
        <crowd.url>http://localhost:${cargo.crowd.servlet.port}/crowd</crowd.url>

        <!-- Crowd configuration -->
        <ldapMode>CROWD</ldapMode>
        <crowd.webapp.version>${crowd.version}</crowd.webapp.version>
        <crowd.confluence.application.name>confluence</crowd.confluence.application.name>
        <crowd.confluence.application.password>password</crowd.confluence.application.password>

        <cargo.goal>start</cargo.goal>
        <unpack.stuff>true</unpack.stuff>
    </properties>
</project>

