<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.mule.tooling</groupId>
        <artifactId>mule-runtime-tooling-client-parent</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <artifactId>mule-runtime-tooling-tests</artifactId>
    <version>4.0-SNAPSHOT</version>
    <name>Mule Runtime Tooling Client :: Tests</name>
    <description>Integration Tests for Mule Runtime Tooling Client</description>

    <properties>
        <formatterConfigPath>../formatter.xml</formatterConfigPath>
        <runtime.location>${project.build.directory}/runtimes</runtime.location>
        <mule.distribution.folder>mule-enterprise-standalone-${mule.version}</mule.distribution.folder>
        <mulePluginClassifier>mule-plugin</mulePluginClassifier>

        <maven.version>3.3.9</maven.version>
        <aether.version>1.0.2.v20150114</aether.version>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.8</version>
                <executions>
                    <execution>
                        <id>unpack-mule-standalone</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>com.mulesoft.mule.distributions</groupId>
                                    <artifactId>mule-ee-distribution-standalone</artifactId>
                                    <version>${mule.version}</version>
                                    <type>tar.gz</type>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>${runtime.location}</outputDirectory>
                            <overWriteReleases>true</overWriteReleases>
                            <overWriteSnapshots>true</overWriteSnapshots>
                            <skip>${skipTests}</skip>
                        </configuration>
                    </execution>
                    <execution>
                        <id>copy-agent-mule</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>com.mulesoft.agent</groupId>
                                    <artifactId>mule-agent-plugin</artifactId>
                                    <version>${mule.agent.version}</version>
                                    <type>zip</type>
                                    <overWrite>true</overWrite>
                                    <outputDirectory>
                                        ${runtime.location}/${mule.distribution.folder}/server-plugins/mule-agent-plugin/
                                    </outputDirectory>
                                </artifactItem>
                            </artifactItems>
                            <skip>${skipTests}</skip>
                            <overWriteReleases>true</overWriteReleases>
                            <overWriteSnapshots>true</overWriteSnapshots>
                        </configuration>
                    </execution>
                    <execution>
                        <id>get-extensions</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.mule.modules</groupId>
                                    <artifactId>mule-module-file-extension-common</artifactId>
                                    <version>${mule.version}</version>
                                    <classifier>${mulePluginClassifier}</classifier>
                                    <overWrite>true</overWrite>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>org.mule.modules</groupId>
                                    <artifactId>mule-module-ftp</artifactId>
                                    <version>${mule.version}</version>
                                    <classifier>${mulePluginClassifier}</classifier>
                                    <overWrite>true</overWrite>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>org.mule.modules</groupId>
                                    <artifactId>mule-module-file</artifactId>
                                    <version>${mule.version}</version>
                                    <classifier>${mulePluginClassifier}</classifier>
                                    <overWrite>true</overWrite>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>org.mule.modules</groupId>
                                    <artifactId>mule-module-db</artifactId>
                                    <version>${mule.version}</version>
                                    <classifier>${mulePluginClassifier}</classifier>
                                    <overWrite>true</overWrite>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>org.mule.modules</groupId>
                                    <artifactId>mule-module-email</artifactId>
                                    <version>${mule.version}</version>
                                    <classifier>${mulePluginClassifier}</classifier>
                                    <overWrite>true</overWrite>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>org.mule.modules</groupId>
                                    <artifactId>mule-module-http-ext</artifactId>
                                    <version>${mule.version}</version>
                                    <classifier>${mulePluginClassifier}</classifier>
                                    <overWrite>true</overWrite>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>org.mule.modules</groupId>
                                    <artifactId>mule-module-sockets</artifactId>
                                    <version>${mule.version}</version>
                                    <classifier>${mulePluginClassifier}</classifier>
                                    <overWrite>true</overWrite>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>org.mule.modules</groupId>
                                    <artifactId>mule-module-jms</artifactId>
                                    <version>${mule.version}</version>
                                    <classifier>${mulePluginClassifier}</classifier>
                                    <overWrite>true</overWrite>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>org.mule.modules</groupId>
                                    <artifactId>mule-module-validation</artifactId>
                                    <version>${mule.version}</version>
                                    <classifier>${mulePluginClassifier}</classifier>
                                    <overWrite>true</overWrite>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>org.mule.modules</groupId>
                                    <artifactId>mule-module-wsc</artifactId>
                                    <version>${mule.version}</version>
                                    <classifier>${mulePluginClassifier}</classifier>
                                    <overWrite>true</overWrite>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>${project.build.directory}/extensions</outputDirectory>
                            <useBaseVersion>true</useBaseVersion>
                            <overWriteSnapshots>true</overWriteSnapshots>
                        </configuration>
                    </execution>
                    <execution>
                        <id>unpack-email-extension</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.mule.modules</groupId>
                                    <artifactId>mule-module-email</artifactId>
                                    <version>${mule.version}</version>
                                    <classifier>${mulePluginClassifier}</classifier>
                                    <overWrite>false</overWrite>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>${project.build.directory}/extensions/mule-module-email-${mule.version}-${mulePluginClassifier}</outputDirectory>
                            <overWriteSnapshots>true</overWriteSnapshots>
                        </configuration>
                    </execution>
                    <execution>
                        <id>unpack-ftp-extension</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.mule.modules</groupId>
                                    <artifactId>mule-module-ftp</artifactId>
                                    <version>${mule.version}</version>
                                    <classifier>${mulePluginClassifier}</classifier>
                                    <overWrite>false</overWrite>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>${project.build.directory}/extensions/mule-module-ftp-${mule.version}-${mulePluginClassifier}</outputDirectory>
                            <overWriteSnapshots>true</overWriteSnapshots>
                        </configuration>
                    </execution>
                    <execution>
                        <id>unpack-file-extension-common-extension</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.mule.modules</groupId>
                                    <artifactId>mule-module-file-extension-common</artifactId>
                                    <version>${mule.version}</version>
                                    <classifier>${mulePluginClassifier}</classifier>
                                    <overWrite>false</overWrite>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>${project.build.directory}/extensions/mule-module-file-extension-common-${mule.version}-${mulePluginClassifier}</outputDirectory>
                            <overWriteSnapshots>true</overWriteSnapshots>
                        </configuration>
                    </execution>
                    <execution>
                        <id>unpack-sockets-extension</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.mule.modules</groupId>
                                    <artifactId>mule-module-sockets</artifactId>
                                    <version>${mule.version}</version>
                                    <classifier>${mulePluginClassifier}</classifier>
                                    <overWrite>false</overWrite>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>${project.build.directory}/extensions/mule-module-sockets-${mule.version}-${mulePluginClassifier}</outputDirectory>
                            <overWriteSnapshots>true</overWriteSnapshots>
                        </configuration>
                    </execution>
                    <execution>
                        <id>unpack-http-extension</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.mule.modules</groupId>
                                    <artifactId>mule-module-http-ext</artifactId>
                                    <version>${mule.version}</version>
                                    <classifier>${mulePluginClassifier}</classifier>
                                    <overWrite>false</overWrite>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>${project.build.directory}/extensions/mule-module-http-ext-${mule.version}-${mulePluginClassifier}</outputDirectory>
                            <overWriteSnapshots>true</overWriteSnapshots>
                        </configuration>
                    </execution>
                    <execution>
                        <id>unpack-db-extension</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.mule.modules</groupId>
                                    <artifactId>mule-module-db</artifactId>
                                    <version>${mule.version}</version>
                                    <classifier>${mulePluginClassifier}</classifier>
                                    <overWrite>false</overWrite>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>${project.build.directory}/extensions/mule-module-db-${mule.version}-${mulePluginClassifier}</outputDirectory>
                            <overWriteSnapshots>true</overWriteSnapshots>
                        </configuration>
                    </execution>
                    <execution>
                        <id>unpack-file-extension</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.mule.modules</groupId>
                                    <artifactId>mule-module-file</artifactId>
                                    <version>${mule.version}</version>
                                    <classifier>${mulePluginClassifier}</classifier>
                                    <overWrite>false</overWrite>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>${project.build.directory}/extensions/mule-module-file-${mule.version}-${mulePluginClassifier}</outputDirectory>
                            <overWriteSnapshots>true</overWriteSnapshots>
                        </configuration>
                    </execution>
                    <execution>
                        <id>unpack-jms-extension</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.mule.modules</groupId>
                                    <artifactId>mule-module-jms</artifactId>
                                    <version>${mule.version}</version>
                                    <classifier>${mulePluginClassifier}</classifier>
                                    <overWrite>false</overWrite>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>${project.build.directory}/extensions/mule-module-jms-${mule.version}-${mulePluginClassifier}</outputDirectory>
                            <overWriteSnapshots>true</overWriteSnapshots>
                        </configuration>
                    </execution>
                    <execution>
                        <id>unpack-validation-extension</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.mule.modules</groupId>
                                    <artifactId>mule-module-validation</artifactId>
                                    <version>${mule.version}</version>
                                    <classifier>${mulePluginClassifier}</classifier>
                                    <overWrite>false</overWrite>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>${project.build.directory}/extensions/mule-module-validation-${mule.version}-${mulePluginClassifier}</outputDirectory>
                            <overWriteSnapshots>true</overWriteSnapshots>
                        </configuration>
                    </execution>
                    <execution>
                        <id>unpack-wsc-extension</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.mule.modules</groupId>
                                    <artifactId>mule-module-wsc</artifactId>
                                    <version>${mule.version}</version>
                                    <classifier>${mulePluginClassifier}</classifier>
                                    <overWrite>false</overWrite>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>${project.build.directory}/extensions/mule-module-wsc-${mule.version}-${mulePluginClassifier}</outputDirectory>
                            <overWriteSnapshots>true</overWriteSnapshots>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.8</version>
                <configuration>
                    <skip>${skipTests}</skip>
                </configuration>
                <executions>
                    <execution>
                        <id>configure-pristine-runtimes</id>
                        <phase>pre-integration-test</phase>
                        <configuration>
                            <target>
                                <copy file="${project.build.testOutputDirectory}/descriptors/mule-agent.yml" todir="${runtime.location}/${mule.distribution.folder}/conf/" overwrite="true" />

                                <delete file="${runtime.location}/${mule.distribution.folder}/lib/mule/mmc-agent-api-${mule.version}.jar" />
                                <delete file="${runtime.location}/${mule.distribution.folder}/lib/mule/mmc-agent-impl-${mule.version}.jar" />
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-install-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <packaging>jar</packaging>
                    <version>${mule.version}</version>
                    <localRepositoryPath>${runtime.location}/${mule.distribution.folder}/lib/mule/repository</localRepositoryPath>
                </configuration>
                <executions>
                    <execution>
                        <id>install-db-extension-into-mule-repository</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <configuration>
                            <file>${project.build.directory}/extensions/mule-module-db-${mule.version}-${mulePluginClassifier}.jar</file>
                            <groupId>org.mule.modules</groupId>
                            <artifactId>mule-module-db</artifactId>
                            <classifier>${mulePluginClassifier}</classifier>
                        </configuration>
                    </execution>
                    <execution>
                        <id>install-email-extension-into-mule-repository</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <configuration>
                            <file>${project.build.directory}/extensions/mule-module-email-${mule.version}-${mulePluginClassifier}.jar</file>
                            <groupId>org.mule.modules</groupId>
                            <artifactId>mule-module-email</artifactId>
                            <classifier>${mulePluginClassifier}</classifier>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <skip>true</skip>
                    <systemProperties>
                        <property>
                            <name>MULE_HOME</name>
                            <value>${runtime.location}/${mule.distribution.folder}</value>
                        </property>
                    </systemProperties>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.19.1</version>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.maven.surefire</groupId>
                        <artifactId>surefire-junit47</artifactId>
                        <version>2.19.1</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <includes>
                        <include>**/integration/test/**</include>
                    </includes>
                    <testFailureIgnore>false</testFailureIgnore>
                </configuration>
                <executions>
                    <execution>
                        <id>integration-test</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.mule.tooling</groupId>
            <artifactId>mule-runtime-tooling-bootstrap</artifactId>
            <version>${project.parent.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.icegreen</groupId>
            <artifactId>greenmail</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.mule.tooling</groupId>
            <artifactId>mule-runtime-tooling-tests-utils</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.derby</groupId>
            <artifactId>derbynet</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-model</artifactId>
            <version>${maven.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.eclipse.aether</groupId>
            <artifactId>aether-api</artifactId>
            <version>${aether.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.eclipse.aether</groupId>
            <artifactId>aether-util</artifactId>
            <version>${aether.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.eclipse.aether</groupId>
            <artifactId>aether-connector-basic</artifactId>
            <version>${aether.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.eclipse.aether</groupId>
            <artifactId>aether-transport-file</artifactId>
            <version>${aether.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-aether-provider</artifactId>
            <version>${maven.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>xmlunit</groupId>
            <artifactId>xmlunit</artifactId>
            <version>1.6</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>xml-apis</groupId>
                    <artifactId>xml-apis</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.1</version>
            <scope>test</scope>
        </dependency>

        <!-- Just to let Maven build this project at the end of the reactor, these dependencies cannot be included in surefire classpath -->
        <dependency>
            <groupId>org.mule.tooling</groupId>
            <artifactId>mule-runtime-tooling-client</artifactId>
            <version>${project.version}</version>
            <type>pom</type>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>*</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
</project>
