Docker [SOLVED]: Maven integration tests with 2 modules

Docker [SOLVED]: Maven integration tests with 2 modules

Home Forums Automation Tools Docker Tutorials Docker [SOLVED]: Maven integration tests with 2 modules

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #245034

    Cloudy Point
    Keymaster

    QuestionQuestion

    I have an application with 2 modules:

    • Web JSF (WAR deployed on Tomcat)

    • REST Services (WAR deployed on Wildfly)

    For integration tests I use maven plugins:

    • maven failsafe plugin

    • fabric8 maven plugin

    My tests source code and resources are located in both applications src/integration-test/java.

    In integration tests phase fabric8 builds Wildfly docker image, copies built articact (REST Services WAR), starts container and runs tests. It works correctly.

    But… I would like to configure maven to deploy 2 applications (
    Web JSF WAR artifact and REST Services WAR) and run integration tests from JSF WAR/src/integration-test/java.
    Using fabric8 plugin its easy to build and run Tomcat and Wildfly containers but I cant find how to deploy 2 different artifacts from different maven modules.
    Maybe do you have any idea?

    Best regards,
    MJ.

    #245035

    Cloudy Point
    Keymaster

    Accepted AnswerAnswer

    io.fabric8 docker-maven-plugin supports multiple images. You can create a module responsible for running the integration tests. This module will depend on 2 WAR artifacts you’ve mentioned in the question.

        <dependencies>
            <dependency>
                <groupId>com.your.maven.group.here</groupId>
                <artifactId>your-maven-artifact</artifactId>
                <version>${project.version}</version>
                <type>war</type>
            </dependency>
    
            <dependency>
                ...
            </dependency>
        </dependencies>
    

    Then you can setup necessary containers using io.fabric8. Here is an example from my project (some details are removing for sake of simplicity and conciseness of the answer). The example is not about Tomcat and Wildfly but just to illustrate the idea.

        <plugin>
            <groupId>io.fabric8</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <configuration>
                <images>
                    <image>
                        ....
                    </image>
                    <image>
                        <name>my-admin-site</name>
                        <alias>admin-ux</alias>
                        <build>
                            <from>jetty</from>
                            <ports>
                                <port>8080</port>
                            </ports>
                            <runCmds>
                                <run>mkdir -p /run/jetty /tmp/jetty</run>
                                <run>chmod -R 1777 /tmp</run>
                                <run>chown -R jetty:jetty /var/lib/jetty /run/jetty /tmp/jetty</run>
                            </runCmds>
                            <assembly>
                                <mode>dir</mode>
                                <basedir>/var/lib/jetty</basedir>
                                <inline xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2">
                                    <id>my-admin-ux</id>
                                    <dependencySets>
                                        <dependencySet>
                                            <includes>
                                                <include>com.your.maven.group.here:your-maven-artifact:war</include>
                                            </includes>
                                            <outputDirectory>./webapps</outputDirectory>
                                            <outputFileNameMapping>myAdminSite.war</outputFileNameMapping>
                                        </dependencySet>
                                    </dependencySets>
                                    <files>
                                        <file>
                                            <source>src/main/docker/admin-ux/resources/service.properties</source>
                                            <outputDirectory>./resources</outputDirectory>
                                        </file>
                                    </files>
                                </inline>
                                <user>jetty:jetty</user>
                            </assembly>
                        </build>
                        <run>
                            <ports>
                                <port>10540:8080</port>
                            </ports>
                            <links>
                                <link>zookeeper:zookeeper</link>
                            </links>
                        </run>
                    </image>
                    <image>
                        .....
                    </image>
                </images>
            </configuration>
        </plugin>
    

    Source: https://stackoverflow.com/questions/47954630/maven-integration-tests-with-2-modules
    Author: Alex Binkovsky
    Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.