cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Testing helper functions

y-pankaj
Node Link

I am developing a neo4j plugin. So currently I am writing a neo4j procedure which calls a helper function ( present in a helper class ). A simplified snippet of the helper function is given below:

public Result runQuery(String query, Transaction tx) {
    return tx.execute(query);
}

I wanted to test the helper function. I am using the Neo4j driver to spin up a database and test my helper function. But my issue is that the helper function uses the transaction from org.neo4j.graphdb.Transaction and the transaction generated from Neo4j driver is from org.neo4j.driver.Transaction.

Below is a snippet from the test class.

    @Test
    public void testRunQuery() {
        try(Session session = driver.session()) {
            // this is from org.neo4j.driver.Transaction
            Transaction tx = session.beginTransaction();
            String query = "..."
            // below function accepts tx which is from org.neo4j.graphdb.Transaction
            Result result = helper.runQuery(query, tx);
        }
        
    }

How do I test my function as the helper function accepts a transaction which is of a different type from what is initialized in the test function?
1 REPLY 1

A driver is never going to be calling custom procedure or functions directly, it has no way to do so. A driver will execute a Cypher query, and that Cypher query will make the procedure or function call. So the invocation of your helper function will be performed within the Cypher query, you'll never be directly making the Java method call to your helper in your test code, and as such you'll never be passing the transaction yourself, so there will never be an opportunity for mismatches of the Transaction object type.

Here's a good resource for performing testing of your procs and functions: