Testing Uno4j Unmanaged Extension for version 2.2.3

I like to create unit tests for my unmanaged extension that I wrote for a small Neo4j project.

GraphDatabaseService db = new TestGraphDatabaseFactory()
                .newImpermanentDatabaseBuilder()
                .setConfig(GraphDatabaseSettings.pagecache_memory, "512M")
                .setConfig( GraphDatabaseSettings.string_block_size, "60" )
                .setConfig( GraphDatabaseSettings.array_block_size, "300" )
                .newGraphDatabase();

      

I want to use an approach similar to the code above in my @Before class, which I understand is a new way to write unit tests.

I like to ask:

  • How to disable automatic authentication using configuration settings.
  • How can I register our extension

I managed to achieve my goal with the code below, but I am getting a bunch of deprecated warnings.

ImpermanentGraphDatabase db = new ImpermanentGraphDatabase();
ServerConfigurator config = new ServerConfigurator(db);
        config.configuration().setProperty("dbms.security.auth_enabled", false);
        config.getThirdpartyJaxRsPackages().add(new ThirdPartyJaxRsPackage("com.mine.graph.neo4j", "/extensions/mine"));
testBootstrapper = new WrappingNeoServerBootstrapper(db, config);
testBootstrapper.start();

      

+3


source to share


1 answer


My solutions is to create your own TestServer based on Neo4j test classes so you can set properties and load UMX

public class Neo4jTestServer  {
private AbstractNeoServer server;
private GraphDatabaseService database;

public Neo4jTestServer() {

    try {
        ServerControls controls = TestServerBuilders.newInProcessBuilder()
                .withExtension("/fd", "org.flockdata.neo4j")
                .withConfig("dbms.security.auth_enabled", "false")
                .newServer();

        initialise(controls);

    } catch (Exception e) {
        throw new RuntimeException("Error starting in-process server",e);
    }

}

private void initialise(ServerControls controls) throws Exception {

    Field field = InProcessServerControls.class.getDeclaredField("server");
    field.setAccessible(true);
    server = (AbstractNeoServer) field.get(controls);
    database = server.getDatabase().getGraph();
}

/**
 * Retrieves the base URL of the Neo4j database server used in the test.
 *
 * @return The URL of the Neo4j test server
 */
public String url() {
    return server.baseUri().toString();
}}

      

You will also need InProcessServer to return your test server using UMX



public class Neo4jInProcessServer implements Neo4jServer{
private Neo4jTestServer testServer;

public Neo4jInProcessServer()  {
    this.testServer = new Neo4jTestServer();
}

public String url() {
    return testServer.url();
}}

      

Finally, you need to return InProcessServer from your config class

    @Override
public Neo4jServer neo4jServer() {

    return new Neo4jInProcessServer();
}

      

+3


source







All Articles