<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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>
    <groupId>org.mule.modules</groupId>
    <artifactId>mule-connection-test-module</artifactId>
    <version>1.0.0</version>
    <packaging>mule-extension</packaging>
    <name>Mule Connection Test Module</name>
    <description>Provides components to allow testing of connectors' connections</description>

    <parent>
        <groupId>org.mule.extensions</groupId>
        <artifactId>mule-modules-parent</artifactId>
        <version>1.1.3</version>
    </parent>

    <properties>
        <licensePath>../LICENSE_HEADER.txt</licensePath>
        <formatterConfigPath>../formatter.xml</formatterConfigPath>
        <mavenResourcesVersion>3.0.2</mavenResourcesVersion>
        <munit.extensions.maven.plugin.version>1.0.0-BETA3</munit.extensions.maven.plugin.version>
        <munit.version>2.2.0</munit.version>
        <skipTests>${skipIntegrationTests}</skipTests>
        <skipMunitTests>${skipIntegrationTests}</skipMunitTests>
        <maven.helper.plugin.version>3.0.0</maven.helper.plugin.version>
        <docker.maven.plugin.version>0.25.2</docker.maven.plugin.version>
        <munit.input.directory>src/test/munit</munit.input.directory>
        <munit.output.directory>${basedir}/target/test-mule/munit</munit.output.directory>
        <docker.skip>${skipTests}</docker.skip>
    </properties>

    <build>
        <plugins>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>${maven.helper.plugin.version}</version>
                <executions>
                    <execution>
                        <id>reserve-network-port</id>
                        <phase>generate-test-resources</phase>
                        <goals>
                            <goal>reserve-network-port</goal>
                        </goals>
                        <configuration>
                            <portNames>
                                <portName>proxy.port</portName>
                                <portName>real.port</portName>
                                <portName>toxiproxy.port</portName>
                            </portNames>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>${mavenResourcesVersion}</version>
                <executions>
                    <execution>
                        <id>copy-munit-resources</id>
                        <phase>process-test-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${munit.output.directory}</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${munit.input.directory}</directory>
                                    <filtering>true</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>com.mulesoft.munit</groupId>
                <artifactId>munit-extensions-maven-plugin</artifactId>
                <version>${munit.extensions.maven.plugin.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <phase>integration-test</phase>
                    </execution>
                </executions>
                <configuration>
                    <runtimeConfiguration>
                        <discoverRuntimes>
                            <product>CE</product>
                            <includeSnapshots>true</includeSnapshots>
                            <minMuleVersion>4.1.4</minMuleVersion>
                        </discoverRuntimes>
                    </runtimeConfiguration>
                </configuration>
                <dependencies>
                    <!-- MUnit Dependencies -->
                    <dependency>
                        <groupId>com.mulesoft.munit</groupId>
                        <artifactId>munit-runner</artifactId>
                        <version>${munit.version}</version>
                        <classifier>mule-plugin</classifier>
                    </dependency>
                    <dependency>
                        <groupId>com.mulesoft.munit</groupId>
                        <artifactId>munit-tools</artifactId>
                        <version>${munit.version}</version>
                        <classifier>mule-plugin</classifier>
                    </dependency>
                    <dependency>
                        <groupId>org.mule.connectors</groupId>
                        <artifactId>mule-http-connector</artifactId>
                        <version>1.5.3</version>
                        <classifier>mule-plugin</classifier>
                    </dependency>
                    <dependency>
                        <groupId>org.mule.connectors</groupId>
                        <artifactId>mule-sockets-connector</artifactId>
                        <version>1.1.5</version>
                        <classifier>mule-plugin</classifier>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.7</version>
        </dependency>
        <dependency>
            <groupId>eu.rekawek.toxiproxy</groupId>
            <artifactId>toxiproxy-java</artifactId>
            <version>2.1.3</version>
        </dependency>
    </dependencies>

    <profiles>
    <profile>
        <id>docker</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>io.fabric8</groupId>
                    <artifactId>docker-maven-plugin</artifactId>
                    <version>${docker.maven.plugin.version}</version>
                    <configuration>
                        <images>
                            <image>
                                <name>shopify/toxiproxy</name>
                                <alias>toxiproxy</alias>
                                <run>
                                    <network>
                                        <mode>host</mode>
                                    </network>
                                    <ports>
                                        <port>${toxiproxy.port}:8474</port>
                                        <port>${proxy.port}:${proxy.port}</port>
                                        <port>${real.port}:${real.port}</port>
                                    </ports>
                                </run>
                            </image>
                        </images>
                        <verbose>true</verbose>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>org.slf4j</groupId>
                            <artifactId>slf4j-api</artifactId>
                            <version>1.7.24</version>
                        </dependency>
                        <dependency>
                            <groupId>org.slf4j</groupId>
                            <artifactId>jcl-over-slf4j</artifactId>
                                <version>1.7.24</version>
                            </dependency>
                        </dependencies>
                        <executions>
                            <execution>
                                <id>start</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>stop</goal>
                                    <goal>build</goal>
                                    <goal>start</goal>
                                </goals>
                                <configuration>
                                    <showLogs>true</showLogs>
                                    <logStdout>true</logStdout>
                                </configuration>
                            </execution>
                            <execution>
                                <id>stop</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>stop</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <distributionManagement>
        <downloadUrl>http://www.mulesoft.org/display/MULE/Download</downloadUrl>
        <repository>
            <id>mule-releases</id>
            <name>Mule Release Repository</name>
            <url>https://repository-master.mulesoft.org/nexus/content/repositories/releases</url>
        </repository>
        <snapshotRepository>
            <id>mule-snapshots</id>
            <name>Mule Snapshot Repository</name>
            <url>https://repository-master.mulesoft.org/nexus/content/repositories/snapshots</url>
            <uniqueVersion>false</uniqueVersion>
        </snapshotRepository>
    </distributionManagement>

    <repositories>
        <repository>
            <id>mule</id>
            <name>Mule Repository</name>
            <url>https://repository.mulesoft.org/nexus/content/repositories/public/</url>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>mule-plugin</id>
            <name>Mule Repository</name>
            <url>https://repository.mulesoft.org/nexus/content/repositories/public/</url>
        </pluginRepository>
    </pluginRepositories>

</project>
