1 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 24 public class RunAllGroovyScriptsSuite extends SecurityTestSupport { 25 26 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 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 } 68 | Popular Tags |