我正在尝试为Neo4j项目开发一些测试文件 . 我发现Neo4j提供了JUnit规则(http://neo4j.com/docs/stable/server-unmanaged-extensions-testing.html),我试着用它进行测试 . 但是,它并不像通讯员那样工作 .
我的代码与Neo4j帮助页面完全相同:
@Rule
public Neo4jRule neo4j = new Neo4jRule()
.withFixture( "CREATE (admin:Admin)" )
.withFixture( new Function<GraphDatabaseService, Void>()
{
@Override
public Void apply( GraphDatabaseService graphDatabaseService ) throws RuntimeException
{
try (Transaction tx = graphDatabaseService.beginTx())
{
graphDatabaseService.createNode( DynamicLabel.label( "Admin" ));
tx.success();
}
return null;
}
} );
@Test
public void shouldWorkWithServer() throws Exception
{
// Given
URI serverURI = neo4j.httpURI();
// When I access the server
HTTP.Response response = HTTP.GET( serverURI.toString() );
// Then it should reply
assertEquals(200, response.status());
}
我收到此错误:
Failed tests: shouldWorkWithServer(test.Test): expected:<200> but was:<500>
我试着解决'db / data /'路径:
URI serverURI = neo4j.httpURI().resolve("db/data/");
结果是一样的 . 我也尝试使用TestServerBuilders,并使用默认的'neo4j:neo4j'生成Http Authentication头,并再次出现相同的错误 . 服务器确实创建了,我可以通过getGraphDatabaseService()访问它并查看节点,但我无法通过HTTP访问它 .
Neo4j版本是3.2.1,JUnit版本是4.11
1 回答
如果使用Maven,请不要忘记声明依赖项的顺序具有重要性 . 因此,您应该在“test”之后声明“提供的”依赖项,因此在提供的测试库之前使用测试库的实现 . 这是所有JEE相关库的良好实践 .
在您的情况下,请确保在org.neo4j.test之后声明javax.ws.rs:javax.ws.rs-api:2.0:neo4j-harness:2.3.1