Source Code Cross Referenced for AllTestSuite.java in  » Scripting » groovy-1.0 » groovy » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Scripting » groovy 1.0 » groovy.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package groovy.util;
002:
003:        import groovy.lang.GroovyClassLoader;
004:        import groovy.lang.Script;
005:        import junit.framework.Test;
006:        import junit.framework.TestSuite;
007:        import org.codehaus.groovy.control.CompilationFailedException;
008:        import org.codehaus.groovy.runtime.ScriptTestAdapter;
009:
010:        import java.io.File;
011:        import java.io.IOException;
012:        import java.util.Collection;
013:        import java.util.Iterator;
014:        import java.util.logging.Logger;
015:
016:        /**
017:         * AllTestSuite can be used in extension of GroovyTestSuite to execute TestCases written in Groovy
018:         * from inside a Java IDE.
019:         * AllTestSuite collects all files below a given directory that comply to a given pattern.
020:         * From these files, a TestSuite is constructed that can be run via an IDE graphical Test runner.
021:         * The files are assumed to be Groovy source files and be either a TestCase or a Script that can
022:         * be wrapped transparently into a TestCase.
023:         * The directory and the pattern can be set via System properties (see this classes' constants for details.)
024:         *
025:         * When setting the loglevel of this class to FINEST, all file loading will be logged.
026:         *
027:         * See also groovy.util.AllTestSuiteTest.groovy
028:         * @author Dierk Koenig based on a prototype by Andrew Glover
029:         * todo: dk: make FileNameFinder injectable
030:         */
031:        public class AllTestSuite extends TestSuite {
032:
033:            /** The System Property to set as base directory for collection of Test Cases.
034:             * The pattern will be used as an Ant fileset include basedir.
035:             * Key is "groovy.test.dir".
036:             * Default value is "./test/".
037:             */
038:            public static final String SYSPROP_TEST_DIR = "groovy.test.dir";
039:
040:            /** The System Property to set as the filename pattern for collection of Test Cases.
041:             * The pattern will be used as Regualar Expression pattern applied with the find
042:             * operator agains each candidate file.path.
043:             * Key is "groovy.test.pattern".
044:             * Default value is "Test.groovy".
045:             */
046:            public static final String SYSPROP_TEST_PATTERN = "groovy.test.pattern";
047:
048:            private static Logger LOG = Logger.getLogger(AllTestSuite.class
049:                    .getName());
050:            private static ClassLoader JAVA_LOADER = AllTestSuite.class
051:                    .getClassLoader();
052:            private static GroovyClassLoader GROOVY_LOADER = new GroovyClassLoader(
053:                    JAVA_LOADER);
054:
055:            private static final String[] EMPTY_ARGS = new String[] {};
056:            private static IFileNameFinder FINDER = null;
057:
058:            static { // this is only needed since the Groovy Build compiles *.groovy files after *.java files
059:                try {
060:                    Class finderClass = Class
061:                            .forName("groovy.util.FileNameFinder");
062:                    FINDER = (IFileNameFinder) finderClass.newInstance();
063:                } catch (Exception e) {
064:                    throw new RuntimeException(
065:                            "Cannot find and instantiate class FileNameFinder",
066:                            e);
067:                }
068:            }
069:
070:            public static Test suite() {
071:                String basedir = System
072:                        .getProperty(SYSPROP_TEST_DIR, "./test/");
073:                String pattern = System.getProperty(SYSPROP_TEST_PATTERN,
074:                        "**/*Test.groovy");
075:                return suite(basedir, pattern);
076:            }
077:
078:            public static Test suite(String basedir, String pattern) {
079:                AllTestSuite suite = new AllTestSuite();
080:                String fileName = "";
081:                try {
082:                    Collection filenames = FINDER
083:                            .getFileNames(basedir, pattern);
084:                    for (Iterator iter = filenames.iterator(); iter.hasNext();) {
085:                        fileName = (String) iter.next();
086:                        LOG.finest("trying to load " + fileName);
087:                        suite.loadTest(fileName);
088:                    }
089:                } catch (CompilationFailedException e1) {
090:                    e1.printStackTrace();
091:                    throw new RuntimeException(
092:                            "CompilationFailedException when loading "
093:                                    + fileName, e1);
094:                } catch (IOException e2) {
095:                    throw new RuntimeException("IOException when loading "
096:                            + fileName, e2);
097:                }
098:                return suite;
099:            }
100:
101:            protected void loadTest(String fileName)
102:                    throws CompilationFailedException, IOException {
103:                Class type = compile(fileName);
104:                if (!Test.class.isAssignableFrom(type)
105:                        && Script.class.isAssignableFrom(type)) {
106:                    addTest(new ScriptTestAdapter(type, EMPTY_ARGS));
107:                } else {
108:                    addTestSuite(type);
109:                }
110:            }
111:
112:            protected Class compile(String fileName)
113:                    throws CompilationFailedException, IOException {
114:                return GROOVY_LOADER.parseClass(new File(fileName));
115:            }
116:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.