<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">
    <parent>
        <groupId>com.atlassian.confluence.plugin</groupId>
        <artifactId>func-test-project</artifactId>
        <version>2.13.4</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <artifactId>func-test</artifactId>
    <packaging>jar</packaging>

    <name>Confluence Plugin Functional Test Library</name>

    <properties>
        <http.port>1990</http.port>
        <rmi.port>9899</rmi.port>
        <cargo.wait>false</cargo.wait>
        <selenium.skip>false</selenium.skip>
        <selenium.port>4444</selenium.port>
        <selenium.browser>*firefox</selenium.browser>
        <singleWindow>true</singleWindow>

        <maven.test.it.skip>${maven.test.skip}</maven.test.it.skip>
        <maven.test.unit.skip>${maven.test.skip}</maven.test.unit.skip>

        <tomcat.installer.url>
            https://maven.atlassian.com/content/groups/public/org/apache/tomcat/apache-tomcat/7.0.47/apache-tomcat-7.0.47-windows-x86.zip
        </tomcat.installer.url>

        <base.webapp.directory>${project.build.directory}</base.webapp.directory>

        <confluence.data.version>${confluence.version}</confluence.data.version>
        <confluence.http.port>${http.port}</confluence.http.port>
        <confluence.rmi.port>${rmi.port}</confluence.rmi.port>
        <confluence.wait>${cargo.wait}</confluence.wait>

        <jvmargs.debug.confluence />
        <jvm.args.custom />
        <jvm.args.xmx>1024m</jvm.args.xmx>
        <jvm.args>-Xmx${jvm.args.xmx} ${jvm.args.custom} ${jvmargs.debug.confluence}</jvm.args>
    </properties>

    <profiles>
        <profile>
            <id>plugin-debug</id>
            <build>
                <defaultGoal>verify</defaultGoal>
            </build>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <properties>
                <maven.test.skip>true</maven.test.skip>
                <base.webapp.directory>${project.build.directory}/debug</base.webapp.directory>
                <cargo.wait>true</cargo.wait>

                <jvmargs.debug.confluence>-Xdebug -Xnoagent -Xrunjdwp:server=y,transport=dt_socket,address=5005,suspend=n</jvmargs.debug.confluence>
            </properties>
        </profile>
        <profile>
            <id>jwebunit-tests-only</id>
            <properties>
                <selenium.browser>*firefox /import/tools/firefox/3.5/firefox-bin</selenium.browser>
                <selenium.skip>true</selenium.skip>
            </properties>

            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <skip>${maven.test.unit.skip}</skip>
                            <excludes>
                                <exclude>it/**/*</exclude>
                                <exclude>**/Abstract*</exclude>
                                <exclude>**/Mock*</exclude>
                                <exclude>**/*$*</exclude>
                            </excludes>
                        </configuration>
                        <executions>
                            <execution>
                                <id>acceptance_tests</id>
                                <phase>integration-test</phase>
                                <goals>
                                    <goal>test</goal>
                                </goals>
                                <configuration>
                                    <skip>${maven.test.it.skip}</skip>
                                    <excludes>
                                        <exclude>it/com/atlassian/confluence/plugin/functest/selenium/*</exclude>
                                        <exclude>**/Abstract*</exclude>
                                        <exclude>**/Mock*</exclude>
                                        <exclude>**/*$*</exclude>
                                    </excludes>
                                    <includes>
                                        <include>it/com/atlassian/confluence/plugin/functest/*</include>
                                    </includes>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>dchui-safari</id>
            <properties>
                <selenium.browser>*safari</selenium.browser>
            </properties>
        </profile>
    </profiles>

    <dependencies>
        <dependency>
            <groupId>com.atlassian.confluence</groupId>
            <artifactId>confluence</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>net.sourceforge.jwebunit</groupId>
            <artifactId>jwebunit-htmlunit-plugin</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium.client-drivers</groupId>
            <artifactId>selenium-java-client-driver</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>axis</groupId>
            <artifactId>axis</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>axis</groupId>
            <artifactId>axis-jaxrpc</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>axis</groupId>
            <artifactId>axis-saaj</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>net.sourceforge.cssparser</groupId>
            <artifactId>cssparser</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.eclipse.aether</groupId>
            <artifactId>aether-connector-basic</artifactId>
            <version>1.0.0.v20140518</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.aether</groupId>
            <artifactId>aether-transport-http</artifactId>
            <version>1.0.0.v20140518</version>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.httpcomponents</groupId>
                    <artifactId>httpclient</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-settings-builder</artifactId>
            <version>3.2.5</version>
        </dependency>
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-aether-provider</artifactId>
            <version>3.2.5</version>
        </dependency>
    </dependencies>

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>atlassian-plugin.xml</include>
                    <include>func-test.properties</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>false</filtering>
                <excludes>
                    <exclude>func-test.properties</exclude>
                    <exclude>atlassian-plugin.xml</exclude>
                    <exclude>webtester.properties.example</exclude>
                </excludes>
            </resource>
        </resources>

        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>axistools-maven-plugin</artifactId>
                <version>1.4</version>
                <configuration>
                    <urls>
                        <url>https://pug.jira-dev.com/wiki/plugins/servlet/soap-axis1/confluenceservice-v1?wsdl</url>
                    </urls>
                    <outputDirectory>src/main/java</outputDirectory>
                    <packageSpace>com.atlassian.confluence.plugin.functest.remote.soap.stub</packageSpace>
                    <testCases>false</testCases>
                    <serverSide>false</serverSide>
                    <subPackageByFileName>false</subPackageByFileName>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <skip>${maven.test.unit.skip}</skip>
                    <excludes>
                        <exclude>it/**/*</exclude>
                        <exclude>**/*Abstract*</exclude>
                        <exclude>**/*Mock*</exclude>
                        <exclude>**/*$*</exclude>
                    </excludes>
                    <systemProperties>
                        <property>
                            <name>com.atlassian.confluence.plugin.functest.selenium.port</name>
                            <value>${selenium.port}</value>
                        </property>
                    </systemProperties>
                </configuration>
                <executions>
                    <execution>
                        <id>acceptance_tests</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <configuration>
                            <skip>${maven.test.it.skip}</skip>
                            <excludes>
                                <exclude>none</exclude>
                                <exclude>**/*Abstract*</exclude>
                                <exclude>**/*Mock*</exclude>
                                <exclude>**/*$*</exclude>
                            </excludes>
                            <includes>
                                <include>it/**/*java</include>
                            </includes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.7</version>
                <executions>
                    <execution>
                        <id>generate-integration-test-config</id>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <phase>pre-integration-test</phase>
                        <configuration>
                            <tasks>
                                <mkdir dir="${project.build.directory}/test-classes" />

                                <taskdef name="propertyfile" classname="org.apache.tools.ant.taskdefs.optional.PropertyFile" classpathref="maven.plugin.classpath" />
                                <propertyfile file="${project.build.directory}/test-classes/webtester.properties" comment="Confluence plugin functional test configuration file">
                                    <entry key="confluence.auth.admin.username" value="admin" />
                                    <entry key="confluence.auth.admin.password" value="admin" />
                                    <entry key="confluence.webapp.protocol" value="http" />
                                    <entry key="confluence.webapp.host" value="localhost" />
                                    <entry key="confluence.webapp.port" value="${http.port}" />
                                    <entry key="confluence.webapp.context.path" value="/confluence" />
                                    <entry key="confluence.webapp.soap.path" value="/rpc/soap-axis/confluenceservice-v1?wsdl" />
                                    <entry key="confluence.plugin.jar" value="${project.build.directory}/${project.build.finalName}.jar" />
                                    <!--
                                    Indicate whether the plugin should be installed as as bundled plugin (something that will be done by Atlassian Test Harness).
                                    If this property is false, the plugin test lib will install the plugin, once per integration-test phase.
                                    -->
                                    <entry key="confluence.plugin.bundled" value="false" />
                                    <entry key="confluence.data.export" value="${basedir}/src/test/resources/confluence-demo-site.zip" />
                                    <entry key="maven.settings.localRepository" value="${settings.localRepository}" />
                                </propertyfile>
                            </tasks>
                        </configuration>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.ant</groupId>
                        <artifactId>ant-nodeps</artifactId>
                        <version>1.8.1</version>
                    </dependency>
                    <dependency>
                        <groupId>ant</groupId>
                        <artifactId>ant-optional</artifactId>
                        <version>1.5.2</version>
                    </dependency>
                </dependencies>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>selenium-maven-plugin</artifactId>
                <version>2.3</version>
                <executions>
                    <execution>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start-server</goal>
                        </goals>
                        <configuration>
                            <background>true</background>
                            <forcedBrowserMode>${selenium.browser}</forcedBrowserMode>
                            <port>${selenium.port}</port>
                            <skip>${selenium.skip}</skip>
                            <timeout>60000</timeout>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>com.atlassian.maven.plugins</groupId>
                <artifactId>maven-confluence-plugin</artifactId>
                <version>6.1.7</version>
                <configuration>
                    <containerId>tomcat7x</containerId>
                    <httpPort>${confluence.http.port}</httpPort>
                    <jvmArgs>${jvm.args}</jvmArgs>
                    <productVersion>${confluence.version}</productVersion>
                    <productDataVersion>${confluence.data.version}</productDataVersion>
                    <allowGoogleTracking>false</allowGoogleTracking>
                    <forceUpdateCheck>false</forceUpdateCheck>
                    <skipAmpsPomCheck>true</skipAmpsPomCheck>
                    <skipAllPrompts>true</skipAllPrompts>
                </configuration>
                <executions>
                    <execution>
                        <id>pre-integration-test</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <wait>${confluence.wait}</wait>
                        </configuration>
                    </execution>
                    <execution>
                        <id>post-integration-test</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
