本文介绍了尝试使用neo4j grails插件,但它不会加速文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试neo4j插件,我创建了一个简单的测试,如下所示:
package com.iibs.graph
import groovy.util.GroovyTestCase
import com.iibs.graph.Node
$ b 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
断言found.node instanceof org.neo4j.graphdb.Node
}
}
基于以下文档:
此测试是预计会通过没有任何问题,但我收到以下错误:
|失败:testCRUD(com.iibs.graph.NodeTests)
|断言失败:
断言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:
at junit.framework.TestSuite.runTest(TestSuite.java:255)
at junit.framework.TestSuite.run(TestSuite.java:250)
|已完成1次集成测试,1次失败1s
我是否以错误的方式使用API?
另外,如果我将上一个断言行更改为:
断言found.getNode()instanceof org.neo4j.graphdb.Node
错误是不同的:
失败:testCRUD(com.iibs.graph.NodeTests)
| groovy.lang.MissingMethodException:没有方法的签名:com.iibs.graph.Node.getNode()适用于参数类型:()values:[]
可能的解决方案: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)
|完成1次集成测试,1次失败0m 2s
如错误所示,其中一种解决方案是使用 getMongo 。这与mongo有什么关系。这是我的实体:
package com.iibs.graph
import groovy.transform.ToString;
$ b @ToString(includes ='name')
class Node {
字符串名称
static mapWith = neo4j
static constraints = {
}
}
谢谢, 解决方案
该插件的文档尚未针对2.x进行更新 - 这是第一个里程碑。简单地说,域实例不再具有节点
属性,因为我们仅依赖于Cypher内部。域实例的 id
属性引用图中节点上的 __ id __
属性。
I am trying neo4j plugin and I created a simple test as follows:
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
}
}
Based on the documentation: http://projects.spring.io/grails-data-mapping/neo4j/manual/ref/Additional%20Gorm%20Methods/getNode.htmlthis test is expected to pass without any problems, however I am getting the following error:
| 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
Am I using the API in a wrong way?
Also, if I changing the last assertion line to:
assert found.getNode() instanceof org.neo4j.graphdb.Node
The error is different:
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
As shown in the error, one of the proposed solutions is to use getMongo. What does it have to do with mongo. Here is my entity:
package com.iibs.graph
import groovy.transform.ToString;
@ToString(includes='name')
class Node {
String name
static mapWith = "neo4j"
static constraints = {
}
}
Thanks,
解决方案
The docs for the plugin have not yet been updated for 2.x - it's the first milestone.
In short, domain instances no longer have a node
property since we're relying on Cypher internally only. The id
property of the domain instance refers to the __id__
property on the node in the graph.
这篇关于尝试使用neo4j grails插件,但它不会加速文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!