Source Code Cross Referenced for DefaultExceptionHandlerConfigTest.java in  » Testing » mockrunner-0.4 » com » mockrunner » test » web » 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 » mockrunner 0.4 » com.mockrunner.test.web 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.mockrunner.test.web;
002:
003:        import java.io.IOException;
004:        import java.rmi.RemoteException;
005:
006:        import javax.servlet.ServletException;
007:        import javax.servlet.http.HttpServletRequest;
008:        import javax.servlet.http.HttpServletResponse;
009:
010:        import junit.framework.TestCase;
011:
012:        import org.apache.struts.action.ActionForm;
013:        import org.apache.struts.action.ActionForward;
014:        import org.apache.struts.action.ActionMapping;
015:        import org.apache.struts.action.DynaActionForm;
016:        import org.apache.struts.action.ExceptionHandler;
017:        import org.apache.struts.config.ExceptionConfig;
018:
019:        import com.mockrunner.mock.web.MockActionForward;
020:        import com.mockrunner.mock.web.MockActionMapping;
021:        import com.mockrunner.mock.web.MockHttpServletRequest;
022:        import com.mockrunner.mock.web.MockHttpServletResponse;
023:        import com.mockrunner.struts.DefaultExceptionHandlerConfig;
024:
025:        public class DefaultExceptionHandlerConfigTest extends TestCase {
026:            public void testConfigConstructor() throws Exception {
027:                ExceptionConfig config = new ExceptionConfig();
028:                config.setHandler(TestExceptionHandler.class.getName());
029:                config.setType(IOException.class.getName());
030:                DefaultExceptionHandlerConfig handlerConfig = new DefaultExceptionHandlerConfig(
031:                        config);
032:                doTestCanHandle(handlerConfig);
033:                doTestHandle(handlerConfig);
034:                assertSame(config, handlerConfig.getExceptionConfig());
035:                assertTrue(handlerConfig.getExceptionHandler() instanceof  TestExceptionHandler);
036:            }
037:
038:            public void testConfigAndHandlerConstructor() throws Exception {
039:                ExceptionConfig config = new ExceptionConfig();
040:                TestExceptionHandler handler = new TestExceptionHandler();
041:                config.setType(IOException.class.getName());
042:                DefaultExceptionHandlerConfig handlerConfig = new DefaultExceptionHandlerConfig(
043:                        handler, config);
044:                doTestCanHandle(handlerConfig);
045:                doTestHandle(handlerConfig);
046:                assertSame(config, handlerConfig.getExceptionConfig());
047:                assertSame(handler, handlerConfig.getExceptionHandler());
048:                assertSame(TestExceptionHandler.class.getName(), config
049:                        .getHandler());
050:            }
051:
052:            public void testExceptionAndHandlerConstructor() throws Exception {
053:                TestExceptionHandler handler = new TestExceptionHandler();
054:                DefaultExceptionHandlerConfig handlerConfig = new DefaultExceptionHandlerConfig(
055:                        handler, IOException.class);
056:                doTestCanHandle(handlerConfig);
057:                doTestHandle(handlerConfig);
058:                ExceptionConfig config = handlerConfig.getExceptionConfig();
059:                assertSame(TestExceptionHandler.class.getName(), config
060:                        .getHandler());
061:                assertSame(IOException.class.getName(), config.getType());
062:            }
063:
064:            public void testExceptionConstructor() throws Exception {
065:                DefaultExceptionHandlerConfig handlerConfig = new DefaultExceptionHandlerConfig(
066:                        IOException.class);
067:                doTestCanHandle(handlerConfig);
068:                ExceptionConfig config = handlerConfig.getExceptionConfig();
069:                assertSame(ExceptionHandler.class.getName(), config
070:                        .getHandler());
071:                assertSame(IOException.class.getName(), config.getType());
072:            }
073:
074:            private void doTestCanHandle(DefaultExceptionHandlerConfig config) {
075:                assertFalse(config.canHandle(null));
076:                assertFalse(config.canHandle(new Exception()));
077:                assertFalse(config.canHandle(new IllegalArgumentException()));
078:                assertTrue(config.canHandle(new IOException()));
079:                assertTrue(config.canHandle(new RemoteException()));
080:            }
081:
082:            private void doTestHandle(DefaultExceptionHandlerConfig config)
083:                    throws Exception {
084:                MockActionMapping mapping = new MockActionMapping();
085:                ActionForm form = new DynaActionForm();
086:                MockHttpServletRequest request = new MockHttpServletRequest();
087:                MockHttpServletResponse response = new MockHttpServletResponse();
088:                assertNull(config
089:                        .handle(null, mapping, form, request, response));
090:                doTestNotCalled(config);
091:                assertNull(config.handle(new Exception(), mapping, form,
092:                        request, response));
093:                Exception exception = new RemoteException();
094:                ActionForward forward = (ActionForward) config.handle(
095:                        exception, mapping, form, request, response);
096:                doTestCalled(config, exception, mapping, form, request,
097:                        response);
098:                assertTrue(forward instanceof  MockActionForward);
099:                assertEquals("testname", ((MockActionForward) forward)
100:                        .getName());
101:            }
102:
103:            private void doTestNotCalled(DefaultExceptionHandlerConfig config) {
104:                TestExceptionHandler handler = (TestExceptionHandler) config
105:                        .getExceptionHandler();
106:                assertFalse(handler.wasExecuteCalled());
107:            }
108:
109:            private void doTestCalled(DefaultExceptionHandlerConfig config,
110:                    Exception exc, ActionMapping mapping, ActionForm form,
111:                    HttpServletRequest request, HttpServletResponse response) {
112:                TestExceptionHandler handler = (TestExceptionHandler) config
113:                        .getExceptionHandler();
114:                assertTrue(handler.wasExecuteCalled());
115:                assertSame(exc, handler.getException());
116:                assertSame(config.getExceptionConfig(), handler
117:                        .getExceptionConfig());
118:                assertSame(mapping, handler.getMapping());
119:                assertSame(form, handler.getForm());
120:                assertSame(request, handler.getRequest());
121:                assertSame(response, handler.getResponse());
122:            }
123:
124:            public static class TestExceptionHandler extends ExceptionHandler {
125:                private Exception exception;
126:                private ExceptionConfig exceptionConfig;
127:                private ActionMapping mapping;
128:                private ActionForm form;
129:                private HttpServletRequest request;
130:                private HttpServletResponse response;
131:                private boolean executeCalled = false;
132:
133:                public ActionForward execute(Exception exc,
134:                        ExceptionConfig config, ActionMapping mapping,
135:                        ActionForm form, HttpServletRequest request,
136:                        HttpServletResponse response) throws ServletException {
137:                    executeCalled = true;
138:                    this .exception = exc;
139:                    this .exceptionConfig = config;
140:                    this .mapping = mapping;
141:                    this .form = form;
142:                    this .request = request;
143:                    this .response = response;
144:                    return new MockActionForward("testname");
145:                }
146:
147:                public Exception getException() {
148:                    return exception;
149:                }
150:
151:                public ExceptionConfig getExceptionConfig() {
152:                    return exceptionConfig;
153:                }
154:
155:                public ActionForm getForm() {
156:                    return form;
157:                }
158:
159:                public ActionMapping getMapping() {
160:                    return mapping;
161:                }
162:
163:                public HttpServletRequest getRequest() {
164:                    return request;
165:                }
166:
167:                public HttpServletResponse getResponse() {
168:                    return response;
169:                }
170:
171:                public boolean wasExecuteCalled() {
172:                    return executeCalled;
173:                }
174:            }
175:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.