Search in sources :

Example 26 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 27 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 28 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 29 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 30 with Graph

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

the class AncestorTestCase method test.

@Test
@Graph({ "root contains child1", "child1 contains child11", "child1 contains child12", "root contains child2", "child12 contains child121", "child1 contains child13" })
public void test() {
    PathExpander expander = PathExpanders.forTypeAndDirection(Rels.contains, Direction.INCOMING);
    List<Node> nodeSet = new ArrayList<Node>();
    Map<String, Node> graph = data.get();
    nodeSet.add(graph.get("child1"));
    nodeSet.add(graph.get("root"));
    try (Transaction transaction = gdb.beginTx()) {
        Node ancestor = AncestorsUtil.lowestCommonAncestor(nodeSet, expander);
        assertEquals(graph.get("root"), ancestor);
        nodeSet.clear();
        nodeSet.add(graph.get("child12"));
        nodeSet.add(graph.get("child11"));
        ancestor = AncestorsUtil.lowestCommonAncestor(nodeSet, expander);
        assertEquals(graph.get("child1"), ancestor);
        nodeSet.clear();
        nodeSet.add(graph.get("child121"));
        nodeSet.add(graph.get("child12"));
        ancestor = AncestorsUtil.lowestCommonAncestor(nodeSet, expander);
        assertEquals(graph.get("child12"), ancestor);
        nodeSet.clear();
        nodeSet.add(graph.get("child11"));
        nodeSet.add(graph.get("child13"));
        ancestor = AncestorsUtil.lowestCommonAncestor(nodeSet, expander);
        assertEquals(graph.get("child1"), ancestor);
        nodeSet.clear();
        nodeSet.add(graph.get("child2"));
        nodeSet.add(graph.get("child121"));
        ancestor = AncestorsUtil.lowestCommonAncestor(nodeSet, expander);
        assertEquals(graph.get("root"), ancestor);
        nodeSet.clear();
        nodeSet.add(graph.get("child11"));
        nodeSet.add(graph.get("child12"));
        nodeSet.add(graph.get("child13"));
        ancestor = AncestorsUtil.lowestCommonAncestor(nodeSet, expander);
        assertEquals(graph.get("child1"), ancestor);
        nodeSet.clear();
        nodeSet.add(graph.get("child11"));
        nodeSet.add(graph.get("child12"));
        nodeSet.add(graph.get("child13"));
        nodeSet.add(graph.get("child121"));
        ancestor = AncestorsUtil.lowestCommonAncestor(nodeSet, expander);
        assertEquals(graph.get("child1"), ancestor);
        nodeSet.clear();
        nodeSet.add(graph.get("child11"));
        nodeSet.add(graph.get("child12"));
        nodeSet.add(graph.get("child13"));
        nodeSet.add(graph.get("child121"));
        nodeSet.add(graph.get("child2"));
        ancestor = AncestorsUtil.lowestCommonAncestor(nodeSet, expander);
        assertEquals(graph.get("root"), ancestor);
        nodeSet.clear();
        nodeSet.add(graph.get("child11"));
        nodeSet.add(graph.get("child12"));
        nodeSet.add(graph.get("child13"));
        nodeSet.add(graph.get("child121"));
        nodeSet.add(graph.get("child12"));
        nodeSet.add(graph.get("root"));
        ancestor = AncestorsUtil.lowestCommonAncestor(nodeSet, expander);
        assertEquals(graph.get("root"), ancestor);
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) ArrayList(java.util.ArrayList) PathExpander(org.neo4j.graphdb.PathExpander) Graph(org.neo4j.test.GraphDescription.Graph) 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