<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright The WildFly Authors
  ~ SPDX-License-Identifier: Apache-2.0
  -->
<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">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.wildfly.security.vault</groupId>
        <artifactId>wildfly-vault-parent</artifactId>
        <!--
        Maintain separation between the artifact id and the version to help prevent
        merge conflicts between commits changing the GA and those changing the V.
        -->
        <version>1.0.1.Final</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <artifactId>wildfly-vault-tests</artifactId>
    <packaging>jar</packaging>

    <name>WildFly Vault Feature Pack -- Testsuite</name>
    <description>WildFly Vault Feature Pack TestSuite</description>

    <properties>

        <version.org.jboss.arquillian>1.9.5.Final</version.org.jboss.arquillian>
        <version.org.wildfly.arquillian>5.0.1.Final</version.org.wildfly.arquillian>
        <version.jakarta.servlet-api>6.0.0</version.jakarta.servlet-api>
        <surefire.memory.args>-Xmx512m -XX:MetaspaceSize=128m</surefire.memory.args>
        <surefire.jpda.args>-agentlib:jdwp=transport=dt_socket,address=*:${as.debug.port},server=y,suspend=y</surefire.jpda.args>
        <as.debug.port>8787</as.debug.port>
        <surefire.system.args>${surefire.memory.args}</surefire.system.args>
        <server.jvm.args>${surefire.memory.args}</server.jvm.args>
        <server.jboss.args>--stability=default</server.jboss.args>
        <!-- Feature pack to use to provision vault -->
        <vault.feature.pack.groupId>${project.groupId}</vault.feature.pack.groupId>
        <vault.feature.pack.artifactId>wildfly-vault-feature-pack</vault.feature.pack.artifactId>
        <vault.feature.pack.version>${project.version}</vault.feature.pack.version>
        <base.feature.pack.groupId>org.wildfly.security</base.feature.pack.groupId>
        <base.feature.pack.artifactId>wildfly-ee-galleon-pack</base.feature.pack.artifactId>
        <base.feature.pack.version>${version.org.wildfly}</base.feature.pack.version>
        <!-- For some reason this needs to be true if base.feature.pack.artifactId=wildfly-galleon-pack
             But make it externally controllable in case someone wants to test with this turned off -->
        <ignore.not.excluded.layers>true</ignore.not.excluded.layers>
        <overwrite.provisioned.server>true</overwrite.provisioned.server>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.jboss.arquillian</groupId>
                <artifactId>arquillian-bom</artifactId>
                <version>${version.org.jboss.arquillian}</version>
                <scope>import</scope>
                <type>pom</type>
            </dependency>
            <dependency>
                <groupId>org.wildfly.arquillian</groupId>
                <artifactId>wildfly-arquillian-container-managed</artifactId>
                <version>${version.org.wildfly.arquillian}</version>
                <scope>test</scope>
                <exclusions>
                    <exclusion>
                        <groupId>org.wildfly.core</groupId>
                        <artifactId>wildfly-launcher</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.wildfly.arquillian</groupId>
            <artifactId>wildfly-arquillian-container-managed</artifactId>
        </dependency>
        <dependency>
            <groupId>org.wildfly.launcher</groupId>
            <artifactId>wildfly-launcher</artifactId>
            <version>${version.org.wildfly.launcher}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>testcontainers</artifactId>
        </dependency>
        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>testcontainers-vault</artifactId>
            <version>${version.org.testcontainers}</version>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>${version.org.junit}</version>
            <scope>test</scope>
        </dependency>

        <!-- Subsystem production classes -->
        <dependency>
            <groupId>org.wildfly.security.vault</groupId>
            <artifactId>wildfly-vault-subsystem</artifactId>
        </dependency>

        <!-- Subsystem test utilities (SubsystemTestCase + test resources) -->
        <dependency>
            <groupId>org.wildfly.security.vault</groupId>
            <artifactId>wildfly-vault-subsystem</artifactId>
            <type>test-jar</type>
            <scope>test</scope>
        </dependency>

        <!-- WildFly subsystem test framework -->
        <dependency>
            <groupId>org.wildfly.core</groupId>
            <artifactId>wildfly-subsystem-test</artifactId>
            <version>${version.org.wildfly.core}</version>
            <type>pom</type>
            <scope>test</scope>
        </dependency>

        <!-- Required by subsystem test framework -->
        <dependency>
            <groupId>org.wildfly.core</groupId>
            <artifactId>wildfly-embedded</artifactId>
            <version>${version.org.wildfly.core}</version>
            <scope>test</scope>
        </dependency>

        <!-- Arquillian @RunAsClient management ops: ManagementRequestHandlerFactory on test classpath -->
        <dependency>
            <groupId>org.wildfly.core</groupId>
            <artifactId>wildfly-protocol</artifactId>
            <version>${version.org.wildfly.core}</version>
            <scope>test</scope>
        </dependency>

        <!-- JUnit vintage engine — AbstractSubsystemBaseTest uses JUnit 4 @BeforeClass internally -->
        <dependency>
            <groupId>org.junit.vintage</groupId>
            <artifactId>junit-vintage-engine</artifactId>
            <version>${version.org.junit}</version>
            <scope>test</scope>
        </dependency>

        <!-- Override jboss-logging 3.5.x from Arquillian; WildFly Core 32+ requires 3.6.x -->
        <dependency>
            <groupId>org.jboss.logging</groupId>
            <artifactId>jboss-logging</artifactId>
            <version>3.6.2.Final</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>io.smallrye.certs</groupId>
            <artifactId>smallrye-certificate-generator</artifactId>
            <version>0.9.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.arquillian.junit5</groupId>
            <artifactId>arquillian-junit5-container</artifactId>
            <version>${version.org.jboss.arquillian}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.shrinkwrap</groupId>
            <artifactId>shrinkwrap-api</artifactId>
            <version>${version.org.jboss.shrinkwrap}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.shrinkwrap</groupId>
            <artifactId>shrinkwrap-impl-base</artifactId>
            <version>${version.org.jboss.shrinkwrap}</version>
            <scope>test</scope>
        </dependency>
        <!-- Servlet API for VaultSecretServlet deployed by HashiCorpVaultCrudIntegrationTestCase -->
        <dependency>
            <groupId>jakarta.servlet</groupId>
            <artifactId>jakarta.servlet-api</artifactId>
            <version>${version.jakarta.servlet-api}</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <executions>
                    <execution>
                        <id>create-test-jar</id>
                        <goals>
                            <goal>test-jar</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>create-empty-source-jar</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                        <configuration>
                            <classifier>sources</classifier>
                        </configuration>
                    </execution>
                    <execution>
                        <id>create-empty-javadoc-jar</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                        <configuration>
                            <classifier>javadoc</classifier>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>test-jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- Provision traditional unzipped server installations -->
            <plugin>
                <groupId>org.wildfly.plugins</groupId>
                <artifactId>wildfly-maven-plugin</artifactId>
                <configuration>
                    <log-provisioning-time>${galleon.log.time}</log-provisioning-time>
                    <offline-provisioning>${galleon.offline}</offline-provisioning>
                    <record-provisioning-state>true</record-provisioning-state>
                    <overwrite-provisioned-server>${overwrite.provisioned.server}</overwrite-provisioned-server>
                    <galleon-options>
                        <jboss-fork-embedded>${galleon.fork.embedded}</jboss-fork-embedded>
                        <optional-packages>passive+</optional-packages>
                        <config-stability-level>default</config-stability-level>
                        <package-stability-level>default</package-stability-level>
                    </galleon-options>
                </configuration>
                <executions>
                    <!-- Provision with layers -->
                   <execution>
                        <id>wildfly-layers-provisioning</id>
                        <goals>
                            <goal>provision</goal>
                        </goals>
                        <phase>pre-integration-test</phase>
                        <configuration>
                            <provisioning-dir>${project.build.directory}/wildfly-layers</provisioning-dir>
                            <layers>
                                <layer>base-server</layer>
                                <layer>elytron</layer>
                                <layer>management</layer>
                                <layer>core-tools</layer>
                                <layer>web-server</layer>
                                <layer>hashicorp-vault</layer>
                            </layers>
                        </configuration>
                    </execution>
                    <!-- provision full server -->
                    <execution>
                        <id>wildfly-full-provisioning</id>
                        <goals>
                            <goal>provision</goal>
                        </goals>
                        <phase>pre-integration-test</phase>
                        <configuration>
                            <provisioning-dir>${project.build.directory}/wildfly-full</provisioning-dir>
                           <layers>
                                <layer>base-server</layer>
                                <layer>elytron</layer>
                                <layer>management</layer>
                                <layer>core-tools</layer>
                                <layer>web-server</layer>
                                <layer>hashicorp-vault</layer>
                            </layers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>**/*IntegrationTestCase.java</exclude>
                    </excludes>
                    <systemProperties>
                        <arquillian.launch>wildfly</arquillian.launch>
                        <server.jvm.args>${server.jvm.args}</server.jvm.args>
                        <server.jboss.args>${server.jboss.args}</server.jboss.args>
                    </systemProperties>
                    <argLine>${surefire.system.args}</argLine>
                </configuration>
                <executions>
                    <execution>
                        <id>default-test</id>
                        <phase>none</phase>
                    </execution>
                    <execution>
                        <id>layers-tests</id>
                        <phase>test</phase>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <configuration>
                            <systemProperties>
                                <jboss.home>${project.build.directory}/wildfly-layers</jboss.home>
                            </systemProperties>
                            <reportNameSuffix>wildfly-layers</reportNameSuffix>
                        </configuration>
                    </execution>
                    <execution>
                        <id>complete-dist-tests</id>
                        <phase>test</phase>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <configuration>
                            <systemProperties>
                                <jboss.home>${project.build.directory}/wildfly-full</jboss.home>
                            </systemProperties>
                            <reportNameSuffix>wildfly-full</reportNameSuffix>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                        <configuration>
                            <includes>
                                <include>**/*IntegrationTestCase.java</include>
                            </includes>
                            <!-- Only use Jupiter; Vintage would re-discover inherited JUnit 4 @Test methods -->
                            <excludeJUnit5Engines>
                                <excludeJUnit5Engine>junit-vintage</excludeJUnit5Engine>
                            </excludeJUnit5Engines>
                            <systemPropertyVariables>
                                <jboss.home>${project.build.directory}/wildfly-layers</jboss.home>
                                <arquillian.launch>wildfly</arquillian.launch>
                                <server.jvm.args>${server.jvm.args}</server.jvm.args>
                                <server.jboss.args>${server.jboss.args}</server.jboss.args>
                            </systemPropertyVariables>
                            <argLine>${surefire.memory.args}</argLine>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!-- Skip deploying testsuite to the repository by default (integration tests only). -->
            <!-- If you enable deploy for a release, *-sources / *-javadoc classifiers and test sources are attached (see maven-jar-plugin and maven-source-plugin test-jar above). -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <profiles>

        <!-- Default single feature pack provisioning -->
        <profile>
            <id>default.provisioning.profile</id>
            <activation>
                <property>
                    <name>!base.feature.pack.artifactId</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.wildfly.plugins</groupId>
                        <artifactId>wildfly-maven-plugin</artifactId>
                        <configuration>
                            <feature-packs>
                                <feature-pack>
                                    <location>${vault.feature.pack.groupId}:${vault.feature.pack.artifactId}:${vault.feature.pack.version}</location>
                                </feature-pack>
                            </feature-packs>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>specified.base.provisioning.profile</id>
            <activation>
                <property>
                    <name>base.feature.pack.version</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.wildfly.plugins</groupId>
                        <artifactId>wildfly-maven-plugin</artifactId>
                        <configuration>
                            <galleon-options>
                                <!-- For some reason this needs to be true if base.feature.pack.artifactId=wildfly-galleon-pack -->
                                <ignore-not-excluded-layers>${ignore.not.excluded.layers}</ignore-not-excluded-layers>
                            </galleon-options>
                            <feature-packs>
                                <feature-pack>
                                    <location>${base.feature.pack.groupId}:${base.feature.pack.artifactId}:${base.feature.pack.version}</location>
                                    <inherit-packages>false</inherit-packages>
                                </feature-pack>
                                <feature-pack>
                                    <location>${vault.feature.pack.groupId}:${vault.feature.pack.artifactId}:${vault.feature.pack.version}</location>
                                </feature-pack>
                            </feature-packs>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <!--
          Debugging profiles.
        -->
        <profile>
            <id>debug.profile</id>
            <activation><property><name>debug</name></property></activation>
            <properties>
                <server.jvm.args>${surefire.memory.args} ${surefire.jpda.args}</server.jvm.args>
            </properties>
        </profile>
        <profile>
            <id>debug.client.profile</id>
            <activation><property><name>debug-client</name></property></activation>
            <properties>
                <surefire.system.args>${surefire.memory.args} ${surefire.jpda.args}</surefire.system.args>
            </properties>
        </profile>
    </profiles>

</project>
