Source Code Cross Referenced for MessageStoreInterceptorTest.java in  » Web-Framework » struts-2.0.11 » org » apache » struts2 » 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 » Web Framework » struts 2.0.11 » org.apache.struts2.interceptor 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: MessageStoreInterceptorTest.java 471756 2006-11-06 15:01:43Z husted $
003:         *
004:         * Licensed to the Apache Software Foundation (ASF) under one
005:         * or more contributor license agreements.  See the NOTICE file
006:         * distributed with this work for additional information
007:         * regarding copyright ownership.  The ASF licenses this file
008:         * to you under the Apache License, Version 2.0 (the
009:         * "License"); you may not use this file except in compliance
010:         * with the License.  You may obtain a copy of the License at
011:         *
012:         *  http://www.apache.org/licenses/LICENSE-2.0
013:         *
014:         * Unless required by applicable law or agreed to in writing,
015:         * software distributed under the License is distributed on an
016:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017:         * KIND, either express or implied.  See the License for the
018:         * specific language governing permissions and limitations
019:         * under the License.
020:         */
021:        package org.apache.struts2.interceptor;
022:
023:        import java.util.ArrayList;
024:        import java.util.HashMap;
025:        import java.util.LinkedHashMap;
026:        import java.util.List;
027:        import java.util.Map;
028:
029:        import org.apache.struts2.StrutsTestCase;
030:        import org.easymock.EasyMock;
031:
032:        import com.opensymphony.xwork2.Action;
033:        import com.opensymphony.xwork2.ActionContext;
034:        import com.opensymphony.xwork2.ActionInvocation;
035:        import com.opensymphony.xwork2.ActionSupport;
036:
037:        /**
038:         * Test case for MessageStoreInterceptor.
039:         *
040:         * @version $Date: 2006-11-06 10:01:43 -0500 (Mon, 06 Nov 2006) $ $Id: MessageStoreInterceptorTest.java 471756 2006-11-06 15:01:43Z husted $
041:         */
042:        public class MessageStoreInterceptorTest extends StrutsTestCase {
043:
044:            public void testStoreMessage() throws Exception {
045:                MessageStoreInterceptor interceptor = new MessageStoreInterceptor();
046:                interceptor.setAllowRequestParameterSwitch(true);
047:                interceptor
048:                        .setOperationMode(MessageStoreInterceptor.STORE_MODE);
049:
050:                Map paramMap = new LinkedHashMap();
051:                Map sessionMap = new LinkedHashMap();
052:
053:                ActionSupport action = new ActionSupport();
054:                action.addActionError("some action error 1");
055:                action.addActionError("some action error 2");
056:                action.addActionMessage("some action message 1");
057:                action.addActionMessage("some action message 2");
058:                action.addFieldError("field1", "some field error 1");
059:                action.addFieldError("field2", "some field error 2");
060:
061:                ActionContext actionContext = new ActionContext(new HashMap());
062:                actionContext.put(ActionContext.PARAMETERS, paramMap);
063:                actionContext.put(ActionContext.SESSION, sessionMap);
064:
065:                // Mock (ActionInvocation)
066:                ActionInvocation mockActionInvocation = EasyMock
067:                        .createControl().createMock(ActionInvocation.class);
068:                mockActionInvocation.getInvocationContext();
069:                EasyMock.expectLastCall().andReturn(actionContext);
070:                EasyMock.expectLastCall().anyTimes();
071:
072:                mockActionInvocation.invoke();
073:                EasyMock.expectLastCall().andReturn(Action.SUCCESS);
074:
075:                mockActionInvocation.getAction();
076:                EasyMock.expectLastCall().andReturn(action);
077:
078:                EasyMock.replay(mockActionInvocation);
079:
080:                interceptor.init();
081:                interceptor.intercept(mockActionInvocation);
082:                interceptor.destroy();
083:
084:                assertEquals(sessionMap.size(), 3);
085:                assertTrue(sessionMap
086:                        .containsKey(MessageStoreInterceptor.actionErrorsSessionKey));
087:                assertTrue(sessionMap
088:                        .containsKey(MessageStoreInterceptor.actionMessagesSessionKey));
089:                assertTrue(sessionMap
090:                        .containsKey(MessageStoreInterceptor.fieldErrorsSessionKey));
091:
092:                List actionErrors = (List) sessionMap
093:                        .get(MessageStoreInterceptor.actionErrorsSessionKey);
094:                List actionMessages = (List) sessionMap
095:                        .get(MessageStoreInterceptor.actionMessagesSessionKey);
096:                Map fieldErrors = (Map) sessionMap
097:                        .get(MessageStoreInterceptor.fieldErrorsSessionKey);
098:
099:                assertEquals(actionErrors.size(), 2);
100:                assertEquals(actionMessages.size(), 2);
101:                assertEquals(fieldErrors.size(), 2);
102:
103:                assertTrue(actionErrors.contains("some action error 1"));
104:                assertTrue(actionErrors.contains("some action error 2"));
105:                assertTrue(actionMessages.contains("some action message 1"));
106:                assertTrue(actionMessages.contains("some action message 2"));
107:                assertTrue(fieldErrors.containsKey("field1"));
108:                assertTrue(fieldErrors.containsKey("field2"));
109:                assertEquals(((List) fieldErrors.get("field1")).size(), 1);
110:                assertEquals(((List) fieldErrors.get("field2")).size(), 1);
111:                assertEquals(((List) fieldErrors.get("field1")).get(0),
112:                        "some field error 1");
113:                assertEquals(((List) fieldErrors.get("field2")).get(0),
114:                        "some field error 2");
115:
116:                EasyMock.verify(mockActionInvocation);
117:            }
118:
119:            public void testRetrieveMessage() throws Exception {
120:                MessageStoreInterceptor interceptor = new MessageStoreInterceptor();
121:                interceptor
122:                        .setOperationMode(MessageStoreInterceptor.RETRIEVE_MODE);
123:                interceptor.setAllowRequestParameterSwitch(true);
124:
125:                ActionSupport action = new ActionSupport();
126:
127:                ActionInvocation mockActionInvocation = EasyMock
128:                        .createControl().createMock(ActionInvocation.class);
129:                mockActionInvocation.invoke();
130:                EasyMock.expectLastCall().andReturn(Action.SUCCESS);
131:
132:                Map paramsMap = new LinkedHashMap();
133:                Map sessionMap = new LinkedHashMap();
134:
135:                List actionErrors = new ArrayList();
136:                List actionMessages = new ArrayList();
137:                Map fieldErrors = new LinkedHashMap();
138:
139:                actionErrors.add("some action error 1");
140:                actionErrors.add("some action error 2");
141:                actionMessages.add("some action messages 1");
142:                actionMessages.add("some action messages 2");
143:                List field1Errors = new ArrayList();
144:                field1Errors.add("some field error 1");
145:                List field2Errors = new ArrayList();
146:                field2Errors.add("some field error 2");
147:                fieldErrors.put("field1", field1Errors);
148:                fieldErrors.put("field2", field2Errors);
149:
150:                sessionMap.put(MessageStoreInterceptor.actionErrorsSessionKey,
151:                        actionErrors);
152:                sessionMap.put(
153:                        MessageStoreInterceptor.actionMessagesSessionKey,
154:                        actionMessages);
155:                sessionMap.put(MessageStoreInterceptor.fieldErrorsSessionKey,
156:                        fieldErrors);
157:
158:                ActionContext actionContext = new ActionContext(new HashMap());
159:                actionContext.put(ActionContext.PARAMETERS, paramsMap);
160:                actionContext.put(ActionContext.SESSION, sessionMap);
161:
162:                mockActionInvocation.getInvocationContext();
163:                EasyMock.expectLastCall().andReturn(actionContext);
164:                EasyMock.expectLastCall().anyTimes();
165:
166:                mockActionInvocation.getAction();
167:                EasyMock.expectLastCall().andReturn(action);
168:
169:                EasyMock.replay(mockActionInvocation);
170:
171:                interceptor.init();
172:                interceptor.intercept(mockActionInvocation);
173:                interceptor.destroy();
174:
175:                assertEquals(action.getActionErrors().size(), 2);
176:                assertEquals(action.getActionMessages().size(), 2);
177:                assertEquals(action.getFieldErrors().size(), 2);
178:                assertTrue(action.getActionErrors().contains(
179:                        "some action error 1"));
180:                assertTrue(action.getActionErrors().contains(
181:                        "some action error 2"));
182:                assertTrue(action.getActionMessages().contains(
183:                        "some action messages 1"));
184:                assertTrue(action.getActionMessages().contains(
185:                        "some action messages 2"));
186:                assertEquals(((List) action.getFieldErrors().get("field1"))
187:                        .size(), 1);
188:                assertEquals(((List) action.getFieldErrors().get("field2"))
189:                        .size(), 1);
190:                assertEquals(((List) action.getFieldErrors().get("field1"))
191:                        .get(0), "some field error 1");
192:                assertEquals(((List) action.getFieldErrors().get("field2"))
193:                        .get(0), "some field error 2");
194:
195:                EasyMock.verify(mockActionInvocation);
196:            }
197:
198:            public void testRequestOperationMode1() throws Exception {
199:
200:                Map paramMap = new LinkedHashMap();
201:                paramMap.put("operationMode",
202:                        new String[] { MessageStoreInterceptor.RETRIEVE_MODE });
203:
204:                ActionContext actionContext = new ActionContext(new HashMap());
205:                actionContext.put(ActionContext.PARAMETERS, paramMap);
206:
207:                ActionInvocation mockActionInvocation = EasyMock
208:                        .createControl().createMock(ActionInvocation.class);
209:                mockActionInvocation.getInvocationContext();
210:                EasyMock.expectLastCall().andReturn(actionContext);
211:                EasyMock.expectLastCall().anyTimes();
212:
213:                EasyMock.replay(mockActionInvocation);
214:
215:                MessageStoreInterceptor interceptor = new MessageStoreInterceptor();
216:                String operationMode = interceptor
217:                        .getRequestOperationMode(mockActionInvocation);
218:
219:                assertEquals(operationMode,
220:                        MessageStoreInterceptor.RETRIEVE_MODE);
221:
222:                EasyMock.verify(mockActionInvocation);
223:            }
224:
225:            public void testRequestOperationMode2() throws Exception {
226:
227:                Map paramMap = new LinkedHashMap();
228:                paramMap.put("operationMode",
229:                        new String[] { MessageStoreInterceptor.STORE_MODE });
230:
231:                ActionContext actionContext = new ActionContext(new HashMap());
232:                actionContext.put(ActionContext.PARAMETERS, paramMap);
233:
234:                ActionInvocation mockActionInvocation = EasyMock
235:                        .createControl().createMock(ActionInvocation.class);
236:                mockActionInvocation.getInvocationContext();
237:                EasyMock.expectLastCall().andReturn(actionContext);
238:                EasyMock.expectLastCall().anyTimes();
239:
240:                EasyMock.replay(mockActionInvocation);
241:
242:                MessageStoreInterceptor interceptor = new MessageStoreInterceptor();
243:                String operationMode = interceptor
244:                        .getRequestOperationMode(mockActionInvocation);
245:
246:                assertEquals(operationMode, MessageStoreInterceptor.STORE_MODE);
247:
248:                EasyMock.verify(mockActionInvocation);
249:            }
250:
251:            public void testRequestOperationMode3() throws Exception {
252:
253:                Map paramMap = new LinkedHashMap();
254:
255:                ActionContext actionContext = new ActionContext(new HashMap());
256:                actionContext.put(ActionContext.PARAMETERS, paramMap);
257:
258:                ActionInvocation mockActionInvocation = EasyMock
259:                        .createControl().createMock(ActionInvocation.class);
260:                mockActionInvocation.getInvocationContext();
261:                EasyMock.expectLastCall().andReturn(actionContext);
262:                EasyMock.expectLastCall().anyTimes();
263:
264:                EasyMock.replay(mockActionInvocation);
265:
266:                MessageStoreInterceptor interceptor = new MessageStoreInterceptor();
267:                String operationMode = interceptor
268:                        .getRequestOperationMode(mockActionInvocation);
269:
270:                assertEquals(operationMode, MessageStoreInterceptor.NONE);
271:
272:                EasyMock.verify(mockActionInvocation);
273:
274:            }
275:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.