Search in sources :

Example 81 with NotFoundException

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

Example 82 with NotFoundException

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

Example 83 with NotFoundException

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

Example 84 with NotFoundException

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

Example 85 with NotFoundException

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