<?xml version="1.0" encoding="UTF-8"?>
<!--
  Copyright (c) 2019, 2020 Oracle and/or its affiliates.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  -->

<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>io.helidon.tests.integration.dbclient</groupId>
        <artifactId>helidon-tests-integration-dbclient-project</artifactId>
        <version>2.0.0-RC2</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <groupId>io.helidon.tests.integration.dbclient</groupId>
    <artifactId>heldion-tests-integration-dbclient-jdbc</artifactId>
    <name>Integration Tests: DB Client JDBC</name>

    <properties>
        <mysql.port>3306</mysql.port>
        <mysql.host>127.0.0.1</mysql.host>
        <mysql.database>pokemon</mysql.database>
        <mysql.user>user</mysql.user>
        <mysql.password>password</mysql.password>
        <mysql.roootpw>root</mysql.roootpw>
    </properties>

    <dependencies>
        <dependency>
            <groupId>io.helidon.tests.integration.dbclient</groupId>
            <artifactId>heldion-tests-integration-dbclient-common</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.helidon.config</groupId>
            <artifactId>helidon-config</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.helidon.config</groupId>
            <artifactId>helidon-config-yaml</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.helidon.dbclient</groupId>
            <artifactId>helidon-dbclient-jdbc</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.zaxxer</groupId>
            <artifactId>HikariCP</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-jdk14</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-all</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <testResources>
            <testResource>
                <directory>src/test/resources</directory>
                <filtering>true</filtering>
            </testResource>
        </testResources>

        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${version.plugin.surefire}</version>
                <configuration>
                    <skipTests>true</skipTests>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>${version.plugin.surefire}</version>
                <configuration>
                    <parallel>methods</parallel>
                    <threadCount>10</threadCount>
                </configuration>
                <executions>
                    <!-- Wait for database to start up and initialize database-->
                    <execution>
                        <id>init</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                        <configuration>
                            <includes>
                                <include>io.helidon.tests.integration.dbclient.jdbc.init.*IT</include>
                            </includes>
                        </configuration>
                    </execution>
                    <!-- Run ingegration tests. -->
                    <execution>
                        <id>test</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                        <configuration>
                            <dependenciesToScan>
                                <dependency>io.helidon.tests.integration.dbclient:heldion-tests-integration-dbclient-common</dependency>
                            </dependenciesToScan>
                            <includes>
                                <include>io.helidon.tests.integration.dbclient.common.tests.simple.*IT</include>
                                <include>io.helidon.tests.integration.dbclient.common.tests.statement.*IT</include>
                                <include>io.helidon.tests.integration.dbclient.common.tests.transaction.*IT</include>
                                <include>io.helidon.tests.integration.dbclient.common.tests.interceptor.*IT</include>
                                <include>io.helidon.tests.integration.dbclient.common.tests.dbresult.*IT</include>
                                <include>io.helidon.tests.integration.dbclient.common.tests.mapping.*IT</include>
                                <include>io.helidon.tests.integration.dbclient.common.tests.health.*IT</include>
                                <include>io.helidon.tests.integration.dbclient.common.tests.metrics.*IT</include>
                            </includes>
                        </configuration>
                    </execution>
                    <!-- Database cleanup. -->
                    <execution>
                        <id>destroy</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                        <configuration>
                            <includes>
                                <include>io.helidon.tests.integration.dbclient.jdbc.destroy.*IT</include>
                            </includes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

        </plugins>

    </build>

    <profiles>
        <!--
             mvn -pl common,jdbc -Pdebug,docker install \
                 -Dit.jdbc.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8787 -Xnoagent -Djava.compiler=NONE" \
                 -Dit.jdbc.test='**/ExceptionalStmtIT#testCreateNamedQueryNamedArgsSetOrderArg'
        -->
        <profile>
            <id>debug</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <version>${version.plugin.surefire}</version>
                        <executions>
                            <execution>
                                <id>test</id>
                                <configuration>
                                    <debugForkedProcess>${it.jdbc.debug}</debugForkedProcess>
                                    <test>${it.jdbc.test}</test>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>test</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <version>${version.plugin.surefire}</version>
                        <executions>
                            <execution>
                                <id>test</id>
                                <configuration>
                                    <test>${it.jdbc.test}</test>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>docker</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <version>0.31.0</version>
                        <executions>
                            <execution>
                                <id>start</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>start</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>stop</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>stop</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <images>
                                <image>
                                    <name>mysql:8</name>
                                    <alias>mysql</alias>
                                    <run>
                                        <env>
                                            <MYSQL_USER>${mysql.user}</MYSQL_USER>
                                            <MYSQL_PASSWORD>${mysql.password}</MYSQL_PASSWORD>
                                            <MYSQL_ROOT_PASSWORD>${mysql.roootpw}</MYSQL_ROOT_PASSWORD>
                                            <MYSQL_DATABASE>${mysql.database}</MYSQL_DATABASE>
                                        </env>
                                        <hostname>${mysql.host}</hostname>
                                        <ports>
                                            <port>${mysql.host}:${mysql.port}:3306</port>
                                        </ports>
                                        <wait>
                                            <log>MySQL server is up an running</log>
                                            <tcp>
                                                <host>127.0.0.1</host>
                                                <ports>
                                                    <port>${mysql.port}</port>
                                                </ports>
                                            </tcp>
                                            <time>120000</time>
                                        </wait>
                                    </run>
                                </image>
                            </images>
                            <showLogs>true</showLogs>
                            <startParallel>false</startParallel>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

</project>
