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));
}
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");
}
}
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")));
}
}
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);
}
}
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());
}
}
Aggregations