在 arquillian 中使用自定义独立-full.xml

Use custom standalone-full.xml with arquillian

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

中来加载这个 standalone-full.xml

我该怎么做?

我无法放入以下行,因为它是默认的 jboss 文件,而不是我覆盖的独立 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

我们使用以下配置:

<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 中,我们有:

  • 应用-roles.properties
  • 申请-users.properties
  • logging.properties
  • mgmt-users.properties
  • mgmt-groups.properties
  • standalone.xml

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

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

  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 和独立-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和自定义独立-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>

工作正常…