Search in sources :

Example 76 with Relationship

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

the class AutoIndexOperationsTest method shouldNotSeeDeletedRelationshipWhenQueryingWithStartAndEndNode.

@Test
public void shouldNotSeeDeletedRelationshipWhenQueryingWithStartAndEndNode() {
    RelationshipType type = MyRelTypes.TEST;
    long startId;
    long endId;
    Relationship rel;
    try (Transaction tx = db.beginTx()) {
        Node start = db.createNode();
        Node end = db.createNode();
        startId = start.getId();
        endId = end.getId();
        rel = start.createRelationshipTo(end, type);
        rel.setProperty("Type", type.name());
        tx.success();
    }
    try (Transaction tx = db.beginTx()) {
        ReadableRelationshipIndex autoRelationshipIndex = db.index().getRelationshipAutoIndexer().getAutoIndex();
        Node start = db.getNodeById(startId);
        Node end = db.getNodeById(endId);
        IndexHits<Relationship> hits = autoRelationshipIndex.get("Type", type.name(), start, end);
        assertEquals(1, count(hits));
        assertEquals(1, hits.size());
        rel.delete();
        autoRelationshipIndex = db.index().getRelationshipAutoIndexer().getAutoIndex();
        hits = autoRelationshipIndex.get("Type", type.name(), start, end);
        assertEquals(0, count(hits));
        assertEquals(0, hits.size());
        tx.success();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Relationship(org.neo4j.graphdb.Relationship) Node(org.neo4j.graphdb.Node) RelationshipType(org.neo4j.graphdb.RelationshipType) ReadableRelationshipIndex(org.neo4j.graphdb.index.ReadableRelationshipIndex) Test(org.junit.Test)

Example 77 with Relationship

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

the class RelationshipIT method get_all_properties_on_a_relationship.

@Test
@Graph(nodes = { @NODE(name = "Romeo", setNameProperty = true), @NODE(name = "Juliet", setNameProperty = true) }, relationships = { @REL(start = "Romeo", end = "Juliet", type = "LOVES", properties = { @PROP(key = "cost", value = "high", type = GraphDescription.PropType.STRING), @PROP(key = "since", value = "1day", type = GraphDescription.PropType.STRING) }) })
public void get_all_properties_on_a_relationship() throws Exception {
    Relationship loves = getFirstRelationshipFromRomeoNode();
    String response = gen().expectedStatus(ClientResponse.Status.OK).get(getRelPropsURI(loves)).entity();
    assertTrue(response.contains("high"));
}
Also used : Relationship(org.neo4j.graphdb.Relationship) Graph(org.neo4j.test.GraphDescription.Graph) Test(org.junit.Test)

Example 78 with Relationship

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

the class RelationshipIT method set_single_property_on_a_relationship.

@Test
@Graph(nodes = { @NODE(name = "Romeo", setNameProperty = true), @NODE(name = "Juliet", setNameProperty = true) }, relationships = { @REL(start = "Romeo", end = "Juliet", type = "LOVES", properties = { @PROP(key = "cost", value = "high", type = GraphDescription.PropType.STRING) }) })
public void set_single_property_on_a_relationship() throws Exception {
    Relationship loves = getFirstRelationshipFromRomeoNode();
    assertThat(loves, inTx(graphdb(), hasProperty("cost").withValue("high")));
    gen().expectedStatus(ClientResponse.Status.NO_CONTENT).payload("\"deadly\"").put(getRelPropURI(loves, "cost")).entity();
    assertThat(loves, inTx(graphdb(), hasProperty("cost").withValue("deadly")));
}
Also used : Relationship(org.neo4j.graphdb.Relationship) Graph(org.neo4j.test.GraphDescription.Graph) Test(org.junit.Test)

Example 79 with Relationship

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

the class RelationshipIT method shouldReturn204WhenPropertyIsRemovedFromRelationship.

@Test
@Title("Remove property from a relationship")
@Documented("See the example request below.")
@Graph(nodes = { @NODE(name = "Romeo", setNameProperty = true), @NODE(name = "Juliet", setNameProperty = true) }, relationships = { @REL(start = "Romeo", end = "Juliet", type = "LOVES", properties = { @PROP(key = "cost", value = "high", type = GraphDescription.PropType.STRING) }) })
public void shouldReturn204WhenPropertyIsRemovedFromRelationship() {
    data.get();
    Relationship loves = getFirstRelationshipFromRomeoNode();
    gen().expectedStatus(Status.NO_CONTENT.getStatusCode()).delete(getPropertiesUri(loves) + "/cost").entity();
}
Also used : Relationship(org.neo4j.graphdb.Relationship) Graph(org.neo4j.test.GraphDescription.Graph) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test) Title(org.neo4j.test.TestData.Title)

Example 80 with Relationship

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

the class RelationshipIT method shouldReturn204WhenPropertiesAreRemovedFromRelationship.

@Test
@Title("Remove properties from a relationship")
@Graph(nodes = { @NODE(name = "Romeo", setNameProperty = true), @NODE(name = "Juliet", setNameProperty = true) }, relationships = { @REL(start = "Romeo", end = "Juliet", type = "LOVES", properties = { @PROP(key = "cost", value = "high", type = GraphDescription.PropType.STRING) }) })
public void shouldReturn204WhenPropertiesAreRemovedFromRelationship() {
    Relationship loves = getFirstRelationshipFromRomeoNode();
    gen().expectedStatus(Status.NO_CONTENT.getStatusCode()).delete(functionalTestHelper.relationshipPropertiesUri(loves.getId())).entity();
}
Also used : Relationship(org.neo4j.graphdb.Relationship) Graph(org.neo4j.test.GraphDescription.Graph) Test(org.junit.Test) Title(org.neo4j.test.TestData.Title)

Aggregations

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