有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java使用定制的standalonefull。带arquillian的xml

我正在使用wildfly容器和arquillian进行集成测试。 在某些情况下,我希望使用JMS和独立完整。带有一些自定义配置的xml在服务器启动时加载。 所以,对于我的int测试,我想加载这个独立的完整测试。将其放入src/test/resources中

我该怎么做

我不能放下面一行,因为它是默认的jboss文件,而不是我的重写独立完整文件。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>
            <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>

用在阿奎利安。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

共 (2) 个答案

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

    • 应用程序角色。属性
    • 应用程序用户。属性
    • 日志记录。属性
    • 管理用户。属性
    • 管理小组。属性
    • 独立的。xml

    看起来你需要所有这些文件才能启动,但没有办法把它们独立起来。xml位于与配置的其余部分不同的目录中

  2. # 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和custom 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>
      

    在阿奎利安。xml:

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

    它很好用