-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathTypeHierarchyTest.java
More file actions
162 lines (113 loc) · 5.76 KB
/
Copy pathTypeHierarchyTest.java
File metadata and controls
162 lines (113 loc) · 5.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import java.io.File;
import java.util.Collections;
import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.neo4j.graphdb.GraphDatabaseService;
//import org.neo4j.kernel.logging.BufferingLogger;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.test.TestGraphDatabaseFactory;
import org.neo4j.graphdb.Result;
import visitors.WiggleVisitor;
import com.sun.source.tree.CompilationUnitTree;
import com.sun.tools.javac.api.JavacTaskImpl;
public class TypeHierarchyTest {
private GraphDatabaseService graphDb;
@Before
public void prepareTestDatabase() {
// create temporary database for each unit test.
GraphDatabaseSettings.BoltConnector bolt = GraphDatabaseSettings.boltConnector( "0" );
//graphDb = new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().newGraphDatabase();
graphDb = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(new File("/tmp/data/databases/4.db")).setConfig( bolt.type, "BOLT" )
.setConfig( bolt.enabled, "true" )
.setConfig( bolt.address, "localhost:7689" )
.newGraphDatabase();;
}
@After
public void destroyTestDatabase() {
graphDb.shutdown();
}
@Test
public void testExtends() throws Exception {
String src = "class A{\n"
+ "static class B extends A{}\n"
+ "static class C extends B{}\n"
+ "}";
JavacTaskImpl task = utils.TestUtils.getTask(src);
List<? extends CompilationUnitTree> parse = (List<? extends CompilationUnitTree>) task.parse();
task.analyze(); // attribute with symbols?
CompilationUnitTree u = parse.get(0);
WiggleVisitor v = new WiggleVisitor(task, graphDb, Collections.singletonMap("projectName", "Test_Extends"));
v.scan(u, null);
// ExecutionEngine engine = new ExecutionEngine(graphDb, new BufferingLogger());
Result result = graphDb.execute("start n=node(*) MATCH (m)-[r]->(n) RETURN m,r,n");
// ExecutionResult result = engine.execute("start n=node(*) MATCH m-[r]->n RETURN m,r,n");
System.out.println(result.resultAsString());
}
@Test
public void testRuntime() throws Exception {
String src =
"public class RunTimeTest {\n" +
" private static void safe() {\n" +
" emptyMethod();\n" +
" }\n" +
" private static void unsafe(String httpParamCmd) throws Exception {\n" +
" eval(httpParamCmd);\n" +
" }\n" +
" private static void eval(String cmd) throws Exception {\n" +
" Runtime.getRuntime().exec(cmd);\n" +
" }\n" +
" private static void emptyMethod() {\n" +
" }\n" +
"}";
JavacTaskImpl task = utils.TestUtils.getTask(src);
List<? extends CompilationUnitTree> parse = (List<? extends CompilationUnitTree>) task.parse();
task.analyze(); // attribute with symbols?
CompilationUnitTree u = parse.get(0);
WiggleVisitor v = new WiggleVisitor(task, graphDb, Collections.singletonMap("projectName", "RunTimeTest"));
v.scan(u, null);
Result result = graphDb.execute("start 起始节点=node(*) MATCH (终止节点)-[关系]->(起始节点) RETURN id(终止节点),关系, id(起始节点)");
System.out.println(result.resultAsString());
Thread.sleep(10000000);
}
@Test
public void testHelloWorld() throws Exception {
String src =
"";
JavacTaskImpl task = utils.TestUtils.getTask(src);
List<? extends CompilationUnitTree> parse = (List<? extends CompilationUnitTree>) task.parse();
task.analyze(); // attribute with symbols?
CompilationUnitTree u = parse.get(0);
WiggleVisitor v = new WiggleVisitor(task, graphDb, Collections.singletonMap("projectName", "RunTimeTest"));
v.scan(u, null);
//ExecutionEngine engine = new ExecutionEngine(graphDb, new BufferingLogger());
Result result = graphDb.execute("start 起始节点=node(*) MATCH (终止节点)-[关系]->(起始节点) RETURN id(终止节点),关系, id(起始节点)");
//ExecutionResult result = engine.execute("start n=node(*) MATCH m-[r]->n RETURN m,r,n");
System.out.println(result.resultAsString());
}
@Test
public void testMultipleExtendsAndImplements() throws Exception {
String src = "class A implements Cloneable{\n"
+ "static class B extends A{}\n"
+ "static class C extends B{}\n"
+ "static class D extends Z{}\n"
+ "}";
String src2 = "import java.io.*;\n"
+ "class Z implements Cloneable, Serializable{\n"
+ "static class Y extends Z{}\n"
+ "}";
JavacTaskImpl task = utils.TestUtils.getTask(src, src2);
List<? extends CompilationUnitTree> parse = (List<? extends CompilationUnitTree>) task.parse();
task.analyze(); // attribute with symbols?
CompilationUnitTree u1 = parse.get(0);
CompilationUnitTree u2 = parse.get(1);
WiggleVisitor v = new WiggleVisitor(task, graphDb, Collections.singletonMap("projectName", "Test_Extends"));
v.scan(u1, null);
v.scan(u2, null);
// ExecutionEngine engine = new ExecutionEngine(graphDb, new BufferingLogger());
// ExecutionResult result = engine.execute("start n=node(*) MATCH m-[r]->n RETURN m,r,n");
// System.out.println(result.dumpToString());
}
}