我正在尝试neo4j插件,我创建了一个简单的测试,如下所示:
package com.iibs.graph
import groovy.util.GroovyTestCase
import com.iibs.graph.Node
public class NodeTests extends GroovyTestCase {
void testCRUD() {
Node.deleteAll(Node.list())
Node node = new Node(name: "Name")
node.save(flush: true, failOnError: true)
Node found = Node.findByName("Name")
assert found instanceof Node
assert found.getName() == "Name"
assert found.node instanceof org.neo4j.graphdb.Node
}
}
基于文档:http://projects.spring.io/grails-data-mapping/neo4j/manual/ref/Additional%20Gorm%20Methods/getNode.html 预计此测试会毫无问题地通过,但是我收到以下错误:
| Failure: testCRUD(com.iibs.graph.NodeTests)
| Assertion failed:
assert found.node instanceof org.neo4j.graphdb.Node
| | |
| null false
com.iibs.graph.Node(Name)
at com.iibs.graph.NodeTests.testCRUD(NodeTests.groovy:20)
at junit.framework.TestCase.runTest(TestCase.java:176)
at junit.framework.TestCase.runBare(TestCase.java:141)
at junit.framework.TestResult$1.protect(TestResult.java:122)
at junit.framework.TestResult.runProtected(TestResult.java:142)
at junit.framework.TestResult.run(TestResult.java:125)
at junit.framework.TestCase.run(TestCase.java:129)
at junit.framework.TestSuite.runTest(TestSuite.java:255)
at junit.framework.TestSuite.run(TestSuite.java:250)
| Completed 1 integration test, 1 failed in 0m 1s
我是否以错误的方式使用API?
另外,如果我将最后一个断言行更改为:
assert found.getNode() instanceof org.neo4j.graphdb.Node
错误不同:
Failure: testCRUD(com.iibs.graph.NodeTests)
| groovy.lang.MissingMethodException: No signature of method: com.iibs.graph.Node.getNode() is applicable for argument types: () values: []
Possible solutions: getName(), getId(), setName(java.lang.String), getMongo(), getAll(), getCount()
at com.iibs.graph.NodeTests.testCRUD(NodeTests.groovy:20)
at junit.framework.TestCase.runTest(TestCase.java:176)
at junit.framework.TestCase.runBare(TestCase.java:141)
at junit.framework.TestResult$1.protect(TestResult.java:122)
at junit.framework.TestResult.runProtected(TestResult.java:142)
at junit.framework.TestResult.run(TestResult.java:125)
at junit.framework.TestCase.run(TestCase.java:129)
at junit.framework.TestSuite.runTest(TestSuite.java:255)
at junit.framework.TestSuite.run(TestSuite.java:250)
| Completed 1 integration test, 1 failed in 0m 2s
如错误所示,建议的解决方案之一是使用 getMongo 。它与mongo有什么关系。这是我的实体:
package com.iibs.graph
import groovy.transform.ToString;
@ToString(includes='name')
class Node {
String name
static mapWith = "neo4j"
static constraints = {
}
}
谢谢,
答案 0 :(得分:2)
该插件的文档尚未针对2.x更新 - 它是第一个里程碑。
简而言之,域实例不再具有node
属性,因为我们仅在内部依赖于Cypher。域实例的id
属性引用图中节点上的__id__
属性。