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
}
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());
}
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);
}
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);
}
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));
}
Aggregations