简体   繁体   English

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

[英]How to test unmanaged extension for Neo4j server using JUnit

I'm trying to develop some test file for a Neo4j project. 我正在尝试为Neo4j项目开发一些测试文件。 I have found that Neo4j provides JUnit Rule ( http://neo4j.com/docs/stable/server-unmanaged-extensions-testing.html ) and I have try to use it for testing. 我发现Neo4j提供了JUnit规则( http://neo4j.com/docs/stable/server-unmanaged-extensions-testing.html ),我已经尝试使用它进行测试。 However, it does not work as intendant. 但是,它不能按预期方式工作。

My code is exactly as in the Neo4j help page: 我的代码与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());
}

I'm receiving this error: 我收到此错误:

Failed tests:   shouldWorkWithServer(test.Test): expected:<200> but was:<500>

I have try to resolve 'db/data/' path: 我尝试解析“ db / data /”路径:

URI serverURI = neo4j.httpURI().resolve("db/data/");

The result has been same. 结果是一样的。 I have also try to use TestServerBuilders instead and generate Http Authentication header with default 'neo4j:neo4j' and have got same error again. 我也尝试改用TestServerBuilders并使用默认的'neo4j:neo4j'生成Http Authentication标头,并再次遇到相同的错误。 The server does created, I can access to it via getGraphDatabaseService() and see the nodes, but I can not access it via HTTP. 服务器确实创建了,我可以通过getGraphDatabaseService()访问它并查看节点,但是不能通过HTTP访问它。

The Neo4j version is 3.2.1 and the JUnit version is 4.11 Neo4j版本是3.2.1,JUnit版本是4.11

If using Maven, do not forget that the order you declare the dependencies has an importance. 如果使用Maven,请不要忘记声明依赖项的顺序很重要。 Therefore, you should declare the "provided" dependencies after the "test" ones, so the implementation of the test library is used prior to the provided one. 因此,应该在“测试”之后声明“提供的”依赖关系,以便在所提供的依赖之前使用测试库的实现。 That is good practice for all the JEE related libraries. 对于所有与JEE相关的库,这都是一个好习惯。

In your case, make sure you declare javax.ws.rs:javax.ws.rs-api:2.0 after org.neo4j.test:neo4j-harness:2.3.1 在您的情况下,请确保在org.neo4j.test:neo4j-harness:2.3.1之后声明javax.ws.rs:javax.ws.rs-api:2.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM