Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何动态设置嵌入式WildFly服务器,以便使用Maven进行测试_Java_Maven_Jboss_Integration Testing_Wildfly 10 - Fatal编程技术网

Java 如何动态设置嵌入式WildFly服务器,以便使用Maven进行测试

Java 如何动态设置嵌入式WildFly服务器,以便使用Maven进行测试,java,maven,jboss,integration-testing,wildfly-10,Java,Maven,Jboss,Integration Testing,Wildfly 10,我有一个关于如何在运行中设置嵌入式Wildfly 10服务器进行集成测试的问题 <!-- Loading Wildfly 10 on the fly and copy it into the target folder. --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</arti

我有一个关于如何在运行中设置嵌入式Wildfly 10服务器进行集成测试的问题

<!-- Loading Wildfly 10 on the fly and copy it into the target folder. -->
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>unpack</id>
            <phase>process-test-classes</phase>
            <goals>
                <goal>unpack</goal>
            </goals>
            <configuration>
                <artifactItems>
                    <artifactItem>
                        <groupId>org.wildfly</groupId>
                        <artifactId>wildfly-dist</artifactId>
                        <version>10.0.0.Final</version>
                        <type>zip</type>
                        <overWrite>false</overWrite>
                        <outputDirectory>target</outputDirectory>
                    </artifactItem>
                </artifactItems>
            </configuration>
        </execution>
    </executions>
</plugin>

<plugin>
    <groupId>org.wildfly.plugins</groupId>
    <artifactId>wildfly-maven-plugin</artifactId>
    <version>1.1.0.Alpha1</version>
    <configuration>
        <jbossHome>target/wildfly-10.0.0.Final</jbossHome>
        <hostname>127.0.0.1</hostname>
        <!--  <port>9990</port> -->
        <filename>${project.build.finalName}.war</filename>
        <java-opts>
            <java-opt>-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005</java-opt>
        </java-opts>
        <commands>
            <command>/subsystem=logging/file-handler=debug:add(level=DEBUG,autoflush=true,file={"relative-to"=>"jboss.server.log.dir",
                "path"=>"debug.log"})</command>
            <command>/subsystem=logging/logger=org.jboss.as:add(level=DEBUG,handlers=[debug])</command>
        </commands>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.6.4</version>
        </dependency>
    </dependencies>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>deploy</goal>
            </goals>
        </execution>
        <execution>
            <id>start-wildfly</id>
            <phase>test-compile</phase>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
        <execution>
            <id>shutdown-wildfly</id>
            <phase>test</phase>
            <goals>
                <goal>shutdown</goal>
            </goals>
        </execution>
    </executions>
</plugin>

org.apache.maven.plugins
maven依赖插件
打开
过程测试类
打开
野生蝇
野蝇区
10.0.0.1决赛
拉链
假的
目标
org.wildfly.plugins
wildfly maven插件
1.1.0.1
target/wildfly-10.0.0.Final
127.0.0.1
${project.build.finalName}.war
-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005
/subsystem=logging/file handler=debug:add(level=debug,autoflush=true,file={“relative to”=>“jboss.server.log.dir”,
“路径”=>“debug.log”})
/subsystem=logging/logger=org.jboss.as:add(level=DEBUG,handlers=[DEBUG])
org.slf4j
slf4j-log4j12
1.6.4
包裹
部署
开始狂飞
测试编译
跑
关闭野蝇
测试
关闭
首先,Maven动态下载服务器,将其保存到目标文件夹。稍后我要复制一个新的standalone.xml,启动服务器,运行集成测试并停止服务器

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.example.FunctionalTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.071  sec <<< FAILURE! - in com.example.FunctionalTest
basicPingTest(com.example.FunctionalTest)  Time elapsed: 0.07 sec  <<< ERROR!
java.net.ConnectException: Connection refused
at com.example.FunctionalTest.basicPingTest(FunctionalTest.java:39)

Results :

Tests in error: 
 FunctionalTest.basicPingTest:39 » Connect Connection refused

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
直到现在,我还看不到我已经启动了服务器

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.example.FunctionalTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.071  sec <<< FAILURE! - in com.example.FunctionalTest
basicPingTest(com.example.FunctionalTest)  Time elapsed: 0.07 sec  <<< ERROR!
java.net.ConnectException: Connection refused
at com.example.FunctionalTest.basicPingTest(FunctionalTest.java:39)

Results :

Tests in error: 
 FunctionalTest.basicPingTest:39 » Connect Connection refused

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
-------------------------------------------------------
T T S T S
-------------------------------------------------------
运行com.example.FunctionalTest

测试运行:1,失败:0,错误:1,跳过:0,经过的时间:0.071秒我建议看一下哪个将负责容器生命周期管理,并通过将它们部署到容器来运行测试。很好的一点是,这还允许从IDE中运行测试,因为测试(运行程序)本身将管理容器生命周期

当使用WildFly Maven插件控制容器时,Maven Failsafe插件应用于此类集成测试,因为它确保在执行测试后,容器也会在发生故障时安全关闭

您还可以使用Hibernate搜索,我们使用Arquillian来运行集成测试。查看src/test/resources/arquillian.xml,在这里我们指向一些特定的服务器配置文件,以代替standalone.xml

本POM还展示了如何使用Maven依赖插件下载WildFly并在运行测试之前提取它