<?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>
    <artifactId>camel-container-tests</artifactId>
    <groupId>org.drools</groupId>
    <version>7.41.0.Final</version>
  </parent>
  <modelVersion>4.0.0</modelVersion>

  <artifactId>camel-container-integration-tests</artifactId>

  <name>Container tests for Camel integration</name>
  <description>
    Container tests for Camel integration
  </description>

  <properties>
    <!-- <container.port/> can't define the default port value, because the build-helper-maven-plugin:reserve-network-port
         is not able to override the value of the property. The port number would then always be the same
         (the default one, unless changed from outside) -->
    <kie.server.context>kie-server-services</kie.server.context>
    <kie.server.classifier>ee7</kie.server.classifier>
    <container.hostname>localhost</container.hostname>
    <container.port>8080</container.port>
    <kie.server.base.http.url>http://${container.hostname}:${container.port}/${kie.server.context}/services/rest/server</kie.server.base.http.url>
    <kie.maven.settings.custom>${user.home}/.m2/settings.xml</kie.maven.settings.custom>
    <org.kie.server.mode.production>PRODUCTION</org.kie.server.mode.production>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-rs-client</artifactId>
      <exclusions>
        <exclusion>
          <artifactId>woodstox-core</artifactId>
          <groupId>com.fasterxml.woodstox</groupId>
        </exclusion>
      </exclusions>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-transports-http-hc</artifactId>
      <scope>runtime</scope>
      <exclusions>
        <exclusion>
          <artifactId>woodstox-core</artifactId>
          <groupId>com.fasterxml.woodstox</groupId>
        </exclusion>
      </exclusions>
    </dependency>

    <dependency>
      <groupId>org.drools</groupId>
      <artifactId>camel-container-tests-api</artifactId>
    </dependency>
    <dependency>
      <groupId>org.kie</groupId>
      <artifactId>kie-ci</artifactId>
    </dependency>
    <dependency>
      <groupId>org.jbpm</groupId>
      <artifactId>jbpm-bpmn2</artifactId>
    </dependency>
    <dependency>
      <groupId>org.kie.server</groupId>
      <artifactId>kie-server-api</artifactId>
    </dependency>

    <dependency>
      <groupId>org.codehaus.jettison</groupId>
      <artifactId>jettison</artifactId>
    </dependency>

    <dependency>
      <groupId>org.drools</groupId>
      <artifactId>camel-container-tests-module</artifactId>
      <type>war</type>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>org.kie.server</groupId>
      <artifactId>kie-server</artifactId>
      <!-- default, may be overridden in container specific profiles -->
      <classifier>${kie.server.classifier}</classifier>
      <type>war</type>
    </dependency>

    <dependency>
      <groupId>org.drools</groupId>
      <artifactId>drools-core</artifactId>
      <type>test-jar</type>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.assertj</groupId>
      <artifactId>assertj-core</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <testResources>
      <testResource>
        <directory>src/test/resources</directory>
        <filtering>false</filtering>
      </testResource>
      <testResource>
        <directory>src/test/filtered-resources</directory>
        <filtering>true</filtering>
      </testResource>
    </testResources>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <configuration>
          <systemProperties combine.children="append">
            <org.apache.cxf.stax.allowInsecureParser>1</org.apache.cxf.stax.allowInsecureParser>
          </systemProperties>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>wildfly</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
              <execution>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>unpack</goal>
                </goals>
                <configuration>
                  <artifactItems>
                    <artifactItem>
                      <groupId>org.wildfly</groupId>
                      <artifactId>wildfly-dist</artifactId>
                      <version>${version.org.wildfly}</version>
                      <type>zip</type>
                      <outputDirectory>${project.build.directory}/application-server</outputDirectory>
                    </artifactItem>
                    <artifactItem>
                      <groupId>org.wildfly.camel</groupId>
                      <artifactId>wildfly-camel-patch</artifactId>
                      <version>${version.org.wildfly.camel}</version>
                      <type>tar.gz</type>
                      <outputDirectory>${project.build.directory}/application-server/wildfly-${version.org.wildfly}</outputDirectory>
                    </artifactItem>
                  </artifactItems>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven2-plugin</artifactId>
            <configuration>
              <container>
                <containerId>wildfly19x</containerId>
                <home>${project.build.directory}/application-server/wildfly-${version.org.wildfly}</home>
                <type>installed</type>
                <systemProperties>
                  <kie.maven.settings.custom>${kie.maven.settings.custom}</kie.maven.settings.custom>
                  <org.kie.server.mode>${org.kie.server.mode.production}</org.kie.server.mode>
                </systemProperties>
              </container>
              <deployables>
                <deployable>
                  <groupId>org.kie.server</groupId>
                  <artifactId>kie-server</artifactId>
                  <!-- default, may be overridden in container specific profiles -->
                  <classifier>${kie.server.classifier}</classifier>
                  <type>war</type>
                  <properties>
                    <context>${kie.server.context}</context>
                  </properties>
                  <pingURL>${kie.server.base.http.url}</pingURL>
                  <pingTimeout>300000</pingTimeout>
                </deployable>
                <deployable>
                  <groupId>org.drools</groupId>
                  <artifactId>camel-container-tests-module</artifactId>
                  <type>war</type>
                </deployable>
              </deployables>
              <configuration>
                <users>
                  <user>
                    <name>yoda</name>
                    <password>test</password>
                    <roles>
                      <role>kie-server</role>
                      <role>guest</role>
                    </roles>
                  </user>
                </users>
                <properties>
                  <cargo.jboss.configuration>standalone-full-camel</cargo.jboss.configuration>
                  <cargo.servlet.port>${container.port}</cargo.servlet.port>

                  <!--
                  <cargo.start.jvmargs>
                    -Xdebug
                    -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8787
                    -Xnoagent
                  </cargo.start.jvmargs>
                  -->
                </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>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>eap</id>
      <activation>
        <property>
          <name>eap.url</name>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
              <execution>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>run</goal>
                </goals>
                <configuration>
                  <target>
                    <get src="${eap.url}" dest="${project.build.directory}/eap.zip" />
                    <unzip src="${project.build.directory}/eap.zip" dest="${project.build.directory}/application-server">
                      <cutdirsmapper dirs="1" />
                    </unzip>
                    <get src="${fuse.on.eap.url}" dest="${project.build.directory}/fuse-on-eap.jar"/>
                    <java jar="${project.build.directory}/fuse-on-eap.jar" fork="true" dir="${project.build.directory}/application-server" />
                  </target>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven2-plugin</artifactId>
            <configuration>
              <container>
                <containerId>wildfly19x</containerId>
                <home>${project.build.directory}/application-server</home>
                <type>installed</type>
                <systemProperties>
                  <kie.maven.settings.custom>${kie.maven.settings.custom}</kie.maven.settings.custom>
                  <org.kie.server.mode>${org.kie.server.mode.production}</org.kie.server.mode>
                </systemProperties>
              </container>
              <deployables>
                <deployable>
                  <groupId>org.drools</groupId>
                  <artifactId>camel-container-tests-module</artifactId>
                  <type>war</type>
                </deployable>
                <deployable>
                  <location>${kie.server.war}</location>
                  <type>war</type>
                  <properties>
                    <context>${kie.server.context}</context>
                  </properties>
                  <pingURL>${kie.server.base.http.url}</pingURL>
                  <pingTimeout>300000</pingTimeout>
                </deployable>
              </deployables>
              <configuration>
                <properties>
                  <cargo.jboss.configuration>standalone-full</cargo.jboss.configuration>
                  <cargo.jvmargs>-Djava.net.preferIPv4Stack=true</cargo.jvmargs>
                </properties>
                <users>
                  <user>
                    <name>yoda</name>
                    <password>test</password>
                    <roles>
                      <role>kie-server</role>
                      <role>guest</role>
                    </roles>
                  </user>
                </users>
              </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>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>custom-container</id>
      <activation>
        <!-- The tests are not executed unless specific container profile is used. Disable cargo by default. -->
        <activeByDefault>true</activeByDefault>
        <property>
          <name>custom-container</name>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven2-plugin</artifactId>
            <executions>
              <execution>
                <id>start-container</id>
                <phase>none</phase>
                <goals/>
                <!-- do nothing, container is not managed by cargo -->
              </execution>
              <execution>
                <id>stop-container</id>
                <phase>none</phase>
                <goals/>
                <!-- do nothing, container is not managed by cargo -->
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <!-- Integration tests are skipped by default. They are activated when specific container profile is used. -->
      <id>skipITs-by-default</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <build>
        <pluginManagement>
          <plugins>
            <plugin>
              <artifactId>maven-failsafe-plugin</artifactId>
              <configuration>
                <skipITs>true</skipITs>
              </configuration>
            </plugin>
          </plugins>
        </pluginManagement>
      </build>
    </profile>
  </profiles>
</project>
