Search in sources :

Example 11 with Relationship

use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.

the class Neo4jConstraintsTest method testDeleteNodeWithRel3.

@Test
public void testDeleteNodeWithRel3() {
    // make sure we can delete in wrong order
    Node node0 = getGraphDb().createNode();
    Node node1 = getGraphDb().createNode();
    Node node2 = getGraphDb().createNode();
    Relationship rel0 = node0.createRelationshipTo(node1, MyRelTypes.TEST);
    Relationship rel1 = node0.createRelationshipTo(node2, MyRelTypes.TEST);
    node1.delete();
    rel0.delete();
    Transaction tx = getTransaction();
    tx.success();
    tx.close();
    setTransaction(getGraphDb().beginTx());
    node2.delete();
    rel1.delete();
    node0.delete();
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) Test(org.junit.Test)

Example 12 with Relationship

use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.

the class Neo4jConstraintsTest method testAddPropertyDeletedRelationship.

@Test
public void testAddPropertyDeletedRelationship() {
    Node node1 = getGraphDb().createNode();
    Node node2 = getGraphDb().createNode();
    Relationship rel = node1.createRelationshipTo(node2, MyRelTypes.TEST);
    rel.delete();
    try {
        rel.setProperty(key, 1);
        Transaction tx = getTransaction();
        tx.success();
        tx.close();
        fail("Add property on deleted rel should not validate");
    } catch (Exception e) {
    // good
    }
    node1.delete();
    node2.delete();
}
Also used : 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 13 with Relationship

use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.

the class Neo4jConstraintsTest method testChangePropertyDeletedRelationship.

@Test
public void testChangePropertyDeletedRelationship() {
    Node node1 = getGraphDb().createNode();
    Node node2 = getGraphDb().createNode();
    Relationship rel = node1.createRelationshipTo(node2, MyRelTypes.TEST);
    rel.setProperty(key, 1);
    rel.delete();
    try {
        rel.setProperty(key, 2);
        Transaction tx = getTransaction();
        tx.success();
        tx.close();
        fail("Change property on deleted rel should not validate");
    } catch (Exception e) {
    // ok
    }
    node1.delete();
    node2.delete();
}
Also used : 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 14 with Relationship

use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.

the class Neo4jConstraintsTest method testDeleteReferenceNodeOrLastNodeIsOk.

@Test
public void testDeleteReferenceNodeOrLastNodeIsOk() {
    Transaction tx = getTransaction();
    for (int i = 0; i < 10; i++) {
        getGraphDb().createNode();
    }
    // empty the DB instance
    for (Node node : getGraphDb().getAllNodes()) {
        for (Relationship rel : node.getRelationships()) {
            rel.delete();
        }
        node.delete();
    }
    tx.success();
    tx.close();
    tx = getGraphDb().beginTx();
    assertFalse(getGraphDb().getAllNodes().iterator().hasNext());
    // TODO: this should be valid, fails right now!
    // assertEquals( 0, numNodesPost );
    tx.success();
    tx.close();
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) Test(org.junit.Test)

Example 15 with Relationship

use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.

the class RelationshipProxyTest method createDropRelationshipLongStringProperty.

@Test
public void createDropRelationshipLongStringProperty() {
    Label markerLabel = DynamicLabel.label("marker");
    String testPropertyKey = "testProperty";
    String propertyValue = RandomStringUtils.randomAscii(255);
    try (Transaction tx = db.beginTx()) {
        Node start = db.createNode(markerLabel);
        Node end = db.createNode(markerLabel);
        Relationship relationship = start.createRelationshipTo(end, withName("type"));
        relationship.setProperty(testPropertyKey, propertyValue);
        tx.success();
    }
    try (Transaction tx = db.beginTx()) {
        Relationship relationship = db.getRelationshipById(0);
        assertEquals(propertyValue, relationship.getProperty(testPropertyKey));
        tx.success();
    }
    try (Transaction tx = db.beginTx()) {
        Relationship relationship = db.getRelationshipById(0);
        relationship.removeProperty(testPropertyKey);
        tx.success();
    }
    try (Transaction tx = db.beginTx()) {
        Relationship relationship = db.getRelationshipById(0);
        assertFalse(relationship.hasProperty(testPropertyKey));
        tx.success();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) Label(org.neo4j.graphdb.Label) DynamicLabel(org.neo4j.graphdb.DynamicLabel) Test(org.junit.Test)

Aggregations

Relationship (org.neo4j.graphdb.Relationship)484 Node (org.neo4j.graphdb.Node)367 Test (org.junit.Test)250 Transaction (org.neo4j.graphdb.Transaction)138 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)48 LinkedList (java.util.LinkedList)45 RelationshipType (org.neo4j.graphdb.RelationshipType)37 NotFoundException (org.neo4j.graphdb.NotFoundException)35 Path (org.neo4j.graphdb.Path)29 HashMap (java.util.HashMap)27 Direction (org.neo4j.graphdb.Direction)25 HashSet (java.util.HashSet)24 ArrayList (java.util.ArrayList)18 RelationshipIndex (org.neo4j.graphdb.index.RelationshipIndex)18 WeightedPath (org.neo4j.graphalgo.WeightedPath)14 EmbeddedGraphDatabase (org.neo4j.kernel.EmbeddedGraphDatabase)14 List (java.util.List)13 Map (java.util.Map)13 PropertyContainer (org.neo4j.graphdb.PropertyContainer)12 Graph (org.neo4j.test.GraphDescription.Graph)11