10

I have had no issue running a maven war project on an embedded server for its own integration tests, but now I need to run multiple wars and test from a different project.

I would like to setup the following scenario...

I have two Maven war projects in my local workspace called War1 and War2. I would like to have a 3rd Maven project, WarIntegration, that contains only integration tests and does the following:

  1. Packages War1
  2. Packages War2
  3. Starts an embedded server
  4. Deploys both wars to same embedded server
  5. Runs integration tests contained within WarIntegration (which will make http calls to War1 and War2)
  6. Stops embedded server

Is this possible? What plugin setup will achieve this? What kind of project should WarIntergration be (packaging)? Should War1 and War2 be modules in WarIntegration or dependencies? Can all of the configuration be aded to the WarIntegration project or would it have to be spread across the projects?

This is similar to this question, except we must use an embedded server that is started and stopped by the project (probably when we run verify) and we need a separate project for integration tests: I have a multi-module Maven 2 POM that has two WARs, how can I configure it to deploy both wars prior to running tests?

Community
  • 1
  • 1
smp7d
  • 4,947
  • 2
  • 26
  • 48
  • How are you starting / stopping your embedded server? – Roy Truelove Jun 21 '12 at 19:19
  • 1
    The packaging of war1 and war1 should be done by the project itself. I would suggest to only define an dependency to the two other project. – khmarbaise Jun 21 '12 at 19:54
  • @Roy Truelove I'd like to attach the startup and deploys to the pre integration phase and the shutdown to the post integration phase. – smp7d Jun 22 '12 at 12:55
  • @khmarbaise What plugin/configuration can I use to deploy the two wars to the embedded server? What king of packaging should the WarIntegration use? – smp7d Jun 22 '12 at 12:56
  • 2
    This slide-show http://www.slideshare.net/wakaleo/automated-deployment-with-maven-going-the-whole-nine-yards talks mentions something that may be of use, starting on slide 29. It appears that Cargo, a plug-in for maven, can be configured with multiple deployable war dependencies. You may be able to use cargo to start up a tomcat instance, deploy WAR dependencies, and then run the acceptance tests. – walnutmon Jun 22 '12 at 15:05
  • @walnutmon Thanks, the cargo plugin worked for what I was trying to do. – smp7d Jun 25 '12 at 15:55

2 Answers2

6

I was able to achieve this using the cargo-maven2-plugin.

Here are the relevant pieces of the pom for anyone who is interested...

...
<groupId>com.test</groupId>
<artifactId>webapp-integration</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
...
<dependencies>
        ...
        <dependency>
            <artifactId>webapp1</artifactId>
            <groupId>com.test</groupId>
            <version>1.0</version>
            <type>war</type>
        </dependency>
        <dependency>
            <groupId>webapp2</groupId>
            <artifactId>com.test</artifactId>
            <version>1.0-SNAPSHOT</version>
            <type>war</type>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.cargo</groupId>
                <artifactId>cargo-maven2-plugin</artifactId>
                <version>1.2.2</version>
                <configuration>
                    <container>
                        <containerId>jetty6x</containerId>
                        <type>embedded</type>
                    </container>
                    <configuration>
                        <type>standalone</type>
                        <properties>
                            <cargo.servlet.port>8085</cargo.servlet.port>
                        </properties>
                        <deployables>
                            <deployable>
                                <artifactId>webapp1</artifactId>
                                <groupId>com.test</groupId>
                                <type>war</type>
                                <pingURL>http://localhost:8085/testapp/</pingURL>
                                <properties>
                                    <context>testapp</context>
                                </properties>
                            </deployable>
                            <deployable>
                                <artifactId>webapp2</artifactId>
                                <groupId>com.test</groupId>
                                <type>war</type>
                                <pingURL>http://localhost:8085/testapp2/</pingURL>
                                <properties>
                                    <context>testapp2</context>
                                </properties>
                            </deployable>
                        </deployables>
                    </configuration>
                </configuration>
                <executions>
                    <execution>
                        <id>start-server</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>stop-server</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.12</version>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.maven.surefire</groupId>
                        <artifactId>surefire-junit47</artifactId>
                        <version>2.12</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <groups>com.test.integration.IntegrationTestMarker</groups>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                        <configuration>
                            <includes>
                                <include>**/*.class</include>
                            </includes>
                            <skipTests>false</skipTests>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
smp7d
  • 4,947
  • 2
  • 26
  • 48
3

Watch out, the DEPLOYABLES element is a child of plugin/configuration, NOT plugin/configuration/configuration.

The example above should be :

<plugins>
        <plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven2-plugin</artifactId>
            <version>1.2.2</version>
            <configuration>
                <container>...</container>
                <configuration>
                    <type>standalone</type>
                    <properties>
                        <cargo.servlet.port>8085</cargo.servlet.port>
                    </properties>
                </configuration>
                <deployables>
                     <deployable>
                            <artifactId>webapp1</artifactId>
                            <groupId>com.test</groupId>
                            <type>war</type>
                            <pingURL>http://localhost:8085/testapp/</pingURL>
                            <properties>
                                <context>testapp</context>
                            </properties>
                      </deployable>
                      <deployable>
                            <artifactId>webapp2</artifactId>
                            <groupId>com.test</groupId>
                            <type>war</type>
                            <pingURL>http://localhost:8085/testapp2/</pingURL>
                            <properties>
                                <context>testapp2</context>
                            </properties>
                      </deployable>
                 </deployables>
             </configuration>
        </plugin>
 </plugins>

Hope that helps !

Brice
  • 31
  • 1