<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>5.3.0-QR20240130120105</version>
        <relativePath>../../pom.xml</relativePath>
    </parent>

    <artifactId>crowd-sql-server-upgrade-test-runner</artifactId>
    <name>Atlassian Crowd - SQL Server Upgrade Test Runner</name>

    <properties>
        <sqlcmd.auth>${env.SQLCMD_AUTH}</sqlcmd.auth> <!-- Set to -U sa -P <password> -->
        <sqlcmd.binary>sqlcmd</sqlcmd.binary>
        <crowd.cargo.servlet.port>8095</crowd.cargo.servlet.port>
        <license.scope>test</license.scope>
    </properties>

    <!--
        An acceptance test to bring Crowd up against a SQL Server database with a 1.6
         schema and verify that the in-place upgrade succeeds.
     -->

    <dependencies>
        <!-- Test fundamentals -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>

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

        <!-- Crowd acceptance test framework -->
        <dependency>
            <groupId>com.atlassian.crowd</groupId>
            <artifactId>crowd-acceptance-test</artifactId>
            <version>${project.version}</version>
        </dependency>

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

        <!-- Running Crowd; these need to be compile scope for Cargo -->
        <dependency>
            <groupId>com.atlassian.crowd</groupId>
            <artifactId>crowd-web-app</artifactId>
            <type>war</type>
        </dependency>
        <dependency>
            <groupId>javax.transaction</groupId>
            <artifactId>jta</artifactId>
        </dependency>
        <dependency>
            <groupId>net.sourceforge.jtds</groupId>
            <artifactId>jtds</artifactId>
        </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>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>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
        </plugins>
    </build>

<profiles>
<profile>
    <id>sqlserver</id>

    <build>
        <plugins>
            <!-- Set up an empty SQL Server Crowd database -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>exec-sqlcmd-create-db</id>
                        <phase>pre-integration-test</phase>
                        <configuration>
                            <executable>${sqlcmd.binary}</executable>
                            <commandlineArgs>${sqlcmd.auth} -i src/test/sql/create-crowd-db.sql</commandlineArgs>
                        </configuration>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>exec-sqlcmd-create-db-tables</id>
                        <phase>pre-integration-test</phase>
                        <configuration>
                            <executable>${sqlcmd.binary}</executable>
                            <commandlineArgs>${sqlcmd.auth} -i src/test/sql/create-crowd-db-tables.sql</commandlineArgs>
                        </configuration>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <!-- Import a snapshot of 1.6.1 data -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>dbunit-maven-plugin</artifactId>
                <version>${dbunit-maven-plugin.version}</version>
                <configuration>
                    <driver>net.sourceforge.jtds.jdbc.Driver</driver>
                    <url>jdbc:jtds:sqlserver://localhost:1433/crowd-integration-test</url>
                    <!-- username and password are from create-crowd-db.sql -->
                    <username>crowdtestuser</username>
                    <password>test</password>
                    <dataTypeFactoryName>org.dbunit.ext.mssql.MsSqlDataTypeFactory</dataTypeFactoryName>
                    <escapePattern>[?]</escapePattern>
                    <transaction>true</transaction>
                    <ordered>true</ordered>
                </configuration>
                <executions>
                    <execution>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>operation</goal>
                        </goals>
                        <configuration>
                            <type>MSSQL_CLEAN_INSERT</type>
                            <src>src/test/dbunit/minimal-initial-1.6.1-data.xml</src>
                        </configuration>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>net.sourceforge.jtds</groupId>
                        <artifactId>jtds</artifactId>
                        <version>${jtds.version}</version>
                        <scope>runtime</scope>
                    </dependency>
                </dependencies>
            </plugin>

            <!-- Copy over a canned crowd-home -->
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.4.3</version>
                <executions>
                    <execution>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/crowd-home</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>src/test/crowd-home</directory>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- Launch Crowd in Tomcat -->
            <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>${crowd.cargo.goal}</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>stop-container</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>

                <configuration>
                    <container>
                        <timeout>1200000</timeout> <!-- Potentially a slow startup -->
                        <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>
                            <dependency>
                                <groupId>javax.transaction</groupId>
                                <artifactId>jta</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>javax.mail</groupId>
                                <artifactId>javax.mail-api</artifactId>
                            </dependency>
                            <dependency>
                                <groupId>com.sun.mail</groupId>
                                <artifactId>javax.mail</artifactId>
                            </dependency>
                            <dependency>
                                <groupId>net.sourceforge.jtds</groupId>
                                <artifactId>jtds</artifactId>
                            </dependency>
                        </dependencies>
                    </container>

                    <configuration>
                        <home>${project.build.directory}/${cargo.containerid}-crowd/container/</home>
                        <properties>
                            <cargo.servlet.port>${crowd.cargo.servlet.port}</cargo.servlet.port>
                            <cargo.jvmargs>-Xmx256m -Djava.awt.headless=true</cargo.jvmargs>
                        </properties>
                    </configuration>

                    <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/console/favicon.ico</pingURL>
                        </deployable>
                    </deployables>
                </configuration>
            </plugin>

            <!-- Run a simple test that ensures it came up cleanly -->
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <configuration>
                            <skip>false</skip>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</profile>
</profiles>

</project>
