graphaware / neo4j-framework

GraphAware Neo4j Framework
244 stars 68 forks source link

How to register some UDFs to the module test #68

Closed ziadloo closed 7 years ago

ziadloo commented 7 years ago

Considering friendship-strength-counter-module example, if I have developed some user-defined functions in the same project, how can I register them to the embedded database in the test code?

The examples I've found on how to write tests for UDFs take a different approach to setup an embedded database than in the examples here. They use

public class UdfTest
{
    @Rule
    public Neo4jRule neo4j = new Neo4jRule()
        .withFunction(Udf.class);

    @Test
    public void someTest() throws Throwable
    {
        try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), Config.build().withEncryptionLevel(Config.EncryptionLevel.NONE).toConfig())) {
            Session session = driver.session();

            long nodeId = session.run( "MATCH (n) RETURN myFunc(n)" )
                .single()
                .get(0).asLong();

            assertEquals(nodeId, 1);
        }
    }
}

How can I setup an embedded database in the test code adding a new module to Neo4j and some UDFs at the same time?

bachmanm commented 7 years ago

something like this:

(((GraphDatabaseFacade) database).getDependencyResolver().resolveDependency(Procedures.class)).registerProcedure(MyProc.class);