Source Code Cross Referenced for MessageStoreInterceptorTest.java in  » J2EE » webwork-2.2.6 » com » opensymphony » webwork » interceptor » 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 » J2EE » webwork 2.2.6 » com.opensymphony.webwork.interceptor 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2002-2007 by OpenSymphony
003:         * All rights reserved.
004:         */
005:        package com.opensymphony.webwork.interceptor;
006:
007:        import java.util.ArrayList;
008:        import java.util.HashMap;
009:        import java.util.LinkedHashMap;
010:        import java.util.List;
011:        import java.util.Map;
012:
013:        import org.easymock.MockControl;
014:
015:        import com.opensymphony.webwork.WebWorkTestCase;
016:        import com.opensymphony.xwork.Action;
017:        import com.opensymphony.xwork.ActionContext;
018:        import com.opensymphony.xwork.ActionInvocation;
019:        import com.opensymphony.xwork.ActionSupport;
020:
021:        /**
022:         * Test case for MessageStoreInterceptor.
023:         * 
024:         * @author tmjee
025:         * 
026:         * @version $Date$ $Id$
027:         */
028:        public class MessageStoreInterceptorTest extends WebWorkTestCase {
029:
030:            public void testStoreMessage() throws Exception {
031:                MessageStoreInterceptor interceptor = new MessageStoreInterceptor();
032:                interceptor.setAllowRequestParameterSwitch(true);
033:                interceptor
034:                        .setOperationMode(MessageStoreInterceptor.STORE_MODE);
035:
036:                Map paramMap = new LinkedHashMap();
037:                Map sessionMap = new LinkedHashMap();
038:
039:                ActionSupport action = new ActionSupport();
040:                action.addActionError("some action error 1");
041:                action.addActionError("some action error 2");
042:                action.addActionMessage("some action message 1");
043:                action.addActionMessage("some action message 2");
044:                action.addFieldError("field1", "some field error 1");
045:                action.addFieldError("field2", "some field error 2");
046:
047:                ActionContext actionContext = new ActionContext(new HashMap());
048:                actionContext.put(ActionContext.PARAMETERS, paramMap);
049:                actionContext.put(ActionContext.SESSION, sessionMap);
050:
051:                // Mock (ActionInvocation)
052:                MockControl mockControlActionInvocation = MockControl
053:                        .createControl(ActionInvocation.class);
054:                ActionInvocation mockActionInvocation = (ActionInvocation) mockControlActionInvocation
055:                        .getMock();
056:                mockControlActionInvocation.expectAndDefaultReturn(
057:                        mockActionInvocation.getInvocationContext(),
058:                        actionContext);
059:
060:                mockControlActionInvocation.expectAndDefaultReturn(
061:                        mockActionInvocation.invoke(), Action.SUCCESS);
062:
063:                mockControlActionInvocation.expectAndDefaultReturn(
064:                        mockActionInvocation.getAction(), action);
065:
066:                mockControlActionInvocation.replay();
067:
068:                interceptor.init();
069:                interceptor.intercept(mockActionInvocation);
070:                interceptor.destroy();
071:
072:                assertEquals(sessionMap.size(), 3);
073:                assertTrue(sessionMap
074:                        .containsKey(MessageStoreInterceptor.actionErrorsSessionKey));
075:                assertTrue(sessionMap
076:                        .containsKey(MessageStoreInterceptor.actionMessagesSessionKey));
077:                assertTrue(sessionMap
078:                        .containsKey(MessageStoreInterceptor.fieldErrorsSessionKey));
079:
080:                List actionErrors = (List) sessionMap
081:                        .get(MessageStoreInterceptor.actionErrorsSessionKey);
082:                List actionMessages = (List) sessionMap
083:                        .get(MessageStoreInterceptor.actionMessagesSessionKey);
084:                Map fieldErrors = (Map) sessionMap
085:                        .get(MessageStoreInterceptor.fieldErrorsSessionKey);
086:
087:                assertEquals(actionErrors.size(), 2);
088:                assertEquals(actionMessages.size(), 2);
089:                assertEquals(fieldErrors.size(), 2);
090:
091:                assertTrue(actionErrors.contains("some action error 1"));
092:                assertTrue(actionErrors.contains("some action error 2"));
093:                assertTrue(actionMessages.contains("some action message 1"));
094:                assertTrue(actionMessages.contains("some action message 2"));
095:                assertTrue(fieldErrors.containsKey("field1"));
096:                assertTrue(fieldErrors.containsKey("field2"));
097:                assertEquals(((List) fieldErrors.get("field1")).size(), 1);
098:                assertEquals(((List) fieldErrors.get("field2")).size(), 1);
099:                assertEquals(((List) fieldErrors.get("field1")).get(0),
100:                        "some field error 1");
101:                assertEquals(((List) fieldErrors.get("field2")).get(0),
102:                        "some field error 2");
103:
104:                mockControlActionInvocation.verify();
105:            }
106:
107:            public void testRetrieveMessage() throws Exception {
108:                MessageStoreInterceptor interceptor = new MessageStoreInterceptor();
109:                interceptor
110:                        .setOperationMode(MessageStoreInterceptor.RETRIEVE_MODE);
111:                interceptor.setAllowRequestParameterSwitch(true);
112:
113:                ActionSupport action = new ActionSupport();
114:
115:                MockControl mockControlActionInvocation = MockControl
116:                        .createControl(ActionInvocation.class);
117:                ActionInvocation mockActionInvocation = (ActionInvocation) mockControlActionInvocation
118:                        .getMock();
119:                mockControlActionInvocation.expectAndDefaultReturn(
120:                        mockActionInvocation.invoke(), Action.SUCCESS);
121:
122:                Map paramsMap = new LinkedHashMap();
123:                Map sessionMap = new LinkedHashMap();
124:
125:                List actionErrors = new ArrayList();
126:                List actionMessages = new ArrayList();
127:                Map fieldErrors = new LinkedHashMap();
128:
129:                actionErrors.add("some action error 1");
130:                actionErrors.add("some action error 2");
131:                actionMessages.add("some action messages 1");
132:                actionMessages.add("some action messages 2");
133:                List field1Errors = new ArrayList();
134:                field1Errors.add("some field error 1");
135:                List field2Errors = new ArrayList();
136:                field2Errors.add("some field error 2");
137:                fieldErrors.put("field1", field1Errors);
138:                fieldErrors.put("field2", field2Errors);
139:
140:                sessionMap.put(MessageStoreInterceptor.actionErrorsSessionKey,
141:                        actionErrors);
142:                sessionMap.put(
143:                        MessageStoreInterceptor.actionMessagesSessionKey,
144:                        actionMessages);
145:                sessionMap.put(MessageStoreInterceptor.fieldErrorsSessionKey,
146:                        fieldErrors);
147:
148:                ActionContext actionContext = new ActionContext(new HashMap());
149:                actionContext.put(ActionContext.PARAMETERS, paramsMap);
150:                actionContext.put(ActionContext.SESSION, sessionMap);
151:
152:                mockControlActionInvocation.expectAndDefaultReturn(
153:                        mockActionInvocation.getInvocationContext(),
154:                        actionContext);
155:
156:                mockControlActionInvocation.expectAndDefaultReturn(
157:                        mockActionInvocation.getAction(), action);
158:
159:                mockControlActionInvocation.replay();
160:
161:                interceptor.init();
162:                interceptor.intercept(mockActionInvocation);
163:                interceptor.destroy();
164:
165:                assertEquals(action.getActionErrors().size(), 2);
166:                assertEquals(action.getActionMessages().size(), 2);
167:                assertEquals(action.getFieldErrors().size(), 2);
168:                assertTrue(action.getActionErrors().contains(
169:                        "some action error 1"));
170:                assertTrue(action.getActionErrors().contains(
171:                        "some action error 2"));
172:                assertTrue(action.getActionMessages().contains(
173:                        "some action messages 1"));
174:                assertTrue(action.getActionMessages().contains(
175:                        "some action messages 2"));
176:                assertEquals(((List) action.getFieldErrors().get("field1"))
177:                        .size(), 1);
178:                assertEquals(((List) action.getFieldErrors().get("field2"))
179:                        .size(), 1);
180:                assertEquals(((List) action.getFieldErrors().get("field1"))
181:                        .get(0), "some field error 1");
182:                assertEquals(((List) action.getFieldErrors().get("field2"))
183:                        .get(0), "some field error 2");
184:
185:                mockControlActionInvocation.verify();
186:            }
187:
188:            public void testRequestOperationMode1() throws Exception {
189:
190:                Map paramMap = new LinkedHashMap();
191:                paramMap.put("operationMode",
192:                        new String[] { MessageStoreInterceptor.RETRIEVE_MODE });
193:
194:                ActionContext actionContext = new ActionContext(new HashMap());
195:                actionContext.put(ActionContext.PARAMETERS, paramMap);
196:
197:                MockControl mockControlActionInvocation = MockControl
198:                        .createControl(ActionInvocation.class);
199:                ActionInvocation mockActionInvocation = (ActionInvocation) mockControlActionInvocation
200:                        .getMock();
201:                mockControlActionInvocation.expectAndDefaultReturn(
202:                        mockActionInvocation.getInvocationContext(),
203:                        actionContext);
204:
205:                mockControlActionInvocation.replay();
206:
207:                MessageStoreInterceptor interceptor = new MessageStoreInterceptor();
208:                String operationMode = interceptor
209:                        .getRequestOperationMode(mockActionInvocation);
210:
211:                assertEquals(operationMode,
212:                        MessageStoreInterceptor.RETRIEVE_MODE);
213:
214:                mockControlActionInvocation.verify();
215:            }
216:
217:            public void testRequestOperationMode2() throws Exception {
218:
219:                Map paramMap = new LinkedHashMap();
220:                paramMap.put("operationMode",
221:                        new String[] { MessageStoreInterceptor.STORE_MODE });
222:
223:                ActionContext actionContext = new ActionContext(new HashMap());
224:                actionContext.put(ActionContext.PARAMETERS, paramMap);
225:
226:                MockControl mockControlActionInvocation = MockControl
227:                        .createControl(ActionInvocation.class);
228:                ActionInvocation mockActionInvocation = (ActionInvocation) mockControlActionInvocation
229:                        .getMock();
230:                mockControlActionInvocation.expectAndDefaultReturn(
231:                        mockActionInvocation.getInvocationContext(),
232:                        actionContext);
233:
234:                mockControlActionInvocation.replay();
235:
236:                MessageStoreInterceptor interceptor = new MessageStoreInterceptor();
237:                String operationMode = interceptor
238:                        .getRequestOperationMode(mockActionInvocation);
239:
240:                assertEquals(operationMode, MessageStoreInterceptor.STORE_MODE);
241:
242:                mockControlActionInvocation.verify();
243:            }
244:
245:            public void testRequestOperationMode3() throws Exception {
246:
247:                Map paramMap = new LinkedHashMap();
248:
249:                ActionContext actionContext = new ActionContext(new HashMap());
250:                actionContext.put(ActionContext.PARAMETERS, paramMap);
251:
252:                MockControl mockControlActionInvocation = MockControl
253:                        .createControl(ActionInvocation.class);
254:                ActionInvocation mockActionInvocation = (ActionInvocation) mockControlActionInvocation
255:                        .getMock();
256:                mockControlActionInvocation.expectAndDefaultReturn(
257:                        mockActionInvocation.getInvocationContext(),
258:                        actionContext);
259:
260:                mockControlActionInvocation.replay();
261:
262:                MessageStoreInterceptor interceptor = new MessageStoreInterceptor();
263:                String operationMode = interceptor
264:                        .getRequestOperationMode(mockActionInvocation);
265:
266:                assertEquals(operationMode, MessageStoreInterceptor.NONE);
267:
268:                mockControlActionInvocation.verify();
269:            }
270:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.