<?xml version="1.0" encoding="UTF-8"?>
<!--
  #%L
  Wildfly Camel Testsuite
  %%
  Copyright (C) 2013 - 2014 RedHat
  %%
  Licensed 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.
  #L%
  -->

<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.wildfly.camel</groupId>
        <artifactId>wildfly-camel-itests</artifactId>
        <version>4.2.0</version>
    </parent>

    <name>Wildfly Camel :: Testsuite :: Docker</name>

    <artifactId>wildfly-camel-itests-docker</artifactId>

    <!-- Properties -->
    <properties>
        <docker.image.name>wildflyext/wildfly-camel</docker.image.name>
        <docker.alias.master>wildfly-camel</docker.alias.master>
        <docker.cmd.master>-b 0.0.0.0 -bmanagement 0.0.0.0 -c standalone-camel.xml</docker.cmd.master>
        <wildfly.mgmt.address>vagrant.origin</wildfly.mgmt.address>
        <wildfly.mgmt.username>admin</wildfly.mgmt.username>
        <wildfly.mgmt.password>admin</wildfly.mgmt.password>
    </properties>
    
    <!-- Dependencies -->
    <dependencies>
    
        <!-- Provided -->
        <dependency>
            <groupId>org.wildfly.camel</groupId>
            <artifactId>wildfly-camel-docker</artifactId>
            <version>${project.version}</version>
            <scope>provided</scope>
            <type>pom</type>
        </dependency>
        
        <!-- Test -->
        <dependency>
            <groupId>org.wildfly.camel</groupId>
            <artifactId>wildfly-camel-itests-common</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.arquillian.junit</groupId>
            <artifactId>arquillian-junit-container</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.wildfly.arquillian</groupId>
            <artifactId>wildfly-arquillian-container-remote</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <!-- Build -->
    <build>
        <plugins>
            <plugin>
                <groupId>io.fabric8</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>start-containers</id>
                        <phase>process-test-sources</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                        <configuration>
                            <images>
                                <image>
                                    <name>${docker.image.name}</name>
                                    <alias>${docker.alias.master}</alias>
                                    <run>
                                        <env>
                                            <WILDFLY_MANAGEMENT_USER>${wildfly.mgmt.username}</WILDFLY_MANAGEMENT_USER>
                                            <WILDFLY_MANAGEMENT_PASSWORD>${wildfly.mgmt.password}</WILDFLY_MANAGEMENT_PASSWORD>
                                        </env>
                                        <ports>
                                            <port>8080:8080</port>
                                            <port>9990:9990</port>
                                        </ports>
                                        <cmd>${docker.cmd.master}</cmd>
                                        <log>
                                            <enabled>true</enabled>
                                        </log>
                                        <wait>
                                            <url>http://${env.DOCKER_IP}:8080</url>
                                            <time>${env.DOCKER_PLUGIN_TIMEOUT}</time>
                                        </wait>
                                    </run>
                                </image>
                            </images>
                        </configuration>
                    </execution>
                    <execution>
                        <id>stop-containers</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                        <configuration>
                            <images>
                                <image>
                                    <alias>${docker.alias.master}</alias>
                                </image>
                            </images>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>process-test-sources</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <!-- [FIXME #175] Deployment fails with missing/unavailable dependencies -->
                                <sleep seconds="10" />
                                <echo>=========================================================================</echo>
                                <echo>docker run --rm -ti -p 8080:8080 -p 9990:9990 -e WILDFLY_MANAGEMENT_USER=${wildfly.mgmt.username} -e WILDFLY_MANAGEMENT_PASSWORD=${wildfly.mgmt.password} --name=${docker.alias.master} ${docker.image.name} ${docker.cmd.master}</echo>
                                <echo>=========================================================================</echo>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.gmaven</groupId>
                <artifactId>groovy-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>set-selinux-properties</id>
                        <phase>process-test-sources</phase>
                        <goals>
                            <goal>execute</goal>
                        </goals>
                        <configuration>
                            <source>
                                // Change target directory SELinux label on environments that support it
                                if (System.properties['os.name'].toLowerCase().equals('linux')) {
                                    def proc = ["which", "chcon"].execute()
                                    proc.waitFor()
                                    if(proc.exitValue() == 0) {
                                        "chcon -Rt svirt_sandbox_file_t ${project.build.directory}".execute()
                                    }
                                }
                            </source>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <systemPropertyVariables>
                        <wildfly.mgmt.address>${wildfly.mgmt.address}</wildfly.mgmt.address>
                        <wildfly.mgmt.username>${wildfly.mgmt.username}</wildfly.mgmt.username>
                        <wildfly.mgmt.password>${wildfly.mgmt.password}</wildfly.mgmt.password>
                    </systemPropertyVariables>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <!-- Profiles -->
    <profiles>
        <profile>
            <id>docker.timeout</id>
            <activation>
                <property>
                    <name>!env.DOCKER_PLUGIN_TIMEOUT</name>
                </property>
            </activation>
            <properties>
                <env.DOCKER_PLUGIN_TIMEOUT>60000</env.DOCKER_PLUGIN_TIMEOUT>
            </properties>
        </profile>
    </profiles>

</project>
