gpt4 book ai didi

java - 如何使用 JUnit 测试 Neo4j 服务器的非托管扩展

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:27:42 24 4
gpt4 key购买 nike

我正在尝试为 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 header ,并且再次遇到相同的错误。服务器确实已创建,我可以通过 getGraphDatabaseService() 访问它并查看节点,但我无法通过 HTTP 访问它。

Neo4j版本为3.2.1,JUnit版本为4.11

最佳答案

如果使用 Maven,请不要忘记声明依赖项的顺序很重要。因此,您应该在“测试”依赖项之后声明“提供的”依赖项,以便在提供的依赖项之前使用测试库的实现。这对于所有与 JEE 相关的库都是很好的做法。

在您的情况下,确保在 org.neo4j.test:neo4j-harness:2.3.1 之后声明 javax.ws.rs:javax.ws.rs-api:2.0

关于java - 如何使用 JUnit 测试 Neo4j 服务器的非托管扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34803542/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com