<?xml version="1.0" encoding="UTF-8"?>
<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">
  <parent>
    <groupId>org.kie</groupId>
    <artifactId>kie-wb-distributions</artifactId>
    <version>7.1.0.Beta2</version>
  </parent>
  <modelVersion>4.0.0</modelVersion>

  <artifactId>kie-wb-tests</artifactId>
  <packaging>pom</packaging>

  <name>KIE (Drools) Workbench Tests :: Parent</name>
  <description>Parent for integration tests for KIE Workbench and KIE Drools Workbench</description>

  <modules>
    <module>kie-wb-tests-rest</module>
    <module>kie-wb-tests-gui</module>
  </modules>

  <properties>
    <deployable.classifier.tomcat8>tomcat8</deployable.classifier.tomcat8>
    <deployable.classifier.wildfly10>wildfly10</deployable.classifier.wildfly10>
    <deployable.classifier.eap7>eap7</deployable.classifier.eap7>
    <deployable.classifier.swarm>swarm</deployable.classifier.swarm>
    <deployable.context>kie-wb</deployable.context>

    <deployable.groupId>org.kie</deployable.groupId>
    <deployable.artifactId>kie-wb</deployable.artifactId>
    <deployable.version>${version.org.kie}</deployable.version>

    <deployment.timeout>90000</deployment.timeout>

    <container.host>localhost</container.host>
    <container.port>8080</container.port>
    <kie.wb.url>http://${container.host}:${container.port}/${deployable.context}</kie.wb.url>

    <version.tomcat8>8.5.11</version.tomcat8>
    <version.wildfly10>10.1.0.Final</version.wildfly10>
  </properties>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.kie</groupId>
        <artifactId>kie-wb-tests-rest</artifactId>
        <version>${version.org.kie}</version>
      </dependency>
      <dependency>
        <groupId>org.kie</groupId>
        <artifactId>kie-wb-tests-gui</artifactId>
        <version>${version.org.kie}</version>
      </dependency>
      <dependency>
        <groupId>org.kie</groupId>
        <artifactId>kie-drools-wb-webapp</artifactId>
        <version>${deployable.version}</version>
        <classifier>${deployable.classifier.swarm}</classifier>
      </dependency>
      <dependency>
        <groupId>org.kie</groupId>
        <artifactId>kie-wb-webapp</artifactId>
        <version>${deployable.version}</version>
        <classifier>${deployable.classifier.swarm}</classifier>
      </dependency>
      <dependency>
        <groupId>org.kie</groupId>
        <artifactId>kie-wb</artifactId>
        <version>${deployable.version}</version>
        <classifier>${deployable.classifier.wildfly10}</classifier>
        <type>war</type>
      </dependency>
      <dependency>
        <groupId>org.kie</groupId>
        <artifactId>kie-drools-wb</artifactId>
        <version>${deployable.version}</version>
        <classifier>${deployable.classifier.wildfly10}</classifier>
        <type>war</type>
      </dependency>
      <dependency>
        <groupId>org.kie</groupId>
        <artifactId>kie-wb</artifactId>
        <version>${deployable.version}</version>
        <classifier>${deployable.classifier.eap7}</classifier>
        <type>war</type>
      </dependency>
      <dependency>
        <groupId>org.kie</groupId>
        <artifactId>kie-drools-wb</artifactId>
        <version>${deployable.version}</version>
        <classifier>${deployable.classifier.eap7}</classifier>
        <type>war</type>
      </dependency>
      <dependency>
        <groupId>org.kie</groupId>
        <artifactId>kie-wb</artifactId>
        <version>${deployable.version}</version>
        <classifier>${deployable.classifier.tomcat8}</classifier>
        <type>war</type>
      </dependency>
      <dependency>
        <groupId>org.kie</groupId>
        <artifactId>kie-drools-wb</artifactId>
        <version>${deployable.version}</version>
        <classifier>${deployable.classifier.tomcat8}</classifier>
        <type>war</type>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>link.bek.tools</groupId>
      <artifactId>issue-keeper-junit</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.assertj</groupId>
      <artifactId>assertj-core</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.codehaus.cargo</groupId>
          <artifactId>cargo-maven2-plugin</artifactId>
          <configuration>
            <container>
              <containerId>${cargo.container.id}</containerId>
              <systemProperties>
                <kie.maven.settings.custom>${project.build.testOutputDirectory}/settings.xml</kie.maven.settings.custom>
                <!-- Fixes issue when Tomcat hangs during deployment due to insufficient amount of entropy.
                     The property specifies less secure source of entropy, which is fine for testing.
                     See https://wiki.apache.org/tomcat/HowTo/FasterStartUp#Entropy_Source for more info -->
                <java.security.egd>file:/dev/./urandom</java.security.egd>
              </systemProperties>
            </container>
            <deployables>
              <deployable>
                <groupId>${deployable.groupId}</groupId>
                <artifactId>${deployable.artifactId}</artifactId>
                <!-- default, may be overridden in container specific profiles -->
                <classifier>${deployable.classifier}</classifier>
                <type>war</type>
                <properties>
                  <context>${deployable.context}</context>
                </properties>
                <pingURL>${kie.wb.url}</pingURL>
                <pingTimeout>${deployment.timeout}</pingTimeout>
              </deployable>
            </deployables>
            <configuration>
              <properties>
                <cargo.servlet.port>${container.port}</cargo.servlet.port>
                <cargo.servlet.users>
                  admin:admin1234;:admin|restAll:restAll1234;:admin,rest-all|restProject:restProject1234;:admin,rest-project|noRest:noRest1234;:admin
                </cargo.servlet.users>
              </properties>
            </configuration>
          </configuration>
          <executions>
            <execution>
              <id>start-container</id>
              <phase>pre-integration-test</phase>
              <goals>
                <goal>start</goal>
              </goals>
            </execution>
            <execution>
              <id>stop-container</id>
              <phase>post-integration-test</phase>
              <goals>
                <goal>stop</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-failsafe-plugin</artifactId>
          <configuration>
            <systemPropertyVariables>
              <kie.wb.url>${kie.wb.url}</kie.wb.url>
            </systemPropertyVariables>
            <failIfNoTests>false</failIfNoTests>
            <argLine>-Xmx1024m -Dfile.encoding=UTF-8</argLine>
          </configuration>
          <executions>
            <execution>
              <goals>
                <goal>integration-test</goal>
                <goal>verify</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
        <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>build-helper-maven-plugin</artifactId>
          <executions>
            <execution>
              <id>reserve-network-port</id>
              <goals>
                <goal>reserve-network-port</goal>
              </goals>
              <phase>pre-integration-test</phase>
              <configuration>
                <portNames>
                  <portName>container.port</portName>
                </portNames>
              </configuration>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>kie-drools-wb</id>
      <properties>
        <deployable.groupId>org.kie</deployable.groupId>
        <deployable.artifactId>kie-drools-wb</deployable.artifactId>
        <deployable.context>kie-drools-wb</deployable.context>
      </properties>
    </profile>

    <profile>
      <id>kie-wb</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <properties>
        <deployable.groupId>org.kie</deployable.groupId>
        <deployable.artifactId>kie-wb</deployable.artifactId>
        <deployable.context>kie-wb</deployable.context>
      </properties>
    </profile>

    <profile>
      <id>wildfly10</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <dependencies>
        <dependency>
          <groupId>org.kie</groupId>
          <artifactId>kie-wb</artifactId>
          <classifier>${deployable.classifier.wildfly10}</classifier>
          <scope>test</scope>
          <type>war</type>
        </dependency>
        <dependency>
          <groupId>org.kie</groupId>
          <artifactId>kie-drools-wb</artifactId>
          <classifier>${deployable.classifier.wildfly10}</classifier>
          <scope>test</scope>
          <type>war</type>
        </dependency>
      </dependencies>
      <properties>
        <cargo.container.id>wildfly10x</cargo.container.id>
      </properties>
      <build>
        <pluginManagement>
          <plugins>
            <plugin>
              <groupId>org.codehaus.cargo</groupId>
              <artifactId>cargo-maven2-plugin</artifactId>
              <configuration>
                <container>
                  <type>installed</type>
                  <artifactInstaller>
                    <groupId>org.wildfly</groupId>
                    <artifactId>wildfly-dist</artifactId>
                    <version>${version.wildfly10}</version>
                  </artifactInstaller>
                </container>
                <configuration>
                  <properties>
                    <cargo.jboss.configuration>standalone-full</cargo.jboss.configuration>
                    <cargo.jvmargs>-Xmx1024m</cargo.jvmargs>
                  </properties>
                </configuration>
                <deployables>
                  <deployable>
                    <groupId>${deployable.groupId}</groupId>
                    <artifactId>${deployable.artifactId}</artifactId>
                    <classifier>${deployable.classifier.wildfly10}</classifier>
                    <type>war</type>
                  </deployable>
                </deployables>
              </configuration>
            </plugin>
          </plugins>
        </pluginManagement>
      </build>
    </profile>
    <profile>
      <id>eap7</id>
      <activation>
        <property>
          <name>container</name>
          <value>eap7</value>
        </property>
      </activation>
      <dependencies>
        <dependency>
          <groupId>org.kie</groupId>
          <artifactId>kie-wb</artifactId>
          <classifier>${deployable.classifier.eap7}</classifier>
          <scope>test</scope>
          <type>war</type>
        </dependency>
        <dependency>
          <groupId>org.kie</groupId>
          <artifactId>kie-drools-wb</artifactId>
          <classifier>${deployable.classifier.eap7}</classifier>
          <scope>test</scope>
          <type>war</type>
        </dependency>
      </dependencies>
      <properties>
        <!-- The EAP 7.x binary can't be anonymously downloaded due to license issues. It can be downloaded manually
             and for free (e.g. from http://www.jboss.org/products/eap/download/) and the zip location needs to be specified
             here or via system property when running the build (don't forget to use the `file://` prefix when
             referencing the zip from local filesystem). -->
        <eap7.download.url>valid-url-for-eap-7-zip-needs-to-be-specified-here-or-via-cmd-line</eap7.download.url>
      </properties>
      <build>
        <pluginManagement>
          <plugins>
            <plugin>
              <groupId>org.codehaus.cargo</groupId>
              <artifactId>cargo-maven2-plugin</artifactId>
              <configuration>
                <container>
                  <type>installed</type>
                  <!-- WildFly ~= EAP 7, so just reuse the wildfly10x containerId -->
                  <containerId>wildfly10x</containerId>
                  <type>installed</type>
                  <zipUrlInstaller>
                    <url>${eap7.download.url}</url>
                  </zipUrlInstaller>
                </container>
                <configuration>
                  <properties>
                    <cargo.jboss.configuration>standalone-full</cargo.jboss.configuration>
                    <cargo.jvmargs>-Xmx1024m</cargo.jvmargs>
                  </properties>
                </configuration>
                <deployables>
                  <deployable>
                    <groupId>${deployable.groupId}</groupId>
                    <artifactId>${deployable.artifactId}</artifactId>
                    <classifier>${deployable.classifier.eap7}</classifier>
                    <type>war</type>
                  </deployable>
                </deployables>
              </configuration>
            </plugin>
          </plugins>
        </pluginManagement>
      </build>
    </profile>
    <profile>
      <id>tomcat8</id>
      <activation>
        <property>
          <name>container</name>
          <value>tomcat8</value>
        </property>
      </activation>
      <dependencies>
        <dependency>
          <groupId>org.kie</groupId>
          <artifactId>kie-wb</artifactId>
          <classifier>${deployable.classifier.tomcat8}</classifier>
          <type>war</type>
        </dependency>
        <dependency>
          <groupId>org.kie</groupId>
          <artifactId>kie-drools-wb</artifactId>
          <classifier>${deployable.classifier.tomcat8}</classifier>
          <type>war</type>
        </dependency>
        <dependency>
          <groupId>org.kie</groupId>
          <artifactId>kie-tomcat-integration</artifactId>
        </dependency>
        <dependency>
          <groupId>org.jboss.spec.javax.security.jacc</groupId>
          <artifactId>jboss-jacc-api_1.5_spec</artifactId>
        </dependency>
        <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-api</artifactId>
        </dependency>
        <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-jdk14</artifactId>
        </dependency>
      </dependencies>
      <properties>
        <cargo.container.id>tomcat8x</cargo.container.id>
      </properties>
      <build>
        <pluginManagement>
          <plugins>
            <plugin>
              <groupId>org.codehaus.cargo</groupId>
              <artifactId>cargo-maven2-plugin</artifactId>
              <configuration>
                <container>
                  <type>installed</type>
                  <artifactInstaller>
                    <groupId>org.apache.tomcat</groupId>
                    <artifactId>tomcat</artifactId>
                    <version>${version.tomcat8}</version>
                  </artifactInstaller>
                  <systemProperties>
                    <org.jboss.logging.provider>jdk</org.jboss.logging.provider>
                  </systemProperties>
                  <dependencies>
                    <dependency>
                      <groupId>org.slf4j</groupId>
                      <artifactId>slf4j-api</artifactId>
                    </dependency>
                    <dependency>
                      <groupId>org.slf4j</groupId>
                      <artifactId>slf4j-jdk14</artifactId>
                    </dependency>
                    <dependency>
                      <groupId>org.kie</groupId>
                      <artifactId>kie-tomcat-integration</artifactId>
                    </dependency>
                    <dependency>
                      <groupId>org.jboss.spec.javax.security.jacc</groupId>
                      <artifactId>jboss-jacc-api_1.5_spec</artifactId>
                    </dependency>
                  </dependencies>
                </container>
                <configuration>
                  <properties>
                    <cargo.jvmargs>-Xmx1024m</cargo.jvmargs>
                  </properties>
                </configuration>
                <deployables>
                  <deployable>
                    <groupId>${deployable.groupId}</groupId>
                    <artifactId>${deployable.artifactId}</artifactId>
                    <classifier>${deployable.classifier.tomcat8}</classifier>
                    <type>war</type>
                  </deployable>
                </deployables>
              </configuration>
            </plugin>
          </plugins>
        </pluginManagement>
      </build>
    </profile>

    <profile>
      <id>wildfly-swarm</id>
      <activation>
        <property>
          <name>container</name>
          <value>wildfly-swarm</value>
        </property>
      </activation>
      <properties>
        <deployable.context/>
        <cargo.maven.skip>true</cargo.maven.skip>
      </properties>
      <dependencies>
        <dependency>
          <groupId>org.kie</groupId>
          <artifactId>kie-drools-wb-webapp</artifactId>
          <classifier>${deployable.classifier.swarm}</classifier>
          <exclusions>
            <exclusion>
              <groupId>*</groupId>
              <artifactId>*</artifactId>
            </exclusion>
          </exclusions>
        </dependency>
        <dependency>
          <groupId>org.kie</groupId>
          <artifactId>kie-wb-webapp</artifactId>
          <classifier>${deployable.classifier.swarm}</classifier>
          <exclusions>
            <exclusion>
              <groupId>*</groupId>
              <artifactId>*</artifactId>
            </exclusion>
          </exclusions>
        </dependency>
      </dependencies>
      <build>
        <pluginManagement>
          <plugins>
            <plugin>
              <groupId>org.wildfly.swarm</groupId>
              <artifactId>wildfly-swarm-plugin</artifactId>
              <executions>
                <execution>
                  <id>start</id>
                  <phase>pre-integration-test</phase>
                  <goals>
                    <goal>multistart</goal>
                  </goals>
                  <configuration>
                    <properties>
                      <!-- Not ideal as it relies on the module structure, but for now it is safe to assume that all testing modules
                           are children of this one.-->
                      <swarm.project.stage.file>${project.build.testOutputDirectory}/sample-swarm-config.yml</swarm.project.stage.file>
                      <swarm.logging>INFO</swarm.logging>
                      <swarm.bind.address>127.0.0.1</swarm.bind.address>
                      <org.uberfire.nio.git.dir>${project.build.directory}/wb-dirs</org.uberfire.nio.git.dir>
                      <org.uberfire.nio.git.ssh.cert.dir>${project.build.directory}/wb-dirs</org.uberfire.nio.git.ssh.cert.dir>
                      <org.uberfire.metadata.index.dir>${project.build.directory}/wb-dirs</org.uberfire.metadata.index.dir>
                      <org.guvnor.m2repo.dir>${project.build.directory}/wb-dirs</org.guvnor.m2repo.dir>
                    </properties>
                    <processes>
                      <process>
                        <groupId>org.kie</groupId>
                        <artifactId>${deployable.artifactId}-webapp</artifactId>
                        <classifier>${deployable.classifier.swarm}</classifier>
                      </process>
                      <properties>
                        <start.timeout.seconds>120</start.timeout.seconds>
                      </properties>
                    </processes>
                  </configuration>
                </execution>
                <execution>
                  <id>stop</id>
                  <phase>post-integration-test</phase>
                  <goals>
                    <goal>stop</goal>
                  </goals>
                </execution>
              </executions>
            </plugin>
          </plugins>
        </pluginManagement>
      </build>
    </profile>
    <profile>
      <id>productized</id>
      <activation>
        <property>
          <name>productized</name>
        </property>
      </activation>
      <properties>
        <!-- We can not run the tests on WildFly 10 as there is no wildfly10-redhat.war being created. We also can not
             easily run the tests on EAP7 as that requires custom URL pointing to the EAP7 zip. The only option would be
             to run the tests on Tomcat, but that proved unreliable in some cases (needs to be investigated again, see
             https://issues.jboss.org/browse/GUVNOR-3015) -->
        <skipTests>true</skipTests>
        <cargo.maven.skip>true</cargo.maven.skip>
      </properties>
    </profile>
    <!-- Tests are enabled by default. Specific modules (like Selenium UI tests) may disable them as they require
         additional resources (e.g. browser) which are not always available. Such additional tests are then enabled
         by specific profile. -->
    <profile>
      <id>disable-cargo-and-tests</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven2-plugin</artifactId>
            <executions>
              <execution>
                <id>start-container</id>
                <phase>none</phase>
                <!-- do nothing, container is not managed by Cargo! -->
                <goals/>
              </execution>
              <execution>
                <id>stop-container</id>
                <phase>none</phase>
                <!-- do nothing, container is not managed by Cargo! -->
                <goals/>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <configuration>
              <skipITs>true</skipITs>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

</project>