Source Code Cross Referenced for TestClass.java in  » Testing » testng » org » testng » 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 » Testing » testng » org.testng 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.testng;
002:
003:        import java.lang.reflect.Method;
004:        import java.util.ArrayList;
005:        import java.util.HashMap;
006:        import java.util.List;
007:        import java.util.Map;
008:
009:        import org.testng.internal.ConfigurationMethod;
010:        import org.testng.internal.NoOpTestClass;
011:        import org.testng.internal.RunInfo;
012:        import org.testng.internal.TestNGMethod;
013:        import org.testng.internal.Utils;
014:        import org.testng.internal.annotations.IAnnotationFinder;
015:
016:        /**
017:         * This class represents a test class:
018:         * - The test methods
019:         * - The configuration methods (test and method)
020:         * - The class file
021:         * 
022:         * @author <a href="mailto:cedric@beust.com">Cedric Beust</a>
023:         * @author <a href='mailto:the_mindstorm@evolva.ro'>Alexandru Popescu</a>
024:         */
025:        public class TestClass extends NoOpTestClass implements  ITestClass {
026:            /* generated */
027:            private static final long serialVersionUID = -8077917128278361294L;
028:            transient private IAnnotationFinder m_annotationFinder = null;
029:            // The Strategy used to locate test methods (TestNG, JUnit, etc...)
030:            transient private ITestMethodFinder m_testMethodFinder = null;
031:
032:            transient protected Map<Class, Class> m_testClasses = new HashMap<Class, Class>();
033:            transient protected Map<Class, Object[]> m_instanceMap = new HashMap<Class, Object[]>();
034:
035:            private IClass m_iClass = null;
036:            private RunInfo m_runInfo = null;
037:
038:            public TestClass(IClass cls, String testName,
039:                    ITestMethodFinder testMethodFinder,
040:                    IAnnotationFinder annotationFinder, RunInfo runInfo) {
041:                init(cls, testName, testMethodFinder, annotationFinder, runInfo);
042:            }
043:
044:            public TestClass(IClass cls, TestClass tc) {
045:                init(cls, tc.getTestName(), tc.getTestMethodFinder(), tc
046:                        .getAnnotationFinder(), tc.getRunInfo());
047:            }
048:
049:            public String getTestName() {
050:                return m_testName;
051:            }
052:
053:            public IAnnotationFinder getAnnotationFinder() {
054:                return m_annotationFinder;
055:            }
056:
057:            private void init(IClass cls, String testName,
058:                    ITestMethodFinder testMethodFinder,
059:                    IAnnotationFinder annotationFinder, RunInfo runInfo) {
060:                log(3, "Creating TestClass for " + cls);
061:                m_iClass = cls;
062:                m_testClass = cls.getRealClass();
063:                m_testName = testName;
064:                m_runInfo = runInfo;
065:                m_testMethodFinder = testMethodFinder;
066:                m_annotationFinder = annotationFinder;
067:                initMethods();
068:                initTestClassesAndInstances();
069:            }
070:
071:            private void initTestClassesAndInstances() {
072:                //
073:                // TestClasses and instances
074:                //
075:                Object[] instances = getInstances(false);
076:                for (Object instance : instances) {
077:                    Class cls = instance.getClass();
078:                    if (null == m_testClasses.get(cls)) {
079:                        m_testClasses.put(cls, cls);
080:                        m_instanceMap.put(cls, instances);
081:                    }
082:                }
083:
084:            }
085:
086:            public Object[] getInstances(boolean create) {
087:                return m_iClass.getInstances(create);
088:            }
089:
090:            public long[] getInstanceHashCodes() {
091:                return m_iClass.getInstanceHashCodes();
092:            }
093:
094:            public int getInstanceCount() {
095:                return m_iClass.getInstanceCount();
096:            }
097:
098:            public void addInstance(Object instance) {
099:                m_iClass.addInstance(instance);
100:            }
101:
102:            private void initMethods() {
103:                ITestNGMethod[] methods = m_testMethodFinder
104:                        .getTestMethods(m_testClass);
105:                m_testMethods = createTestMethods(methods);
106:
107:                m_beforeSuiteMethods = ConfigurationMethod
108:                        .createSuiteConfigurationMethods(m_testMethodFinder
109:                                .getBeforeSuiteMethods(m_testClass),
110:                                m_annotationFinder, true);
111:                m_afterSuiteMethods = ConfigurationMethod
112:                        .createSuiteConfigurationMethods(m_testMethodFinder
113:                                .getAfterSuiteMethods(m_testClass),
114:                                m_annotationFinder, false);
115:
116:                m_beforeTestConfMethods = ConfigurationMethod
117:                        .createTestConfigurationMethods(
118:                                m_testMethodFinder
119:                                        .getBeforeTestConfigurationMethods(m_testClass),
120:                                m_annotationFinder, true);
121:                m_afterTestConfMethods = ConfigurationMethod
122:                        .createTestConfigurationMethods(m_testMethodFinder
123:                                .getAfterTestConfigurationMethods(m_testClass),
124:                                m_annotationFinder, false);
125:
126:                m_beforeClassMethods = ConfigurationMethod
127:                        .createClassConfigurationMethods(m_testMethodFinder
128:                                .getBeforeClassMethods(m_testClass),
129:                                m_annotationFinder, true);
130:                m_afterClassMethods = ConfigurationMethod
131:                        .createClassConfigurationMethods(m_testMethodFinder
132:                                .getAfterClassMethods(m_testClass),
133:                                m_annotationFinder, false);
134:
135:                m_beforeGroupsMethods = ConfigurationMethod
136:                        .createBeforeConfigurationMethods(
137:                                m_testMethodFinder
138:                                        .getBeforeGroupsConfigurationMethods(m_testClass),
139:                                m_annotationFinder, true);
140:                m_afterGroupsMethods = ConfigurationMethod
141:                        .createAfterConfigurationMethods(
142:                                m_testMethodFinder
143:                                        .getAfterGroupsConfigurationMethods(m_testClass),
144:                                m_annotationFinder, false);
145:
146:                m_beforeTestMethods = ConfigurationMethod
147:                        .createTestMethodConfigurationMethods(
148:                                m_testMethodFinder
149:                                        .getBeforeTestMethods(m_testClass),
150:                                m_annotationFinder, true);
151:                m_afterTestMethods = ConfigurationMethod
152:                        .createTestMethodConfigurationMethods(
153:                                m_testMethodFinder
154:                                        .getAfterTestMethods(m_testClass),
155:                                m_annotationFinder, false);
156:
157:            }
158:
159:            /**
160:             * Create the test methods that belong to this class (rejects
161:             * all those that belong to a different class).
162:             */
163:            private ITestNGMethod[] createTestMethods(ITestNGMethod[] methods) {
164:                List<ITestNGMethod> vResult = new ArrayList<ITestNGMethod>();
165:                for (ITestNGMethod tm : methods) {
166:                    Method m = tm.getMethod();
167:                    if (m.getDeclaringClass().isAssignableFrom(m_testClass)) {
168:                        log(4, "Adding method " + tm + " on TestClass "
169:                                + m_testClass);
170:                        vResult
171:                                .add(new TestNGMethod(
172:                                        /* tm.getRealClass(), */m,
173:                                        m_annotationFinder));
174:                    } else {
175:                        log(4, "Rejecting method " + tm + " for TestClass "
176:                                + m_testClass);
177:                    }
178:                }
179:
180:                ITestNGMethod[] result = vResult
181:                        .toArray(new ITestNGMethod[vResult.size()]);
182:                return result;
183:            }
184:
185:            private RunInfo getRunInfo() {
186:                return m_runInfo;
187:            }
188:
189:            public ITestMethodFinder getTestMethodFinder() {
190:                return m_testMethodFinder;
191:            }
192:
193:            private void log(int level, String s) {
194:                Utils.log("TestClass", level, s);
195:            }
196:
197:            private static void ppp(String s) {
198:                System.out.println("[TestClass] " + s);
199:            }
200:
201:            public void dump() {
202:                ppp("\n======\nTESTCLASS: " + m_testClass.getName());
203:                for (ITestNGMethod m : m_beforeClassMethods) {
204:                    ppp("BeforeClass : " + m);
205:                }
206:                for (ITestNGMethod m : m_beforeTestMethods) {
207:                    ppp("BeforeMethod:\t" + m);
208:                }
209:                for (ITestNGMethod m : m_testMethods) {
210:                    ppp("Test        :\t\t" + m);
211:                }
212:                for (ITestNGMethod m : m_afterTestMethods) {
213:                    ppp("AfterMethod :\t" + m);
214:                }
215:                for (ITestNGMethod m : m_afterClassMethods) {
216:                    ppp("AfterClass  : " + m);
217:                }
218:                ppp("\n======\n");
219:            }
220:
221:            @Override
222:            public String toString() {
223:                return "[TestClass " + m_testClass + "]";
224:            }
225:
226:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.