Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assigning node labels. #156

Open
dwjohnston opened this issue Apr 15, 2016 · 3 comments
Open

Assigning node labels. #156

dwjohnston opened this issue Apr 15, 2016 · 3 comments

Comments

@dwjohnston
Copy link

Is it possible to assign node labels in the xml?

From what I can see here and here I should be using the following format to assign labels to nodes:

<node id = "1" labels = ":FOO"> <data key = "labels">:FOO</data></node>

This doesn't work for the neo4j java API.

Here's my full graph xml:

<?xml version="1.0" encoding="UTF-8"?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
 http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">

    <key id = "labels" for = "node" attr.name = "labels" attr.type = "string"></key>


    <graph id="G" edgedefault="undirected">

        <node id="1" labels = ":FOO">
            <data key = "labels">:FOO</data>
        </node>

        <node id="2" labels = ":FOO">
            <data key = "labels">:FOO</data>
        </node>

        <node id="3" labels = ":FOO">
            <data key = "labels">:FOO</data>
        </node>

        <node id="4" labels = ":FOO">
            <data key = "labels">:FOO</data>
        </node>



    </graph>
</graphml>

And my test code:

@UsingDataSet(locations = "NoSqlUnitTestTest.xml", loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public class NoSqlUnitTestTest {

    @ClassRule
    public static EmbeddedNeo4j embeddedNeo4j = newEmbeddedNeo4jRule().build();

    @Rule
    public Neo4jRule neo4jRule = new Neo4jRule(
            newEmbeddedNeoServerConfiguration().build(), this);

    @Inject
    GraphDatabaseService graphDb;


    @Test
    public void TestTest1() {

        Label l = DynamicLabel.label("FOO");

        try (Transaction tx = graphDb.beginTx()) {
            // Test set up sanity tests
            ResourceIterator<Node> createdNodes = graphDb.findNodes(l);
            int i = 0;
            while (createdNodes.hasNext()) {
                i++;
                createdNodes.next();
            }
            assertEquals(3, i);   //FAIL - 3 != 0 

            tx.success();
        }

    }

    @Test
    public void TestTest2() {

        try (Transaction tx = graphDb.beginTx()) {
            Iterable<Node> allNodes = GlobalGraphOperations.at(graphDb)
                    .getAllNodes();

            int i = 0;
            for (Node node : allNodes) {
                i++;
            }
            assertEquals(4, i);    //SUCCESS

            tx.success();
        }
    }

}

Is it possible to configure nosql-unit to assign labels this way?

@dwjohnston
Copy link
Author

Apologies, the forth node is meant to have a :BAR label. I can't edit the post because I'm using an out of date browser.

@dwjohnston
Copy link
Author

if anyone is interested, here's a work around:

You import the label as a property, and assign it as an actual label in your test setup:

    @Before
    public void setup(){
        try (Transaction tx = graphDb.beginTx()) {
            Iterable<Node> allNodes = GlobalGraphOperations.at(graphDb)
                    .getAllNodes();

            int i = 0;
            for (Node node : allNodes) {
                String labels = (String) node.getProperty("labels"); 
                String[] labelsSplit = labels.split(" ");

                for (String str : labelsSplit){
                    node.addLabel(DynamicLabel.label(str));
                }

            }

            tx.success();
        }
    }

@lordofthejars
Copy link
Owner

Hi, first of all thank you very much for using NoSQLUnit. The answer, no it is not supported yet, but if you want and can you can provide a PR fixing it. It is about adding <data key="label">PAGE</data> support in the reader and writer of GraphML parser.

It should not be very difficult if you can contribute, the PR would be more than welcomed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants