4

我正在为一个大型 Web 项目设置一个集成测试模块。集成测试模块与 web 项目本身是分开的,它有自己的 pom.xml 文件。

这个想法是使用 maven-soapui-plugin 发送请求并验证响应。设置soapui-plugin 并不麻烦。但是,我无法弄清楚如何告诉 jetty-maven-plugin 从远程存储库部署战争。

如果我理解正确,jetty-maven-plugin 有一个名为 '<webApp>/<webApp>' 的属性,它可以让我指定要部署的 war 文件。问题是模块本身中不存在war文件。

我听说我可以使用 maven 程序集插件通过项目 artifactId 从存储库中检索战争,但我还没有弄清楚我将如何去做。

这是我想要的摘要:

  1. 从存储库等中检索特定的战争,例如通过其 artifactId。
  2. 将这场战争部署到 jetty-maven-plugin(目标部署战争?)
  3. 让 maven-soapui-plugin 运行测试并在集成测试阶段报告结果。

我很确定我已经完成了第 3 步,但我非常不确定如何实现第 1 步和第 2 步。

任何帮助是极大的赞赏

4

2 回答 2

6

也许可以使用它dependency:copy来检索战争,解压它并使用 maven jetty 插件让整个事情工作,但这将是 hacky 和有点丑陋。更清洁的解决方案是使用Maven Cargo 插件,这是我的建议。下面是一个示例 POM,展示了如何使用其坐标检索 WAR 工件以及如何使用 Cargo 将其部署在嵌入式 Jetty 容器上:

<dependencies>
  <dependency>
    <groupId>war group id</groupId>
    <artifactId>war artifact id</artifactId>
    <type>war</type>
    <version>war version</version>
  </dependency>
  ...
</dependencies>
...
<build>
  <plugins>
    <plugin>
      <groupId>org.codehaus.cargo</groupId>
      <artifactId>cargo-maven2-plugin</artifactId>
      <configuration>
        <!-- Container configuration -->
        <container>
          <containerId>jetty6x</containerId>
          <type>embedded</type>
        </container>
        <!-- Configuration to use with the container or the deployer -->
        <configuration>
          <deployables>
            <deployable>
              <groupId>war group id</groupId>
              <artifactId>war artifact id</artifactId>
              <type>war</type>
              <properties>
                <context>war context</context>
              </properties>
            </deployable>
          </deployables>
        </configuration>
        <!-- Don't wait, execute the tests after the container is started -->
        <wait>false</wait>
      </configuration>
      <executions>
        <execution>
          <id>start-container</id>
          <phase>pre-integration-test</phase>
          <goals>
            <goal>start</goal>
          </goals>
        </execution>
        <execution>
          <id>stop-container</id>
          <phase>post-integration-test</phase>
          <goals>
            <goal>stop</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
    ...
  </plugins>
  ...
</build>

integration-test最后,只需在阶段上绑定soapui插件即可。

于 2010-04-20T19:37:03.850 回答
4

我在做同样的事情,John,但我对 Jetty 插件采取了不同的方法。我认为最终的结果是一样的。我正在开发一个集成测试套件来针对多个 Web 服务 WAR 运行。我dependency:copypackage阶段中使用,然后是为<contextHandler/>s 配置的列表maven-jetty-plugin

<project>
    …
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-wars</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>

                        <configuration>
                            <outputDirectory>${project.build.directory}/wars-to-be-tested</outputDirectory>
                            <stripVersion>true</stripVersion>
                            <artifactItems>
                                …
                                <artifactItem>
                                    <groupId>groupId</groupId>
                                    <artifactId>artifactId</artifactId>
                                    <version>version</version>
                                    <type>war</type>
                                </artifactItem>
                                …
                            </artifactItems>
                        </configuration>
                    </execution>
               </executions>
            </plugin>

            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>7.1.3.v20100526</version>
                <configuration>
                    …
                    <contextHandlers>
                        …
                        <contextHandler implementation="org.mortbay.jetty.plugin.JettyWebAppContext">
                            <war>${project.build.directory}/wars-to-be-tested/artifactId.war</war>
                            <contextPath>/context</contextPath>
                        </contextHandler>
                    </contextHandlers>
                </configuration>

                <executions>
                    <execution>
                        <id>start-jetty</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <scanIntervalSeconds>0</scanIntervalSeconds>
                            <daemon>true</daemon>
                        </configuration>
                    </execution>

                    <execution>
                        <id>stop-jetty</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

我更愿意将各种战争声明为依赖项,然后用于dependency:copy-dependencies设置wars-to-be-tested目录;这将允许 Maven 反应器确定它需要在将要测试的战争之后构建我的集成测试模块。我遇到的问题是 Jetty 插件认为我想“覆盖”所有被列为依赖项的战争(在我看到它发生之前我什至从未听说过这个概念);我不知道允许这种情况发生是否会伤害任何东西,但我不喜欢它,所以我采用了这种dependency:copy方法。

这只是使用 Cargo 的替代方法。我会自己研究,但我只是想提供另一种方法。

于 2010-12-09T13:40:38.490 回答