<?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>quarkus-integration-tests-parent</artifactId>
        <groupId>io.quarkus</groupId>
        <version>999-SNAPSHOT</version>
        <relativePath>../</relativePath>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>quarkus-integration-test-oidc</artifactId>
    <name>Quarkus - Integration Tests - OpenID Connect Adapter</name>
    <description>Module that contains OpenID Connect related tests</description>

    <properties>
        <keycloak.url>http://localhost:8180/auth</keycloak.url>
    </properties>
  
    <dependencies>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-oidc</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-resteasy-jsonb</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkus.keycloak</groupId>
            <artifactId>quarkus-keycloak-adapter</artifactId>
            <version>1.0.0.Alpha1</version>
        </dependency>

        <!-- test dependencies -->
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-junit5</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>rest-assured</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
            <plugin>
                <groupId>io.quarkus</groupId>
                <artifactId>quarkus-maven-plugin</artifactId>
                <version>${project.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>build</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>test-keycloak</id>
            <activation>
                <property>
                    <name>test-keycloak</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <skip>false</skip>
                            <systemPropertyVariables>
                                <keycloak.url>${keycloak.url}</keycloak.url>
                            </systemPropertyVariables>
                        </configuration>
                    </plugin>
                    <plugin>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <configuration>
                            <skip>false</skip>
                            <systemPropertyVariables>
                                <keycloak.url>${keycloak.url}</keycloak.url>
                            </systemPropertyVariables>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>io.quarkus</groupId>
                        <artifactId>quarkus-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>build</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>native-image</id>
            <activation>
                <property>
                    <name>native</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>integration-test</goal>
                                    <goal>verify</goal>
                                </goals>
                                <configuration>
                                    <systemProperties>
                                        <native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
                                    </systemProperties>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>io.quarkus</groupId>
                        <artifactId>quarkus-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>native-image</id>
                                <goals>
                                    <goal>native-image</goal>
                                </goals>
                                <configuration>
                                    <reportErrorsAtRuntime>false</reportErrorsAtRuntime>
                                    <cleanupServer>true</cleanupServer>
                                    <enableHttpUrlHandler>true</enableHttpUrlHandler>
                                    <enableServer>false</enableServer>
                                    <dumpProxies>false</dumpProxies>
                                    <!-- Requires Quarkus Graal fork to work, will fail otherwise
                                      <enableRetainedHeapReporting>true</enableRetainedHeapReporting>
                                      <enableCodeSizeReporting>true</enableCodeSizeReporting>
                                    -->
                                    <graalvmHome>${graalvmHome}</graalvmHome>
                                    <debugBuildProcess>false</debugBuildProcess>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>docker-keycloak</id>
            <activation>
                <property>
                    <name>docker</name>
                </property>
            </activation>
            <properties>
                <keycloak.url>http://localhost:8180/auth</keycloak.url>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <version>0.28.0</version>
                        <configuration>
                            <images>
                                <image>
                                    <name>quay.io/keycloak/keycloak</name>
                                    <alias>quarkus-test-keycloak</alias>
                                    <run>
                                        <ports>
                                            <port>8180:8080</port>
                                        </ports>
                                        <env>
                                            <KEYCLOAK_USER>admin</KEYCLOAK_USER>
                                            <KEYCLOAK_PASSWORD>admin</KEYCLOAK_PASSWORD>
                                        </env>
                                        <log>
                                            <prefix>Keycloak:</prefix>
                                            <date>default</date>
                                            <color>cyan</color>
                                        </log>
                                        <wait>
                                            <!-- good docs found at: http://dmp.fabric8.io/#build-healthcheck -->
                                            <http>
                                                <url>http://localhost:8180</url>
                                            </http>
                                            <time>100000</time>
                                        </wait>
                                    </run>
                                </image>
                            </images>
                            <allContainers>true</allContainers>
                        </configuration>
                        <executions>
                            <execution>
                                <id>docker-start</id>
                                <phase>compile</phase>
                                <goals>
                                    <goal>stop</goal>
                                    <goal>start</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>docker-stop</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>stop</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

    </profiles>

</project>
