Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.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 Maven Cargo:Cargo部署战争前的集成测试运行_Java_Maven_Maven Cargo_Maven Failsafe Plugin - Fatal编程技术网

Java Maven Cargo:Cargo部署战争前的集成测试运行

Java Maven Cargo:Cargo部署战争前的集成测试运行,java,maven,maven-cargo,maven-failsafe-plugin,Java,Maven,Maven Cargo,Maven Failsafe Plugin,集成pom.xml如下所示 org.apache.maven.plugins maven故障保护插件 2.12 集成测试 集成测试 验证 org.codehaus.cargo cargo-maven2-plugin 1.4.8 tomcat7x http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.16/bin/apache-tomcat-7.0.16.zip ${project.build.directory}/downloads ${pro

集成
pom.xml
如下所示


org.apache.maven.plugins
maven故障保护插件
2.12
集成测试
集成测试
验证
org.codehaus.cargo
cargo-maven2-plugin
1.4.8
tomcat7x
http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.16/bin/apache-tomcat-7.0.16.zip
${project.build.directory}/downloads
${project.build.directory}/extracts
9090
com.yahoo.pryme_services.inventory
服务
战争
http://localhost:9090/services/rest/hello
启动容器
开始
预集成测试
停止容器
停止
整合后测试
这个测试看起来像

公共类TestHelloIT{
@试验
公共void testHello(){
最终字符串url=”http://localhost:9090/services/rest";
最终客户端=ClientBuilder.newClient();
最终WebTarget=client.target(url.path(“hello”);
final Invocation.Builder=target.request();
最终响应=builder.get();
assertEquals(Response.Status.ACCEPTED.getStatusCode(),Response.getStatus());
}
}
当我运行
mvn clean install
时,我看到测试运行并失败,而cargo在日志中没有位置,说明它正在部署

[INFO] Scanning for projects...
[INFO] 
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Pryme REST Services Integration Test 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ integration ---
[INFO] Deleting /Users/harith/IdeaProjects/pryme_services/inventory/integration/target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ integration ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ integration ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ integration ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/harith/IdeaProjects/pryme_services/inventory/integration/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ integration ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /Users/harith/IdeaProjects/pryme_services/inventory/integration/target/test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ integration ---
[INFO] Surefire report directory: /Users/harith/IdeaProjects/pryme_services/inventory/integration/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.yahoo.pryme_services.inventory.integration.TestHelloIT
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.469 sec <<< FAILURE!
testHello(com.yahoo.pryme_services.inventory.integration.TestHelloIT)  Time elapsed: 0.435 sec  <<< ERROR!
javax.ws.rs.ProcessingException: java.net.ConnectException: Connection refused
    at org.glassfish.jersey.client.HttpUrlConnector.apply(HttpUrlConnector.java:229)
    at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:224)
    at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:655)
    at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:652)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
    at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:424)
    at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:652)
    at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:387)
    at org.glassfish.jersey.client.JerseyInvocation$Builder.get(JerseyInvocation.java:291)
    at com.yahoo.pryme_services.inventory.integration.TestHelloIT.testHello(TestHelloIT.java:20)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
    at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Caused by: java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:579)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:175)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:211)
    at sun.net.www.http.HttpClient.New(HttpClient.java:308)
    at sun.net.www.http.HttpClient.New(HttpClient.java:326)
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:996)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:932)
    at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:850)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1300)
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:468)
    at org.glassfish.jersey.client.HttpUrlConnector._apply(HttpUrlConnector.java:321)
    at org.glassfish.jersey.client.HttpUrlConnector.apply(HttpUrlConnector.java:227)
    ... 40 more


Results :
[INFO]正在扫描项目。。。
[信息]
[信息]使用线程计数为1的生成器org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder
[信息]
[信息]------------------------------------------------------------------------
[信息]构建Pryme REST服务集成测试1.0-SNAPSHOT
[信息]------------------------------------------------------------------------
[信息]
[信息]---maven clean插件:2.5:clean(默认清洁)@integration---
[信息]删除/Users/harith/IdeaProjects/pryme_services/inventory/integration/target
[信息]
[信息]---maven资源插件:2.6:resources(默认资源)@integration---
[警告]使用平台编码(实际上是UTF-8)复制过滤后的资源,即构建依赖于平台!
[信息]正在复制0资源
[信息]
[信息]---maven编译器插件:2.5.1:编译(默认编译)@integration---
[信息]无需编译-所有类都是最新的
[信息]
[信息]---maven资源插件:2.6:testResources(默认testResources)@integration---
[警告]使用平台编码(实际上是UTF-8)复制过滤后的资源,即构建依赖于平台!
[信息]跳过不存在的资源目录/Users/harith/IdeaProjects/pryme_services/inventory/integration/src/test/resources
[信息]
[信息]---maven编译器插件:2.5.1:testCompile(默认testCompile)@integration---
[警告]未使用平台编码UTF-8设置文件编码,即生成依赖于平台!
[信息]将1个源文件编译为/Users/harith/IdeaProjects/pryme_services/inventory/integration/target/test类
[信息]
[信息]---maven surefire插件:2.12.4:测试(默认测试)@integration---
[信息]Surefire报告目录:/Users/harith/IdeaProjects/pryme_services/inventory/integration/target/Surefire报告
-------------------------------------------------------
T T S T S
-------------------------------------------------------
运行com.yahoo.pryme_services.inventory.integration.TestHelloIT

测试运行:1,失败:0,错误:1,跳过:0,经过的时间:0.469秒。将其从TestHelloIT重命名为HelloIT,它应该可以工作

为了理解为什么会出现这种情况,让我们提醒自己Maven的生命周期:

validate
compile
test
package
integration-test
verify
install
deploy
您会注意到,您的测试正在运行,并且在Surefire插件中失败。Surefire插件在测试阶段运行,也就是说,它在应用程序打包(更不用说部署)到集成测试阶段的容器之前运行

实际上,您已经正确地为Failsafe插件命名了测试,这是您希望它在集成测试阶段运行的插件。默认情况下,它选择名为
**/it*.java
**/it.java
**/ITCase.java
的类

但是,Surefire插件的命名约定是
***/Test*.java
***/Test.java
***/TestCase.java
。因此,您所要做的就是命名测试,以便两个插件都能获取它,而且由于Surefire首先运行并失败,所以它甚至没有到达容器将要部署的位置


其余的看起来很好,应该可以工作。

谢谢@mardoz,它似乎没有在测试阶段运行,我可以看到tomcat正在部署。但是现在部署tomcat之后,我看不到任何
HelloIT.java
正在运行。我还缺什么吗?