Source Code Cross Referenced for TestControllerRequestProcessor.java in  » Web-Framework » Strecks » org » strecks » controller » 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 » Strecks » org.strecks.controller 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005-2006 the original author or authors.
003:         * 
004:         * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
005:         * in compliance with the License. You may obtain a copy of the License at
006:         * 
007:         * http://www.apache.org/licenses/LICENSE-2.0
008:         * 
009:         * Unless required by applicable law or agreed to in writing, software distributed under the License
010:         * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
011:         * or implied. See the License for the specific language governing permissions and limitations under
012:         * the License.
013:         */
014:
015:        package org.strecks.controller;
016:
017:        import static org.easymock.EasyMock.expect;
018:        import static org.easymock.classextension.EasyMock.createMock;
019:        import static org.easymock.classextension.EasyMock.replay;
020:        import static org.easymock.classextension.EasyMock.verify;
021:
022:        import java.io.IOException;
023:
024:        import javax.servlet.ServletContext;
025:        import javax.servlet.ServletException;
026:        import javax.servlet.http.HttpServletRequest;
027:        import javax.servlet.http.HttpServletResponse;
028:
029:        import org.apache.struts.action.Action;
030:        import org.apache.struts.action.ActionForm;
031:        import org.apache.struts.action.ActionMapping;
032:        import org.apache.struts.action.ActionServlet;
033:        import org.apache.struts.config.ModuleConfig;
034:        import org.strecks.context.impl.TestContextFactoryImpl;
035:        import org.strecks.context.impl.TestContextImpl;
036:        import org.strecks.controller.impl.ReadOnlyControllerAction;
037:        import org.strecks.controller.impl.SimpleBindableForm;
038:        import org.strecks.controller.impl.TestAction;
039:        import org.strecks.form.controller.DelegatingForm;
040:        import org.strecks.form.controller.WrappingForm;
041:        import org.strecks.form.handler.FormWrapper;
042:        import org.strecks.form.handler.FormPopulateSource;
043:        import org.strecks.form.handler.FormPopulateSourceImpl;
044:        import org.strecks.form.handler.FormValidationHandler;
045:        import org.strecks.form.handler.FormValidationHandlerImpl;
046:        import org.strecks.form.handler.ValidateBindFormWrapper;
047:        import org.strecks.form.impl.SimpleStrutsForm;
048:        import org.strecks.preprocess.RequestPreprocessor;
049:        import org.testng.annotations.Test;
050:
051:        /**
052:         * @author Phil Zoio
053:         */
054:        public class TestControllerRequestProcessor {
055:
056:            // Note we can't test processValidate() and processActionForm() since they still use the superclass, for which the
057:            // dependencies must be resolved
058:
059:            @Test
060:            public void testInit() throws ServletException {
061:
062:                ModuleConfig config = createMock(ModuleConfig.class);
063:                ServletContext context = createMock(ServletContext.class);
064:                ActionServlet servlet = createMock(ActionServlet.class);
065:
066:                expect(servlet.getServletContext()).andReturn(context);
067:                expect(config.getPrefix()).andReturn("prefix");
068:
069:                replay(config);
070:                replay(context);
071:                replay(servlet);
072:
073:                ControllerRequestProcessor controllerRequestProcessor = new ControllerRequestProcessor();
074:                controllerRequestProcessor.init(servlet, config);
075:
076:                verify(config);
077:                verify(context);
078:                verify(servlet);
079:
080:                ControllerProcessorDelegate delegate = controllerRequestProcessor
081:                        .getDelegate();
082:                ActionCreator actionCreator = controllerRequestProcessor
083:                        .getActionCreator();
084:
085:                assert null != delegate;
086:                assert null != actionCreator;
087:
088:            }
089:
090:            @Test
091:            public void testProcessCachedMessages() throws ServletException,
092:                    IOException {
093:
094:                RequestPreprocessor handler = createMock(RequestPreprocessor.class);
095:
096:                handler.preprocessRequest(null);
097:
098:                replay(handler);
099:
100:                ControllerRequestProcessor controllerRequestProcessor = new ControllerRequestProcessor();
101:                controllerRequestProcessor.setRequestPreprocessor(handler);
102:                controllerRequestProcessor.preProcessCachedMessages(null);
103:
104:                verify(handler);
105:
106:            }
107:
108:            @Test
109:            public void testBasicProcessActionCreate() throws ServletException,
110:                    IOException {
111:
112:                ActionMapping mapping = createMock(ActionMapping.class);
113:                expect(mapping.getType()).andReturn(TestAction.class.getName())
114:                        .times(2);
115:
116:                replay(mapping);
117:
118:                ControllerRequestProcessor controllerRequestProcessor = new ControllerRequestProcessor();
119:                controllerRequestProcessor
120:                        .setActionCreator(new ActionCreatorImpl());
121:                Action action1 = controllerRequestProcessor
122:                        .processActionCreate(null, null, mapping);
123:                Action action2 = controllerRequestProcessor
124:                        .processActionCreate(null, null, mapping);
125:
126:                assert action1 != null;
127:                assert action1 instanceof  ReadOnlyControllerAction;
128:
129:                verify(mapping);
130:
131:                assert action1 != null;
132:                assert action1 == action2;
133:                assert controllerRequestProcessor.hasAction(TestAction.class
134:                        .getName());
135:
136:            }
137:
138:            @Test
139:            public void testProcessActionCreateInteractions() throws Exception {
140:
141:                ActionMapping mapping = createMock(ActionMapping.class);
142:                ActionCreatorImpl creator = createMock(ActionCreatorImpl.class);
143:
144:                expect(mapping.getType()).andReturn(TestAction.class.getName());
145:                expect(creator.createAction(TestAction.class)).andReturn(
146:                        new ReadOnlyControllerAction());
147:                expect(mapping.getType()).andReturn(TestAction.class.getName());
148:
149:                replay(mapping);
150:                replay(creator);
151:
152:                ControllerRequestProcessor controllerRequestProcessor = new ControllerRequestProcessor();
153:                controllerRequestProcessor.setActionCreator(creator);
154:
155:                Action action1 = controllerRequestProcessor
156:                        .processActionCreate(null, null, mapping);
157:                Action action2 = controllerRequestProcessor
158:                        .processActionCreate(null, null, mapping);
159:
160:                verify(mapping);
161:                verify(creator);
162:
163:                assert action1 != null;
164:                assert controllerRequestProcessor.hasAction(TestAction.class
165:                        .getName());
166:
167:                // check that same instance is returned
168:                assert action1 == action2;
169:
170:            }
171:
172:            /**
173:             * Tests standard action processing
174:             */
175:            @Test
176:            public void testProcessRegularAction() throws Exception {
177:
178:                Action action = createMock(Action.class);
179:                ModuleConfig config = createMock(ModuleConfig.class);
180:                ServletContext context = createMock(ServletContext.class);
181:                ActionServlet servlet = createMock(ActionServlet.class);
182:
183:                expect(servlet.getServletContext()).andReturn(context);
184:                expect(config.getPrefix()).andReturn("");
185:                expect(
186:                        action.execute(null, null, (HttpServletRequest) null,
187:                                (HttpServletResponse) null)).andReturn(null)
188:                        .times(1);
189:
190:                replay(action);
191:                replay(config);
192:                replay(context);
193:                replay(servlet);
194:
195:                ControllerRequestProcessor controllerRequestProcessor = new ControllerRequestProcessor();
196:                controllerRequestProcessor.init(servlet, config);
197:                controllerRequestProcessor
198:                        .setActionContextFactory(new TestContextFactoryImpl());
199:                controllerRequestProcessor.processActionPerform(null, null,
200:                        action, null, null);
201:
202:                verify(action);
203:                verify(config);
204:                verify(context);
205:                verify(servlet);
206:
207:            }
208:
209:            /**
210:             * Tests controller action processing
211:             */
212:            @Test
213:            public void testProcessControllerAction() throws Exception {
214:
215:                ModuleConfig config = createMock(ModuleConfig.class);
216:                ServletContext context = createMock(ServletContext.class);
217:                ActionServlet servlet = createMock(ActionServlet.class);
218:                ReadOnlyControllerAction action = createMock(ReadOnlyControllerAction.class);
219:                ControllerProcessorDelegate delegate = createMock(ControllerProcessorDelegate.class);
220:
221:                expect(servlet.getServletContext()).andReturn(context);
222:                expect(config.getPrefix()).andReturn("prefix");
223:                expect(
224:                        delegate.handleActionPerform(action,
225:                                new TestContextImpl())).andReturn(null)
226:                        .times(1);
227:
228:                replay(action);
229:                replay(config);
230:                replay(context);
231:                replay(servlet);
232:
233:                ControllerRequestProcessor controllerRequestProcessor = new ControllerRequestProcessor();
234:                controllerRequestProcessor.init(servlet, config);
235:                controllerRequestProcessor.setDelegate(delegate);
236:                controllerRequestProcessor
237:                        .setActionContextFactory(new TestContextFactoryImpl());
238:                controllerRequestProcessor.processActionPerform(null, null,
239:                        action, null, null);
240:
241:                verify(action);
242:                verify(config);
243:                verify(context);
244:                verify(servlet);
245:
246:            }
247:
248:            /**
249:             * Tests null action form
250:             */
251:            @Test
252:            public void testPostProcessActionForm1() throws Exception {
253:                FormWrapper delegate = createMock(FormWrapper.class);
254:
255:                replay(delegate);
256:
257:                ControllerRequestProcessor processor = new ControllerRequestProcessor();
258:                processor.setFormHandler(delegate);
259:
260:                processor.postProcessActionForm(null, null, null);
261:
262:                verify(delegate);
263:
264:            }
265:
266:            /**
267:             * Tests standard Struts action form
268:             */
269:            @Test
270:            public void testPostProcessActionForm2() throws Exception {
271:                FormWrapper delegate = createMock(FormWrapper.class);
272:                ActionForm form = new ActionForm() {
273:
274:                    private static final long serialVersionUID = 1L;
275:                };
276:
277:                expect(delegate.wrapForm(form, null)).andReturn(form);
278:                replay(delegate);
279:
280:                ControllerRequestProcessor processor = new ControllerRequestProcessor();
281:                processor.setFormHandler(delegate);
282:
283:                processor.postProcessActionForm(null, null, form);
284:
285:                verify(delegate);
286:
287:            }
288:
289:            /**
290:             * Tests interaction of form
291:             */
292:            @Test
293:            public void testValidBindingForm2() throws Exception {
294:
295:                FormWrapper delegate = createMock(FormWrapper.class);
296:                DelegatingForm form = createMock(DelegatingForm.class);
297:
298:                expect(delegate.wrapForm(form, null)).andReturn(form);
299:                delegate.handleBindingForm(form, null);
300:                delegate.handleValidForm(form, null);
301:
302:                replay(delegate);
303:
304:                ControllerRequestProcessor processor = new ControllerRequestProcessor();
305:                processor.setFormHandler(delegate);
306:
307:                processor.postProcessActionForm(null, null, form);
308:
309:                verify(delegate);
310:
311:            }
312:
313:            /**
314:             * Tests Form which is both <code>Validatable</code> and <code>Bindable</code>
315:             */
316:            @Test
317:            public void testValidBindingForm3() throws Exception {
318:                HttpServletRequest request = createMock(HttpServletRequest.class);
319:
320:                FormWrapper delegate = new ValidateBindFormWrapper();
321:                SimpleBindableForm simpleBindableForm = new SimpleBindableForm();
322:
323:                ControllerRequestProcessor processor = new ControllerRequestProcessor();
324:                processor.setFormHandler(delegate);
325:
326:                assert processor.postProcessActionForm(request, null,
327:                        simpleBindableForm) instanceof  WrappingForm;
328:
329:            }
330:
331:            /**
332:             * Tests Form which is both <code>Validatable</code> and <code>Bindable</code>
333:             */
334:            @Test
335:            public void testValidBindingForm4() throws Exception {
336:                HttpServletRequest request = createMock(HttpServletRequest.class);
337:
338:                FormWrapper delegate = new ValidateBindFormWrapper();
339:                ActionForm actionForm = new SimpleStrutsForm();
340:
341:                ControllerRequestProcessor processor = new ControllerRequestProcessor();
342:                processor.setFormHandler(delegate);
343:
344:                assert (processor.postProcessActionForm(request, null,
345:                        actionForm) == actionForm);
346:
347:            }
348:
349:            /**
350:             * Checks prepopulate for returning raw form
351:             */
352:            @Test
353:            public void testPrePopulate2() throws Exception {
354:
355:                FormPopulateSource delegate = new FormPopulateSourceImpl();
356:                ActionForm actionForm = new SimpleStrutsForm();
357:                DelegatingForm delegator = new DelegatingForm(actionForm);
358:
359:                ControllerRequestProcessor processor = new ControllerRequestProcessor();
360:                processor.setFormPopulationSource(delegate);
361:
362:                assert actionForm == processor.prePopulate(delegator, null);
363:                assert actionForm == processor.prePopulate(actionForm, null);
364:
365:            }
366:
367:            /**
368:             * Checks preValidate for returning form passed in
369:             */
370:            @Test
371:            public void testPreValidate() throws Exception {
372:
373:                FormValidationHandler delegate = new FormValidationHandlerImpl();
374:                ActionForm actionForm = new SimpleStrutsForm();
375:                DelegatingForm delegator = new DelegatingForm(actionForm);
376:
377:                ControllerRequestProcessor processor = new ControllerRequestProcessor();
378:                processor.setFormValidationHandler(delegate);
379:
380:                assert delegator == processor.preValidate(delegator, null);
381:                assert actionForm == processor.preValidate(actionForm, null);
382:
383:            }
384:
385:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.