我正在尝试为我的Spring网络应用创建一些测试。我有一些使用MockMvc的测试类和使用Selenium的Cucumber测试类。所有测试都执行连接到InProcessServer实例的CRUD操作。
使用Gradle运行测试时,MockMvc测试类运行并通过,但是当执行Cucumber测试步骤时,我得到以下内容:
2015-09-17 16:44:05 DEBUG org.apache.http.wire - http-outgoing-3 >> "POST /db/data/transaction/commit HTTP/1.1[\r][\n]"
2015-09-17 16:44:05 DEBUG org.apache.http.wire - http-outgoing-3 >> "Content-Type: application/json;charset=UTF-8[\r][\n]"
2015-09-17 16:44:05 DEBUG org.apache.http.wire - http-outgoing-3 >> "Accept: application/json;charset=UTF-8[\r][\n]"
2015-09-17 16:44:05 DEBUG org.apache.http.wire - http-outgoing-3 >> "User-Agent: neo4j-ogm.java/1.0[\r][\n]"
2015-09-17 16:44:05 DEBUG org.apache.http.wire - http-outgoing-3 >> "Content-Length: 131[\r][\n]"
2015-09-17 16:44:05 DEBUG org.apache.http.wire - http-outgoing-3 >> "Host: localhost:7478[\r][\n]"
2015-09-17 16:44:05 DEBUG org.apache.http.wire - http-outgoing-3 >> "Connection: Keep-Alive[\r][\n]"
2015-09-17 16:44:05 DEBUG org.apache.http.wire - http-outgoing-3 >> "Accept-Encoding: gzip,deflate[\r][\n]"
2015-09-17 16:44:05 DEBUG org.apache.http.wire - http-outgoing-3 >> "[\r][\n]"
2015-09-17 16:44:05 DEBUG org.apache.http.wire - http-outgoing-3 >> "{"statements":[{"statement":"MATCH (n:`User`) RETURN COUNT(n)","parameters":{},"resultDataContents":["row"],"includeStats":false}]}"
2015-09-17 16:44:05 DEBUG org.apache.http.wire - http-outgoing-3 << "HTTP/1.1 404 Not Found[\r][\n]"
2015-09-17 16:44:05 DEBUG org.apache.http.wire - http-outgoing-3 << "Date: Thu, 17 Sep 2015 15:44:05 GMT[\r][\n]"
2015-09-17 16:44:05 DEBUG org.apache.http.wire - http-outgoing-3 << "Cache-Control: must-revalidate,no-cache,no-store[\r][\n]"
2015-09-17 16:44:05 DEBUG org.apache.http.wire - http-outgoing-3 << "Content-Type: text/html; charset=ISO-8859-1[\r][\n]"
2015-09-17 16:44:05 DEBUG org.apache.http.wire - http-outgoing-3 << "Content-Length: 304[\r][\n]"
2015-09-17 16:44:05 DEBUG org.apache.http.wire - http-outgoing-3 << "Server: Jetty(9.2.4.v20141103)[\r][\n]"
2015-09-17 16:44:05 DEBUG org.apache.http.wire - http-outgoing-3 << "[\r][\n]"
2015-09-17 16:44:05 DEBUG org.apache.http.wire - http-outgoing-3 << "<html>[\n]"
2015-09-17 16:44:05 DEBUG org.apache.http.wire - http-outgoing-3 << "<head>[\n]"
2015-09-17 16:44:05 DEBUG org.apache.http.wire - http-outgoing-3 << "<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>[\n]"
2015-09-17 16:44:05 DEBUG org.apache.http.wire - http-outgoing-3 << "<title>Error 404 </title>[\n]"
2015-09-17 16:44:05 DEBUG org.apache.http.wire - http-outgoing-3 << "</head>[\n]"
2015-09-17 16:44:05 DEBUG org.apache.http.wire - http-outgoing-3 << "<body>[\n]"
2015-09-17 16:44:05 DEBUG org.apache.http.wire - http-outgoing-3 << "<h2>HTTP ERROR: 404</h2>[\n]"
2015-09-17 16:44:05 DEBUG org.apache.http.wire - http-outgoing-3 << "<p>Problem accessing /db/data/transaction/commit. Reason:[\n]"
2015-09-17 16:44:05 DEBUG org.apache.http.wire - http-outgoing-3 << "<pre> Not Found</pre></p>[\n]"
2015-09-17 16:44:05 DEBUG org.apache.http.wire - http-outgoing-3 << "<hr /><i><small>Powered by Jetty://</small></i>[\n]"
2015-09-17 16:44:05 DEBUG org.apache.http.wire - http-outgoing-3 << "</body>[\n]"
2015-09-17 16:44:05 DEBUG org.apache.http.wire - http-outgoing-3 << "</html>[\n]"
2015-09-17 16:44:05 INFO o.s.d.n.config.Neo4jConfiguration - Intercepted exception
可能导致这种情况的原因是什么?这必须是Neo4j服务器,因为在测试完成后没有服务器在端口7478上运行,并且它也不是测试Web服务器,因为这是在随机端口上配置的,例如。
2015-09-17 16:44:04 INFO o.s.b.c.e.j.JettyEmbeddedServletContainer - Jetty started on port(s) 37837 (http/1.1)
修改
@Configuration
@EnableNeo4jRepositories(basePackages = "co.sens.data.repositories")
@EnableTransactionManagement
@ComponentScan("co.sens.data")
public class Neo4jTestConfiguration extends Neo4jConfiguration {
@Override
public SessionFactory getSessionFactory() {
return new SessionFactory("co.sens.data");
}
@Bean
@Override
public Neo4jServer neo4jServer() {
return new InProcessServer();
}
@Override
@Bean
public Session getSession() throws Exception {
return super.getSession();
}
}