<?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.inventory</groupId>
    <artifactId>hawkular-inventory-parent</artifactId>
    <version>1.0.2.Final</version>
  </parent>

  <artifactId>hawkular-inventory-itest</artifactId>
  <name>Hawkular Inventory Integration Tests</name>

  <build>
    <plugins>
      <plugin>
        <groupId>org.revapi</groupId>
        <artifactId>revapi-maven-plugin</artifactId>
        <configuration>
          <skip>true</skip>
        </configuration>
      </plugin>

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

  <dependencies>
    <!-- tests are reused in another modules, so dependencies are transitively needed -->

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

    <dependency>
      <groupId>com.fasterxml.jackson.module</groupId>
      <artifactId>jackson-module-jaxb-annotations</artifactId>
      <version>${version.com.fasterxml.jackson.core}</version>
    </dependency>

    <dependency>
      <groupId>com.squareup.okhttp</groupId>
      <artifactId>okhttp</artifactId>
    </dependency>

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

    <dependency>
      <groupId>org.hawkular.inventory</groupId>
      <artifactId>hawkular-inventory-json-helper</artifactId>
      <version>${project.version}</version>
    </dependency>

    <dependency>
      <groupId>org.hawkular.commons</groupId>
      <artifactId>hawkular-inventory-paths</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.hawkular.inventory</groupId>
      <artifactId>hawkular-inventory-feature-pack</artifactId>
      <version>${project.version}</version>
      <type>pom</type>
      <scope>provided</scope>
    </dependency>

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

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

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

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

  <profiles>
    <profile>
      <id>itest</id>

      <properties>

        <!-- hawkular dist properties -->
        <hawkular.bind.address>127.0.0.1</hawkular.bind.address>
        <hawkular.port.offset>0</hawkular.port.offset>
        <!-- $hawkular.management.port must be equal to $hawkular.port.offset + 9990 -->
        <hawkular.management.port>9990</hawkular.management.port>
        <hawkular.agent.enabled>false</hawkular.agent.enabled>
        <hawkular.log.root>INFO</hawkular.log.root>
        <hawkular.log.console>INFO</hawkular.log.console>
        <hawkular.log.bus>INFO</hawkular.log.bus>
        <hawkular.log.cmdgw>INFO</hawkular.log.cmdgw>
        <hawkular.log.inventory>INFO</hawkular.log.inventory>
        <hawkular.log.inventory.rest.requests>INFO</hawkular.log.inventory.rest.requests>
        <hawkular.log.nest>INFO</hawkular.log.nest>
        <hawkular.log.datastax.driver>INFO</hawkular.log.datastax.driver>
        <hawkular.log.cassandra>INFO</hawkular.log.cassandra>
        <sql.jdbc.url>jndi:java:/jboss/datasources/HawkularInventoryDS_hsqldb</sql.jdbc.url>
      </properties>

      <build>
        <plugins>

          <plugin>
            <groupId>org.revapi</groupId>
            <artifactId>revapi-maven-plugin</artifactId>
            <configuration>
              <skip>true</skip>
            </configuration>
          </plugin>

          <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>


          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <executions>
              <execution>
                <id>copy-resources</id>
                <phase>process-classes</phase>
                <goals>
                  <goal>copy-resources</goal>
                </goals>
                <configuration>
                  <overwrite>true</overwrite>
                  <outputDirectory>${project.build.directory}/${project.build.finalName}/standalone/configuration/</outputDirectory>
                  <resources>
                    <resource>
                      <directory>${project.basedir}/src/test/resources/standalone-configuration/</directory>
                      <filtering>false</filtering>
                    </resource>
                  </resources>
                </configuration>
              </execution>
            </executions>
          </plugin>

          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
              <execution>
                <id>deploy-embedded-cassandra</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>
                    </artifactItem>
                  </artifactItems>
                  <outputDirectory>
                    ${project.build.directory}/${project.build.finalName}/modules/system/layers/hawkular/org/hawkular/nest/main/deployments/
                  </outputDirectory>
                </configuration>
              </execution>
            </executions>
          </plugin>

          <!-- Remove Command Gateway as it is not required for running Inventory itests  -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-clean-plugin</artifactId>
            <executions>
              <execution>
                <id>delete-command-gateway</id>
                <phase>process-classes</phase>
                <goals>
                  <goal>clean</goal>
                </goals>
                <configuration>
                  <excludeDefaultDirectories>true</excludeDefaultDirectories>
                  <filesets>
                    <fileset>
                      <directory>${project.build.directory}/${project.build.finalName}/modules/system/layers/hawkular/org/hawkular/nest/main/deployments</directory>
                      <includes>
                        <include>hawkular-command-gateway-war*.war</include>
                      </includes>
                    </fileset>
                  </filesets>
                </configuration>
              </execution>
            </executions>
          </plugin>

          <!-- Start WildFly and run integration tests -->
          <plugin>
            <groupId>org.wildfly.plugins</groupId>
            <artifactId>wildfly-maven-plugin</artifactId>
            <configuration>
              <jboss-home>${project.build.directory}/${project.artifactId}-${project.version}</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.bind.address}</javaOpt>
                <javaOpt>-Djboss.socket.binding.port-offset=${hawkular.port.offset}</javaOpt>
                <javaOpt>-Dhawkular.agent.enabled=${hawkular.agent.enabled}</javaOpt>
                <javaOpt>-Dhawkular.log.root=${hawkular.log.root}</javaOpt>
                <javaOpt>-Dhawkular.log.console=${hawkular.log.console}</javaOpt>
                <javaOpt>-Dhawkular.log.bus=${hawkular.log.bus}</javaOpt>
                <javaOpt>-Dhawkular.log.cmdgw=${hawkular.log.cmdgw}</javaOpt>
                <javaOpt>-Dhawkular.log.inventory=${hawkular.log.inventory}</javaOpt>
                <javaOpt>-Dhawkular.log.inventory.rest.requests=${hawkular.log.inventory.rest.requests}</javaOpt>
                <javaOpt>-Dhawkular.log.nest=${hawkular.log.nest}</javaOpt>
                <javaOpt>-Dhawkular.log.datastax.driver=${hawkular.log.datastax.driver}</javaOpt>
                <javaOpt>-Dhawkular.log.cassandra=${hawkular.log.cassandra}</javaOpt>
                <javaOpt>-Dsql.jdbc.url=${sql.jdbc.url}</javaOpt>
                <javaOpt>-Dhawkular.backend=embedded_cassandra</javaOpt>
                <javaOpt>-Dhawkular.allowed-cors-origins=http://allowed.origin</javaOpt>
                <javaOpt>-Dhawkular.allowed-cors-access-control-allow-headers=kachny,kachny</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>

          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <configuration>
              <testClassesDirectory>${project.build.testOutputDirectory}</testClassesDirectory>

              <includes>
                <include>**/*ITest*</include>
              </includes>

              <systemPropertyVariables>
                <hawkular.bind.address>${hawkular.bind.address}</hawkular.bind.address>
                <hawkular.port.offset>${hawkular.port.offset}</hawkular.port.offset>
                <!--output over-the-wire traffic-->
                <hawkular.itest.httpWire>${http.log.wire}</hawkular.itest.httpWire>
              </systemPropertyVariables>
              <!--<argLine>-Xdebug -Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=y</argLine>-->
            </configuration>
            <executions>
              <execution>
                <goals>
                  <goal>integration-test</goal>
                  <goal>verify</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
