Search in sources :

Example 61 with Node

use of org.neo4j.graphdb.Node in project neo4j by neo4j.

the class TestNeo4j method testGetAllNodes.

@Test
public void testGetAllNodes() {
    long highId = getIdGenerator(IdType.NODE).getHighestPossibleIdInUse();
    if (highId >= 0 && highId < 10000) {
        long count = Iterables.count(getGraphDb().getAllNodes());
        boolean found = false;
        Node newNode = getGraphDb().createNode();
        newTransaction();
        long oldCount = count;
        count = 0;
        for (Node node : getGraphDb().getAllNodes()) {
            count++;
            if (node.equals(newNode)) {
                found = true;
            }
        }
        assertTrue(found);
        assertEquals(count, oldCount + 1);
        // Tests a bug in the "all nodes" iterator
        Iterator<Node> allNodesIterator = getGraphDb().getAllNodes().iterator();
        assertNotNull(allNodesIterator.next());
        newNode.delete();
        newTransaction();
        found = false;
        count = 0;
        for (Node node : getGraphDb().getAllNodes()) {
            count++;
            if (node.equals(newNode)) {
                found = true;
            }
        }
        assertTrue(!found);
        assertEquals(count, oldCount);
    }
// else we skip test, takes too long
}
Also used : Node(org.neo4j.graphdb.Node) Test(org.junit.Test)

Example 62 with Node

use of org.neo4j.graphdb.Node in project neo4j by neo4j.

the class TestNeo4j method testNodeChangePropertyArray.

@Test
public void testNodeChangePropertyArray() throws Exception {
    getTransaction().close();
    Node node;
    try (Transaction tx = getGraphDb().beginTx()) {
        node = getGraphDb().createNode();
        tx.success();
    }
    try (Transaction tx = getGraphDb().beginTx()) {
        node.setProperty("test", new String[] { "value1" });
        tx.success();
    }
    try (Transaction ignored = getGraphDb().beginTx()) {
        node.setProperty("test", new String[] { "value1", "value2" });
    // no success, we wanna test rollback on this operation
    }
    try (Transaction tx = getGraphDb().beginTx()) {
        String[] value = (String[]) node.getProperty("test");
        assertEquals(1, value.length);
        assertEquals("value1", value[0]);
        tx.success();
    }
    setTransaction(getGraphDb().beginTx());
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Test(org.junit.Test)

Example 63 with Node

use of org.neo4j.graphdb.Node in project neo4j by neo4j.

the class TestNeo4jCacheAndPersistence method testNodeRemoveProperty.

@Test
public void testNodeRemoveProperty() {
    Node node1 = getGraphDb().getNodeById(node1Id);
    Node node2 = getGraphDb().getNodeById(node2Id);
    Relationship rel = node1.getSingleRelationship(MyRelTypes.TEST, Direction.BOTH);
    // test remove property
    assertEquals(1, node1.removeProperty(key1));
    assertEquals(2, node2.removeProperty(key1));
    assertEquals(1, rel.removeProperty(key1));
    assertEquals(string1, node1.removeProperty(key2));
    assertEquals(string2, node2.removeProperty(key2));
    assertEquals(string1, rel.removeProperty(key2));
    assertTrue(node1.removeProperty(arrayKey) != null);
    assertTrue(node2.removeProperty(arrayKey) != null);
    assertTrue(rel.removeProperty(arrayKey) != null);
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) Test(org.junit.Test)

Example 64 with Node

use of org.neo4j.graphdb.Node in project neo4j by neo4j.

the class TestNeo4jCacheAndPersistence method testNodeChangeProperty.

@Test
public void testNodeChangeProperty() {
    Node node1 = getGraphDb().getNodeById(node1Id);
    Node node2 = getGraphDb().getNodeById(node2Id);
    Relationship rel = node1.getSingleRelationship(MyRelTypes.TEST, Direction.BOTH);
    // test change property
    node1.setProperty(key1, int2);
    node2.setProperty(key1, int1);
    rel.setProperty(key1, int2);
    int[] newIntArray = new int[] { 3, 2, 1 };
    node1.setProperty(arrayKey, newIntArray);
    node2.setProperty(arrayKey, newIntArray);
    rel.setProperty(arrayKey, newIntArray);
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) Test(org.junit.Test)

Example 65 with Node

use of org.neo4j.graphdb.Node in project neo4j by neo4j.

the class TestNeo4jCacheAndPersistence method testNodeGetProperties.

@Test
public void testNodeGetProperties() {
    Node node1 = getGraphDb().getNodeById(node1Id);
    assertTrue(!node1.hasProperty(null));
    Iterator<String> keys = node1.getPropertyKeys().iterator();
    keys.next();
    keys.next();
    assertTrue(node1.hasProperty(key1));
    assertTrue(node1.hasProperty(key2));
}
Also used : Node(org.neo4j.graphdb.Node) Test(org.junit.Test)

Aggregations

Node (org.neo4j.graphdb.Node)1281 Test (org.junit.Test)781 Transaction (org.neo4j.graphdb.Transaction)540 Relationship (org.neo4j.graphdb.Relationship)375 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)146 NotFoundException (org.neo4j.graphdb.NotFoundException)78 File (java.io.File)65 LinkedList (java.util.LinkedList)60 RelationshipType (org.neo4j.graphdb.RelationshipType)58 HashMap (java.util.HashMap)57 Label (org.neo4j.graphdb.Label)57 Path (org.neo4j.graphdb.Path)52 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)46 HashSet (java.util.HashSet)45 Map (java.util.Map)45 WeightedPath (org.neo4j.graphalgo.WeightedPath)37 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)35 ArrayList (java.util.ArrayList)30 List (java.util.List)27 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)26