<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://maven.apache.org/POM/4.0.0"
         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.eclipse.dirigible</groupId>
        <artifactId>dirigible-tests</artifactId>
        <version>14.69.0</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <properties>
        <license.header.location>../../licensing-header.txt</license.header.location>
        <parent.pom.folder>../../</parent.pom.folder>
    </properties>

    <name>Tests - Integration Tests</name>
    <artifactId>dirigible-tests-integrations</artifactId>
    <packaging>jar</packaging>

    <dependencies>
        <dependency>
            <groupId>com.icegreen</groupId>
            <artifactId>greenmail</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-suite</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.eclipse.dirigible</groupId>
            <artifactId>dirigible-application</artifactId>
            <scope>compile</scope>
        </dependency>
        <!-- Template modules are bundled into the application fat jar in production but are not
             resolved transitively here (via the group-templates aggregator pom), so the integration
             test that exercises the events template generation depends on it explicitly to load its
             content into the test registry. -->
        <dependency>
            <groupId>org.eclipse.dirigible</groupId>
            <artifactId>dirigible-components-template-application-events-java</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.eclipse.dirigible</groupId>
            <artifactId>dirigible-components-template-application-dao-java</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.eclipse.dirigible</groupId>
            <artifactId>dirigible-tests-framework</artifactId>
        </dependency>
        <dependency>
            <groupId>com.codeborne</groupId>
            <artifactId>selenide</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>compile</scope>
        </dependency>
        <!-- ExternalFrontendIT runs an in-process OpenID Connect provider that signs its tokens and
             serves the JWKS with Nimbus (com.nimbusds.*), which this artifact carries. It arrives
             transitively through the application as well; declared so the contract is visible. Gson,
             which writes the provider's answers, is inherited from the parent pom. -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-oauth2-jose</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-junit-jupiter</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-db</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-test-spring-junit5</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.eclipse.dirigible</groupId>
            <artifactId>
                dirigible-components-core-initializers
            </artifactId>
        </dependency>
        <dependency>
            <groupId>org.webjars.npm</groupId>
            <artifactId>stomp__stompjs</artifactId>
            <version>${stompjs.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>net.revelc.code.formatter</groupId>
                <artifactId>formatter-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <!-- JUnit 5 tag selection lives here (not in the root pom) so only this module -
                     which has the JUnit 5 engine and the tagged ITs - applies it. Empty by default
                     (full run); the PR smoke job passes -Dit.groups="!ui | smoke", and the master/
                     nightly IT jobs shard the suite via -Dit.groups="!ui" / "ui & !sample & !camel" /
                     "sample | camel" (see .github/workflows/build.yml). Putting it in the
                     root failsafe config breaks other modules (e.g. dirigible-cli) that run failsafe
                     without a JUnit 5 engine, since non-empty groups require one on the classpath. -->
                <configuration>
                    <groups>${it.groups}</groups>
                    <excludedGroups>${it.excludedGroups}</excludedGroups>
                    <!-- Fresh JVM per test class. Every IT boots a full Dirigible context per test
                         method (@DirtiesContext AFTER_EACH_TEST_METHOD) and closed contexts do not
                         release all their heap (schedulers, engine pools, statics), so a single
                         shared fork accumulates the leak across the ~85 IT classes and OOMs late in
                         the full run (the -Xmx6g fork died at DependsOnHarmoniaIT). Per-class forks
                         bound the accumulation at one class; JVM startup is noise next to the
                         per-method Spring boots. ExitOnOutOfMemoryError kills the fork on the first
                         OOM instead of letting a heap-thrashing JVM drag the job out for hours.
                         argLine here REPLACES the root pom's (no merge) - keep the add-opens list. -->
                    <reuseForks>false</reuseForks>
                    <!-- The -javaagent is the launcher agent the executable jar delivers via its
                         Launcher-Agent-Class manifest entry in production; the ITs run from the
                         plain classpath, so the flag is the equivalent delivery here. It only
                         captures Instrumentation - PlatformScopeDependencyIT exercises the
                         scope-platform appends through it. -->
                    <argLine>
                        -Xmx6g
                        -XX:+ExitOnOutOfMemoryError
                        --add-opens=java.base/java.lang=ALL-UNNAMED
                        --add-opens=java.base/java.lang.reflect=ALL-UNNAMED
                        --add-opens=java.base/java.nio=ALL-UNNAMED
                        -javaagent:${project.build.directory}/launcher-agent.jar
                    </argLine>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-launcher-agent</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.eclipse.dirigible</groupId>
                                    <artifactId>dirigible-components-core-launcher-agent</artifactId>
                                    <version>${project.version}</version>
                                    <destFileName>launcher-agent.jar</destFileName>
                                    <outputDirectory>${project.build.directory}</outputDirectory>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <configuration>
                    <skip>${skipITs}</skip>
                </configuration>
                <executions>
                    <execution>
                        <id>build-ts-test-sources</id>
                        <phase>generate-test-sources</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>
                                ${basedir}/src/main/resources/META-INF/dirigible/modules-tests/build-source${script.extension}
                            </executable>
                            <workingDirectory>
                                src/main/resources/META-INF/dirigible/modules-tests
                            </workingDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>Windows 11</id>
            <activation>
                <os>
                    <family>dos</family>
                </os>
            </activation>
            <properties>
                <script.extension>.bat</script.extension>
            </properties>
        </profile>
        <profile>
            <id>Windows</id>
            <activation>
                <os>
                    <family>Windows</family>
                </os>
            </activation>
            <properties>
                <script.extension>.bat</script.extension>
            </properties>
        </profile>
        <profile>
            <id>unix</id>
            <activation>
                <os>
                    <family>unix</family>
                </os>
            </activation>
            <properties>
                <script.extension>.sh</script.extension>
            </properties>
        </profile>
    </profiles>

</project>
