1
2
3
4
5
6
7 package groovy.security;
8
9 import java.io.File;
10 import java.util.ArrayList;
11 import java.util.Iterator;
12 import java.util.List;
13
14 import junit.framework.TestCase;
15 import junit.framework.TestResult;
16 import junit.framework.TestSuite;
17
18 /***
19 * Run all the .groovy scripts found under the src/test tree with a security manager active.
20 * Not currently part of the build because it adds about 4 minutes to the build process.
21 *
22 * @author Steve Goetze
23 */
24 public class RunAllGroovyScriptsSuite extends SecurityTestSupport {
25
26 /***
27 * Find all Groovy script test cases in the source tree and execute them with a security policy in effect.
28 * The complete filename of the groovy source file is used as the codebase so that the proper grants can be
29 * made for each script.
30 */
31 protected void executeTests(File dir, TestResult result) throws Exception {
32 File[] files = dir.listFiles();
33 List traverseList = new ArrayList();
34 for (int i = 0; i < files.length; i++) {
35 File file = files[i];
36 if (file.isDirectory()) {
37 traverseList.add(file);
38 }
39 else {
40 String name = file.getName();
41 if (name.endsWith("Test.groovy") || name.endsWith("Bug.groovy")) {
42
43 Class clazz = parseClass(file);
44 if (TestCase.class.isAssignableFrom(clazz)) {
45 TestSuite suite = new TestSuite(clazz);
46 suite.run(result);
47 }
48 }
49 }
50 }
51 for (Iterator iter = traverseList.iterator(); iter.hasNext();) {
52 executeTests((File) iter.next(), result);
53 }
54 }
55
56 public void testGroovyScripts() throws Exception {
57 if (!isSecurityAvailable()) {
58 return;
59 }
60 TestResult result = new TestResult();
61 executeTests(new File("src/test"), result);
62 if (!result.wasSuccessful()) {
63 new SecurityTestResultPrinter(System.out).print(result);
64 fail("At least one groovy testcase did not run under the secure groovy environment. Results in the testcase output");
65 }
66 }
67 }