<?xml version='1.0' encoding='UTF-8'?>

<!--
  ~ Licensed to the Apache Software Foundation (ASF) under one
  ~ or more contributor license agreements.  See the NOTICE file
  ~ distributed with this work for additional information
  ~ regarding copyright ownership.  The ASF licenses this file
  ~ to you under the Apache License, Version 2.0 (the
  ~ "License"); you may not use this file except in compliance
  ~ with the License.  You may obtain a copy of the License at
  ~
  ~   http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing,
  ~ software distributed under the License is distributed on an
  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  ~ KIND, either express or implied.  See the License for the
  ~ specific language governing permissions and limitations
  ~ under the License.
  -->

<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>org.apache.continuum</groupId>
    <artifactId>continuum</artifactId>
    <version>1.5-SNAPSHOT</version>
  </parent>
  <artifactId>continuum-webapp-test</artifactId>
  <name>Continuum :: Webapp Tests</name>
  <packaging>pom</packaging>

  <build>
    <testSourceDirectory>src/test/testng</testSourceDirectory>
    <testResources>
      <testResource>
        <directory>src/test/resources</directory>
        <filtering>true</filtering>
        <includes>
          <include>**/*</include>
        </includes>
      </testResource>
    </testResources>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>testCompile</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.5</version>
        <executions>
          <execution>
            <goals>
              <goal>testResources</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.3</version>
        <executions>
          <execution>
            <phase>generate-resources</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <tasks>
                <copy todir="${project.build.directory}" overwrite="true">
                  <filterchain>
                    <expandproperties />
                  </filterchain>
                  <fileset dir="src/appserver-base"/>
                </copy>
                <delete dir="${project.build.directory}/example-svn"/>
                <copy todir="${project.build.directory}/example-svn">
                  <fileset dir="src/test/example-svn"/>
                </copy>
                <!-- This doesn't work, SVN doesn't like the file:/ URL it gives
                <makeurl file="${project.build.directory}/example-svn" property="svn.base.url"/>
                -->
                <path id="svn.repo.dir">
                  <pathelement location="${project.build.directory}/example-svn"/>
                </path>
                <pathconvert refid="svn.repo.dir" targetos="unix" property="svn.base.url"/>
                <echo file="${project.build.directory}/filter.properties">
                  svn.base.url=file://localhost${svn.base.url}
                  continuum.port=${continuum.port}
                  baseUrl=${baseUrl}
                </echo>
              </tasks>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>properties-maven-plugin</artifactId>
        <version>1.0-alpha-2</version>
        <executions>
          <execution>
            <phase>generate-resources</phase>
            <goals>
              <goal>read-project-properties</goal>
            </goals>
            <configuration>
              <files>
                <file>${project.build.directory}/filter.properties</file>
              </files>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>selenium-maven-plugin</artifactId>
        <version>2.3</version>
        <executions>
          <execution>
            <id>start-selenium</id>
            <phase>pre-integration-test</phase>
            <goals>
              <goal>start-server</goal>
            </goals>
          </execution>
          <execution>
            <id>stop-selenium</id>
            <phase>post-integration-test</phase>
            <goals>
              <goal>stop-server</goal>
            </goals>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-server</artifactId>
            <version>${selenium.version}</version>
          </dependency>
          <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-remote-driver</artifactId>
            <version>${selenium.version}</version>
          </dependency>
          <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-api</artifactId>
            <version>${selenium.version}</version>
          </dependency>
        </dependencies>
      </plugin>
      <plugin>
        <groupId>org.codehaus.cargo</groupId>
        <artifactId>cargo-maven2-plugin</artifactId>
        <version>1.2.3</version>
        <configuration>
          <container>
            <containerId>${container.name}</containerId>
            <log>${project.build.directory}/logs/${container.name}.log</log>
            <output>${project.build.directory}/logs/${container.name}.out</output>
            <timeout>180000</timeout>
            <systemProperties>
              <appserver.base>${project.build.directory}</appserver.base>
              <derby.system.home>${project.build.directory}</derby.system.home>
              <svn.base.url>${svn.base.url}</svn.base.url>
              <continuum.port>${continuum.port}</continuum.port>
              <baseUrl>${baseUrl}</baseUrl>
              <plexus.system.path>${plexus.system.path}</plexus.system.path>
            </systemProperties>
            <dependencies>
              <dependency>
                <groupId>org.apache.derby</groupId>
                <artifactId>derby</artifactId>
              </dependency>
              <dependency>
                <groupId>javax.mail</groupId>
                <artifactId>mail</artifactId>
              </dependency>
              <dependency>
                <groupId>javax.activation</groupId>
                <artifactId>activation</artifactId>
              </dependency>
            </dependencies>
          </container>
          <configuration>
            <properties>
              <cargo.servlet.port>${continuum.port}</cargo.servlet.port>
              <cargo.jvmargs>${cargo.jvmargs}</cargo.jvmargs>
              <cargo.datasource.datasource.users>
                cargo.datasource.driver=org.apache.derby.jdbc.EmbeddedDriver|
                cargo.datasource.url=jdbc:derby:${project.build.directory}/databases/${container.name}/users;create=true|
                cargo.datasource.jndi=jdbc/users|
                cargo.datasource.username=sa
              </cargo.datasource.datasource.users>
              <cargo.datasource.datasource.builds>
                cargo.datasource.driver=org.apache.derby.jdbc.EmbeddedDriver|
                cargo.datasource.url=jdbc:derby:${project.build.directory}/databases/${container.name}/builds;create=true|
                cargo.datasource.jndi=jdbc/continuum|
                cargo.datasource.username=sa
              </cargo.datasource.datasource.builds>
              <cargo.resource.resource.mail>
                cargo.resource.name=mail/Session|
                cargo.resource.type=javax.mail.Session|
                cargo.resource.factory=org.apache.naming.factory.MailSessionFactory|
                cargo.resource.parameters=mail.smtp.host=localhost
              </cargo.resource.resource.mail>
            </properties>
          </configuration>
          <deployables>
            <deployable>
              <artifactId>continuum-webapp</artifactId>
              <type>war</type>
              <properties>
                <context>continuum</context>
              </properties>
            </deployable>
            <deployable>
              <artifactId>continuum-buildagent-webapp</artifactId>
              <type>war</type>
              <properties>
                <context>continuum-buildagent</context>
              </properties>
            </deployable>
            <!-- Test resources -->
            <deployable>
              <location>${sampleProjectsDir}</location>
              <type>war</type>
              <properties>
                <context>example-projects</context>
              </properties>
            </deployable>
          </deployables>
        </configuration>
        <executions>
          <execution>
            <id>start-container</id>
            <phase>pre-integration-test</phase>
            <goals>
              <goal>start</goal>
            </goals>
          </execution>
          <execution>
            <id>stop-container</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>
        <configuration>
          <!-- Better to be able to see the results output from the listener as we go -->
          <redirectTestOutputToFile>false</redirectTestOutputToFile>
          <suiteXmlFiles>
            <suiteXmlFile>src/test/testng/config/testng.xml</suiteXmlFile>
          </suiteXmlFiles>
        </configuration>
        <executions>
          <execution>
            <id>integration-tests</id>
            <phase>integration-test</phase>
            <goals>
              <goal>integration-test</goal>
            </goals>
            <configuration>
              <systemProperties>
                <property>
                  <name>baseUrl</name>
                  <value>${baseUrl}</value>
                </property>
                <property>
                  <name>buildAgentUrl</name>
                  <value>${buildAgentUrl}</value>
                </property>
                <property>
                  <name>appserverBase</name>
                  <value>${appserverBase}</value>
                </property>
                <property>
                  <name>browser</name>
                  <value>${browser}</value>
                </property>
                <property>
                  <name>seleniumHost</name>
                  <value>${seleniumHost}</value>
                </property>
                <property>
                  <name>seleniumPort</name>
                  <value>${seleniumPort}</value>
                </property>
                <property>
                  <name>sampleProjectsDir</name>
                  <value>${sampleProjectsDir}</value>
                </property>
                <property>
                  <name>agentRepoName</name>
                  <value>${agentRepoName}</value>
                </property>
                <property>
                  <name>agentRepo</name>
                  <value>${agentRepo}</value>
                </property>
              </systemProperties>
            </configuration>
          </execution>
          <execution>
            <id>verify-integration-tests</id>
            <goals>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>selenium-maven-plugin</artifactId>
          <version>2.3</version>
          <configuration>
            <port>${seleniumPort}</port>
            <background>true</background>
            <logOutput>true</logOutput>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>

  <dependencies>
    <dependency>
      <groupId>org.testng</groupId>
      <artifactId>testng</artifactId>
      <version>6.2.1</version>
      <scope>test</scope>
    </dependency>

    <!-- deployables -->
    <dependency>
      <groupId>org.apache.continuum</groupId>
      <artifactId>continuum-webapp</artifactId>
      <type>war</type>
    </dependency>
    <dependency>
      <groupId>org.apache.continuum</groupId>
      <artifactId>continuum-buildagent-webapp</artifactId>
      <type>war</type>
    </dependency>

    <!-- container dependencies -->
    <dependency>
      <groupId>org.apache.derby</groupId>
      <artifactId>derby</artifactId>
    </dependency>
    <dependency>
      <groupId>javax.mail</groupId>
      <artifactId>mail</artifactId>
    </dependency>
    <dependency>
      <groupId>javax.activation</groupId>
      <artifactId>activation</artifactId>
    </dependency>

    <!-- dependencies below are for code in src/test/it -->
    <dependency>
      <groupId>org.codehaus.plexus</groupId>
      <artifactId>plexus-utils</artifactId>
    </dependency>
    <dependency>
      <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
    </dependency>
    <dependency>
      <groupId>org.seleniumhq.selenium.server</groupId>
      <artifactId>selenium-server</artifactId>
      <version>1.0.1</version>
      <exclusions>
        <exclusion>
          <groupId>commons-logging</groupId>
          <artifactId>commons-logging</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.seleniumhq.selenium.client-drivers</groupId>
      <artifactId>selenium-java-client-driver</artifactId>
      <version>1.0.1</version>
      <scope>test</scope>
      <exclusions>
        <exclusion>
          <groupId>commons-logging</groupId>
          <artifactId>commons-logging</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
  </dependencies>

  <profiles>
    <profile>
      <id>disable-cargo</id>
      <activation>
        <property>
          <name>baseUrl</name>
        </property>
      </activation>
      <build>
        <pluginManagement>
          <plugins>
            <plugin>
              <groupId>org.codehaus.cargo</groupId>
              <artifactId>cargo-maven2-plugin</artifactId>
              <configuration>
                <deployables>
                  <!-- Skip all but test resources -->
                  <deployable>
                    <location>${sampleProjectsDir}</location>
                    <type>war</type>
                    <properties>
                      <context>example-projects</context>
                    </properties>
                  </deployable>
                </deployables>
              </configuration>
            </plugin>
          </plugins>
        </pluginManagement>
      </build>
    </profile>
    <profile>
      <id>disable-selenium-server</id>
      <activation>
        <property>
          <name>seleniumHost</name>
        </property>
      </activation>
      <build>
        <pluginManagement>
          <plugins>
            <plugin>
              <groupId>org.codehaus.mojo</groupId>
              <artifactId>selenium-maven-plugin</artifactId>
              <configuration>
                <skip>true</skip>
              </configuration>
            </plugin>
          </plugins>
        </pluginManagement>
      </build>
    </profile>
    <profile>
      <id>firefox</id>
      <properties>
        <browser>*firefox</browser>
      </properties>
    </profile>
    <profile>
      <id>iexplore</id>
      <activation>
        <property>
          <name>browser</name>
          <value>iexplore</value>
        </property>
      </activation>
      <properties>
        <browser>*iexplore</browser>
      </properties>
    </profile>
    <profile>
      <id>safari</id>
      <activation>
        <property>
          <name>browser</name>
          <value>safari</value>
        </property>
      </activation>
      <properties>
        <browser>*safari</browser>
      </properties>
    </profile>
    <profile>
      <id>otherbrowser</id>
      <activation>
        <property>
          <name>browser</name>
          <value>other</value>
        </property>
      </activation>
      <properties>
        <browser>*custom ${browserPath}</browser>
      </properties>
    </profile>
    <profile>
      <id>headless</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>selenium-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>xvfb</id>
                <phase>validate</phase>
                <goals>
                  <goal>xvfb</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>reporting</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-report-plugin</artifactId>
            <executions>
              <execution>
                <id>report-only</id>
                <phase>integration-test</phase>
                <goals>
                  <goal>report-only</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>tomcat7x</id>
      <activation>
        <activeByDefault>true</activeByDefault>
        <!-- -DseleniumHost profile cancels this, so we need to trigger on that as well -->
        <property>
          <name>seleniumHost</name>
        </property>
      </activation>
      <build>
        <pluginManagement>
          <plugins>
            <plugin>
              <groupId>org.codehaus.cargo</groupId>
              <artifactId>cargo-maven2-plugin</artifactId>
              <configuration>
                <container>
                  <zipUrlInstaller>
                    <url>
                      http://archive.apache.org/dist/tomcat/tomcat-7/v${tomcat7x.version}/bin/apache-tomcat-${tomcat7x.version}.zip
                    </url>
                    <downloadDir>${user.home}/.cargo</downloadDir>
                  </zipUrlInstaller>
                </container>
              </configuration>
            </plugin>
          </plugins>
        </pluginManagement>
      </build>
      <properties>
        <container.name>tomcat7x</container.name>
        <tomcat7x.version>7.0.29</tomcat7x.version>
      </properties>
    </profile>
    <profile>
      <id>jetty7x</id>
      <build>
        <pluginManagement>
          <plugins>
            <plugin>
              <groupId>org.codehaus.cargo</groupId>
              <artifactId>cargo-maven2-plugin</artifactId>
              <configuration>
                <container>
                  <artifactInstaller>
                    <groupId>org.eclipse.jetty</groupId>
                    <artifactId>jetty-distribution</artifactId>
                    <version>${jetty7x.version}</version>
                  </artifactInstaller>
                </container>
              </configuration>
            </plugin>
          </plugins>
        </pluginManagement>
      </build>
      <properties>
        <container.name>jetty7x</container.name>
        <jetty7x.version>7.6.5.v20120716</jetty7x.version>
      </properties>
    </profile>
    <profile>
      <id>debug</id>
      <properties>
        <cargo.jvmargs>
          -Xmx512m
          -XX:MaxPermSize=128m
          -Xdebug
          -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005
          -Xnoagent
          -Djava.compiler=NONE
        </cargo.jvmargs>
      </properties>
    </profile>
  </profiles>
  <properties>
    <seleniumHost>localhost</seleniumHost>
    <seleniumPort>4444</seleniumPort>
    <continuum.port>9595</continuum.port>
    <baseUrl>http://localhost:${continuum.port}/continuum</baseUrl>
    <sampleProjectsDir>${basedir}/src/test/example-projects</sampleProjectsDir>
    <sampleProjectsUrl>http://localhost:${continuum.port}</sampleProjectsUrl>
    <buildAgentUrl>http://localhost:${continuum.port}/continuum-buildagent/xmlrpc</buildAgentUrl>
    <appserverBase>${project.build.directory}</appserverBase>
    <browser>*firefox</browser>
    <browserPath/>
    <cargo.jvmargs>-Xmx512m -XX:MaxPermSize=128m</cargo.jvmargs>
    <plexus.system.path/>
    <selenium.version>2.41.0</selenium.version>
    <agentRepoName>purgeable</agentRepoName>
    <agentRepo>${project.build.directory}/data/build-agent/.m2/repository</agentRepo>
  </properties>
</project>
