0

我正在为 Maven 中的 WCC 组件构建集成测试。

在 Mavenpom.xml中,我也配置了一个插件:

  1. 构建组件
  2. 部署组件
  3. 启用组件
  4. 重启组件

完成后,我正在着手获取Maven-Failsafe-Plugin以测试已安装的插件。

在我可以测试插件之前,我需要设置一些东西。我决定最简单的方法是为我的集成测试创建一个父类,如果它还没有运行,它只会初始化。

例子:

@BeforeClass
public static initialize()
{  
   //lazy init here
}

因为我的组件已经从 Maven 配置中安装/启用,所以我想利用该信息而不是为集成测试复制它。

在我的pom.xml我有:

<plugin>
  <groupId>org.ucmtwine</groupId>
  <artifactId>ucm-maven-plugin</artifactId>
  <version>0.1.2-SNAPSHOT</version>
  <extensions>true</extensions> <!-- Allows WCC packaging type -->
  <configuration>
    <servers>
      <server>            
        <id>sandbox</id>
        <url>http://localhost:16200/cs/idcplg</url>
        <username>myUser</username>
        <password>myPass</password>
        <adminServer>
          <hostname>localhost</hostname> 
          <serverName>AdminAServer</serverName> 
          <wlsServerName>UCM_server1</wlsServerName> 
        </adminServer>
      </server>
    </servers>
  </configuration>
</plugin>

如何从我的@BeforeClass初始化方法中访问该信息?此外,我的 Maven 插件也支持-Dserver,因此用户可以选择要使用的服务器配置(基于 ID)。我也将如何访问该参数?

注意:我没有settings.xml为此使用。

4

1 回答 1

0

IMO you shouldn't try to do this. The settings.xml as a typical Maven file accessible by Maven and Maven Plugins. The component is a standalone piece of code, you shouldn't try to mix these two. I can think of several options:

  • feed your component integration test with the right configuration, e.g. via system properties or properties file. In both cases you probably need to have an extra maven-plugin the prepare this (during pre-integration-test). However, this makes it a bit harder to directly run within you IDE.
  • use your maven-plugin to do the real integration tests of the component. In the end this is probably also the preferred way of how the component is used.
  • Don't use maven-failsafe-plugin for this. Make a separate Java project for integration testing where you control the environment settings.

The first two matches closest to your requirements, but I'd prefer the third option.

于 2017-08-04T09:59:53.690 回答