Search in sources :

Example 56 with Graph

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

the class ShortestPathDocIT method shouldReturnAllShortestPathsRestrictedByReltypesOnPost.

@Documented("Get shortest path restricted by relationship type.")
@Test
@Graph({ "A knows B", "B likes C", "A knows D", "D knows E", "E knows C" })
public void shouldReturnAllShortestPathsRestrictedByReltypesOnPost() throws JsonParseException {
    Node source = data.get().get("C");
    String sourceUri = functionalTestHelper.nodeUri(source.getId());
    Node target = data.get().get("A");
    String targetUri = functionalTestHelper.nodeUri(target.getId());
    String uri = (String) getNodeLevelPluginMetadata(ShortestPath.class, source.getId()).get(SHORTEST_PATHS);
    String body = "{\"target\":\"" + targetUri + "\",\"types\":[\"knows\"]}";
    String result = performPost(uri, body);
    List<Map<String, Object>> list = JsonHelper.jsonToList(result);
    assertThat(list, notNullValue());
    assertThat(list.size(), equalTo(1));
    Map<String, Object> map = list.get(0);
    assertThat(map.get("start").toString(), containsString(sourceUri));
    assertThat(map.get("end").toString(), containsString(targetUri));
    assertThat((Integer) map.get("length"), equalTo(3));
}
Also used : Node(org.neo4j.graphdb.Node) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Map(java.util.Map) Graph(org.neo4j.test.GraphDescription.Graph) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Example 57 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() {
    Map<String, Node> graph = data.get();
    Node a = graph.get("a");
    Node b = graph.get("b");
    try (Transaction tx = graphdb.beginTx()) {
        assertTrue(tx.getNodeById(a.getId()).hasLabel(label("Person")), "Person label missing");
        assertTrue(tx.getNodeById(b.getId()).hasLabel(label("Banana")), "Banana label missing");
        assertTrue(tx.getNodeById(b.getId()).hasLabel(label("Apple")), "Apple label missing");
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Graph(org.neo4j.test.GraphDescription.Graph) Test(org.junit.jupiter.api.Test)

Example 58 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() {
    Map<String, Node> graph = data.get();
    Node a = graph.get("a");
    Node b = graph.get("b");
    try (Transaction tx = graphdb.beginTx()) {
        assertTrue(tx.getNodeById(a.getId()).hasLabel(label("Person")));
        assertTrue(tx.getNodeById(b.getId()).hasLabel(label("Banana")));
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Graph(org.neo4j.test.GraphDescription.Graph) Test(org.junit.jupiter.api.Test)

Example 59 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)

Example 60 with Graph

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

the class TestGraphDescription method canCreateMoreInvolvedGraphWithPropertiesAndAutoIndex.

@Test
@Graph(nodes = { @NODE(name = "I", properties = { @PROP(key = "name", value = "me"), @PROP(key = "bool", value = "true", type = GraphDescription.PropType.BOOLEAN) }), @NODE(name = "you", setNameProperty = true) }, relationships = { @REL(start = "I", end = "you", type = "knows", properties = { @PROP(key = "name", value = "relProp"), @PROP(key = "valid", value = "true", type = GraphDescription.PropType.BOOLEAN) }) }, autoIndexRelationships = true)
public void canCreateMoreInvolvedGraphWithPropertiesAndAutoIndex() throws Exception {
    data.get();
    verifyIKnowYou("knows", "me");
    try (Transaction ignored = graphdb.beginTx()) {
        assertEquals(true, data.get().get("I").getProperty("bool"));
        assertFalse("node autoindex enabled.", graphdb().index().getNodeAutoIndexer().isEnabled());
        assertTrue("can't look up rel.", graphdb().index().getRelationshipAutoIndexer().getAutoIndex().get("name", "relProp").hasNext());
        assertTrue("relationship autoindex enabled.", graphdb().index().getRelationshipAutoIndexer().isEnabled());
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Graph(org.neo4j.test.GraphDescription.Graph) Test(org.junit.Test)

Aggregations

Graph (org.neo4j.test.GraphDescription.Graph)96 Test (org.junit.Test)92 Documented (org.neo4j.kernel.impl.annotations.Documented)48 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)37 Title (org.neo4j.test.TestData.Title)36 Node (org.neo4j.graphdb.Node)35 Relationship (org.neo4j.graphdb.Relationship)21 Transaction (org.neo4j.graphdb.Transaction)21 Map (java.util.Map)19 ArrayList (java.util.ArrayList)5 Matchers.containsString (org.hamcrest.Matchers.containsString)4 JsonHelper.jsonToMap (org.neo4j.server.rest.domain.JsonHelper.jsonToMap)4 HashSet (java.util.HashSet)3 Test (org.junit.jupiter.api.Test)3 RelationshipRepresentationTest (org.neo4j.server.rest.repr.RelationshipRepresentationTest)3 Collection (java.util.Collection)2 List (java.util.List)2 JsonNode (org.codehaus.jackson.JsonNode)2 PrettyJSON (org.neo4j.doc.server.rest.PrettyJSON)2 PrettyJSON (org.neo4j.server.rest.PrettyJSON)2