问题
as continuation of Trying out neo4j grails plugin, but it does not mach the docs
I have a test now looks like this:
package com.iibs.graph
import groovy.util.GroovyTestCase
import com.iibs.graph.Node
public class NodeTests extends GroovyTestCase {
def graphDatabaseService
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"
org.neo4j.graphdb.Node graphNode = graphDatabaseService.getNodeById(node.getId())
assert graphNode.instanceOf(org.neo4j.graphdb.Node) == true
}
}
And I am getting an error as follows:
| Running 1 integration test... 1 of 1
| Failure: testCRUD(com.iibs.graph.NodeTests)
| org.neo4j.graphdb.NotFoundException: Node 905482810884096 not found
at org.neo4j.kernel.InternalAbstractGraphDatabase.getNodeById(InternalAbstractGraphDatabase.java:1088)
at com.iibs.graph.NodeTests.testCRUD(NodeTests.groovy:22)
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 far as I understand from the mentioned thread, this should be one of the possible ways to get the node. Or am I wrong?
回答1:
Try the following snippet (did not test myself, just a braindump):
def nodeInstance = ....
nodeInstance.save(flush:true)
String label = nodeInstance.getClass().simpleName
def neoNode = graphDatabaseService.findNodesByLabelAndProperty(DynamicLabel.label(label), "__id__", nodeInstance.id)
来源:https://stackoverflow.com/questions/23490581/cannot-find-node-using-graphdatabaseservice-when-it-is-created-in-the-same-test