在同一测试中创建时,使用graphDatabaseService找不到节点 [英] Cannot find node using graphDatabaseService when it is created in the same test

查看:398
本文介绍了在同一测试中创建时,使用graphDatabaseService找不到节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

继续尝试neo4j grails插件,但它没有文件

我现在有一个测试看起来像这样:

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
    }
}

我收到如下错误:

| 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?

推荐答案

尝试下面的代码片段(没有测试自己,只是一个braindump):

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)

这篇关于在同一测试中创建时,使用graphDatabaseService找不到节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆