【问题标题】:Use custom standalone-full.xml with arquillian将自定义的standalone-full.xml 与 arquillian 一起使用
【发布时间】:2016-12-06 14:41:59
【问题描述】:

我正在使用带有 arquillian 的 Wildfly 容器进行集成测试。 在某些情况下,我想使用 JMS 和 Standalone-full.xml,并在服务器启动时加载一些自定义配置。 所以,对于我的 int 测试,我想通过将它放在 src/test/resources 中来加载这个standalone-full.xml。

我该怎么做?

我无法输入以下行,因为它是默认的 jboss 文件,而不是我覆盖的standalone-full.xml 文件。

<property name="serverConfig">standalone-full.xml</property>

当我指定文件路径(在资源中)时,它不起作用。

<property name="serverConfig">src/test/resources/standalone-full.xml</property>

<property name="serverConfig">/src/test/resources/standalone-full.xml</property>

<property name="serverConfig">${project.basedir}/src/test/resources/standalone-full.xml</property>

[编辑]

当我像这样将 maven 变量放入 surefire-plugin 时:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19.1</version>
            <configuration>
                <reuseForks>true</reuseForks>
                <systemPropertyVariables>
                   <server.standalone.config.path>${project.basedir}/src/test/resources/standalone-full.xml</server.standalone.config.path>
                </systemPropertyVariables>
                <redirectTestOutputToFile>false</redirectTestOutputToFile>
            </configuration>
        </plugin>

并在 arquillian.xml 中使用它

<property name="serverConfig">${server.standalone.config.path}</property>

我有这个错误:

java.lang.IllegalStateException: WFLYCTL0214: Could not get main file: 
D:\my_project_path\int-tests/src/test/resources/standalone-full.xml. Specified
 files must be relative to the configuration dir: D:\wildfly_path\wildfly-
10.1.0.Final\standalone\configuration

【问题讨论】:

    标签: java jboss integration-testing jboss-arquillian wildfly-10


    【解决方案1】:

    我们使用如下配置:

    <build>
        <testResources>
            <testResource>
                <directory>src/test/resources</directory>
            </testResource>
            <testResource>
                <directory>src/test/resources-wildfly-embedded</directory>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${version.surefire}</version>
                <configuration>
                    <systemPropertyVariables>
                        <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
                        <!-- the maven dependency plugin will have already downloaded the server on /target -->
                        <jboss.home>${dir.wildfly.home}</jboss.home>
                        <module.path>${dir.wildfly.modules}</module.path>
                        <!-- Do not use ./test/resources-wildfly/configuration because jboss will write to the
                        config directory and we don't want these files to change -->
                        <jboss.server.config.dir>${project.build.directory}/test-classes/configuration</jboss.server.config.dir>
                        <org.apache.deltaspike.ProjectStage>UnitTest</org.apache.deltaspike.ProjectStage>
                        <server-config>standalone.xml</server-config>
                    </systemPropertyVariables>
    
                    <redirectTestOutputToFile>false</redirectTestOutputToFile>
                </configuration>
            </plugin>
    
        </plugins>
    </build>
    

    在 src/test/resources-wildfly-embedded/configuration 我们有:

    • application-roles.properties
    • application-users.properties
    • logging.properties
    • mgmt-users.properties
    • mgmt-groups.properties
    • standalone.xml

    您似乎需要所有这些文件才能启动工作,但没有办法将standalone.xml 放在与配置的其余部分不同的目录中。

    【讨论】:

    • 是的,但我有多个模块,但它不起作用......但你的回答让我找到了解决方案
    【解决方案2】:

    最后,我使用了另一种方法,因为我有多个模块…… 构建过程分为三个部分。

    1. wildfly 容器部署

      <plugin>
          <artifactId>maven-dependency-plugin</artifactId>
          [...]
          <artifactItem>
              <groupId>org.wildfly</groupId>
          </artifactItem>
      [...]
      <execution>
          <id>stop-test-server</id>
          <phase>post-integration-test</phase>
          <goals>
              <goal>go-offline</goal>
          </goals>
      </execution>
      [...]
      
    2. jboss_home 和standalone-full.xml

      <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.19.1</version>
          <configuration>
              <!-- Fork every test because it will launch a separate AS instance -->
              <reuseForks>true</reuseForks>
              <systemPropertyVariables>
                  <!-- the maven dependency plugin will have already downloaded the server on /target -->
                  <jboss.home>${project.build.directory}/${wildfly.test.embedded.folder}</jboss.home>
                  <server-config>standalone-full.xml</server-config>
              </systemPropertyVariables>
              <redirectTestOutputToFile>false</redirectTestOutputToFile>
          </configuration>
      </plugin>
      
    3. 资源拷贝(jms.rar和自定义standalone-full.xml

      <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>2.7</version>
          <executions>
              <execution>
                  <id>copy-configuration-resource</id>
                  <phase>process-test-resources</phase>
                  <goals>
                      <goal>copy-resources</goal>
                  </goals>
                  <configuration>
                      <outputDirectory>${project.build.directory}/${wildfly.test.embedded.folder}/standalone/configuration</outputDirectory>
                      <resources>
                          <resource>
                              <directory>${project.basedir}/src/test/wildfly-resources/configuration</directory>
                                  <includes>
                                      <include>*.xml</include>
                                      <include>*.properties</include>
                                  </includes>
                              </resource>
                          </resources>
                      </configuration>
                  </execution>
                  <execution>
                      <id>copy-deployment-resource</id>
                      <phase>process-test-resources</phase>
                      <goals>
                          <goal>copy-resources</goal>
                      </goals>
                      <configuration>
                          <outputDirectory>${project.build.directory}/${wildfly.test.embedded.folder}/standalone/deployments</outputDirectory>
                          <resources>
                              <resource>
                                  <directory>${project.basedir}/src/test/wildfly-resources/deployments</directory>
                              <includes>
                                  <include>wmq.jmsra.rar</include>
                              </includes>
                          </resource>
                      </resources>
                  </configuration>
              </execution>
          </executions>
      </plugin>
      

    在 arquillian.xml 中:

    <container qualifier="arquillian-wildfly-managed" default="true" mode="suite">
        <configuration>
            <property name="serverConfig">standalone-full.xml</property>
        </configuration>
    </container>
    

    效果很好……

    【讨论】:

      猜你喜欢
      • 2013-01-13
      • 1970-01-01
      • 1970-01-01
      • 2019-07-30
      • 2014-11-09
      • 2013-10-31
      • 2020-12-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多