<?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.agent</groupId>
    <artifactId>hawkular-agent-itest-parent</artifactId>
    <version>0.11.2.Final</version>
  </parent>

  <artifactId>hawkular-agent-itest</artifactId>

  <name>Hawkular Agent Integration Tests</name>
  <description>A module containing integration tests of Command Gateway and Agent</description>

  <dependencies>

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

    <dependency>
      <groupId>org.mockito</groupId>
      <artifactId>mockito-core</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.testng</groupId>
      <artifactId>testng</artifactId>
      <scope>test</scope>
    </dependency>

    <!-- required by mockito-core, can probably be removed with an upgrade to mockito-core 2.* -->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <scope>test</scope>
    </dependency>

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

    <dependency>
      <groupId>org.hawkular.agent</groupId>
      <artifactId>hawkular-dmr-client</artifactId>
      <version>${project.version}</version>
    </dependency>


    <dependency>
      <groupId>org.hawkular.inventory</groupId>
      <artifactId>hawkular-inventory-json-helper</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.hawkular.cmdgw</groupId>
      <artifactId>hawkular-command-gateway-api</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.wildfly.core</groupId>
      <artifactId>wildfly-controller</artifactId>
      <scope>test</scope>
    </dependency>

  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>com.mycila</groupId>
        <artifactId>license-maven-plugin</artifactId>
        <configuration>
          <excludes combine.children="append">
            <exclude>src/test/resources/**/*.node.txt</exclude>
            <exclude>src/test/resources/**/*.node.txt.actual.txt</exclude>
          </excludes>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <!-- because integration tests are run by maven-failsafe-plugin -->
          <skip>true</skip>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <!-- Integration tests -->
      <id>itest</id>
      <properties>
        <hawkular.agent.itest.run.dir>${project.build.directory}/hawkular-agent-itest-dist</hawkular.agent.itest.run.dir>
        <hawkular.agent.itest.mgmt.user>itest-admin</hawkular.agent.itest.mgmt.user>
        <hawkular.agent.itest.mgmt.password>JGM4-74rK</hawkular.agent.itest.mgmt.password>
        <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>true</hawkular.agent.enabled>

        <hawkular.log>INFO</hawkular.log>
        <hawkular.log.accounts>INFO</hawkular.log.accounts>
        <hawkular.log.agent>INFO</hawkular.log.agent>
        <hawkular.log.alerts>INFO</hawkular.log.alerts>
        <hawkular.log.bus>INFO</hawkular.log.bus>
        <hawkular.log.cmdgw>INFO</hawkular.log.cmdgw>
        <hawkular.log.availcreator>INFO</hawkular.log.availcreator>
        <hawkular.log.pinger>INFO</hawkular.log.pinger>
        <hawkular.log.inventory>INFO</hawkular.log.inventory>
        <hawkular.log.metrics>INFO</hawkular.log.metrics>
        <hawkular.log.nest>INFO</hawkular.log.nest>
        <hawkular.log.datastax.driver>INFO</hawkular.log.datastax.driver>
        <hawkular.log.liquibase>WARN</hawkular.log.liquibase>
        <hawkular.log.cassandra>INFO</hawkular.log.cassandra>
        <hawkular.log.ejb3>WARN</hawkular.log.ejb3>
        <hawkular.log.rewrite>WARN</hawkular.log.rewrite>
        <http.log>ERROR</http.log>
        <http.log.wire>WARN</http.log.wire>
      </properties>

      <dependencies>
        <dependency>
          <groupId>org.hawkular.agent</groupId>
          <artifactId>hawkular-agent-itest-dist</artifactId>
          <version>0.11.2.Final</version>
          <scope>test</scope>
          <type>zip</type>
        </dependency>
      </dependencies>

      <build>
        <plugins>

          <!-- Unzip hawkular-agent-itest-dist under target of the present module -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
              <execution>
                <id>unpack</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>unpack</goal>
                </goals>
                <configuration>
                  <artifactItems>
                    <artifactItem>
                      <groupId>org.hawkular.agent</groupId>
                      <artifactId>hawkular-agent-itest-dist</artifactId>
                      <type>zip</type>
                      <outputDirectory>${hawkular.agent.itest.run.dir}</outputDirectory>
                    </artifactItem>
                  </artifactItems>
                </configuration>
              </execution>
            </executions>
          </plugin>

          <!-- Add a management user to the unzipped hawkular-agent-itest-dist -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
              <execution>
                <phase>pre-integration-test</phase>
                <configuration>
                  <target>
                    <property name="hawkular.agent.itest.standalone.dir" value="${hawkular.agent.itest.run.dir}/hawkular-agent-itest-dist-${project.version}/standalone/configuration" />
                    <!-- keep the encoded password in sync with ${hawkular.agent.itest.mgmt.password} -->
                    <concat append="true" destfile="${hawkular.agent.itest.standalone.dir}/mgmt-users.properties">${line.separator}${hawkular.agent.itest.mgmt.user}=86788b992b0749e353d7b18fb5ca8a63</concat>
                    <concat append="true" destfile="${hawkular.agent.itest.standalone.dir}/mgmt-groups.properties">${line.separator}${hawkular.agent.itest.mgmt.user}=</concat>
                  </target>
                </configuration>
                <goals>
                  <goal>run</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <configuration>
              <includes>
                <include>**/*ITest.class</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 -->
                <org.apache.commons.logging.Log>
                  org.apache.commons.logging.impl.SimpleLog
                </org.apache.commons.logging.Log>
                <org.apache.commons.logging.simplelog.log.org.apache.http>
                  ${http.log}
                </org.apache.commons.logging.simplelog.log.org.apache.http>
                <org.apache.commons.logging.simplelog.log.org.apache.http.wire>
                  ${http.log.wire}
                </org.apache.commons.logging.simplelog.log.org.apache.http.wire>
              </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>

          <!-- Start WildFly from the folder where we unzipped and configured hawkular-agent-itest-dist -->
          <plugin>
            <groupId>org.wildfly.plugins</groupId>
            <artifactId>wildfly-maven-plugin</artifactId>
            <configuration>
              <jboss-home>${hawkular.agent.itest.run.dir}/hawkular-agent-itest-dist-${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=${hawkular.log}</javaOpt>
                <javaOpt>-Dhawkular.log.accounts=${hawkular.log.accounts}</javaOpt>
                <javaOpt>-Dhawkular.log.agent=${hawkular.log.agent}</javaOpt>
                <javaOpt>-Dhawkular.log.alerts=${hawkular.log.alerts}</javaOpt>
                <javaOpt>-Dhawkular.log.bus=${hawkular.log.bus}</javaOpt>
                <javaOpt>-Dhawkular.log.cmdgw=${hawkular.log.cmdgw}</javaOpt>
                <javaOpt>-Dhawkular.log.availcreator=${hawkular.log.availcreator}</javaOpt>
                <javaOpt>-Dhawkular.log.pinger=${hawkular.log.pinger}</javaOpt>
                <javaOpt>-Dhawkular.log.inventory=${hawkular.log.inventory}</javaOpt>
                <javaOpt>-Dhawkular.log.metrics=${hawkular.log.metrics}</javaOpt>
                <javaOpt>-Dhawkular.log.nest=${hawkular.log.nest}</javaOpt>
                <javaOpt>-Dhawkular.log.datastax.driver=${hawkular.log.datastax.driver}</javaOpt>
                <javaOpt>-Dhawkular.log.liquibase=${hawkular.log.liquibase}</javaOpt>
                <javaOpt>-Dhawkular.log.cassandra=${hawkular.log.cassandra}</javaOpt>
                <javaOpt>-Dhawkular.log.ejb3=${hawkular.log.ejb3}</javaOpt>
                <javaOpt>-Dhawkular.log.rewrite=${hawkular.log.rewrite}</javaOpt>
                <javaOpt>-Dhawkular.log.rewrite=${hawkular.log.rewrite}</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-itest.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>

        </plugins>
      </build>
    </profile>
  </profiles>
</project>
