use of org.neo4j.graphdb.NotFoundException in project neo4j by neo4j.
the class Neo4jConstraintsTest method testIllegalPropertyType.
@Test
public void testIllegalPropertyType() {
Node node1 = getGraphDb().createNode();
try {
node1.setProperty(key, new Object());
fail("Shouldn't validate");
} catch (Exception e) {
// good
}
{
Transaction tx = getTransaction();
tx.failure();
tx.close();
}
setTransaction(getGraphDb().beginTx());
try {
getGraphDb().getNodeById(node1.getId());
fail("Node should not exist, previous tx didn't rollback");
} catch (NotFoundException e) {
// good
}
node1 = getGraphDb().createNode();
Node node2 = getGraphDb().createNode();
Relationship rel = node1.createRelationshipTo(node2, MyRelTypes.TEST);
try {
rel.setProperty(key, new Object());
fail("Shouldn't validate");
} catch (Exception e) {
// good
}
try {
Transaction tx = getTransaction();
tx.success();
tx.close();
fail("Shouldn't validate");
} catch (Exception e) {
// good
}
setTransaction(getGraphDb().beginTx());
try {
getGraphDb().getNodeById(node1.getId());
fail("Node should not exist, previous tx didn't rollback");
} catch (NotFoundException e) {
// good
}
try {
getGraphDb().getNodeById(node2.getId());
fail("Node should not exist, previous tx didn't rollback");
} catch (NotFoundException e) {
// good
}
}
use of org.neo4j.graphdb.NotFoundException in project neo4j by neo4j.
the class TestRelationship method testRelationshipChangeProperty.
@Test
public void testRelationshipChangeProperty() {
Integer int1 = new Integer(1);
Integer int2 = new Integer(2);
String string1 = new String("1");
String string2 = new String("2");
Node node1 = getGraphDb().createNode();
Node node2 = getGraphDb().createNode();
Relationship rel1 = node1.createRelationshipTo(node2, MyRelTypes.TEST);
Relationship rel2 = node2.createRelationshipTo(node1, MyRelTypes.TEST);
rel1.setProperty(key1, int1);
rel2.setProperty(key1, string1);
rel1.setProperty(key2, string2);
rel2.setProperty(key2, int2);
try {
rel1.setProperty(null, null);
fail("Null argument should result in exception.");
} catch (IllegalArgumentException e) {
// OK
} catch (NotFoundException e) {
fail("wrong exception");
}
// test type change of exsisting property
// cannot test this for now because of exceptions in PL
rel2.setProperty(key1, int1);
rel1.delete();
rel2.delete();
node2.delete();
node1.delete();
}
use of org.neo4j.graphdb.NotFoundException in project neo4j by neo4j.
the class TestRelationship method deletionOfSameRelationshipTwiceInOneTransactionShouldNotRollbackIt.
@Test(expected = NotFoundException.class)
public void deletionOfSameRelationshipTwiceInOneTransactionShouldNotRollbackIt() {
// Given
GraphDatabaseService db = getGraphDb();
// transaction is opened by test
Node node1 = db.createNode();
Node node2 = db.createNode();
Relationship relationship = node1.createRelationshipTo(node2, TEST);
commit();
// When
Exception exceptionThrownBySecondDelete = null;
try (Transaction tx = db.beginTx()) {
relationship.delete();
try {
relationship.delete();
} catch (IllegalStateException e) {
exceptionThrownBySecondDelete = e;
}
tx.success();
}
// Then
assertNotNull(exceptionThrownBySecondDelete);
try (Transaction tx = db.beginTx()) {
// should throw NotFoundException
db.getRelationshipById(relationship.getId());
tx.success();
}
}
use of org.neo4j.graphdb.NotFoundException in project neo4j by neo4j.
the class TestNeo4jApiExceptions method testNotFoundException.
@Test
public void testNotFoundException() {
Node node1 = graph.createNode();
Node node2 = graph.createNode();
Relationship rel = node1.createRelationshipTo(node2, MyRelTypes.TEST);
long nodeId = node1.getId();
long relId = rel.getId();
rel.delete();
node2.delete();
node1.delete();
newTransaction();
try {
graph.getNodeById(nodeId);
fail("Get node by id on deleted node should throw exception");
} catch (NotFoundException e) {
// good
}
try {
graph.getRelationshipById(relId);
fail("Get relationship by id on deleted node should " + "throw exception");
} catch (NotFoundException e) {
// good
}
// Finally
rollback();
}
use of org.neo4j.graphdb.NotFoundException in project neo4j by neo4j.
the class TestLoopRelationships method getOtherNodeFunctionsCorrectly.
@Test
public void getOtherNodeFunctionsCorrectly() throws Exception {
Node node = getGraphDb().createNode();
Relationship relationship = node.createRelationshipTo(node, TEST);
// assertion code. Same assertions withing the transaction as after it has committed.
for (int i = 0; i < 2; i++) {
assertEquals(node, relationship.getOtherNode(node));
assertEquals(asList(node, node), asList(relationship.getNodes()));
try {
relationship.getOtherNode(getGraphDb().createNode());
fail("Should throw exception if another node is passed into loop.getOtherNode");
} catch (NotFoundException e) {
// Good
}
newTransaction();
}
}
Aggregations