Source Code Cross Referenced for TestCopyFormToContext.java in  » Web-Framework » struts-1.3.8 » org » apache » struts » chain » commands » generic » 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 1.3.8 » org.apache.struts.chain.commands.generic 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: TestCopyFormToContext.java 471754 2006-11-06 14:55:09Z 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.struts.chain.commands.generic;
022:
023:        import junit.framework.TestCase;
024:
025:        import org.apache.struts.action.ActionForm;
026:        import org.apache.struts.action.DynaActionForm;
027:        import org.apache.struts.chain.contexts.MockActionContext;
028:        import org.apache.struts.config.ActionConfig;
029:        import org.apache.struts.config.FormBeanConfig;
030:        import org.apache.struts.config.FormPropertyConfig;
031:        import org.apache.struts.config.impl.ModuleConfigImpl;
032:        import org.apache.struts.mock.MockFormBean;
033:
034:        /**
035:         * @version $Id: TestCopyFormToContext.java 161516 2005-04-15 19:22:47Z
036:         *          germuska $
037:         */
038:        public class TestCopyFormToContext extends TestCase {
039:            private static final String POST_EXECUTION_CONTEXT_KEY = "afterTest";
040:            private MockActionContext context = null;
041:
042:            public static void main(String[] args) {
043:                junit.textui.TestRunner.run(TestCopyFormToContext.class);
044:            }
045:
046:            /*
047:             * @see TestCase#setUp()
048:             */
049:            protected void setUp() throws Exception {
050:                context = new MockActionContext();
051:
052:                ModuleConfigImpl moduleConfig = new ModuleConfigImpl("/");
053:
054:                context.setModuleConfig(moduleConfig);
055:
056:                FormBeanConfig fooFBC = new FormBeanConfig();
057:
058:                fooFBC.setName("foo");
059:                fooFBC.setType("org.apache.struts.mock.MockFormBean");
060:                moduleConfig.addFormBeanConfig(fooFBC);
061:
062:                FormBeanConfig barFBC = new FormBeanConfig();
063:
064:                barFBC.setName("bar");
065:                barFBC.setType("org.apache.struts.action.DynaActionForm"); // use a different type so we can verify lookups better
066:
067:                FormPropertyConfig fpc = new FormPropertyConfig();
068:
069:                fpc.setName("property");
070:                fpc.setType("java.lang.String");
071:                fpc.setInitial("test");
072:                barFBC.addFormPropertyConfig(fpc);
073:                moduleConfig.addFormBeanConfig(barFBC);
074:
075:                ActionConfig testActionConfig = new ActionConfig();
076:
077:                testActionConfig.setPath("/Test");
078:                testActionConfig.setName("foo");
079:                testActionConfig.setScope("request");
080:                moduleConfig.addActionConfig(testActionConfig);
081:
082:                moduleConfig.freeze(); // otherwise, ActionConfigMatcher will be null and we'll get an NPE...
083:            }
084:
085:            public void testLookupByNameAndRequestScope() throws Exception {
086:                CopyFormToContext command = new CopyFormToContext();
087:                String formName = "foo";
088:
089:                command.setFormName(formName);
090:                command.setScope("request");
091:                command.setToKey(POST_EXECUTION_CONTEXT_KEY);
092:
093:                assertNull(context.get(POST_EXECUTION_CONTEXT_KEY));
094:                assertNull(context.getRequestScope().get(formName));
095:                assertNull(context.getSessionScope().get(formName));
096:
097:                command.execute(context);
098:
099:                assertNotNull(context.get(POST_EXECUTION_CONTEXT_KEY));
100:                assertNotNull(context.getRequestScope().get(formName));
101:                assertNull(context.getSessionScope().get(formName));
102:
103:                assertSame(context.get(POST_EXECUTION_CONTEXT_KEY), context
104:                        .getRequestScope().get(formName));
105:
106:                ActionForm theForm = (ActionForm) context
107:                        .get(POST_EXECUTION_CONTEXT_KEY);
108:
109:                assertTrue(theForm instanceof  MockFormBean);
110:            }
111:
112:            public void testLookupByActionPath() throws Exception {
113:                CopyFormToContext command = new CopyFormToContext();
114:
115:                command.setActionPath("/Test");
116:                command.setToKey(POST_EXECUTION_CONTEXT_KEY);
117:
118:                String formName = "foo"; // we know this, even though it's not being used for the lookup.
119:
120:                assertNull(context.get(POST_EXECUTION_CONTEXT_KEY));
121:                assertNull(context.getRequestScope().get(formName));
122:                assertNull(context.getSessionScope().get(formName));
123:
124:                command.execute(context);
125:
126:                assertNotNull(context.get(POST_EXECUTION_CONTEXT_KEY));
127:                assertNotNull(context.getRequestScope().get(formName));
128:                assertNull(context.getSessionScope().get(formName));
129:
130:                assertSame(context.get(POST_EXECUTION_CONTEXT_KEY), context
131:                        .getRequestScope().get(formName));
132:
133:                ActionForm theForm = (ActionForm) context
134:                        .get(POST_EXECUTION_CONTEXT_KEY);
135:
136:                assertTrue(theForm instanceof  MockFormBean);
137:            }
138:
139:            public void testLookupByNameAndSessionScope() throws Exception {
140:                CopyFormToContext command = new CopyFormToContext();
141:                String formName = "bar";
142:
143:                command.setFormName(formName);
144:                command.setScope("session");
145:                command.setToKey(POST_EXECUTION_CONTEXT_KEY);
146:
147:                assertNull(context.get(POST_EXECUTION_CONTEXT_KEY));
148:                assertNull(context.getRequestScope().get(formName));
149:                assertNull(context.getSessionScope().get(formName));
150:
151:                command.execute(context);
152:
153:                assertNotNull(context.get(POST_EXECUTION_CONTEXT_KEY));
154:                assertNull(context.getRequestScope().get(formName));
155:                assertNotNull(context.getSessionScope().get(formName));
156:
157:                assertSame(context.get(POST_EXECUTION_CONTEXT_KEY), context
158:                        .getSessionScope().get(formName));
159:
160:                ActionForm theForm = (ActionForm) context
161:                        .get(POST_EXECUTION_CONTEXT_KEY);
162:
163:                assertTrue(theForm instanceof  DynaActionForm);
164:
165:                DynaActionForm dForm = (DynaActionForm) theForm;
166:
167:                assertEquals("test", dForm.get("property"));
168:            }
169:
170:            public void testExceptionHandlingWithNullFormName()
171:                    throws Exception {
172:                CopyFormToContext command = new CopyFormToContext();
173:                String formName = "bar";
174:
175:                // skip setting form name to test exception
176:                // command.setFormName(formName);
177:                command.setScope("session");
178:                command.setToKey(POST_EXECUTION_CONTEXT_KEY);
179:
180:                assertNull(context.get(POST_EXECUTION_CONTEXT_KEY));
181:                assertNull(context.getRequestScope().get(formName));
182:                assertNull(context.getSessionScope().get(formName));
183:
184:                try {
185:                    command.execute(context);
186:                    fail("Execution should throw an exception when form name is not set.");
187:                } catch (IllegalStateException e) {
188:                    ; // expected.
189:                }
190:            }
191:
192:            public void testExceptionHandlingWithNullEverything()
193:                    throws Exception {
194:                CopyFormToContext command = new CopyFormToContext();
195:                String formName = "bar";
196:
197:                // skip setting form name to test exception
198:                // command.setFormName(formName);
199:                // command.setScope("session");
200:                // command.setToKey(POST_EXECUTION_CONTEXT_KEY);
201:                assertNull(context.get(POST_EXECUTION_CONTEXT_KEY));
202:                assertNull(context.getRequestScope().get(formName));
203:                assertNull(context.getSessionScope().get(formName));
204:
205:                try {
206:                    command.execute(context);
207:                    fail("Execution should throw an exception when no properties are set.");
208:                } catch (IllegalStateException e) {
209:                    ; // expected.
210:                }
211:            }
212:
213:            public void testCopyToDefaultContextKey() throws Exception {
214:                CopyFormToContext command = new CopyFormToContext();
215:                String formName = "foo";
216:
217:                command.setFormName(formName);
218:                command.setScope("request");
219:
220:                assertNull(context.getActionForm());
221:                assertNull(context.getRequestScope().get(
222:                        POST_EXECUTION_CONTEXT_KEY));
223:                assertNull(context.getSessionScope().get(
224:                        POST_EXECUTION_CONTEXT_KEY));
225:
226:                command.execute(context);
227:
228:                assertNotNull(context.getActionForm());
229:                assertNotNull(context.getRequestScope().get(formName));
230:                assertNull(context.getSessionScope().get(formName));
231:
232:                assertSame(context.getActionForm(), context.getRequestScope()
233:                        .get(formName));
234:
235:                ActionForm theForm = (ActionForm) context.getActionForm();
236:
237:                assertTrue(theForm instanceof  MockFormBean);
238:            }
239:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.