<?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">
    <parent>
        <artifactId>quarkus-integration-tests-parent</artifactId>
        <groupId>io.quarkus</groupId>
        <version>1.3.2.Final-redhat-00001</version>
        <relativePath>../</relativePath>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>quarkus-integration-test-jpa-mariadb</artifactId>
    <name>Quarkus - Integration Tests - JPA - MariaDB</name>
    <version>1.3.2.Final-redhat-00001</version>
    <description>Module that contains JPA related tests running with the MariaDB database</description>

    <properties>
        <mariadb.url>jdbc:mariadb://localhost:3306/hibernate_orm_test</mariadb.url>
        <mariadb.image>mariadb:10.4</mariadb.image>
        <ProductVersionOverride>1.3.2.Final</ProductVersionOverride>
    </properties>

    <dependencies>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-undertow</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-hibernate-orm</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-jdbc-mariadb</artifactId>
        </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>
                <executions>
                    <execution>
                        <goals>
                            <goal>build</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>test-mariadb</id>
            <activation>
                <property>
                    <name>test-mariadb</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <skip>false</skip>
                        </configuration>
                    </plugin>
                    <plugin>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <configuration>
                            <skip>false</skip>
                        </configuration>
                    </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>
                                    <graalvmHome>${graalvmHome}</graalvmHome>
                                    <debugBuildProcess>false</debugBuildProcess>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>docker-mariadb</id>
            <activation>
                <property>
                    <name>docker</name>
                </property>
            </activation>
            <properties>
                <mariadb.url>jdbc:mariadb://localhost:3308/hibernate_orm_test</mariadb.url>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <configuration>
                            <images>
                                <image>
                                    <name>${mariadb.image}</name>
                                    <alias>quarkus-test-mariadb</alias>
                                    <run>
                                        <ports>
                                            <port>3308:3306</port>
                                        </ports>
                                        <env>
                                            <MYSQL_USER>hibernate_orm_test</MYSQL_USER>
                                            <MYSQL_PASSWORD>hibernate_orm_test</MYSQL_PASSWORD>
                                            <MYSQL_DATABASE>hibernate_orm_test</MYSQL_DATABASE>
                                            <MYSQL_RANDOM_ROOT_PASSWORD>true</MYSQL_RANDOM_ROOT_PASSWORD>
                                        </env>
                                        <log>
                                            <prefix>MariaDB:</prefix>
                                            <date>default</date>
                                            <color>cyan</color>
                                        </log>
                                        <!-- Speed things up a bit by not actually flushing writes to disk -->
                                        <tmpfs>/var/lib/mysql</tmpfs>
                                        <wait>
                                            <time>20000</time>
                                            <exec>
                                                <postStart>mysqladmin ping -h localhost -u hibernate_orm_test -phibernate_orm_test</postStart>
                                            </exec>
                                        </wait>
                                        <volumes>
                                            <bind>
                                                <volume>${project.basedir}/custom-mariadbconfig:/etc/mysql/conf.d/:Z</volume>
                                            </bind>
                                        </volumes>
                                    </run>
                                </image>
                            </images>
                            <!--Stops all mariadb:10.4 images currently running, not just those we just started.
                              Useful to stop processes still running from a previously failed integration test run -->
                            <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>
