<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/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <artifactId>airsonic-integration-test</artifactId>
    <name>Airsonic Integration Test</name>

    <parent>
        <groupId>org.airsonic.player</groupId>
        <artifactId>airsonic</artifactId>
        <version>11.0.0-SNAPSHOT</version>
    </parent>

    <properties>
        <docker.testing.container>it-container</docker.testing.container>
        <docker.testing.host>http://localhost:4040</docker.testing.host>
        <!-- Used as a music folder, mounted in Docker container during integration tests -->
        <docker.testing.default-music-folder>${project.build.directory}/data/music</docker.testing.default-music-folder>
        <!-- Used as output folder for saving responses during integration tests -->
        <docker.testing.output-folder>${project.build.directory}/data/responses</docker.testing.output-folder>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.xmlunit</groupId>
            <artifactId>xmlunit-core</artifactId>
            <version>2.6.4</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.xmlunit</groupId>
            <artifactId>xmlunit-matchers</artifactId>
            <version>2.6.4</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.airsonic.player</groupId>
            <artifactId>subsonic-rest-api</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-library</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>${jackson.version}</version>
        </dependency>
    </dependencies>

    <build>
        <testResources>
            <testResource>
                <directory>src/test/resources</directory>
                <filtering>false</filtering>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.2.0</version>
                <executions>
                    <execution>
                        <id>default-jar</id>
                        <phase/>
                        <configuration>
                            <finalName>unwanted</finalName>
                            <classifier>unwanted</classifier>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>io.fabric8</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>0.33.0</version>
                <executions>
                    <execution>
                        <id>prepare-it-container</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                        <configuration>
                            <showLogs>true</showLogs>
                            <images>
                                <image>
                                    <name>${docker.container.repo}:latest</name>
                                    <alias>${docker.testing.container}</alias>
                                    <run>
                                        <network>
                                            <mode>host</mode>
                                        </network>
                                        <ports>
                                            <port>4040:4040</port>
                                        </ports>
                                        <wait>
                                            <time>100000</time>
                                            <healthy>true</healthy>
                                        </wait>
                                        <volumes>
                                            <bind>
                                                <!-- This binds a directory inside the integration-test/target directory in the host to the music directory in the Docker container -->
                                                <volume>${docker.testing.default-music-folder}:/airsonic/music</volume>
                                            </bind>
                                        </volumes>
                                    </run>
                                </image>
                            </images>
                        </configuration>
                    </execution>
                    <execution>
                        <id>remove-it-container</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>create-host-music-folder-for-docker</id>
                        <phase>process-resources</phase>
                        <configuration>
                            <target>
                                <delete dir="${docker.testing.default-music-folder}"/>
                                <mkdir dir="${docker.testing.default-music-folder}"/>
                                <delete dir="${docker.testing.output-folder}"/>
                                <mkdir dir="${docker.testing.output-folder}"/>
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.22.2</version>
                <executions>
                    <execution>
                        <configuration>
                            <!-- Skip integration tests by adding -Dfailsafe.skip to the Maven command-line -->
                            <skip>${failsafe.skip}</skip>
                            <systemPropertyVariables>
                                <DockerTestingContainer>${docker.testing.container}</DockerTestingContainer>
                                <DockerTestingHost>${docker.testing.host}</DockerTestingHost>
                                <!-- This is the folder on the host (not on the container), used in org.airsonic.test.Scanner -->
                                <DockerTestingDefaultMusicFolder>${docker.testing.default-music-folder}</DockerTestingDefaultMusicFolder>
                                <IntegrationTestsOutputDirectory>${project.build.directory}/data/responses</IntegrationTestsOutputDirectory>
                            </systemPropertyVariables>
                        </configuration>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>
