Search in sources :

Example 76 with NotFoundException

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) {
    }
}
Also used : Node(org.neo4j.graphdb.Node) NotFoundException(org.neo4j.graphdb.NotFoundException) Test(org.junit.Test)

Example 77 with NotFoundException

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();
}
Also used : Node(org.neo4j.graphdb.Node) NotFoundException(org.neo4j.graphdb.NotFoundException) Test(org.junit.Test)

Example 78 with NotFoundException

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));
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) NotFoundException(org.neo4j.graphdb.NotFoundException) Test(org.junit.Test)

Example 79 with NotFoundException

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();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) NotFoundException(org.neo4j.graphdb.NotFoundException) NotFoundException(org.neo4j.graphdb.NotFoundException) Test(org.junit.Test)

Example 80 with NotFoundException

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();
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) NotFoundException(org.neo4j.graphdb.NotFoundException) Test(org.junit.Test)

Aggregations

NotFoundException (org.neo4j.graphdb.NotFoundException)87 Node (org.neo4j.graphdb.Node)43 Test (org.junit.Test)36 Relationship (org.neo4j.graphdb.Relationship)24 Transaction (org.neo4j.graphdb.Transaction)24 Statement (org.neo4j.kernel.api.Statement)18 EntityNotFoundException (org.neo4j.kernel.api.exceptions.EntityNotFoundException)14 PropertyNotFoundException (org.neo4j.kernel.api.exceptions.PropertyNotFoundException)13 ReentrantLock (java.util.concurrent.locks.ReentrantLock)8 EndNodeNotFoundException (org.neo4j.server.rest.domain.EndNodeNotFoundException)7 StartNodeNotFoundException (org.neo4j.server.rest.domain.StartNodeNotFoundException)7 RelationshipType (org.neo4j.graphdb.RelationshipType)5 ReadOperations (org.neo4j.kernel.api.ReadOperations)4 SchemaRuleNotFoundException (org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException)4 KeyReadOperations (org.neo4j.kernel.impl.api.operations.KeyReadOperations)4 InvalidRecordException (org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)4 Race (org.neo4j.test.Race)4 ArrayList (java.util.ArrayList)3 ConstraintViolationException (org.neo4j.graphdb.ConstraintViolationException)3 StatementTokenNameLookup (org.neo4j.kernel.api.StatementTokenNameLookup)3