<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>ch.so.agi.gretl</groupId>
    <artifactId>gretl-runtime-parent</artifactId>
    <version>6.0.0-SNAPSHOT</version>
  </parent>
  <artifactId>gretl-integration-tests</artifactId>
  <packaging>jar</packaging>
  <name>GRETL Runtime Backing-Service Integration Tests</name>
  <description>Artifact job tests; service scenarios are enabled with backing-services.</description>

  <dependencies>
    <!-- Direct product edges include sources and all test-JVM contributions in coverage aggregation. -->
    <dependency>
      <groupId>ch.so.agi.gretl</groupId>
      <artifactId>gretl-api</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>ch.so.agi.gretl</groupId>
      <artifactId>gretl-runner</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>ch.so.agi.gretl</groupId>
      <artifactId>gretl-groovy</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>ch.so.agi.gretl</groupId>
      <artifactId>gretl-i18n</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>ch.so.agi.gretl</groupId>
      <artifactId>gretl-logging</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>ch.so.agi.gretl</groupId>
      <artifactId>gretl-packager</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>ch.so.agi.gretl</groupId>
      <artifactId>gretl-job-runtime</artifactId>
      <version>${project.version}</version>
    </dependency>
    <!-- Reactor edge: packaging jobs always uses this candidate's distribution. -->
    <dependency>
      <groupId>ch.so.agi.gretl</groupId>
      <artifactId>gretl-dist</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>ch.so.agi.gretl</groupId>
      <artifactId>gretl-cli</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>ch.so.agi.gretl</groupId>
      <artifactId>gretl-database-tasks</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>ch.so.agi.gretl</groupId>
      <artifactId>gretl-io-tasks</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>ch.so.agi.gretl</groupId>
      <artifactId>gretl-ilivalidator</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>ch.so.agi.gretl</groupId>
      <artifactId>gretl-interlis-tasks</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>org.testcontainers</groupId>
      <artifactId>testcontainers</artifactId>
      <version>${testcontainers.version}</version>
      <scope>test</scope>
      <exclusions>
        <exclusion>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-api</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.testcontainers</groupId>
      <artifactId>postgresql</artifactId>
      <version>${testcontainers.version}</version>
      <scope>test</scope>
      <exclusions>
        <exclusion>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-api</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.postgresql</groupId>
      <artifactId>postgresql</artifactId>
      <version>${postgresql.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>commons-net</groupId>
      <artifactId>commons-net</artifactId>
      <version>${commons-net.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.floci</groupId>
      <artifactId>testcontainers-floci</artifactId>
      <version>${testcontainers-floci.version}</version>
      <scope>test</scope>
      <exclusions>
        <exclusion>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-api</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>software.amazon.awssdk</groupId>
      <artifactId>s3</artifactId>
      <version>${aws-sdk.version}</version>
      <scope>test</scope>
      <exclusions>
        <exclusion>
          <groupId>software.amazon.awssdk</groupId>
          <artifactId>netty-nio-client</artifactId>
        </exclusion>
        <exclusion>
          <groupId>software.amazon.awssdk</groupId>
          <artifactId>apache-client</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>software.amazon.awssdk</groupId>
      <artifactId>url-connection-client</artifactId>
      <version>${aws-sdk.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.platform</groupId>
      <artifactId>junit-platform-launcher</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>${jacoco.version}</version>
        <executions>
          <execution>
            <id>coverage-aggregate</id>
            <phase>verify</phase>
            <goals><goal>report-aggregate</goal></goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <systemPropertyVariables>
            <junit.jupiter.extensions.autodetection.enabled>true</junit.jupiter.extensions.autodetection.enabled>
            <gretl.test.runId>${gretl.test.runId}</gretl.test.runId>
            <gretl.test.imageMetadata>${maven.multiModuleProjectDirectory}/gretl-dist/target/image/candidate.json</gretl.test.imageMetadata>
          </systemPropertyVariables>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <includes><include>${gretl.test.includes}</include></includes>
          <excludes><exclude>**/ImageRuntimeIT.java</exclude></excludes>
          <systemPropertyVariables>
            <junit.jupiter.extensions.autodetection.enabled>true</junit.jupiter.extensions.autodetection.enabled>
            <gretl.test.runId>${gretl.test.runId}</gretl.test.runId>
            <gretl.test.imageMetadata>${maven.multiModuleProjectDirectory}/gretl-dist/target/image/candidate.json</gretl.test.imageMetadata>
            <gretl.test.reactorDistribution>${maven.multiModuleProjectDirectory}/gretl-dist/target/dist</gretl.test.reactorDistribution>
            <gretl.test.distributionArchive>${maven.multiModuleProjectDirectory}/gretl-dist/target/gretl-runtime-${project.version}-bin.zip</gretl.test.distributionArchive>
          </systemPropertyVariables>
          <forkCount>1</forkCount>
          <reuseForks>true</reuseForks>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <profiles>
  <profile>
    <id>backing-services</id>
    <build><plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <configuration><systemPropertyVariables>
          <gretl.test.operationCoverageFile>${project.build.directory}/script-operations.txt</gretl.test.operationCoverageFile>
        </systemPropertyVariables></configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <id>reset-script-operation-coverage</id><phase>pre-integration-test</phase><goals><goal>run</goal></goals>
            <configuration><target><delete file="${project.build.directory}/script-operations.txt"/></target></configuration>
          </execution>
          <execution>
            <id>check-script-operation-coverage</id><phase>verify</phase><goals><goal>run</goal></goals>
            <configuration><target>
              <java classname="ch.so.agi.gretl.it.ScriptOperationCoverage" fork="true" failonerror="true">
                <classpath refid="maven.test.classpath"/>
                <arg value="${maven.multiModuleProjectDirectory}/tests/contracts/operation-baseline.json"/>
                <arg value="${project.build.directory}/script-operations.txt"/>
              </java>
            </target></configuration>
          </execution>
        </executions>
      </plugin>
    </plugins></build>
  </profile>
  <profile>
    <id>job-image</id>
    <build><plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <configuration>
          <includes combine.self="override"><include>${gretl.test.includes}</include><include>**/ImageRuntimeIT.java</include></includes>
          <excludes combine.self="override"/>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <id>reset-image-test-report</id><phase>pre-integration-test</phase><goals><goal>run</goal></goals>
            <configuration><target>
              <delete file="${project.build.directory}/failsafe-reports/TEST-ch.so.agi.gretl.it.ImageRuntimeIT.xml"/>
            </target></configuration>
          </execution>
          <execution>
            <id>require-image-tests</id><phase>verify</phase><goals><goal>run</goal></goals>
            <configuration><target>
              <property name="gretl.image.test.report" location="${project.build.directory}/failsafe-reports/TEST-ch.so.agi.gretl.it.ImageRuntimeIT.xml"/>
              <available file="${gretl.image.test.report}" property="gretl.image.tests.ran"/>
              <fail unless="gretl.image.tests.ran" message="job-image requires execution of ImageRuntimeIT"/>
              <xmlproperty file="${gretl.image.test.report}" collapseAttributes="true"/>
              <fail message="ImageRuntimeIT must execute at least one test without skips">
                <condition><not><and>
                  <matches string="${testsuite.tests}" pattern="^[1-9][0-9]*$"/>
                  <equals arg1="${testsuite.skipped}" arg2="0"/>
                </and></not></condition>
              </fail>
            </target></configuration>
          </execution>
        </executions>
      </plugin>
    </plugins></build>
  </profile>
  </profiles>
</project>
