<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.atlassian.crowd</groupId>
        <artifactId>atlassian-crowd</artifactId>
        <version>5.3.6</version>
        <relativePath>../../pom.xml</relativePath>
    </parent>

    <artifactId>crowd-tomcat-encrypted-protocols-test</artifactId>

    <properties>
        <maven-resources-plugin.version>3.0.2</maven-resources-plugin.version>

        <tomcat.server.xml.path />
        <docker.httpd.skip>true</docker.httpd.skip>
        <apr.install.skip>true</apr.install.skip>
        <it.class />
    </properties>

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

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

        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>javax.mail-api</artifactId>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>com.sun.mail</groupId>
            <artifactId>javax.mail</artifactId>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>javax.activation</groupId>
            <artifactId>javax.activation-api</artifactId>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>com.sun.activation</groupId>
            <artifactId>javax.activation</artifactId>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>com.atlassian.db.config</groupId>
            <artifactId>password-cipher-base</artifactId>
            <version>${password.cipher.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.bouncycastle</groupId>
                    <artifactId>bcprov-jdk15on</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <scope>test</scope>
        </dependency>

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

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

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <profiles>
        <profile>
            <id>http-nio</id>
            <properties>
                <tomcat.server.xml.path>${project.build.testOutputDirectory}/tomcat/http/nio/server.xml</tomcat.server.xml.path>
                <it.class>HttpNioEncryptedProtocolTest.class</it.class>
            </properties>
        </profile>

        <profile>
            <id>http-nio2</id>
            <properties>
                <tomcat.server.xml.path>${project.build.testOutputDirectory}/tomcat/http/nio2/server.xml</tomcat.server.xml.path>
                <it.class>HttpNio2EncryptedProtocolTest.class</it.class>
            </properties>
        </profile>

        <profile>
            <id>http-apr</id>
            <properties>
                <tomcat.server.xml.path>${project.build.testOutputDirectory}/tomcat/http/apr/server.xml</tomcat.server.xml.path>
                <it.class>HttpAprEncryptedProtocolTest.class</it.class>
                <apr.install.skip>false</apr.install.skip>
            </properties>
        </profile>

        <profile>
            <id>ajp-nio</id>
            <properties>
                <tomcat.server.xml.path>${project.build.testOutputDirectory}/tomcat/ajp/nio/server.xml</tomcat.server.xml.path>
                <docker.skip>false</docker.skip>
                <docker.httpd.skip>false</docker.httpd.skip>
                <it.class>AjpNioEncryptedProtocolTest.class</it.class>
            </properties>
        </profile>

        <profile>
            <id>ajp-nio2</id>
            <properties>
                <tomcat.server.xml.path>${project.build.testOutputDirectory}/tomcat/ajp/nio2/server.xml</tomcat.server.xml.path>
                <docker.skip>false</docker.skip>
                <docker.httpd.skip>false</docker.httpd.skip>
                <it.class>AjpNio2EncryptedProtocolTest.class</it.class>
            </properties>
        </profile>

        <profile>
            <id>ajp-apr</id>
            <properties>
                <tomcat.server.xml.path>${project.build.testOutputDirectory}/tomcat/ajp/apr/server.xml</tomcat.server.xml.path>
                <docker.skip>false</docker.skip>
                <docker.httpd.skip>false</docker.httpd.skip>
                <it.class>AjpAprEncryptedProtocolTest.class</it.class>
                <apr.install.skip>false</apr.install.skip>
            </properties>
        </profile>

        <profile>
            <!-- launch Crowd with custom server.xml -->
            <id>server-with-custom-server-xml</id>
            <properties>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <!-- this is here to make sure it's executed before cargo in pre-integration-test -->
                        <artifactId>maven-resources-plugin</artifactId>
                        <version>${maven-resources-plugin.version}</version>
                        <executions>
                            <execution>
                                <id>copy-crowd-config-files</id>
                                <goals>
                                    <goal>copy-resources</goal>
                                </goals>
                                <phase>pre-integration-test</phase>
                                <configuration>
                                    <resources>
                                        <resource>
                                            <directory>${basedir}/../src/test/conf/crowd-hsql/common</directory>
                                        </resource>
                                        <resource>
                                            <directory>${basedir}/../src/test/conf/crowd-hsql/crowd1</directory>
                                            <filtering>true</filtering>
                                        </resource>
                                        <resource>
                                            <directory>${project.build.testOutputDirectory}/tomcat/secrets</directory>
                                            <targetPath>${crowd.home}/shared/keys/tomcat</targetPath>
                                        </resource>
                                    </resources>
                                    <outputDirectory>${crowd.home}</outputDirectory>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <artifactId>exec-maven-plugin</artifactId>
                        <groupId>org.codehaus.mojo</groupId>
                        <executions>
                            <execution>
                                <id>Install Apache Portable Runtime</id>
                                <phase>generate-sources</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                                <configuration>
                                    <executable>${project.basedir}/src/test/resources/scripts/install-apr.sh</executable>
                                </configuration>
                            </execution>
                        </executions>
                        <configuration>
                            <skip>${apr.install.skip}</skip>
                        </configuration>
                    </plugin>

                    <plugin>
                        <groupId>org.codehaus.cargo</groupId>
                        <artifactId>cargo-maven2-plugin</artifactId>
                        <executions>

                            <!-- Crowd Container (crowd web-app / security server) + Apache DS -->
                            <execution>
                                <id>start-crowd-container</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>${crowd.cargo.goal}</goal>
                                </goals>
                                <configuration>
                                    <container>
                                        <output>${project.build.directory}/output-crowd.log</output>
                                        <log>${project.build.directory}/cargo-crowd.log</log>
                                        <systemProperties>
                                            <crowd.username.header>true</crowd.username.header>
                                            <crowd.appname.header>true</crowd.appname.header>
                                        </systemProperties>
                                        <dependencies>
                                            <dependency>
                                                <groupId>org.hsqldb</groupId>
                                                <artifactId>hsqldb</artifactId>
                                                <classifier>jdk8</classifier>
                                            </dependency>
                                            <dependency>
                                                <groupId>javax.mail</groupId>
                                                <artifactId>javax.mail-api</artifactId>
                                            </dependency>
                                            <dependency>
                                                <groupId>com.sun.mail</groupId>
                                                <artifactId>javax.mail</artifactId>
                                            </dependency>
                                            <dependency>
                                                <groupId>javax.activation</groupId>
                                                <artifactId>javax.activation-api</artifactId>
                                            </dependency>
                                            <dependency>
                                                <groupId>com.sun.activation</groupId>
                                                <artifactId>javax.activation</artifactId>
                                            </dependency>
                                            <dependency>
                                                <groupId>com.atlassian.db.config</groupId>
                                                <artifactId>password-cipher-base</artifactId>
                                            </dependency>
                                            <dependency>
                                                <groupId>org.slf4j</groupId>
                                                <artifactId>slf4j-api</artifactId>
                                            </dependency>
                                        </dependencies>
                                    </container>
                                    <configuration>
                                        <home>${project.build.directory}/${cargo.containerid}-crowd/container</home>

                                        <configfiles>
                                            <configfile>
                                                <file>${tomcat.server.xml.path}</file>
                                                <todir>conf/</todir>
                                                <tofile>server.xml</tofile>
                                                <configfile>true</configfile>
                                                <overwrite>true</overwrite>
                                            </configfile>
                                        </configfiles>

                                        <properties>
                                            <!-- These must match the provided server.xml -->
                                            <cargo.servlet.port>8095</cargo.servlet.port>
                                            <cargo.rmi.port>8195</cargo.rmi.port>
                                            <cargo.tomcat.ajp.port>8009</cargo.tomcat.ajp.port>

                                            <cargo.jvmargs>-Xms128m -Xmx1024m -Dcrowd.home=${crowd.home}
                                                -Dcrowd.polling.startdelay=86400000 -Djava.awt.headless=true
                                                -Dcluster.node.name=buzz
                                                -Djava.library.path=/usr/lib/x86_64-linux-gnu/
                                            </cargo.jvmargs>
                                        </properties>
                                    </configuration>
                                    <deployables>
                                        <deployable>
                                            <groupId>com.atlassian.crowd</groupId>
                                            <artifactId>crowd-web-app</artifactId>
                                            <type>war</type>
                                            <properties>
                                                <context>crowd</context>
                                            </properties>
                                            <!-- ping a URL that is not Johnson-protected and returns HTTP 200 -->
                                            <pingURL>http://localhost:8095/crowd/console/favicon.ico
                                            </pingURL>
                                            <pingTimeout>${cargo.timeout}</pingTimeout>
                                        </deployable>
                                    </deployables>
                                </configuration>
                            </execution>

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

                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <configuration>
                            <images>
                                <image>
                                    <alias>httpd</alias>
                                    <name>httpd:2.4</name>
                                    <run>
                                        <skip>${docker.httpd.skip}</skip>
                                        <volumes>
                                            <bind>
                                                <volume>
                                                    ${project.build.testOutputDirectory}/tomcat/httpd.conf:/usr/local/apache2/conf/httpd.conf
                                                </volume>
                                            </bind>
                                        </volumes>
                                        <wait>
                                            <log>httpd -D FOREGROUND</log>
                                            <time>1200000</time>
                                        </wait>
                                        <log>
                                            <prefix>httpd</prefix>
                                        </log>
                                        <namingStrategy>alias</namingStrategy>
                                        <network>
                                            <mode>host</mode>
                                        </network>
                                    </run>
                                </image>
                            </images>
                        </configuration>
                        <executions>
                            <execution>
                                <id>start</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>start</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>stop</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>stop</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-failsafe-plugin</artifactId>

                        <executions>
                            <execution>
                                <id>test-tomcat-connectors</id>
                                <goals>
                                    <goal>integration-test</goal>
                                </goals>
                                <phase>integration-test</phase>
                                <configuration>
                                    <includes>
                                        <include>com/atlassian/crowd/acceptance/tests/tomcat/${it.class}</include>
                                    </includes>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>