3

我能够使用这些文档在我的服务器上安装示例插件:http: //docs.neo4j.org/chunked/milestone/server-plugins.html

现在我想开发自己的插件,但我不确定如何调试和单元测试它们。我在哪里可以阅读更多关于此和服务器插件开发的最佳实践的信息?

4

2 回答 2

1

my plugin:

package ru.a360.neo4j.plugins;

import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.server.plugins.*;
import org.neo4j.server.rest.repr.Representation;
import org.neo4j.server.rest.repr.ValueRepresentation;
import org.neo4j.tooling.GlobalGraphOperations;

import java.util.logging.Logger;

@Description("An extension to the Neo4j Server for find routes between two nodes")
public class WarmUp extends ServerPlugin
{
    private Logger logger = Logger.getLogger(WarmUp.class.getName());

    public WarmUp()
    {
    }

    @Name("warm_up")
    @Description("Warm up all nodes and relationships")
    @PluginTarget(GraphDatabaseService.class)
    public Representation warmUp(@Source GraphDatabaseService graphDb)
    {
        long t0 = System.currentTimeMillis();
        int relCount = 0;
        int nodesCount = 0;
        GlobalGraphOperations ggo = GlobalGraphOperations.at(graphDb);
        for (Node n: ggo.getAllNodes())
        {
            for (String prop: n.getPropertyKeys())
            {
                n.getProperty(prop);
            }
            nodesCount++;
        }
        for (Relationship rel: ggo.getAllRelationships())
        {
            for (String prop: rel.getPropertyKeys())
            {
                rel.getProperty(prop);
            }
            relCount++;
        }
        logger.info("warmup;" + (System.currentTimeMillis() - t0) / 1000.0 );
        return ValueRepresentation.string("WARMED UP " + nodesCount + " NODES AND " + relCount + " RELATIONSHIPS");
    }
}

There is new string in main/java/META-INF/services/org.neo4j.server.plugins.ServerPlugin:

ru.a360.neo4j.plugins.WarmUp

I want to write test (test/java/ru/a360/neo4j/plugins/TestNeo.java) like this:

package ru.a360.neo4j.plugins;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class TestNeo {

    @Before
    public void prepareTestData()
    {
    }

    @After
    public void destroyTestDatabase()
    {
    }

    @Test
    public void myTest1()
    {
    }
}
于 2013-03-26T09:19:08.397 回答
1

您可以像简单的 java 项目一样开发插件,测试插件很容易,只需在单元测试中实例化它们并将 Node、GraphDatabaseService 和参数传递给插件方法并检查结果。

于 2012-11-26T10:41:31.850 回答