KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > groovy > security > RunAllGroovyScriptsSuite


1 /*
2  * Created on Apr 7, 2004
3  *
4  * To change the template for this generated file go to
5  * Window - Preferences - Java - Code Generation - Code and Comments
6  */

7 package groovy.security;
8
9 import java.io.File JavaDoc;
10 import java.util.ArrayList JavaDoc;
11 import java.util.Iterator JavaDoc;
12 import java.util.List JavaDoc;
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 JavaDoc dir, TestResult result) throws Exception JavaDoc {
32         File JavaDoc[] files = dir.listFiles();
33         List JavaDoc traverseList = new ArrayList JavaDoc();
34         for (int i = 0; i < files.length; i++) {
35             File JavaDoc file = files[i];
36             if (file.isDirectory()) {
37                 traverseList.add(file);
38             }
39             else {
40                 String JavaDoc name = file.getName();
41                 if (name.endsWith("Test.groovy") || name.endsWith("Bug.groovy")) {
42                 //if (name.endsWith("IanMaceysBug.groovy")) {
43
Class JavaDoc 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 JavaDoc iter = traverseList.iterator(); iter.hasNext();) {
52             executeTests((File JavaDoc) iter.next(), result);
53         }
54     }
55
56     public void testGroovyScripts() throws Exception JavaDoc {
57         if (!isSecurityAvailable()) {
58             return;
59         }
60         TestResult result = new TestResult();
61         executeTests(new File JavaDoc("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 }
68
Popular Tags