Source Code Cross Referenced for AbstractCactusTestCase.java in  » Testing » jakarta-cactus » org » apache » cactus » internal » 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 » jakarta cactus » org.apache.cactus.internal 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * ========================================================================
003:         * 
004:         * Copyright 2003-2004 The Apache Software Foundation.
005:         *
006:         * Licensed under the Apache License, Version 2.0 (the "License");
007:         * you may not use this file except in compliance with the License.
008:         * You may obtain a copy of the License at
009:         * 
010:         *   http://www.apache.org/licenses/LICENSE-2.0
011:         * 
012:         * Unless required by applicable law or agreed to in writing, software
013:         * distributed under the License is distributed on an "AS IS" BASIS,
014:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015:         * See the License for the specific language governing permissions and
016:         * limitations under the License.
017:         * 
018:         * ========================================================================
019:         */
020:        package org.apache.cactus.internal;
021:
022:        import junit.framework.Test;
023:        import junit.framework.TestCase;
024:
025:        import org.apache.cactus.internal.client.ClientTestCaseCaller;
026:        import org.apache.cactus.internal.configuration.ConfigurationInitializer;
027:        import org.apache.cactus.internal.server.ServerTestCaseCaller;
028:        import org.apache.cactus.internal.util.TestCaseImplementChecker;
029:        import org.apache.cactus.spi.client.connector.ProtocolHandler;
030:
031:        /**
032:         * Base class for all Cactus test case extensions.
033:         * 
034:         * Note: We must not add any method that can be called by the end user to this
035:         * class as users will those methods and it will create a runtime dependency to 
036:         * this class. We will then have to break binary compatibility if we wish to
037:         * move this class around or change its implementation.
038:         * 
039:         * @version $Id: AbstractCactusTestCase.java 238991 2004-05-22 11:34:50Z vmassol $
040:         * @since 1.6 
041:         */
042:        public abstract class AbstractCactusTestCase extends TestCase {
043:            /**
044:             * As this class is the first one loaded on the client side, we ensure
045:             * that the Cactus configuration has been initialized. In the future,
046:             * this block will be removed as all initialization will be done in Cactus
047:             * test suites. However, as we still support using Cactus TestCase classes
048:             * we don't have a proper initialization hook and thus we need this hack.
049:             */
050:            static {
051:                ConfigurationInitializer.initialize();
052:            }
053:
054:            /**
055:             * Provides all client side Cactus calling logic.
056:             * Note that we are using a delegate class instead of inheritance in order 
057:             * to hide non public API to the users and thus to be able to easily change
058:             * the implementation.
059:             */
060:            private ClientTestCaseCaller clientCaller;
061:
062:            /**
063:             * Provides all server side Cactus calling logic. 
064:             * Note that we are using a delegate class instead of inheritance in order 
065:             * to hide non public API to the users and thus to be able to easily change
066:             * the implementation.
067:             */
068:            private ServerTestCaseCaller serverCaller;
069:
070:            // Abstract methods -----------------------------------------------------
071:
072:            /**
073:             * Create a protocol handler instance that will be used to connect to the
074:             * server side.
075:             * 
076:             * @return the protocol handler instance
077:             */
078:            protected abstract ProtocolHandler createProtocolHandler();
079:
080:            // Constructors ---------------------------------------------------------
081:
082:            /**
083:             * Default constructor defined in order to allow creating Test Case
084:             * without needing to define constructor (new feature in JUnit 3.8.1).
085:             * Should only be used with JUnit 3.8.1 or greater. 
086:             */
087:            public AbstractCactusTestCase() {
088:                init(null);
089:            }
090:
091:            /**
092:             * Constructs a JUnit test case with the given name.
093:             *
094:             * @param theName the name of the test case
095:             */
096:            public AbstractCactusTestCase(String theName) {
097:                super (theName);
098:                init(null);
099:            }
100:
101:            /**
102:             * Wraps a pure JUnit Test Case in a Cactus Test Case.
103:             *  
104:             * @param theName the name of the test
105:             * @param theTest the Test Case class to wrap
106:             */
107:            public AbstractCactusTestCase(String theName, Test theTest) {
108:                super (theName);
109:                init(theTest);
110:            }
111:
112:            // Public methods -------------------------------------------------------
113:
114:            /**
115:             * JUnit method that is used to run the tests. However, we're intercepting
116:             * it so that we can call the server side of Cactus where the tests will
117:             * be run (instead of on the client side).
118:             *
119:             * @exception Throwable if any exception is thrown during the test. Any
120:             *            exception will be displayed by the JUnit Test Runner
121:             */
122:            public void runBare() throws Throwable {
123:                TestCaseImplementChecker.checkTestName(this );
124:                TestCaseImplementChecker.checkTestName(getServerCaller()
125:                        .getWrappedTest());
126:
127:                runBareClient();
128:            }
129:
130:            /**
131:             * @see CactusTestCase#runBareServer()
132:             */
133:            public void runBareServer() throws Throwable {
134:                getServerCaller().runBareInit();
135:
136:                // Note: We cannot delegate this piece of code in the
137:                // ServerTestCaseDelegate class as it requires to call
138:                // super.runBare()
139:
140:                if (getServerCaller().getWrappedTest() != null) {
141:                    ((TestCase) getServerCaller().getWrappedTest()).runBare();
142:                } else {
143:                    super .runBare();
144:                }
145:            }
146:
147:            // Private methods ------------------------------------------------------
148:
149:            /**
150:             * @param theCaller the client test case calling class
151:             */
152:            private void setClientCaller(ClientTestCaseCaller theCaller) {
153:                this .clientCaller = theCaller;
154:            }
155:
156:            /**
157:             * @param theCaller the server test case calling class
158:             */
159:            private void setServerCaller(ServerTestCaseCaller theCaller) {
160:                this .serverCaller = theCaller;
161:            }
162:
163:            /**
164:             * @return the client test case caller
165:             */
166:            private ClientTestCaseCaller getClientCaller() {
167:                return this .clientCaller;
168:            }
169:
170:            /**
171:             * @return the server test case caller
172:             */
173:            private ServerTestCaseCaller getServerCaller() {
174:                return this .serverCaller;
175:            }
176:
177:            /**
178:             * Initializations common to all constructors.
179:             *  
180:             * @param theTest a pure JUnit Test that Cactus will wrap
181:             */
182:            private void init(Test theTest) {
183:                setClientCaller(new ClientTestCaseCaller(this , theTest,
184:                        createProtocolHandler()));
185:                setServerCaller(new ServerTestCaseCaller(this , theTest));
186:            }
187:
188:            /**
189:             * Introduced for symmetry with {@link #runBareServer()}.
190:             * 
191:             * @see #runBare()
192:             */
193:            private void runBareClient() throws Throwable {
194:                getClientCaller().runBareInit();
195:
196:                // Catch the exception just to have a chance to log it
197:                try {
198:                    getClientCaller().runTest();
199:                } catch (Throwable t) {
200:                    // TODO: Move getLogger to this class instead
201:                    getClientCaller().getLogger().debug("Exception in test", t);
202:                    throw t;
203:                }
204:            }
205:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.