<?xml version="1.0" encoding="UTF-8"?>
<!--

    Copyright 2015 Red Hat, Inc. and/or its affiliates
    and other contributors as indicated by the @author tags.

    Licensed 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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>org.hawkular.alerts</groupId>
    <artifactId>hawkular-alerts</artifactId>
    <version>0.3.2.Final</version>
  </parent>

  <artifactId>hawkular-alerts-rest-tests</artifactId>

  <name>Hawkular Alerts Rest Integration Tests</name>

  <dependencies>

    <dependency>
      <groupId>org.hawkular.alerts</groupId>
      <artifactId>hawkular-alerts-api</artifactId>
      <version>${project.version}</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.hawkular.alerts</groupId>
      <artifactId>hawkular-alerts-bus</artifactId>
      <version>${project.version}</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.hawkular.bus</groupId>
      <artifactId>hawkular-bus-rest-client</artifactId>
      <version>${version.org.hawkular.bus}</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>hawkular-alerts-actions-email</artifactId>
      <version>${project.version}</version>
      <type>war</type>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.jboss.logging</groupId>
      <artifactId>jboss-logging</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.codehaus.groovy</groupId>
      <artifactId>groovy-all</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.codehaus.groovy.modules.http-builder</groupId>
      <artifactId>http-builder</artifactId>
      <scope>test</scope>
    </dependency>

  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <skip>true</skip>
        </configuration>
      </plugin>
      <plugin>
        <groupId>com.mycila</groupId>
        <artifactId>license-maven-plugin</artifactId>
        <configuration>
          <excludes combine.children="append">
            <exclude>**/*.data</exclude>
          </excludes>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>rest-only</id>
      <properties>
        <!-- IMPORTANT: The port must be the port offset + 8080. -->
        <hawkular.host>127.0.0.1</hawkular.host>
        <hawkular.port>8080</hawkular.port>
        <hawkular.path>/hawkular/alerts/</hawkular.path>
        <hawkular.base-uri>http://${hawkular.host}:${hawkular.port}${hawkular.path}</hawkular.base-uri>
        <!-- IMPORTANT: The management port must be the port offset + 9990. -->
        <wildfly.management.port>11887</wildfly.management.port>
      </properties>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <configuration>
              <includes>
                <include>**/*ITest*</include>
              </includes>
              <systemPropertyVariables>
                <hawkular.host>${hawkular.host}</hawkular.host>
                <hawkular.port>${hawkular.port}</hawkular.port>
                <hawkular.base-uri>${hawkular.base-uri}</hawkular.base-uri>
              </systemPropertyVariables>
            </configuration>
            <executions>
              <execution>
                <goals>
                  <goal>integration-test</goal>
                  <goal>verify</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>rest</id>
      <properties>
        <hawkular.host>127.0.0.1</hawkular.host>
        <hawkular.port>8080</hawkular.port>
        <hawkular.path>/hawkular/alerts/</hawkular.path>
        <hawkular.base-uri>http://${hawkular.host}:${hawkular.port}${hawkular.path}</hawkular.base-uri>
        <!-- IMPORTANT: The port must be the port offset + 8080. -->
        <wildfly.port.offset>1897</wildfly.port.offset>
        <!-- IMPORTANT: The management port must be the port offset + 9990. -->
        <wildfly.management.port>11887</wildfly.management.port>
        <hawkular.home>${project.build.directory}</hawkular.home>
        <hawkular.configuration>${hawkular.home}/hawkular-${version.org.hawkular}/standalone/configuration</hawkular.configuration>
        <hawkular.data>${hawkular.home}/hawkular-${version.org.hawkular}/standalone/data</hawkular.data>
        <hawkular.deployments>${hawkular.home}/hawkular-${version.org.hawkular}/modules/org/hawkular/nest/main/deployments</hawkular.deployments>
      </properties>
      <dependencies>
        <dependency>
          <groupId>org.hawkular</groupId>
          <artifactId>hawkular-dist</artifactId>
          <version>${version.org.hawkular}</version>
          <type>tar.gz</type>
          <scope>test</scope>
        </dependency>
      </dependencies>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
              <execution>
                <id>unpack-hawkular</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>unpack-dependencies</goal>
                </goals>
                <configuration>
                  <includeGroupIds>org.hawkular</includeGroupIds>
                  <includeArtifactIds>hawkular-dist</includeArtifactIds>
                  <outputDirectory>
                    ${hawkular.home}
                  </outputDirectory>
                </configuration>
              </execution>
              <execution>
                <id>update-hawkular-alerts</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>copy</goal>
                </goals>
                <configuration>
                  <artifactItems>
                    <artifactItem>
                      <groupId>org.hawkular.alerts</groupId>
                      <artifactId>hawkular-alerts-rest</artifactId>
                      <version>${project.version}</version>
                      <type>war</type>
                      <overWrite>true</overWrite>
                      <outputDirectory>${hawkular.deployments}</outputDirectory>
                      <destFileName>hawkular-alerts-rest.war</destFileName>
                    </artifactItem>
                    <artifactItem>
                      <groupId>org.hawkular.alerts</groupId>
                      <artifactId>hawkular-alerts-actions-email</artifactId>
                      <type>war</type>
                      <overWrite>true</overWrite>
                      <outputDirectory>${hawkular.deployments}</outputDirectory>
                      <destFileName>hawkular-alerts-actions-email.war</destFileName>
                    </artifactItem>
                  </artifactItems>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
              <execution>
                <id>delete-old-hawkular-alert-ears</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>run</goal>
                </goals>
                <configuration>
                  <target>
                    <delete file="${hawkular.deployments}/hawkular-alerts-ear.ear" />
                  </target>
                </configuration>
              </execution>
              <execution>
                <id>rename-hawkular-realm</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>run</goal>
                </goals>
                <configuration>
                  <target>
                    <copy file="${hawkular.configuration}/hawkular-realm.json" tofile="${hawkular.configuration}/hawkular-realm.json.backup" />
                    <copy file="${hawkular.configuration}/hawkular-realm-for-dev.json" tofile="${hawkular.configuration}/hawkular-realm.json" overwrite="true" />
                  </target>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <executions>
              <execution>
                <id>copy-data-dir</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>copy-resources</goal>
                </goals>
                <configuration>
                  <outputDirectory>${hawkular.data}</outputDirectory>
                  <overwrite>true</overwrite>
                  <resources>
                    <resource>
                      <directory>${project.basedir}/src/test/wildfly-data</directory>
                      <includes>
                        <include>**/*</include>
                      </includes>
                    </resource>
                  </resources>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <configuration>
              <systemPropertyVariables>
                <hawkular.host>${hawkular.host}</hawkular.host>
                <hawkular.port>${hawkular.port}</hawkular.port>
                <hawkular.base-uri>${hawkular.base-uri}</hawkular.base-uri>
              </systemPropertyVariables>
            </configuration>
            <executions>
              <execution>
                <id>exec-rest-tests</id>
                <goals>
                  <goal>integration-test</goal>
                </goals>
                <configuration>
                  <includes>
                    <include>**/*ITest*</include>
                  </includes>
                </configuration>
              </execution>
              <execution>
                <id>final-verify</id>
                <goals>
                  <goal>verify</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.wildfly.plugins</groupId>
            <artifactId>wildfly-maven-plugin</artifactId>
            <configuration>
              <jboss-home>${hawkular.home}/hawkular-${version.org.hawkular}</jboss-home>
            </configuration>
            <executions>
              <execution>
                <id>start-wildfly</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>start</goal>
                </goals>
                <configuration>
                  <javaOpts>
                    <javaOpt>-Xms64m</javaOpt>
                    <javaOpt>-Xmx512m</javaOpt>
                    <javaOpt>-Xss256k</javaOpt>
                    <javaOpt>-Djava.net.preferIPv4Stack=true</javaOpt>
                    <javaOpt>-Dsun.rmi.dgc.client.gcInterval=3600000</javaOpt>
                    <javaOpt>-Dsun.rmi.dgc.server.gcInterval=3600000</javaOpt>
                    <javaOpt>-Xdebug</javaOpt>
                    <javaOpt>-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8787</javaOpt>
                    <javaOpt>-Dkeycloak.import=${hawkular.configuration}/hawkular-realm.json</javaOpt>
                  </javaOpts>
                  <startup-timeout>120</startup-timeout>
                </configuration>
              </execution>
              <execution>
                <id>stop-wildfly</id>
                <phase>post-integration-test</phase>
                <goals>
                  <goal>shutdown</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

</project>
