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


001:        package org.uispec4j;
002:
003:        import junit.framework.TestCase;
004:        import org.uispec4j.assertion.Assertion;
005:        import org.uispec4j.assertion.UISpecAssert;
006:        import org.uispec4j.interception.toolkit.UISpecDisplay;
007:
008:        /**
009:         * UISpec4J-enabled TestCase class.<p>
010:         * Test cases derived from this class automatically set up the instanciation mechanism. They can
011:         * also access the application main window by defining an adapter, i.e. a class implementing
012:         * the {@link UISpecAdapter} class.<br>
013:         * The adapter can be set from the test {@link #setUp()} or any test method using the
014:         * {@link #setAdapter(UISpecAdapter)} method.
015:         * The adapter can also be registered by setting the <code>uispec4j.adapter</code> property as follows:
016:         * <pre><code>
017:         * uispec4j.adapter=samples.addressbook.test.Adapter
018:         * </code></pre>
019:         */
020:        public abstract class UISpecTestCase extends TestCase {
021:
022:            static final String ADAPTER_CLASS_PROPERTY = "uispec4j.adapter";
023:            static final String PROPERTY_NOT_DEFINED;
024:
025:            private UISpecAdapter adapter;
026:
027:            static {
028:                PROPERTY_NOT_DEFINED = "Adapter class not defined - the '"
029:                        + ADAPTER_CLASS_PROPERTY
030:                        + "' property must refer to a class implementing the UISpecAdapter interface";
031:                UISpec4J.init();
032:            }
033:
034:            protected UISpecTestCase() {
035:            }
036:
037:            protected UISpecTestCase(String testName) {
038:                super (testName);
039:            }
040:
041:            public void setAdapter(UISpecAdapter adapter) {
042:                this .adapter = adapter;
043:            }
044:
045:            /**
046:             * Initializes the resources needed by the test case.<br>
047:             * NB: If you provide your own implementation, do not forget to call this one first.
048:             */
049:            protected void setUp() throws Exception {
050:                super .setUp();
051:                UISpecDisplay.instance().reset();
052:            }
053:
054:            /**
055:             * Checks whether an unexpected exception had occurred, and releases the test resources.
056:             */
057:            protected void tearDown() throws Exception {
058:                UISpecDisplay.instance().rethrowIfNeeded();
059:                UISpecDisplay.instance().reset();
060:                super .tearDown();
061:            }
062:
063:            private void retrieveAdapter() throws AdapterNotFoundException {
064:                String adapterClassName = System
065:                        .getProperty(ADAPTER_CLASS_PROPERTY);
066:                if (adapterClassName == null) {
067:                    throw new AdapterNotFoundException();
068:                }
069:                try {
070:                    adapter = (UISpecAdapter) Class.forName(adapterClassName)
071:                            .newInstance();
072:                } catch (Exception e) {
073:                    throw new AdapterNotFoundException(adapterClassName, e);
074:                }
075:            }
076:
077:            /**
078:             * Returns the Window created by the adapter.
079:             *
080:             * @throws AdapterNotFoundException if the <code>uispec4j.adapter</code> property does not refer
081:             *                                  to a valid adapter
082:             */
083:            public Window getMainWindow() throws AdapterNotFoundException {
084:                return getAdapter().getMainWindow();
085:            }
086:
087:            /**
088:             * Checks the given assertion.
089:             *
090:             * @see UISpecAssert#assertTrue(Assertion)
091:             */
092:            public void assertTrue(Assertion assertion) {
093:                UISpecAssert.assertTrue(assertion);
094:            }
095:
096:            /**
097:             * Waits for at most 'waitTimeLimit' ms until the assertion is true.
098:             *
099:             * @see UISpecAssert#waitUntil(Assertion, long)
100:             */
101:            public void waitUntil(Assertion assertion, long waitTimeLimit) {
102:                UISpecAssert.waitUntil(assertion, waitTimeLimit);
103:            }
104:
105:            /**
106:             * Checks that the given assertion fails.
107:             *
108:             * @see UISpecAssert#assertFalse(Assertion)
109:             */
110:            public void assertFalse(Assertion assertion) {
111:                UISpecAssert.assertFalse(assertion);
112:            }
113:
114:            /**
115:             * Checks the given assertion.
116:             * If it fails an AssertionFailedError is thrown with the given message.
117:             *
118:             * @see UISpecAssert#assertTrue(String, Assertion)
119:             */
120:            public void assertTrue(String message, Assertion assertion) {
121:                UISpecAssert.assertTrue(message, assertion);
122:            }
123:
124:            /**
125:             * Waits for at most 'waitTimeLimit' ms until the assertion is true.
126:             * If it fails an AssertionFailedError is thrown with the given message.
127:             *
128:             * @see UISpecAssert#waitUntil(String, Assertion, long)
129:             */
130:            public void waitUntil(String message, Assertion assertion,
131:                    long waitTimeLimit) {
132:                UISpecAssert.waitUntil(message, assertion, waitTimeLimit);
133:            }
134:
135:            /**
136:             * Checks that the given assertion fails.
137:             * If it succeeds an AssertionFailedError is thrown with the given message.
138:             *
139:             * @see UISpecAssert#assertFalse(String, Assertion)
140:             */
141:            public void assertFalse(String message, Assertion assertion) {
142:                UISpecAssert.assertFalse(message, assertion);
143:            }
144:
145:            /**
146:             * Returns a negation of the given assertion.
147:             *
148:             * @see UISpecAssert#not(Assertion)
149:             */
150:            public Assertion not(Assertion assertion) {
151:                return UISpecAssert.not(assertion);
152:            }
153:
154:            /**
155:             * Returns the intersection of two assertions.
156:             *
157:             * @see UISpecAssert#and(Assertion[])
158:             */
159:            public Assertion and(Assertion assertion1, Assertion assertion2) {
160:                return UISpecAssert.and(new Assertion[] { assertion1,
161:                        assertion2 });
162:            }
163:
164:            /**
165:             * Returns the intersection of two assertions.
166:             *
167:             * @see UISpecAssert#and(Assertion[])
168:             */
169:            public Assertion and(Assertion[] assertions) {
170:                return UISpecAssert.and(assertions);
171:            }
172:
173:            /**
174:             * Returns the union of two assertions.
175:             */
176:            public Assertion or(Assertion assertion1, Assertion assertion2) {
177:                return UISpecAssert
178:                        .or(new Assertion[] { assertion1, assertion2 });
179:            }
180:
181:            /**
182:             * Returns the union of two assertions.
183:             *
184:             * @see UISpecAssert#or(Assertion[])
185:             */
186:            public Assertion or(Assertion[] assertions) {
187:                return UISpecAssert.or(assertions);
188:            }
189:
190:            /**
191:             * Checks that the given assertion equals the expected parameter.
192:             *
193:             * @see UISpecAssert#assertEquals(boolean, Assertion)
194:             */
195:            public void assertEquals(boolean expected, Assertion assertion) {
196:                UISpecAssert.assertEquals(expected, assertion);
197:            }
198:
199:            /**
200:             * Checks that the given assertion equals the expected parameter.
201:             * If it fails an AssertionFailedError is thrown with the given message.
202:             *
203:             * @see UISpecAssert#assertEquals(String, boolean, Assertion)
204:             */
205:            public void assertEquals(String message, boolean expected,
206:                    Assertion assertion) {
207:                UISpecAssert.assertEquals(message, expected, assertion);
208:            }
209:
210:            private UISpecAdapter getAdapter() throws AdapterNotFoundException {
211:                if (adapter == null) {
212:                    retrieveAdapter();
213:                }
214:                return adapter;
215:            }
216:
217:            static class AdapterNotFoundException extends RuntimeException {
218:                public AdapterNotFoundException() {
219:                    super (PROPERTY_NOT_DEFINED);
220:                }
221:
222:                public AdapterNotFoundException(String adapterClassName,
223:                        Exception e) {
224:                    super ("Adapter class '" + adapterClassName + "' not found",
225:                            e);
226:                }
227:            }
228:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.