use of org.neo4j.graphdb.Node in project neo4j by neo4j.
the class TestLoopRelationships method canAddLoopRelationship.
@Test
public void canAddLoopRelationship() {
Node node = getGraphDb().createNode();
node.createRelationshipTo(node, TEST);
newTransaction();
for (Direction dir : Direction.values()) {
int count = 0;
for (Relationship rel : node.getRelationships(dir)) {
count++;
assertEquals("start node", node, rel.getStartNode());
assertEquals("end node", node, rel.getEndNode());
assertEquals("other node", node, rel.getOtherNode(node));
}
assertEquals(dir.name() + " relationship count", 1, count);
}
}
use of org.neo4j.graphdb.Node in project neo4j by neo4j.
the class TestLoopRelationships method getSingleRelationshipOnNodeWithOneLoopOnly.
@Test
public void getSingleRelationshipOnNodeWithOneLoopOnly() throws Exception {
Node node = getGraphDb().createNode();
Relationship singleRelationship = node.createRelationshipTo(node, TEST);
assertEquals(singleRelationship, node.getSingleRelationship(TEST, Direction.OUTGOING));
assertEquals(singleRelationship, node.getSingleRelationship(TEST, Direction.INCOMING));
assertEquals(singleRelationship, node.getSingleRelationship(TEST, Direction.BOTH));
commit();
newTransaction();
assertEquals(singleRelationship, node.getSingleRelationship(TEST, Direction.OUTGOING));
assertEquals(singleRelationship, node.getSingleRelationship(TEST, Direction.INCOMING));
assertEquals(singleRelationship, node.getSingleRelationship(TEST, Direction.BOTH));
finish();
}
use of org.neo4j.graphdb.Node in project neo4j by neo4j.
the class TestLoopRelationships method cannotDeleteNodeWithLoopStillAttached.
@Test
public void cannotDeleteNodeWithLoopStillAttached() throws Exception {
// Given
GraphDatabaseService db = getGraphDb();
Node node;
try (Transaction tx = db.beginTx()) {
node = db.createNode();
node.createRelationshipTo(node, DynamicRelationshipType.withName("MAYOR_OF"));
tx.success();
}
// And given a transaction deleting just the node
Transaction tx = newTransaction();
node.delete();
tx.success();
// Expect
exception.expect(ConstraintViolationException.class);
exception.expectMessage("Cannot delete node<" + node.getId() + ">, because it still has relationships. " + "To delete this node, you must first delete its relationships.");
// When I commit
tx.close();
}
use of org.neo4j.graphdb.Node in project neo4j by neo4j.
the class TestLoopRelationships method testAddAndRemoveLoopRelationshipAndOtherRelationships.
private void testAddAndRemoveLoopRelationshipAndOtherRelationships(int size) {
for (boolean[] delete : permutations(size)) {
for (int i = 0; i < size; i++) {
Node root = getGraphDb().createNode();
Relationship[] relationships = createRelationships(size, i, root);
for (int j = 0; j < size; j++) {
if (delete[j]) {
relationships[j].delete();
relationships[j] = null;
}
newTransaction();
}
verifyRelationships(String.format("loop on %s of %s, delete %s", i, size, Arrays.toString(delete)), root, i, relationships);
}
}
}
use of org.neo4j.graphdb.Node in project neo4j by neo4j.
the class TestNeo4j method testRandomPropertyName.
@Test
public void testRandomPropertyName() {
Node node1 = getGraphDb().createNode();
String key = "random_" + new Random(System.currentTimeMillis()).nextLong();
node1.setProperty(key, "value");
assertEquals("value", node1.getProperty(key));
node1.delete();
}
Aggregations