Search in sources :

Example 21 with Graph

use of org.neo4j.test.GraphDescription.Graph in project neo4j by neo4j.

the class TraverserIT method shouldGetExpectedHitsWhenTraversingWithDescription.

@Documented("Traversal using a return filter.\n" + "\n" + "In this example, the +none+ prune evaluator is used and a return filter\n" + "is supplied in order to return all names containing \"t\".\n" + "The result is to be returned as nodes and the max depth is\n" + "set to 3.")
@Graph({ "Root knows Mattias", "Root knows Johan", "Johan knows Emil", "Emil knows Peter", "Emil knows Tobias", "Tobias loves Sara" })
@Test
public void shouldGetExpectedHitsWhenTraversingWithDescription() throws JsonParseException {
    Node start = getNode("Root");
    List<Map<String, Object>> rels = new ArrayList<>();
    rels.add(map("type", "knows", "direction", "all"));
    rels.add(map("type", "loves", "direction", "all"));
    String description = createJsonFrom(map("order", "breadth_first", "uniqueness", "node_global", "prune_evaluator", map("language", "javascript", "body", "position.length() > 10"), "return_filter", map("language", "javascript", "body", "position.endNode().getProperty('name').toLowerCase().contains('t')"), "relationships", rels, "max_depth", 3));
    String entity = gen().expectedStatus(200).payload(description).post(getTraverseUriNodes(start)).entity();
    expectNodes(entity, getNodes("Root", "Mattias", "Peter", "Tobias"));
}
Also used : Node(org.neo4j.graphdb.Node) ArrayList(java.util.ArrayList) Map(java.util.Map) Graph(org.neo4j.test.GraphDescription.Graph) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Example 22 with Graph

use of org.neo4j.test.GraphDescription.Graph 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 23 with Graph

use of org.neo4j.test.GraphDescription.Graph 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 24 with Graph

use of org.neo4j.test.GraphDescription.Graph 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 25 with Graph

use of org.neo4j.test.GraphDescription.Graph 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

Graph (org.neo4j.test.GraphDescription.Graph)48 Test (org.junit.Test)47 Documented (org.neo4j.kernel.impl.annotations.Documented)21 Title (org.neo4j.test.TestData.Title)18 Node (org.neo4j.graphdb.Node)17 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)16 Transaction (org.neo4j.graphdb.Transaction)13 Relationship (org.neo4j.graphdb.Relationship)11 Map (java.util.Map)7 ArrayList (java.util.ArrayList)3 RelationshipRepresentationTest (org.neo4j.server.rest.repr.RelationshipRepresentationTest)3 HashSet (java.util.HashSet)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 PrettyJSON (org.neo4j.server.rest.PrettyJSON)2 JsonHelper.jsonToMap (org.neo4j.server.rest.domain.JsonHelper.jsonToMap)2 Collection (java.util.Collection)1 List (java.util.List)1 JsonNode (org.codehaus.jackson.JsonNode)1 PathExpander (org.neo4j.graphdb.PathExpander)1