2012-11-24 152 views

回答

1

您可以像開發簡單的java項目一樣開發插件,測試插件非常簡單,只需在單元測試中實例化它們並將Node,GraphDatabaseService和參數傳遞給插件方法並檢查結果。

1

我的插件:

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"); 
    } 
} 

有一個在主/ JAVA/META-INF /服務新的字符串/ org.neo4j.server.plugins.ServerPlugin:

ru.a360.neo4j.plugins.WarmUp 

我想寫測試(test/java/ru/a360/neo4j/plugins/TestNeo.java)如下:

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() 
    { 
    } 
}