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

    Copyright 2015-2016 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>1.2.2.Final</version>
  </parent>

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

  <name>Hawkular Alerting: Rest Integration Tests</name>

  <dependencies>

    <!-- This project is specific for test so all dependencies are test scope -->
    <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-api</artifactId>
      <version>${project.version}</version>
      <scope>test</scope>
    </dependency>

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

    <dependency>
      <groupId>org.wildfly</groupId>
      <artifactId>wildfly-jms-client-bom</artifactId>
      <version>${version.org.wildfly}</version>
      <type>pom</type>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-core</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-annotations</artifactId>
      <scope>provided</scope>
    </dependency>

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

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

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

    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>hawkular-alerts-actions-webhook-standalone</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>org.slf4j</groupId>
      <artifactId>slf4j-simple</artifactId>
      <version>${version.org.slf4j}</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</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>

    <dependency>
      <groupId>org.codehaus.gpars</groupId>
      <artifactId>gpars</artifactId>
      <scope>test</scope>
      <version>${version.org.codehaus.gpars}</version>
    </dependency>

    <dependency>
      <groupId>org.codehaus.jsr166-mirror</groupId>
      <artifactId>jsr166y</artifactId>
      <scope>test</scope>
      <version>${version.org.codehaus.jsr166-mirror}</version>
    </dependency>

    <dependency>
      <groupId>com.icegreen</groupId>
      <artifactId>greenmail</artifactId>
      <version>${version.com.icegreen}</version>
      <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>

    <!-- This profile requires an external running server of hawkular or hawkular-alerts/standalone -->
    <profile>
      <id>itest-external</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>
              <excludes>
                <excludeFile>org/hawkular/alerts/rest/ClusterITest.class</excludeFile>
                <excludeFile>org/hawkular/alerts/rest/PerfCrudITest.class</excludeFile>
                <exclude>${hawkular.itest-exclude}</exclude>
              </excludes>
              <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>itest</id>
      <properties>
        <hawkular.host>127.0.0.1</hawkular.host>
        <hawkular.port>8080</hawkular.port>
        <hawkular.port.offset>0</hawkular.port.offset>
        <hawkular.path>/hawkular/alerts/</hawkular.path>
        <hawkular.base-uri>http://${hawkular.host}:${hawkular.port}${hawkular.path}</hawkular.base-uri>
        <hawkular.management.port>9990</hawkular.management.port>
        <hawkular.log.alerts>INFO</hawkular.log.alerts>
      </properties>
      <dependencies>
        <dependency>
          <groupId>org.hawkular.commons</groupId>
          <artifactId>hawkular-nest-feature-pack</artifactId>
          <version>${version.org.hawkular.commons}</version>
          <type>pom</type>
          <scope>provided</scope>
          <exclusions>
            <exclusion>
              <groupId>*</groupId>
              <artifactId>*</artifactId>
            </exclusion>
          </exclusions>
        </dependency>
        <dependency>
          <groupId>org.hawkular.commons</groupId>
          <artifactId>hawkular-nest-feature-pack</artifactId>
          <version>${version.org.hawkular.commons}</version>
          <type>zip</type>
          <exclusions>
            <exclusion>
              <groupId>*</groupId>
              <artifactId>*</artifactId>
            </exclusion>
          </exclusions>
        </dependency>
        <dependency>
          <groupId>org.hawkular.commons</groupId>
          <artifactId>hawkular-commons-embedded-cassandra-war</artifactId>
          <version>${version.org.hawkular.commons}</version>
          <type>war</type>
        </dependency>
      </dependencies>
      <build>
        <plugins>
          <!-- Build a wildfly + bus + accounts distro from feature packs -->
          <plugin>
            <groupId>org.wildfly.build</groupId>
            <artifactId>wildfly-server-provisioning-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>server-provisioning</id>
                <goals>
                  <goal>build</goal>
                </goals>
                <phase>compile</phase>
                <configuration>
                  <config-file>server-provisioning.xml</config-file>
                </configuration>
              </execution>
            </executions>
          </plugin>

          <!-- Install hawkular-alerts -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
              <execution>
                <id>install-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-standalone</artifactId>
                      <version>${project.version}</version>
                      <type>war</type>
                      <overWrite>true</overWrite>
                      <outputDirectory>${project.build.directory}/${project.build.finalName}/modules/system/layers/hawkular/org/hawkular/nest/main/deployments</outputDirectory>
                      <destFileName>hawkular-alerts.war</destFileName>
                    </artifactItem>
                    <artifactItem>
                      <groupId>org.hawkular.alerts</groupId>
                      <artifactId>hawkular-alerts-actions-email-standalone</artifactId>
                      <type>war</type>
                      <overWrite>true</overWrite>
                      <outputDirectory>${project.build.directory}/${project.build.finalName}/modules/system/layers/hawkular/org/hawkular/nest/main/deployments</outputDirectory>
                      <destFileName>hawkular-alerts-actions-email.war</destFileName>
                    </artifactItem>
                    <artifactItem>
                      <groupId>org.hawkular.alerts</groupId>
                      <artifactId>hawkular-alerts-actions-file-standalone</artifactId>
                      <type>war</type>
                      <overWrite>true</overWrite>
                      <outputDirectory>${project.build.directory}/${project.build.finalName}/modules/system/layers/hawkular/org/hawkular/nest/main/deployments</outputDirectory>
                      <destFileName>hawkular-alerts-actions-file.war</destFileName>
                    </artifactItem>
                    <artifactItem>
                      <groupId>org.hawkular.commons</groupId>
                      <artifactId>hawkular-commons-embedded-cassandra-war</artifactId>
                      <type>war</type>
                      <overWrite>true</overWrite>
                      <outputDirectory>${project.build.directory}/${project.build.finalName}/modules/system/layers/hawkular/org/hawkular/nest/main/deployments</outputDirectory>
                      <destFileName>hawkular-commons-embedded-cassandra-war.war</destFileName>
                    </artifactItem>
                  </artifactItems>
                </configuration>
              </execution>
            </executions>
          </plugin>

          <!-- Install hawkular-alerts demo data for itests -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <executions>
              <execution>
                <id>copy-users-data</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>copy-resources</goal>
                </goals>
                <configuration>
                  <outputDirectory>${project.build.directory}/${project.build.finalName}/standalone/configuration</outputDirectory>
                  <overwrite>true</overwrite>
                  <resources>
                    <resource>
                      <directory>${project.basedir}/src/test/resources</directory>
                      <includes>
                        <include>application-roles.properties</include>
                        <include>application-users.properties</include>
                      </includes>
                    </resource>
                  </resources>
                </configuration>
              </execution>
            </executions>
          </plugin>

          <!-- Configure hawkular-alerts -->
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>xml-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>transform-standalone-xml</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>transform</goal>
                </goals>
                <configuration>
                  <transformationSets>
                    <!-- standalone.xml -->
                    <transformationSet>
                      <dir>${project.build.directory}/${project.build.finalName}/standalone/configuration</dir>
                      <stylesheet>src/test/resources/standalone-hawkular.xsl</stylesheet>
                      <includes>
                        <include>standalone.xml</include>
                      </includes>
                      <outputDir>${project.build.directory}/${project.build.finalName}/standalone/configuration</outputDir>
                    </transformationSet>
                  </transformationSets>
                </configuration>
              </execution>
            </executions>
          </plugin>

          <!-- Start wildfly -->
          <plugin>
            <groupId>org.wildfly.plugins</groupId>
            <artifactId>wildfly-maven-plugin</artifactId>
            <configuration>
              <jboss-home>${project.build.directory}/${project.build.finalName}</jboss-home>
              <skip>${skipTests}</skip>
              <startupTimeout>240</startupTimeout>
              <port>${hawkular.management.port}</port>
              <javaOpts>
                <javaOpt>-server</javaOpt>
                <javaOpt>-Xms64m</javaOpt>
                <javaOpt>-Xmx512m</javaOpt>
                <javaOpt>-Djava.net.preferIPv4Stack=true</javaOpt>
                <javaOpt>-Djboss.modules.system.pkgs=org.jboss.byteman</javaOpt>
                <javaOpt>-Djava.awt.headless=true</javaOpt>
                <javaOpt>-Djboss.bind.address=${hawkular.host}</javaOpt>
                <javaOpt>-Djboss.socket.binding.port-offset=${hawkular.port.offset}</javaOpt>
                <javaOpt>-Dkeycloak.import=${project.build.directory}/${project.build.finalName}/standalone/configuration/hawkular-realm-for-dev.json</javaOpt>
                <javaOpt>-Dmail.smtp.host=localhost</javaOpt>
                <javaOpt>-Dmail.smtp.port=2525</javaOpt>
                <javaOpt>-Dhawkular.backend=embedded_cassandra</javaOpt>
                <javaOpt>-Dhawkular.log.alerts=${hawkular.log.alerts}</javaOpt>
                <!--<javaOpt>-Xdebug</javaOpt>-->
                <!--<javaOpt>-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y</javaOpt>-->
              </javaOpts>
            </configuration>
            <executions>
              <execution>
                <id>start-wildfly</id>
                <phase>pre-integration-test</phase>
                <configuration>
                  <server-config>standalone.xml</server-config>
                </configuration>
                <goals>
                  <goal>start</goal>
                </goals>
              </execution>
              <execution>
                <id>stop-wildfly</id>
                <phase>post-integration-test</phase>
                <goals>
                  <goal>shutdown</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

          <!-- Configure integration tests -->
          <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>org/hawkular/alerts/rest/IntegrationSuite.class</include>
                  </includes>
                  <excludes>
                    <excludeFile>org/hawkular/alerts/rest/ClusterITest.class</excludeFile>
                    <excludeFile>org/hawkular/alerts/rest/PerfCrudITest.class</excludeFile>
                    <exclude>${hawkular.itest-exclude}</exclude>
                  </excludes>
                </configuration>
              </execution>
              <execution>
                <id>final-verify</id>
                <goals>
                  <goal>verify</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

        </plugins>
      </build>
    </profile>

    <profile>
      <id>perf-itest</id>
      <properties>
        <hawkular.host>127.0.0.1</hawkular.host>
        <hawkular.port>8080</hawkular.port>
        <hawkular.port.offset>0</hawkular.port.offset>
        <hawkular.path>/hawkular/alerts/</hawkular.path>
        <hawkular.base-uri>http://${hawkular.host}:${hawkular.port}${hawkular.path}</hawkular.base-uri>
        <hawkular.management.port>9990</hawkular.management.port>
        <hawkular.log.alerts>INFO</hawkular.log.alerts>
      </properties>
      <dependencies>
        <dependency>
          <groupId>org.hawkular.commons</groupId>
          <artifactId>hawkular-nest-feature-pack</artifactId>
          <version>${version.org.hawkular.commons}</version>
          <type>pom</type>
          <scope>provided</scope>
          <exclusions>
            <exclusion>
              <groupId>*</groupId>
              <artifactId>*</artifactId>
            </exclusion>
          </exclusions>
        </dependency>
        <dependency>
          <groupId>org.hawkular.commons</groupId>
          <artifactId>hawkular-nest-feature-pack</artifactId>
          <version>${version.org.hawkular.commons}</version>
          <type>zip</type>
          <exclusions>
            <exclusion>
              <groupId>*</groupId>
              <artifactId>*</artifactId>
            </exclusion>
          </exclusions>
        </dependency>
        <dependency>
          <groupId>org.hawkular.commons</groupId>
          <artifactId>hawkular-commons-embedded-cassandra-war</artifactId>
          <version>${version.org.hawkular.commons}</version>
          <type>war</type>
        </dependency>
      </dependencies>
      <build>
        <plugins>
          <!-- Build a wildfly + bus + accounts distro from feature packs -->
          <plugin>
            <groupId>org.wildfly.build</groupId>
            <artifactId>wildfly-server-provisioning-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>server-provisioning</id>
                <goals>
                  <goal>build</goal>
                </goals>
                <phase>compile</phase>
                <configuration>
                  <config-file>server-provisioning.xml</config-file>
                </configuration>
              </execution>
            </executions>
          </plugin>

          <!-- Install hawkular-alerts -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
              <execution>
                <id>install-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-standalone</artifactId>
                      <version>${project.version}</version>
                      <type>war</type>
                      <overWrite>true</overWrite>
                      <outputDirectory>${project.build.directory}/${project.build.finalName}/modules/system/layers/hawkular/org/hawkular/nest/main/deployments</outputDirectory>
                      <destFileName>hawkular-alerts.war</destFileName>
                    </artifactItem>
                    <artifactItem>
                      <groupId>org.hawkular.alerts</groupId>
                      <artifactId>hawkular-alerts-actions-email-standalone</artifactId>
                      <type>war</type>
                      <overWrite>true</overWrite>
                      <outputDirectory>${project.build.directory}/${project.build.finalName}/modules/system/layers/hawkular/org/hawkular/nest/main/deployments</outputDirectory>
                      <destFileName>hawkular-alerts-actions-email.war</destFileName>
                    </artifactItem>
                    <artifactItem>
                      <groupId>org.hawkular.alerts</groupId>
                      <artifactId>hawkular-alerts-actions-file-standalone</artifactId>
                      <type>war</type>
                      <overWrite>true</overWrite>
                      <outputDirectory>${project.build.directory}/${project.build.finalName}/modules/system/layers/hawkular/org/hawkular/nest/main/deployments</outputDirectory>
                      <destFileName>hawkular-alerts-actions-file.war</destFileName>
                    </artifactItem>
                    <artifactItem>
                      <groupId>org.hawkular.commons</groupId>
                      <artifactId>hawkular-commons-embedded-cassandra-war</artifactId>
                      <type>war</type>
                      <overWrite>true</overWrite>
                      <outputDirectory>${project.build.directory}/${project.build.finalName}/modules/system/layers/hawkular/org/hawkular/nest/main/deployments</outputDirectory>
                      <destFileName>hawkular-commons-embedded-cassandra-war.war</destFileName>
                    </artifactItem>
                  </artifactItems>
                </configuration>
              </execution>
            </executions>
          </plugin>

          <!-- Install hawkular-alerts demo data for itests -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <executions>
              <execution>
                <id>copy-users-data</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>copy-resources</goal>
                </goals>
                <configuration>
                  <outputDirectory>${project.build.directory}/${project.build.finalName}/standalone/configuration</outputDirectory>
                  <overwrite>true</overwrite>
                  <resources>
                    <resource>
                      <directory>${project.basedir}/src/test/resources</directory>
                      <includes>
                        <include>application-roles.properties</include>
                        <include>application-users.properties</include>
                      </includes>
                    </resource>
                  </resources>
                </configuration>
              </execution>
            </executions>
          </plugin>

          <!-- Configure hawkular-alerts -->
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>xml-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>transform-standalone-xml</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>transform</goal>
                </goals>
                <configuration>
                  <transformationSets>
                    <!-- standalone.xml -->
                    <transformationSet>
                      <dir>${project.build.directory}/${project.build.finalName}/standalone/configuration</dir>
                      <stylesheet>src/test/resources/standalone-hawkular.xsl</stylesheet>
                      <includes>
                        <include>standalone.xml</include>
                      </includes>
                      <outputDir>${project.build.directory}/${project.build.finalName}/standalone/configuration</outputDir>
                    </transformationSet>
                  </transformationSets>
                </configuration>
              </execution>
            </executions>
          </plugin>

          <!-- Start wildfly -->
          <plugin>
            <groupId>org.wildfly.plugins</groupId>
            <artifactId>wildfly-maven-plugin</artifactId>
            <configuration>
              <jboss-home>${project.build.directory}/${project.build.finalName}</jboss-home>
              <skip>${skipTests}</skip>
              <startupTimeout>240</startupTimeout>
              <port>${hawkular.management.port}</port>
              <javaOpts>
                <javaOpt>-server</javaOpt>
                <javaOpt>-Xms64m</javaOpt>
                <javaOpt>-Xmx512m</javaOpt>
                <javaOpt>-Djava.net.preferIPv4Stack=true</javaOpt>
                <javaOpt>-Djboss.modules.system.pkgs=org.jboss.byteman</javaOpt>
                <javaOpt>-Djava.awt.headless=true</javaOpt>
                <javaOpt>-Djboss.bind.address=${hawkular.host}</javaOpt>
                <javaOpt>-Djboss.socket.binding.port-offset=${hawkular.port.offset}</javaOpt>
                <javaOpt>-Dkeycloak.import=${project.build.directory}/${project.build.finalName}/standalone/configuration/hawkular-realm-for-dev.json</javaOpt>
                <javaOpt>-Dmail.smtp.host=localhost</javaOpt>
                <javaOpt>-Dmail.smtp.port=2525</javaOpt>
                <javaOpt>-Dhawkular.backend=embedded_cassandra</javaOpt>
                <javaOpt>-Dhawkular.log.alerts=${hawkular.log.alerts}</javaOpt>
                <!--<javaOpt>-Xdebug</javaOpt>-->
                <!--<javaOpt>-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y</javaOpt>-->
              </javaOpts>
            </configuration>
            <executions>
              <execution>
                <id>start-wildfly</id>
                <phase>pre-integration-test</phase>
                <configuration>
                  <server-config>standalone.xml</server-config>
                </configuration>
                <goals>
                  <goal>start</goal>
                </goals>
              </execution>
              <execution>
                <id>stop-wildfly</id>
                <phase>post-integration-test</phase>
                <goals>
                  <goal>shutdown</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

          <!-- Configure integration tests -->
          <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>org/hawkular/alerts/rest/PerfCrudITest.class</include>
                  </includes>
                  <excludes>
                    <excludeFile>org/hawkular/alerts/rest/ClusterITest.class</excludeFile>
                    <excludeFile>org/hawkular/alerts/rest/IntegrationSuite.class</excludeFile>
                    <exclude>${hawkular.itest-exclude}</exclude>
                  </excludes>
                </configuration>
              </execution>
              <execution>
                <id>final-verify</id>
                <goals>
                  <goal>verify</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

        </plugins>
      </build>
    </profile>

    <!-- This profile prepares a standalone distribution of hawkular-alerts on top of a Wildfly Server -->
    <profile>
      <id>build-standalone</id>
      <activation>
        <property>
          <name>!env</name>
        </property>
      </activation>
      <properties>
        <hawkular.home>${project.build.directory}</hawkular.home>
        <hawkular.standalone.conf>${hawkular.home}/wildfly-${version.org.wildfly}/standalone/configuration</hawkular.standalone.conf>
        <hawkular.data>${hawkular.home}/wildfly-${version.org.wildfly}/standalone/data</hawkular.data>
        <hawkular.deployments>${hawkular.home}/wildfly-${version.org.wildfly}/standalone/deployments</hawkular.deployments>
      </properties>
      <dependencies>

        <dependency>
          <groupId>org.hawkular.commons</groupId>
          <artifactId>hawkular-commons-embedded-cassandra-war</artifactId>
          <version>${version.org.hawkular.commons}</version>
          <type>war</type>
        </dependency>

        <dependency>
          <groupId>org.wildfly</groupId>
          <artifactId>wildfly-dist</artifactId>
          <version>${version.org.wildfly}</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-on-standalone</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>unpack-dependencies</goal>
                </goals>
                <configuration>
                  <includeGroupIds>org.wildfly</includeGroupIds>
                  <includeArtifactIds>wildfly-dist</includeArtifactIds>
                  <outputDirectory>
                    ${hawkular.home}
                  </outputDirectory>
                </configuration>
              </execution>
              <execution>
                <id>update-hawkular-alerts-on-standalone</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>copy</goal>
                </goals>
                <configuration>
                  <artifactItems>
                    <artifactItem>
                      <groupId>org.hawkular.commons</groupId>
                      <artifactId>hawkular-commons-embedded-cassandra-war</artifactId>
                      <type>war</type>
                      <overWrite>true</overWrite>
                      <outputDirectory>${hawkular.deployments}</outputDirectory>
                      <destFileName>hawkular-commons-embedded-cassandra-war.war</destFileName>
                    </artifactItem>
                    <artifactItem>
                      <groupId>org.hawkular.alerts</groupId>
                      <artifactId>hawkular-alerts-rest-standalone</artifactId>
                      <version>${project.version}</version>
                      <type>war</type>
                      <overWrite>true</overWrite>
                      <outputDirectory>${hawkular.deployments}</outputDirectory>
                      <destFileName>hawkular-alerts.war</destFileName>
                    </artifactItem>
                    <artifactItem>
                      <groupId>org.hawkular.alerts</groupId>
                      <artifactId>hawkular-alerts-actions-email-standalone</artifactId>
                      <type>war</type>
                      <overWrite>true</overWrite>
                      <outputDirectory>${hawkular.deployments}</outputDirectory>
                      <destFileName>hawkular-alerts-actions-email.war</destFileName>
                    </artifactItem>
                    <artifactItem>
                      <groupId>org.hawkular.alerts</groupId>
                      <artifactId>hawkular-alerts-actions-file-standalone</artifactId>
                      <type>war</type>
                      <overWrite>true</overWrite>
                      <outputDirectory>${hawkular.deployments}</outputDirectory>
                      <destFileName>hawkular-alerts-actions-file.war</destFileName>
                    </artifactItem>
                    <artifactItem>
                      <groupId>org.hawkular.alerts</groupId>
                      <artifactId>hawkular-alerts-actions-irc-standalone</artifactId>
                      <type>war</type>
                      <overWrite>true</overWrite>
                      <outputDirectory>${hawkular.deployments}</outputDirectory>
                      <destFileName>hawkular-alerts-actions-irc.war</destFileName>
                    </artifactItem>
                    <artifactItem>
                      <groupId>org.hawkular.alerts</groupId>
                      <artifactId>hawkular-alerts-actions-webhook-standalone</artifactId>
                      <type>war</type>
                      <overWrite>true</overWrite>
                      <outputDirectory>${hawkular.deployments}</outputDirectory>
                      <destFileName>hawkular-alerts-actions-webhook.war</destFileName>
                    </artifactItem>
                  </artifactItems>
                </configuration>
              </execution>
            </executions>
          </plugin>

          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>xml-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>transform-standalone-xml-on-standalone</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>transform</goal>
                </goals>
                <configuration>
                  <transformationSets>
                    <!-- standalone.xml -->
                    <transformationSet>
                      <dir>${hawkular.standalone.conf}</dir>
                      <stylesheet>src/test/resources/standalone.xsl</stylesheet>
                      <includes>
                        <include>standalone.xml</include>
                      </includes>
                      <outputDir>${hawkular.standalone.conf}</outputDir>
                    </transformationSet>
                    <!-- standalone-ha.xml -->
                    <transformationSet>
                      <dir>${hawkular.standalone.conf}</dir>
                      <stylesheet>src/test/resources/standalone-ha.xsl</stylesheet>
                      <includes>
                        <include>standalone-ha.xml</include>
                      </includes>
                      <outputDir>${hawkular.standalone.conf}</outputDir>
                    </transformationSet>
                  </transformationSets>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

    <!-- This profile prepares a standalone distribution of hawkular-alerts on top of a Wildfly Server -->
    <profile>
      <id>build-domain-cluster</id>
      <activation>
        <property>
          <name>env</name>
          <value>cluster</value>
        </property>
      </activation>
      <properties>
        <hawkular.home>${project.build.directory}/cluster</hawkular.home>
        <hawkular.domain.conf>${hawkular.home}/wildfly-${version.org.wildfly}/domain/configuration</hawkular.domain.conf>
        <hawkular.alerts1.data>${hawkular.home}/wildfly-${version.org.wildfly}/domain/servers/alerts1/data</hawkular.alerts1.data>
        <hawkular.host>127.0.0.1</hawkular.host>
        <hawkular.port>8230</hawkular.port>
        <hawkular.path>/hawkular/alerts/</hawkular.path>
        <hawkular.base-uri>http://${hawkular.host}:${hawkular.port}${hawkular.path}</hawkular.base-uri>
      </properties>
      <dependencies>

        <dependency>
          <groupId>org.hawkular.commons</groupId>
          <artifactId>hawkular-commons-embedded-cassandra-war</artifactId>
          <version>${version.org.hawkular.commons}</version>
          <type>war</type>
        </dependency>

        <dependency>
          <groupId>org.hawkular.alerts</groupId>
          <artifactId>hawkular-alerts-rest-standalone</artifactId>
          <version>${project.version}</version>
          <type>war</type>
        </dependency>

        <dependency>
          <groupId>org.wildfly</groupId>
          <artifactId>wildfly-dist</artifactId>
          <version>${version.org.wildfly}</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.wildfly</includeGroupIds>
                  <includeArtifactIds>wildfly-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.commons</groupId>
                      <artifactId>hawkular-commons-embedded-cassandra-war</artifactId>
                      <type>war</type>
                      <overWrite>true</overWrite>
                      <outputDirectory>${project.build.directory}</outputDirectory>
                      <destFileName>hawkular-commons-embedded-cassandra-war.war</destFileName>
                    </artifactItem>
                    <artifactItem>
                      <groupId>org.hawkular.alerts</groupId>
                      <artifactId>hawkular-alerts-rest-standalone</artifactId>
                      <version>${project.version}</version>
                      <type>war</type>
                      <overWrite>true</overWrite>
                      <outputDirectory>${project.build.directory}</outputDirectory>
                      <destFileName>hawkular-alerts.war</destFileName>
                    </artifactItem>
                    <artifactItem>
                      <groupId>org.hawkular.alerts</groupId>
                      <artifactId>hawkular-alerts-actions-email-standalone</artifactId>
                      <type>war</type>
                      <overWrite>true</overWrite>
                      <outputDirectory>${project.build.directory}</outputDirectory>
                      <destFileName>hawkular-alerts-actions-email.war</destFileName>
                    </artifactItem>
                  </artifactItems>
                </configuration>
              </execution>
            </executions>
          </plugin>

          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>xml-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>transform-standalone-xml</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>transform</goal>
                </goals>
                <configuration>
                  <transformationSets>
                    <!-- domain.xml -->
                    <transformationSet>
                      <dir>${hawkular.domain.conf}</dir>
                      <stylesheet>src/test/resources/domain.xsl</stylesheet>
                      <includes>
                        <include>domain.xml</include>
                      </includes>
                      <outputDir>${hawkular.domain.conf}</outputDir>
                    </transformationSet>
                    <!-- host.xml -->
                    <transformationSet>
                      <dir>${hawkular.domain.conf}</dir>
                      <stylesheet>src/test/resources/host.xsl</stylesheet>
                      <includes>
                        <include>host.xml</include>
                      </includes>
                      <outputDir>${hawkular.domain.conf}</outputDir>
                    </transformationSet>
                  </transformationSets>
                </configuration>
              </execution>
            </executions>
          </plugin>

          <plugin>
            <groupId>org.wildfly.plugins</groupId>
            <artifactId>wildfly-maven-plugin</artifactId>
            <configuration>
              <jboss-home>${hawkular.home}/wildfly-${version.org.wildfly}</jboss-home>
              <skip>${skipTests}</skip>
              <startupTimeout>240</startupTimeout>
              <serverType>DOMAIN</serverType>
              <domain-config>domain.xml</domain-config>
              <host-config>host.xml</host-config>
            </configuration>
            <executions>
              <execution>
                <id>start-domain</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>start</goal>
                </goals>
              </execution>
              <execution>
                <id>deploy-embedded-cassandra</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>deploy</goal>
                </goals>
                <configuration>
                  <domain>
                    <server-groups>
                      <server-group>cassandra-group</server-group>
                    </server-groups>
                  </domain>
                  <filename>hawkular-commons-embedded-cassandra-war.war</filename>
                </configuration>
              </execution>
              <execution>
                <id>deploy-hawkular-alerts</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>deploy</goal>
                </goals>
                <configuration>
                  <domain>
                    <server-groups>
                      <server-group>hawkular-alerts-group</server-group>
                    </server-groups>
                  </domain>
                  <filename>hawkular-alerts.war</filename>
                </configuration>
              </execution>
              <execution>
                <id>stop-domain</id>
                <phase>post-integration-test</phase>
                <goals>
                  <goal>shutdown</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

          <!-- Adding a delay to let the server to process initial data at deployment -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <configuration>
              <tasks>
                <echo message="Giving some time to the cluster to finish deployment and process initial data..." />
                <sleep seconds="10" />
              </tasks>
            </configuration>
            <executions>
              <execution>
                <id>sleep-for-a-while</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>run</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

          <!-- Configure integration tests -->
          <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-cluster-tests</id>
                <goals>
                  <goal>integration-test</goal>
                </goals>
                <configuration>
                  <includes>
                    <include>org/hawkular/alerts/rest/ClusterITest.class</include>
                  </includes>
                </configuration>
              </execution>
              <execution>
                <id>final-verify</id>
                <goals>
                  <goal>verify</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

        </plugins>
      </build>
    </profile>

  </profiles>

</project>
