<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright (c) WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
  ~
  ~ WSO2 Inc. licenses this file to you 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">
    <parent>
        <artifactId>micro-gateway-parent</artifactId>
        <groupId>org.wso2.am.microgw</groupId>
        <version>3.1.0-m2</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>test-integration</artifactId>
    <name>Micro-GW - Test Integration</name>


    <dependencies>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-jdk14</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.1stleg</groupId>
            <artifactId>jnativehook</artifactId>
            <version>2.1.0</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-transport</artifactId>
        </dependency>
        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-codec-http</artifactId>
        </dependency>
        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-codec-http2</artifactId>
        </dependency>
        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-handler</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.wso2.orbit.org.yaml</groupId>
            <artifactId>snakeyaml</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.mina</groupId>
            <artifactId>mina-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.awaitility</groupId>
            <artifactId>awaitility</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.wso2.am.microgw</groupId>
            <artifactId>org.wso2.micro.gateway.cli</artifactId>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20180813</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.geronimo.specs</groupId>
            <artifactId>geronimo-jms_1.1_spec</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.wso2.andes.wso2</groupId>
            <artifactId>andes-client</artifactId>
        </dependency>
        <dependency>
            <groupId>io.ballerina.messaging</groupId>
            <artifactId>broker-launcher</artifactId>
            <version>0.970.5</version>
        </dependency>


    </dependencies>

    <build>
        <extensions>
            <extension>
                <groupId>kr.motd.maven</groupId>
                <artifactId>os-maven-plugin</artifactId>
                <version>${os.maven.plugin.version}</version>
            </extension>
        </extensions>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unpack-dependencies</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>unpack-dependencies</goal>
                        </goals>
                        <configuration>
                            <includeClassifiers>ballerina-binary-repo</includeClassifiers>
                            <outputDirectory>${project.build.directory}/lib</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${maven.surefire.plugin.version}</version>
                <configuration>
                    <systemPropertyVariables>
                        <toolkit>
                            ${toolkit.dir}
                        </toolkit>
                        <runtime_macos>
                            ${basedir}/../tests/target/micro-gwtmp/wso2am-micro-gw-macos-${project.version}
                        </runtime_macos>
                        <runtime_windows>
                            ${basedir}\..\tests\target\micro-gwtmp\wso2am-micro-gw-windows-${project.version}
                        </runtime_windows>
                        <runtime_linux>
                            ${basedir}/../tests/target/micro-gwtmp/wso2am-micro-gw-linux-${project.version}
                        </runtime_linux>
                        <project.build.directory>${project.build.directory}</project.build.directory>
                        <java.util.logging.config.file>${project.build.testOutputDirectory}/logging.properties</java.util.logging.config.file>
                        <javax.net.ssl.trustStore>${basedir}/resources/ballerinaTruststore.p12</javax.net.ssl.trustStore>
                        <javax.net.ssl.trustStorePassword>ballerina</javax.net.ssl.trustStorePassword>
                    </systemPropertyVariables>
                    <suiteXmlFiles>
                        <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>extract-packs</id>
                        <phase>generate-resources</phase>
                        <configuration>
                            <target>
                                <unzip src="${basedir}/../distribution/target/wso2am-micro-gw-toolkit-${project.version}.zip" dest="${basedir}/../tests/target/micro-gwtmp" />
                                <unzip src="${basedir}/../distribution/target/wso2am-micro-gw-${host.os}-${project.version}.zip" dest="${basedir}/../tests/target/micro-gwtmp" />
                                <chmod file="${basedir}/../tests/target/micro-gwtmp/wso2am-micro-gw-${host.os}-${project.version}/bin/*" perm="+x" />
                                <chmod file="${basedir}/../tests/target/micro-gwtmp/wso2am-micro-gw-${host.os}-${project.version}/lib/jdk8u202-b08-jre/bin/*" perm="+x" />
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>9.4.18.v20190429</version>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>mac</id>
            <activation>
                <os>
                    <family>mac</family>
                </os>
            </activation>
            <properties>
                <host.os>macos</host.os>
                <toolkit.dir>${basedir}/../tests/target/micro-gwtmp/wso2am-micro-gw-toolkit-${project.version}</toolkit.dir>
            </properties>
        </profile>
        <profile>
            <id>unix</id>
            <activation>
                <os>
                    <family>unix</family>
                    <name>Linux</name>
                </os>
            </activation>
            <properties>
                <host.os>linux</host.os>
                <toolkit.dir>${basedir}/../tests/target/micro-gwtmp/wso2am-micro-gw-toolkit-${project.version}</toolkit.dir>
            </properties>
        </profile>
        <profile>
            <id>windows</id>
            <activation>
                <os>
                    <family>windows</family>
                </os>
            </activation>
            <properties>
                <host.os>windows</host.os>
                <toolkit.dir>${basedir}\..\tests\target\micro-gwtmp\wso2am-micro-gw-toolkit-${project.version}</toolkit.dir>
            </properties>
        </profile>
        <profile>
            <id>local-etcd</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>start-docker-for-etcd</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>start</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>stop-docker-for-etcd</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>stop</goal>
                                    <goal>remove</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <images>
                                <image>
                                    <alias>mgw-etcd</alias>
                                    <name>quay.io/coreos/etcd:latest</name>
                                    <run>
                                        <namingStrategy>alias</namingStrategy>
                                        <cmd>
                                            <exec>
                                                <arg>/usr/local/bin/etcd</arg>
                                                <arg>--advertise-client-urls</arg>
                                                <arg>http://127.0.0.1:2379</arg>
                                                <arg>--listen-client-urls</arg>
                                                <arg>http://0.0.0.0:2379</arg>
                                            </exec>
                                        </cmd>
                                        <ports>
                                            <port>2379:2379</port>
                                        </ports>
                                    </run>
                                </image>
                            </images>
                            <skip>${skipITs}</skip>
                        </configuration>
                    </plugin>

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <version>2.22.2</version>
                        <executions>
                            <execution>
                                <id>integration-test-for-etcd</id>
                                <phase>integration-test</phase>
                                <goals>
                                    <goal>integration-test</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>verify-for-etcd</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>verify</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <environmentVariables>
                                <ETCD_HOST>127.0.0.1</ETCD_HOST>
                                <PORT>2379</PORT>
                            </environmentVariables>
                            <systemPropertyVariables>
                                <toolkit>
                                    ${toolkit.dir}
                                </toolkit>
                                <runtime_macos>
                                    ${basedir}/../tests/target/micro-gwtmp/wso2am-micro-gw-macos-${project.version}
                                </runtime_macos>
                                <runtime_windows>
                                    ${basedir}\..\tests\target\micro-gwtmp\wso2am-micro-gw-windows-${project.version}
                                </runtime_windows>
                                <runtime_linux>
                                    ${basedir}/../tests/target/micro-gwtmp/wso2am-micro-gw-linux-${project.version}
                                </runtime_linux>
                                <project.build.directory>${project.build.directory}</project.build.directory>
                                <java.util.logging.config.file>${project.build.testOutputDirectory}/logging.properties</java.util.logging.config.file>
                                <javax.net.ssl.trustStore>${basedir}/resources/ballerinaTruststore.p12</javax.net.ssl.trustStore>
                                <javax.net.ssl.trustStorePassword>ballerina</javax.net.ssl.trustStorePassword>
                            </systemPropertyVariables>
                            <suiteXmlFiles>
                                <suiteXmlFile>src/test/resources/testngEtcd.xml</suiteXmlFile>
                            </suiteXmlFiles>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <properties>
        <maven.test.skip>false</maven.test.skip>
        <skipTests>${maven.test.skip}</skipTests>
        <skipITs>${skipTests}</skipITs>
    </properties>


</project>
