Search in sources :

Example 16 with Graph

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

the class RelationshipIT method get_Relationship_by_ID.

@Test
@Graph("I know you")
public void get_Relationship_by_ID() throws JsonParseException {
    Node node = data.get().get("I");
    Relationship relationship;
    try (Transaction transaction = node.getGraphDatabase().beginTx()) {
        relationship = node.getSingleRelationship(RelationshipType.withName("know"), Direction.OUTGOING);
    }
    String response = gen().expectedStatus(com.sun.jersey.api.client.ClientResponse.Status.OK.getStatusCode()).get(getRelationshipUri(relationship)).entity();
    assertTrue(JsonHelper.jsonToMap(response).containsKey("start"));
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) Graph(org.neo4j.test.GraphDescription.Graph) Test(org.junit.Test)

Example 17 with Graph

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

the class RelationshipIT method get_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 get_single_property_on_a_relationship() throws Exception {
    Relationship loves = getFirstRelationshipFromRomeoNode();
    String response = gen().expectedStatus(ClientResponse.Status.OK).get(getRelPropURI(loves, "cost")).entity();
    assertTrue(response.contains("high"));
}
Also used : Relationship(org.neo4j.graphdb.Relationship) Graph(org.neo4j.test.GraphDescription.Graph) Test(org.junit.Test)

Example 18 with Graph

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

the class TestGraphDescription method ensurePeopleCanEatBananasAndApples.

@Test
@Graph({ "a:Person EATS b:Banana", "a EATS b:Apple" })
public void ensurePeopleCanEatBananasAndApples() throws Exception {
    Map<String, Node> graph = data.get();
    Node a = graph.get("a");
    Node b = graph.get("b");
    try (Transaction ignored = graphdb.beginTx()) {
        assertTrue("Person label missing", a.hasLabel(label("Person")));
        assertTrue("Banana label missing", b.hasLabel(label("Banana")));
        assertTrue("Apple label missing", b.hasLabel(label("Apple")));
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Graph(org.neo4j.test.GraphDescription.Graph) Test(org.junit.Test)

Example 19 with Graph

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

the class TestGraphDescription method ensurePeopleCanEatBananas.

@Test
@Graph({ "a:Person EATS b:Banana" })
public void ensurePeopleCanEatBananas() throws Exception {
    Map<String, Node> graph = data.get();
    Node a = graph.get("a");
    Node b = graph.get("b");
    try (Transaction ignored = graphdb.beginTx()) {
        assertTrue(a.hasLabel(label("Person")));
        assertTrue(b.hasLabel(label("Banana")));
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Graph(org.neo4j.test.GraphDescription.Graph) Test(org.junit.Test)

Example 20 with Graph

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

the class TraverserIT method shouldGetExpectedHitsWhenTraversingAtDepth.

@Documented("Traversal returning nodes below a certain depth.\n" + "\n" + "Here, all nodes at a traversal depth below 3 are returned.")
@Graph({ "Root knows Mattias", "Root knows Johan", "Johan knows Emil", "Emil knows Peter", "Emil knows Tobias", "Tobias loves Sara" })
@Test
public void shouldGetExpectedHitsWhenTraversingAtDepth() throws JsonParseException {
    Node start = getNode("Root");
    String description = createJsonFrom(map("prune_evaluator", map("language", "builtin", "name", "none"), "return_filter", map("language", "javascript", "body", "position.length()<3;")));
    String entity = gen().expectedStatus(200).payload(description).post(getTraverseUriNodes(start)).entity();
    expectNodes(entity, getNodes("Root", "Mattias", "Johan", "Emil"));
}
Also used : Node(org.neo4j.graphdb.Node) Graph(org.neo4j.test.GraphDescription.Graph) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

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