use of org.neo4j.graphdb.NotFoundException in project neo4j by neo4j.
the class NodeTest method testNodeCreateAndDelete.
@Test
public void testNodeCreateAndDelete() {
Node node = getGraphDb().createNode();
long nodeId = node.getId();
getGraphDb().getNodeById(nodeId);
node.delete();
tx.success();
tx.begin();
try {
getGraphDb().getNodeById(nodeId);
fail("Node[" + nodeId + "] should be deleted.");
} catch (NotFoundException ignored) {
}
}
use of org.neo4j.graphdb.NotFoundException in project neo4j by neo4j.
the class NodeTest method testNodeRemoveProperty.
@Test
public void testNodeRemoveProperty() {
String key1 = "key1";
String key2 = "key2";
Integer int1 = 1;
Integer int2 = 2;
String string1 = "1";
String string2 = "2";
Node node1 = getGraphDb().createNode();
Node node2 = getGraphDb().createNode();
try {
if (node1.removeProperty(key1) != null) {
fail("Remove of non existing property should return null");
}
} catch (NotFoundException ignored) {
}
try {
node1.removeProperty(null);
fail("Remove null property should throw exception.");
} catch (IllegalArgumentException ignored) {
}
node1.setProperty(key1, int1);
node2.setProperty(key1, string1);
node1.setProperty(key2, string2);
node2.setProperty(key2, int2);
try {
node1.removeProperty(null);
fail("Null argument should result in exception.");
} catch (IllegalArgumentException ignored) {
}
// test remove property
assertEquals(int1, node1.removeProperty(key1));
assertEquals(string1, node2.removeProperty(key1));
// test remove of non existing property
try {
if (node2.removeProperty(key1) != null) {
fail("Remove of non existing property return null.");
}
} catch (NotFoundException e) {
// must mark as rollback only
}
// getTransaction().failure();
}
use of org.neo4j.graphdb.NotFoundException in project neo4j by neo4j.
the class NodeProxyTest method shouldThrowHumaneExceptionsWhenPropertyDoesNotExist.
@Test
public void shouldThrowHumaneExceptionsWhenPropertyDoesNotExist() throws Exception {
// When
try (Transaction ignored = db.beginTx()) {
Node node = db.createNode();
node.getProperty(PROPERTY_KEY);
}// Then
catch (NotFoundException exception) {
assertThat(exception.getMessage(), containsString(PROPERTY_KEY));
}
}
use of org.neo4j.graphdb.NotFoundException in project neo4j by neo4j.
the class NodeProxyTest method deletionOfSameNodeTwiceInOneTransactionShouldNotRollbackIt.
@Test(expected = NotFoundException.class)
public void deletionOfSameNodeTwiceInOneTransactionShouldNotRollbackIt() {
// Given
Node node;
try (Transaction tx = db.beginTx()) {
node = db.createNode();
tx.success();
}
// When
Exception exceptionThrownBySecondDelete = null;
try (Transaction tx = db.beginTx()) {
node.delete();
try {
node.delete();
} catch (Exception e) {
exceptionThrownBySecondDelete = e;
}
tx.success();
}
// Then
assertThat(exceptionThrownBySecondDelete, instanceOf(NotFoundException.class));
try (Transaction tx = db.beginTx()) {
// should throw NotFoundException
db.getNodeById(node.getId());
tx.success();
}
}
use of org.neo4j.graphdb.NotFoundException in project neo4j by neo4j.
the class Neo4jConstraintsTest method testNodeRelDeleteSemantics.
@Test
public void testNodeRelDeleteSemantics() {
Node node1 = getGraphDb().createNode();
Node node2 = getGraphDb().createNode();
Relationship rel1 = node1.createRelationshipTo(node2, MyRelTypes.TEST);
Relationship rel2 = node1.createRelationshipTo(node2, MyRelTypes.TEST);
node1.setProperty("key1", "value1");
rel1.setProperty("key1", "value1");
newTransaction();
node1.delete();
try {
node1.getProperty("key1");
fail("Should throw exception");
} catch (NotFoundException e) {
// good
}
try {
node1.setProperty("key1", "value2");
fail("Should throw exception");
} catch (NotFoundException e) {
// good
}
try {
node1.removeProperty("key1");
fail("Should throw exception");
} catch (NotFoundException e) {
// good
}
node2.delete();
try {
node2.delete();
fail("Should throw exception");
} catch (NotFoundException e) {
// good
}
try {
node1.getProperty("key1");
fail("Should throw exception");
} catch (NotFoundException e) {
// good
}
try {
node1.setProperty("key1", "value2");
fail("Should throw exception");
} catch (NotFoundException e) {
// good
}
try {
node1.removeProperty("key1");
fail("Should throw exception");
} catch (NotFoundException e) {
// good
}
assertEquals("value1", rel1.getProperty("key1"));
rel1.delete();
try {
rel1.delete();
fail("Should throw exception");
} catch (NotFoundException e) {
// good
}
try {
rel1.getProperty("key1");
fail("Should throw exception");
} catch (NotFoundException e) {
// good
}
try {
rel1.setProperty("key1", "value2");
fail("Should throw exception");
} catch (NotFoundException e) {
// good
}
try {
rel1.removeProperty("key1");
fail("Should throw exception");
} catch (NotFoundException e) {
// good
}
try {
rel1.getProperty("key1");
fail("Should throw exception");
} catch (NotFoundException e) {
// good
}
try {
rel1.setProperty("key1", "value2");
fail("Should throw exception");
} catch (NotFoundException e) {
// good
}
try {
rel1.removeProperty("key1");
fail("Should throw exception");
} catch (NotFoundException e) {
// good
}
try {
node2.createRelationshipTo(node1, MyRelTypes.TEST);
fail("Should throw exception");
} catch (NotFoundException e) {
// good
}
try {
node2.createRelationshipTo(node1, MyRelTypes.TEST);
fail("Should throw exception");
} catch (NotFoundException e) {
// good
}
assertEquals(node1, rel1.getStartNode());
assertEquals(node2, rel2.getEndNode());
Node[] nodes = rel1.getNodes();
assertEquals(node1, nodes[0]);
assertEquals(node2, nodes[1]);
assertEquals(node2, rel1.getOtherNode(node1));
rel2.delete();
// will be marked for rollback so commit will throw exception
rollback();
}
Aggregations