Maven deploy multiple wars to embedded server for integration tests

前端 未结 2 1130
故里飘歌
故里飘歌 2021-01-04 13:34

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.

相关标签:
2条回答
  • 2021-01-04 13:39

    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 !

    0 讨论(0)
  • 2021-01-04 13:46

    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>
    
    0 讨论(0)
提交回复
热议问题