<?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.67.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>
    <offset.container.port>8180</offset.container.port>
    <single.kie.server.base.http.url>http://${container.hostname}:${container.port}/${kie.server.context}/services/rest/server</single.kie.server.base.http.url>
    <separate.kie.server.base.http.url>http://${container.hostname}:${offset.container.port}/${kie.server.context}/services/rest/server</separate.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>jakarta.xml.ws</groupId>
      <artifactId>jakarta.xml.ws-api</artifactId>
    </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>
      <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>generate-resources</phase>
            <configuration>
              <portNames>
                <portName>cargo.jboss.ajp.port</portName>
                <portName>cargo.jboss.https.port</portName>
                <portName>cargo.jboss.management-http.port</portName>
                <portName>cargo.jboss.management-https.port</portName>
              </portNames>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>wildfly</id>
      <!-- wildfly test is disabled because wildfly-camel is not aligned to wildfly 23 -->
      <build>
        <pluginManagement>
          <plugins>
            <plugin>
              <artifactId>maven-failsafe-plugin</artifactId>
              <configuration>
                <skipITs>true</skipITs>
              </configuration>
            </plugin>
          </plugins>
        </pluginManagement>
      </build>
    </profile>
    <profile>
      <id>eap</id>
      <activation>
        <property>
          <name>fuse.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="${fuse.eap.url}" dest="${project.build.directory}/eap-fuse.zip" />
                    <unzip src="${project.build.directory}/eap-fuse.zip" dest="${project.build.directory}/application-server-fuse">
                      <cutdirsmapper dirs="1" />
                    </unzip>
                    <get src="${kie-server.eap.url}" dest="${project.build.directory}/eap-kie-server.zip" />
                    <unzip src="${project.build.directory}/eap-kie-server.zip" dest="${project.build.directory}/application-server-kie-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-fuse" />
                  </target>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven3-plugin</artifactId>
            <executions>
              <execution>
                <id>start-fuse-container</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>start</goal>
                </goals>
                <configuration>
                  <container>
                    <containerId>wildfly23x</containerId>
                    <home>${project.build.directory}/application-server-fuse</home>
                    <type>installed</type>
                    <contextKey>fuse</contextKey>
                    <systemProperties>
                      <kie.server.port>${offset.container.port}</kie.server.port>
                    </systemProperties>
                  </container>
                  <deployables>
                    <deployable>
                      <groupId>org.drools</groupId>
                      <artifactId>camel-container-tests-module</artifactId>
                      <type>war</type>
                    </deployable>
                  </deployables>
                  <configuration>
                    <home>${project.build.directory}/application-server-fuse-configuration</home>
                    <properties>
                      <cargo.jboss.configuration>standalone-full</cargo.jboss.configuration>
                      <cargo.jvmargs>-Djava.net.preferIPv4Stack=true</cargo.jvmargs>
                      <cargo.jboss.ajp.port>${cargo.jboss.ajp.port}</cargo.jboss.ajp.port>
                      <cargo.jboss.https.port>${cargo.jboss.https.port}</cargo.jboss.https.port>
                      <cargo.jboss.management-http.port>${cargo.jboss.management-http.port}</cargo.jboss.management-http.port>
                      <cargo.jboss.management-https.port>${cargo.jboss.management-https.port}</cargo.jboss.management-https.port>
                    </properties>
                  </configuration>
                </configuration>
              </execution>
              <execution>
                <id>stop-fuse-container</id>
                <phase>post-integration-test</phase>
                <goals>
                  <goal>stop</goal>
                </goals>
                <configuration>
                  <container>
                    <contextKey>fuse</contextKey>
                  </container>
                </configuration>
              </execution>
              <execution>
                <id>start-kie-server-container</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>start</goal>
                </goals>
                <configuration>
                  <container>
                    <containerId>wildfly23x</containerId>
                    <home>${project.build.directory}/application-server-kie-server</home>
                    <type>installed</type>
                    <contextKey>kie-server</contextKey>
                    <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>
                      <location>${kie.server.war}</location>
                      <type>war</type>
                      <properties>
                        <context>${kie.server.context}</context>
                      </properties>
                      <pingURL>${separate.kie.server.base.http.url}</pingURL>
                      <pingTimeout>300000</pingTimeout>
                    </deployable>
                  </deployables>
                  <configuration>
                    <home>${project.build.directory}/application-server-kie-server-configuration</home>
                    <properties>
                      <cargo.jboss.configuration>standalone-full</cargo.jboss.configuration>
                      <cargo.jvmargs>-Djava.net.preferIPv4Stack=true</cargo.jvmargs>
                      <cargo.jboss.ajp.port>${cargo.jboss.ajp.port}</cargo.jboss.ajp.port>
                      <cargo.jboss.https.port>${cargo.jboss.https.port}</cargo.jboss.https.port>
                      <cargo.jboss.management-http.port>${cargo.jboss.management-http.port}</cargo.jboss.management-http.port>
                      <cargo.jboss.management-https.port>${cargo.jboss.management-https.port}</cargo.jboss.management-https.port>
                      <cargo.port.offset>100</cargo.port.offset>
                    </properties>
                    <users>
                      <user>
                        <name>yoda</name>
                        <password>test</password>
                        <roles>
                          <role>kie-server</role>
                          <role>guest</role>
                        </roles>
                      </user>
                    </users>
                  </configuration>
                </configuration>
              </execution>
              <execution>
                <id>stop-kie-server-container</id>
                <phase>post-integration-test</phase>
                <goals>
                  <goal>stop</goal>
                </goals>
                <configuration>
                  <container>
                    <contextKey>kie-server</contextKey>
                  </container>
                </configuration>
              </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-maven3-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>
