<!--

    Copyright 2014-2017 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.commons</groupId>
    <artifactId>hawkular-nest-parent</artifactId>
    <version>0.9.2.Final</version>
  </parent>
  <artifactId>hawkular-nest-itest</artifactId>
  <name>Hawkular Nest Integration Tests</name>

  <properties>
    <surefire.testng.verbose>3</surefire.testng.verbose>
    <failsafe.itest.includes>**/*ITest.class</failsafe.itest.includes>

    <hawkular.itest.rest.user>itest-rest</hawkular.itest.rest.user>
    <!-- <hawkular.itest.rest.password> set to a random value using gmaven plugin </hawkular.itest.rest.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.log.root>INFO</hawkular.log.root>
    <hawkular.log.console>TRACE</hawkular.log.console>
    <hawkular.log.bus>TRACE</hawkular.log.bus>
    <hawkular.log.cmdgw>TRACE</hawkular.log.cmdgw>
    <hawkular.log.nest>INFO</hawkular.log.nest>
    <hawkular.log.datastax.driver>INFO</hawkular.log.datastax.driver>
    <hawkular.log.cassandra>INFO</hawkular.log.cassandra>

  </properties>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.jboss.arquillian</groupId>
        <artifactId>arquillian-bom</artifactId>
        <version>${version.org.jboss.arquillian}</version>
        <scope>import</scope>
        <type>pom</type>
      </dependency>

      <dependency>
        <groupId>org.wildfly.arquillian</groupId>
        <artifactId>wildfly-arquillian-container-managed</artifactId>
        <version>${version.org.wildfly.arquillian}</version>
      </dependency>

    </dependencies>
  </dependencyManagement>

  <dependencies>

    <dependency>
      <groupId>com.squareup.okhttp3</groupId>
      <artifactId>okhttp</artifactId>
      <scope>test</scope>
    </dependency>

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

    <dependency>
      <groupId>javax.enterprise</groupId>
      <artifactId>cdi-api</artifactId>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>javax.inject</groupId>
      <artifactId>javax.inject</artifactId>
      <scope>provided</scope>
    </dependency>

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

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

    <dependency>
      <groupId>org.hawkular.commons</groupId>
      <artifactId>hawkular-command-gateway-itest</artifactId>
      <version>${project.version}</version>
      <scope>test</scope>
      <type>test-jar</type>
    </dependency>

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

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

    <dependency>
      <groupId>org.hawkular.commons</groupId>
      <artifactId>hawkular-nest-feature-pack</artifactId>
      <version>${project.version}</version>
      <type>zip</type>
    </dependency>

    <dependency>
      <groupId>org.hawkular.commons</groupId>
      <artifactId>hawkular-rest-status</artifactId>
      <version>${project.version}</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.jboss.arquillian.testng</groupId>
      <artifactId>arquillian-testng-container</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.jboss.shrinkwrap.resolver</groupId>
      <artifactId>shrinkwrap-resolver-impl-maven</artifactId>
      <scope>test</scope>
    </dependency>

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

    <dependency>
      <groupId>org.wildfly.arquillian</groupId>
      <artifactId>wildfly-arquillian-container-managed</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <artifactId>resteasy-jaxrs</artifactId>
      <scope>provided</scope>
    </dependency>

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


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

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <configuration>
          <dependenciesToScan>
            <dependency>org.hawkular.commons:hawkular-command-gateway-itest</dependency>
          </dependenciesToScan>
          <includes>
            <include>${failsafe.itest.includes}</include>
          </includes>
          <systemPropertyVariables>
            <jboss.home>${project.build.directory}/${project.build.finalName}</jboss.home>
            <jboss.options>-Xmx1024m -XX:MaxPermSize=1024m
                -Dhawkular.log.root=${hawkular.log.root}
                -Dhawkular.log.console=${hawkular.log.console}
                -Dhawkular.log.bus=${hawkular.log.bus}
                -Dhawkular.log.cmdgw=${hawkular.log.cmdgw}
                -Dhawkular.log.nest=${hawkular.log.nest}
                -Dhawkular.log.datastax.driver=${hawkular.log.datastax.driver}
                -Dhawkular.log.cassandra=${hawkular.log.cassandra}
                -Dhawkular.backend=embedded_cassandra
            </jboss.options>
            <shrinkwrap.maven.settings>${project.build.directory}/shrinkwrap-maven-settings.xml</shrinkwrap.maven.settings>

            <hawkular.itest.rest.user>${hawkular.itest.rest.user}</hawkular.itest.rest.user>
            <hawkular.itest.rest.password>${hawkular.itest.rest.password}</hawkular.itest.rest.password>

            <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>
            <java.util.logging.config.file>${project.build.testOutputDirectory}/logging.properties</java.util.logging.config.file>
          </systemPropertyVariables>
          <properties>
            <property>
              <name>surefire.testng.verbose</name>
              <value>${surefire.testng.verbose}</value>
            </property>
          </properties>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
      </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.codehaus.gmavenplus</groupId>
        <artifactId>gmavenplus-plugin</artifactId>
        <executions>
          <execution>
            <phase>compile</phase>
            <goals>
              <goal>execute</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <scripts>
            <script><![CDATA[
              import org.apache.maven.settings.io.xpp3.SettingsXpp3Writer
              import org.apache.maven.settings.SettingsUtils
              import org.apache.maven.settings.Settings

              project.properties['hawkular.itest.rest.password'] = UUID.randomUUID().toString()

              Settings settings = SettingsUtils.copySettings(session.settings)
              settings.setServers(null)
              String outputPath = "${project.build.directory}/shrinkwrap-maven-settings.xml"
              Writer out = null
              try {
                out = new OutputStreamWriter(new FileOutputStream(new File(outputPath)), "utf-8")
                new SettingsXpp3Writer().write(out, settings)
              } finally {
                if (out != null) {
                  out.close()
                }
              }
            ]]></script>
          </scripts>
        </configuration>
        <dependencies>
          <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId>
            <version>${version.org.codehaus.groovy}</version>
            <scope>runtime</scope>
          </dependency>
        </dependencies>
      </plugin>

      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>create-itest-users</id>
            <phase>process-classes</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <executable>java</executable>
              <environmentVariables>
                <JBOSS_HOME>${project.build.directory}/${project.build.finalName}</JBOSS_HOME>
              </environmentVariables>
              <arguments>
                <argument>-jar</argument>
                <argument>${project.build.directory}/${project.build.finalName}/jboss-modules.jar</argument>
                <argument>-mp</argument>
                <argument>${project.build.directory}/${project.build.finalName}/modules</argument>
                <argument>org.jboss.as.domain-add-user</argument>
                <argument>-a</argument>
                <argument>--user</argument>
                <argument>${hawkular.itest.rest.user}</argument>
                <argument>--password</argument>
                <argument>${hawkular.itest.rest.password}</argument>
                <argument>--group</argument>
                <argument>read-write,read-only</argument>
              </arguments>
            </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>

    </plugins>
  </build>

</project>
