|
18 | 18 | */ |
19 | 19 | package org.neo4j.graphalgo.algo; |
20 | 20 |
|
| 21 | +import org.junit.AfterClass; |
21 | 22 | import org.junit.BeforeClass; |
22 | 23 | import org.junit.ClassRule; |
23 | 24 | import org.junit.Test; |
24 | 25 | import org.neo4j.graphalgo.ListProc; |
25 | 26 | import org.neo4j.graphalgo.PageRankProc; |
| 27 | +import org.neo4j.graphalgo.linkprediction.LinkPrediction; |
| 28 | +import org.neo4j.graphdb.GraphDatabaseService; |
| 29 | +import org.neo4j.graphdb.factory.GraphDatabaseSettings; |
26 | 30 | import org.neo4j.kernel.impl.proc.Procedures; |
| 31 | +import org.neo4j.kernel.internal.GraphDatabaseAPI; |
| 32 | +import org.neo4j.test.TestGraphDatabaseFactory; |
27 | 33 | import org.neo4j.test.rule.ImpermanentDatabaseRule; |
28 | 34 |
|
| 35 | +import java.util.Arrays; |
| 36 | +import java.util.Collection; |
29 | 37 | import java.util.List; |
30 | 38 | import java.util.stream.Collectors; |
| 39 | +import java.util.stream.Stream; |
31 | 40 |
|
32 | 41 | import static java.util.Arrays.asList; |
33 | 42 | import static java.util.Collections.*; |
|
40 | 49 | public class ListProcTest { |
41 | 50 | @ClassRule |
42 | 51 | public static ImpermanentDatabaseRule DB = new ImpermanentDatabaseRule(); |
| 52 | + public static final List<String> PROCEDURES = asList("algo.pageRank", "algo.pageRank.stream"); |
| 53 | + public static final List<String> FUNCTIONS = Arrays.asList("algo.linkprediction.adamicAdar", "algo.linkprediction.commonNeighbors", "algo.linkprediction.preferentialAttachment", "algo.linkprediction.resourceAllocation", "algo.linkprediction.sameCommunity", |
| 54 | + "algo.linkprediction.totalNeighbors"); |
| 55 | + public static final List<String> ALL = Stream.of(PROCEDURES, FUNCTIONS).flatMap(Collection::stream).collect(Collectors.toList()); |
43 | 56 |
|
44 | 57 | @BeforeClass |
45 | 58 | public static void setUp() throws Exception { |
46 | 59 | Procedures procedures = DB.getDependencyResolver().resolveDependency(Procedures.class); |
47 | 60 | procedures.registerProcedure(ListProc.class); |
48 | 61 | procedures.registerProcedure(PageRankProc.class); |
| 62 | + procedures.registerFunction(LinkPrediction.class); |
| 63 | + } |
| 64 | + |
| 65 | + @AfterClass |
| 66 | + public static void tearDown() { |
| 67 | + DB.shutdown(); |
49 | 68 | } |
50 | 69 |
|
51 | 70 | @Test |
52 | | - public void list() throws Exception { |
53 | | - assertEquals(asList("algo.pageRank","algo.pageRank.stream"), listProcs(null)); |
54 | | - assertEquals(asList("algo.pageRank","algo.pageRank.stream"), listProcs("page")); |
| 71 | + public void listProcedures() throws Exception { |
| 72 | + assertEquals(ALL, listProcs(null)); |
| 73 | + assertEquals(PROCEDURES, listProcs("page")); |
55 | 74 | assertEquals(singletonList("algo.pageRank.stream"), listProcs("stream")); |
56 | 75 | assertEquals(emptyList(), listProcs("foo")); |
57 | 76 | } |
58 | 77 |
|
59 | | - private List<String> listProcs(Object name) { |
60 | | - return DB.execute("CALL algo.list($name)", singletonMap("name", name)).<String>columnAs("name").stream().collect(Collectors.toList()); |
| 78 | + @Test |
| 79 | + public void listFunctions() throws Exception { |
| 80 | + assertEquals(FUNCTIONS, listProcs("linkprediction")); |
61 | 81 | } |
| 82 | + |
62 | 83 | @Test |
63 | 84 | public void listEmpty() throws Exception { |
64 | | - assertEquals(asList("algo.pageRank","algo.pageRank.stream"), |
| 85 | + assertEquals(ALL, |
65 | 86 | DB.execute("CALL algo.list()").<String>columnAs("name").stream().collect(Collectors.toList())); |
66 | 87 | } |
| 88 | + |
| 89 | + private List<String> listProcs(Object name) { |
| 90 | + return DB.execute("CALL algo.list($name)", singletonMap("name", name)).<String>columnAs("name").stream().collect(Collectors.toList()); |
| 91 | + } |
67 | 92 | } |
0 commit comments