cancel
Showing results for 
Search instead for 
Did you mean: 

Loading data to test harness

joe4
Node

Hi guys.

I'm trying to debug a user defined procedure using the test harness as described by Max De Marzi's blog. I'm struggling with adding test data to debug against.

Does the test harness require the data fixture to be embedded in java as a string? I have found no other way (that works) to load data to the harness other than calling .withFixture(String MODEL_STATEMENT) where that model statement is a single cypher statement.

I attempted to load exported cypher scripts files (using apoc) from other databases but those scripts are not compatible with withFixture(File cypherFile) unless there is exactly one cypher statement in the file.

Using .copyFrom(File sourceDirectory) does not load the databases in the folders (properly setup according to the now working javadocs as data/databases/neo4j).

Even if I wanted to launch the Harness and use apoc to execute the exported cypher to preload data during initialization, the harness would have no access to the cypher script file as there's no way to mount the folder or copy the file in.

I'm coming to the conclusion that if I want to debug any stored procedure in Neo4j that leverages apoc, it requires this:

  • Neo4j version 4.0.5
  • APOC version 4.0.0.13
  • Single cypher statement test fixture as a java string.

Am I missing something?

Edit: I was able to load the cypher script file by splitting it by semicolon and line separator:

    @BeforeAll
    static void initialize() throws URISyntaxException, IOException  {

        var pluginDirContainingApocJar = new File(
            ApocConfig.class.getProtectionDomain().getCodeSource().getLocation().toURI())
            .getParentFile().toPath();

        var builder = Neo4jBuilders.newInProcessBuilder()
            .withDisabledServer()  
            .withConfig(GraphDatabaseSettings.plugin_dir, pluginDirContainingApocJar)
            .withConfig(GraphDatabaseSettings.procedure_unrestricted, List.of("apoc.*"))
            .withConfig(ApocSettings.apoc_import_file_enabled, true)
            .withConfig(ApocSettings.apoc_export_file_enabled, true)
            .withFunction(MyFunction.class);
        
        Path cypherScript = Path.of("/import/export-plain.cypher");        
        String fileContents = Files.readString(cypherScript);
        List<String> statements = Arrays.asList(fileContents.split(";\n"));

        for (String statement : statements) {  
            builder.withFixture(statement);
        }
        
        neo4j = builder.build();
    }
1 REPLY 1

accounts
Node Clone

not sure if this is still relevant but you can
A. ,

  • publish you package to the plugins folder
  • start your db in desktop
  • attach debugger to running desktop
  • in browser execute CALL myfunctrion()
  • break point happiness

B.

  • debug using TestServerBuilders
        File f = new File("....\\data");
        this.embeddedDatabaseServer = TestServerBuilders
                .newInProcessBuilder()
                .copyFrom(f)
                .withFunction(MyFunction.class)
                .newServer();

then step into your breakpoints ( of course make sure that your apoc lib is a system dependency )