Neo4j Unmanaged Extension unit testing for version 2.2.3 -
i create unit tests unmanaged extension wrote 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 use approach similar code above in @before test class - understand new way write unit tests.
i ask:
- how can turn automatic authentication off using config settings
- how can register our extension
i manage achieve goal code below 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();
my solutions create own testserver based on neo4j test classes can set properties , 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 base url of neo4j database server used in test. * * @return url of neo4j test server */ public string url() { return server.baseuri().tostring(); }}
you need inprocessserver return testserver umx
public class neo4jinprocessserver implements neo4jserver{ private neo4jtestserver testserver; public neo4jinprocessserver() { this.testserver = new neo4jtestserver(); } public string url() { return testserver.url(); }}
finally, need return inprocessserver configuration class
@override public neo4jserver neo4jserver() { return new neo4jinprocessserver(); }
Comments
Post a Comment