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


001:        /* 
002:         * ========================================================================
003:         * 
004:         * Copyright 2001-2003 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.sample.servlet.unit;
021:
022:        import java.io.Serializable;
023:
024:        import org.apache.cactus.ServletTestCase;
025:        import org.apache.cactus.internal.client.AssertionFailedErrorWrapper;
026:        import org.apache.cactus.internal.client.ServletExceptionWrapper;
027:        import org.apache.cactus.internal.util.JUnitVersionHelper;
028:
029:        import junit.framework.AssertionFailedError;
030:        import junit.framework.ComparisonFailure;
031:
032:        /**
033:         * Verifies the correct handling of exceptions that happen when running
034:         * inside the server. Specifically verifies that serializable,
035:         * non-serializable and {@link AssertionFailedError} exceptions are 
036:         * correctly propagated to the client side.
037:         *
038:         * @version $Id: TestServerSideExceptions.java 238900 2004-04-10 16:11:26Z vmassol $
039:         */
040:        public class TestServerSideExceptions extends ServletTestCase {
041:            /**
042:             * Not serializable exception.
043:             */
044:            public class NotSerializableException extends Exception {
045:                /**
046:                 * @param theMessage the exception message
047:                 */
048:                public NotSerializableException(String theMessage) {
049:                    super (theMessage);
050:                }
051:            }
052:
053:            /**
054:             * Serializable exception.
055:             */
056:            public class SerializableException extends Exception implements 
057:                    Serializable {
058:                /**
059:                 * @param theMessage the exception message
060:                 */
061:                public SerializableException(String theMessage) {
062:                    super (theMessage);
063:                }
064:            }
065:
066:            /**
067:             * @param theTestName the test name to verify
068:             * @return true if the test name to verify corresponds to the currently
069:             *         executing test
070:             */
071:            private boolean checkName(String theTestName) {
072:                return JUnitVersionHelper.getTestCaseName(this ).equals(
073:                        theTestName);
074:            }
075:
076:            /**
077:             * Intercepts running test cases to check for normal exceptions.
078:             * 
079:             * @exception Throwable on test failure
080:             */
081:            public void runBare() throws Throwable {
082:                try {
083:                    super .runBare();
084:                } catch (AssertionFailedErrorWrapper e) {
085:                    // If the test case is "testAssertionFailedError" and the exception
086:                    // is of type AssertionFailedError and contains the text
087:                    // "test assertion failed error", then the test is ok.
088:                    if (checkName("testAssertionFailedError")) {
089:                        assertEquals(AssertionFailedError.class.getName(), e
090:                                .getWrappedClassName());
091:                        assertEquals("test assertion failed error", e
092:                                .getMessage());
093:                        return;
094:                    }
095:
096:                    // If the test case is "testComparisonFailure" and the exception
097:                    // is of type ComparisonFailure and contains the text
098:                    // "test comparison failure", then the test is ok.
099:                    else if (checkName("testComparisonFailure")) {
100:                        assertEquals(ComparisonFailure.class.getName(), e
101:                                .getWrappedClassName());
102:                        assertEquals(
103:                                "test comparison failure expected:<some...> "
104:                                        + "but was:<other...>", e.getMessage());
105:                        return;
106:                    }
107:                } catch (ServletExceptionWrapper e) {
108:                    // If the test case is "testExceptionNotSerializable" and the
109:                    // exception is of type
110:                    // TestServletTestCaseHelper1_ExceptionNotSerializable
111:                    // and contains the text "test non serializable exception", then
112:                    // the test is ok.
113:                    if (checkName("testExceptionNotSerializable")) {
114:                        assertEquals(NotSerializableException.class.getName(),
115:                                e.getWrappedClassName());
116:                        assertEquals("test non serializable exception", e
117:                                .getMessage());
118:                        return;
119:                    }
120:
121:                    // If the test case is "testExceptionSerializable" and the exception
122:                    // is of type TestServletTestCaseHelper1_ExceptionSerializable
123:                    // and contains the text "test serializable exception", then
124:                    // the test is ok.
125:                    else if (checkName("testExceptionSerializable")) {
126:                        assertEquals(SerializableException.class.getName(), e
127:                                .getWrappedClassName());
128:                        assertEquals("test serializable exception", e
129:                                .getMessage());
130:                        return;
131:                    }
132:                }
133:
134:                throw new AssertionFailedError("Unexpected test ["
135:                        + JUnitVersionHelper.getTestCaseName(this ) + "]");
136:            }
137:
138:            //-------------------------------------------------------------------------
139:
140:            /**
141:             * Raises an <code>AssertionFailedError</code> exception. The exception is
142:             * caught in
143:             * <code>TestServletTestCase_InterceptorServletTestCase.runTest()</code>.
144:             * This is to verify that <code>AssertionFailedError</code> raised on the
145:             * server side are properly propagated on the client side.
146:             */
147:            public void testAssertionFailedError() {
148:                throw new AssertionFailedError("test assertion failed error");
149:            }
150:
151:            //-------------------------------------------------------------------------
152:
153:            /**
154:             * Raises a non serializable exception. The exception is
155:             * caught in
156:             * <code>TestServletTestCase_InterceptorServletTestCase.runTest()</code>.
157:             * This is to verify that non serializable exceptions raised on the
158:             * server side are properly propagated on the client side.
159:             *
160:             * @exception NotSerializableException the non serializable exception to
161:             *             throw
162:             */
163:            public void testExceptionNotSerializable()
164:                    throws NotSerializableException {
165:                throw new NotSerializableException(
166:                        "test non serializable exception");
167:            }
168:
169:            //-------------------------------------------------------------------------
170:
171:            /**
172:             * Raises a serializable exception. The exception is
173:             * caught in
174:             * <code>TestServletTestCase_InterceptorServletTestCase.runTest()</code>.
175:             * This is to verify that serializable exceptions raised on the
176:             * server side are properly propagated on the client side.
177:             *
178:             * @exception SerializableException the serializable exception to throw
179:             */
180:            public void testExceptionSerializable()
181:                    throws SerializableException {
182:                throw new SerializableException("test serializable exception");
183:            }
184:
185:            //-------------------------------------------------------------------------
186:
187:            /**
188:             * Verify that the new {@link ComparisonFailure} introduced in JUnit 3.8.1
189:             * is correctly reported as a failure and not as an error in the Test 
190:             * Runner when Cactus is used.
191:             */
192:            public void testComparisonFailure() {
193:                throw new ComparisonFailure("test comparison failure",
194:                        "some value", "other value");
195:            }
196:
197:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.