<?xml version="1.0" encoding="UTF-8"?>
<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>com.hurence.logisland</groupId>
        <artifactId>logisland-service-influxdb</artifactId>
        <version>1.2.0</version>
    </parent>

    <artifactId>logisland-service-influxdb-client</artifactId>
    <packaging>jar</packaging>

    <name>InfluxDB Service Plugin</name>
    <description>Implementation of the influxdb service api</description>

    <properties>
        <influx.client.version>2.15</influx.client.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.influxdb</groupId>
            <artifactId>influxdb-java</artifactId>
            <version>${influx.client.version}</version>
        </dependency>
        <dependency>
            <groupId>com.hurence.logisland</groupId>
            <artifactId>logisland-service-influxdb-api</artifactId>
            <version>${project.version}</version>
        </dependency>

        <dependency>
            <groupId>com.tngtech.java</groupId>
            <artifactId>junit-dataprovider</artifactId>
            <version>1.13.1</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.hurence.logisland</groupId>
            <artifactId>logisland-processor-common</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.hurence.logisland</groupId>
            <artifactId>logisland-utils</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>

    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>com.hurence.logisland</groupId>
                <artifactId>logisland-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                    </execution>
                </executions>

            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <!-- Profile for Integration tests run mechanism and separation from unit tests. Inspired from this page:
            https://www.baeldung.com/maven-integration-test
            If you need additional stuff like resources for the integration tests, please this page to know how to do it.
            To run integration tests, run: mvn -Pintegration-tests clean verify -->
            <id>integration-tests</id>
            <properties> <!-- Integration tests properties -->
                <influxdb.version>1.7-alpine</influxdb.version> <!-- InfluxDB docker image tag -->
            </properties>
            <build>
                <plugins>
                    <plugin> <!-- The configuration section here will be merged with the one already defined in the
                     maven-failsafe-plugin of the root pom.xml. We just add this configuration here for the workaround -->
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <configuration>
                            <!-- Workaround as described here:
                            https://stackoverflow.com/questions/42082131/maven-surefire-verify-java-lang-classnotfoundexception
                            We need to point to the logisland bits due to spring boot usage otherwise we get
                             CalssNotFoundException in integration test -->
                            <additionalClasspathElements>
                                <!-- For finding BulkPut -->
                                <additionalClasspathElement>${basedir}/../../../logisland-processors/logisland-processor-common/target/classes</additionalClasspathElement>
                            </additionalClasspathElements>
                        </configuration>
                    </plugin>
                    <plugin> <!-- Docker maven plugin will be launched at pre-integration-test and post-integration-test
                         phases to start and stop docker images before and after integration tests run. Stop is called even
                         if integration tests fail to anyway stop and remove every docker container -->
                        <groupId>io.fabric8</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <version>0.30.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>influxdb:${influxdb.version}</name>
                                    <run>
                                        <!-- Assign dynamically mapped ports to maven variables (which can be reused in integration tests) -->
                                        <ports>
                                            <port>8086:8086</port>
                                        </ports>
                                        <wait>
                                            <!-- Check for this URL to return a 200 return code .... -->
                                            <url>http://localhost:8086/debug/pprof</url>
                                            <!-- ... but at max 2 minutes -->
                                            <time>120000</time>
                                        </wait>
                                    </run>
                                </image>
                            </images>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
