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


001:        /*
002:         * Copyright (c) 2002-2006 by OpenSymphony
003:         * All rights reserved.
004:         */
005:        package com.opensymphony.webwork.views.jsp;
006:
007:        import com.opensymphony.webwork.ServletActionContext;
008:        import com.opensymphony.webwork.TestAction;
009:        import com.opensymphony.webwork.TestActionTagResult;
010:        import com.opensymphony.webwork.TestConfigurationProvider;
011:        import com.opensymphony.webwork.components.ActionComponent;
012:        import com.opensymphony.xwork.Action;
013:        import com.opensymphony.xwork.ActionContext;
014:        import com.opensymphony.xwork.ActionProxy;
015:        import com.opensymphony.xwork.ActionInvocation;
016:        import com.opensymphony.xwork.config.ConfigurationManager;
017:        import com.opensymphony.xwork.util.OgnlValueStack;
018:
019:        import javax.servlet.jsp.JspException;
020:        import javax.servlet.jsp.PageContext;
021:        import java.util.Map;
022:
023:        /**
024:         * Unit test for {@link ActionTag}.
025:         *
026:         * @author Jason Carreira
027:         * @author tmjee ( tm_jee(at)yahoo.co.uk )
028:         */
029:        public class ActionTagTest extends AbstractTagTest {
030:
031:            public void testActionTagWithNamespace() {
032:                request
033:                        .setupGetServletPath(TestConfigurationProvider.TEST_NAMESPACE
034:                                + "/" + "foo.action");
035:
036:                ActionTag tag = new ActionTag();
037:                tag.setPageContext(pageContext);
038:                tag.setName(TestConfigurationProvider.TEST_NAMESPACE_ACTION);
039:                tag.setId(TestConfigurationProvider.TEST_NAMESPACE_ACTION);
040:
041:                try {
042:                    tag.doStartTag();
043:                    ActionComponent ac = ((ActionComponent) tag.component);
044:                    tag.doEndTag();
045:                    ActionProxy proxy = ac.getProxy();
046:
047:                    Object o = pageContext
048:                            .findAttribute(TestConfigurationProvider.TEST_NAMESPACE_ACTION);
049:                    assertTrue(o instanceof  TestAction);
050:
051:                    assertEquals(TestConfigurationProvider.TEST_NAMESPACE,
052:                            proxy.getNamespace());
053:                } catch (JspException ex) {
054:                    ex.printStackTrace();
055:                    fail();
056:                }
057:            }
058:
059:            public void testSimple() {
060:                request.setupGetServletPath("/foo.action");
061:
062:                ActionTag tag = new ActionTag();
063:                tag.setPageContext(pageContext);
064:                tag.setName("testAction");
065:                tag.setId("testAction");
066:
067:                int stackSize = stack.size();
068:
069:                try {
070:                    tag.doStartTag();
071:                    tag.addParameter("foo", "myFoo");
072:                    tag.doEndTag();
073:
074:                    assertEquals(stack.size(), ActionContext.getContext()
075:                            .getValueStack().size());
076:                    assertEquals("myFoo", stack.findValue("#testAction.foo"));
077:                    assertEquals(stackSize, stack.size());
078:
079:                    Object o = pageContext.findAttribute("testAction");
080:                    assertTrue(o instanceof  TestAction);
081:                    assertEquals("myFoo", ((TestAction) o).getFoo());
082:                    assertEquals(Action.SUCCESS, ((TestAction) o).getResult());
083:                } catch (JspException ex) {
084:                    ex.printStackTrace();
085:                    fail();
086:                }
087:            }
088:
089:            public void testSimpleWithoutServletActionContext() {
090:                ServletActionContext.setRequest(null);
091:                ServletActionContext.setResponse(null);
092:                this .testSimple();
093:            }
094:
095:            public void testActionWithExecuteResult() throws Exception {
096:                ActionTag tag = new ActionTag();
097:                tag.setPageContext(pageContext);
098:                tag.setNamespace("");
099:                tag.setName("testActionTagAction");
100:                tag.setExecuteResult(true);
101:
102:                tag.doStartTag();
103:
104:                // tag clear components on doEndTag
105:                ActionComponent component = (ActionComponent) tag
106:                        .getComponent();
107:
108:                tag.doEndTag();
109:
110:                TestActionTagResult result = (TestActionTagResult) component
111:                        .getProxy().getInvocation().getResult();
112:
113:                assertTrue(stack.getContext().containsKey(
114:                        ServletActionContext.PAGE_CONTEXT));
115:                assertTrue(stack.getContext().get(
116:                        ServletActionContext.PAGE_CONTEXT) instanceof  PageContext);
117:                assertTrue(result.isExecuted());
118:            }
119:
120:            public void testActionWithoutExecuteResult() throws Exception {
121:                ActionTag tag = new ActionTag();
122:                tag.setPageContext(pageContext);
123:                tag.setNamespace("");
124:                tag.setName("testActionTagAction");
125:                tag.setExecuteResult(false);
126:
127:                tag.doStartTag();
128:
129:                // tag clear components on doEndTag, so we need to get it here
130:                ActionComponent component = (ActionComponent) tag
131:                        .getComponent();
132:
133:                tag.doEndTag();
134:
135:                TestActionTagResult result = (TestActionTagResult) component
136:                        .getProxy().getInvocation().getResult();
137:
138:                assertTrue(stack.getContext().containsKey(
139:                        ServletActionContext.PAGE_CONTEXT));
140:                assertTrue(stack.getContext().get(
141:                        ServletActionContext.PAGE_CONTEXT) instanceof  PageContext);
142:                assertNull(result); // result is never executed, hence never set into invocation
143:            }
144:
145:            public void testIngoreContextParamsFalse() throws Exception {
146:                ActionTag tag = new ActionTag();
147:                tag.setPageContext(pageContext);
148:                tag.setNamespace("");
149:                tag.setName("testActionTagAction");
150:                tag.setExecuteResult(false);
151:                tag.setIgnoreContextParams(false);
152:                ActionContext.getContext().getParameters().put("user",
153:                        "Santa Claus");
154:
155:                tag.doStartTag();
156:
157:                // tag clear components on doEndTag, so we need to get it here
158:                ActionComponent component = (ActionComponent) tag
159:                        .getComponent();
160:
161:                tag.doEndTag();
162:
163:                // check parameters, there should be one
164:                ActionInvocation ai = component.getProxy().getInvocation();
165:                ActionContext ac = ai.getInvocationContext();
166:                assertEquals(1, ac.getParameters().size());
167:            }
168:
169:            public void testIngoreContextParamsTrue() throws Exception {
170:                ActionTag tag = new ActionTag();
171:                tag.setPageContext(pageContext);
172:                tag.setNamespace("");
173:                tag.setName("testActionTagAction");
174:                tag.setExecuteResult(false);
175:                tag.setIgnoreContextParams(true);
176:                ActionContext.getContext().getParameters().put("user",
177:                        "Santa Claus");
178:
179:                tag.doStartTag();
180:
181:                // tag clear components on doEndTag, so we need to get it here
182:                ActionComponent component = (ActionComponent) tag
183:                        .getComponent();
184:
185:                tag.doEndTag();
186:
187:                // check parameters, there should be one
188:                ActionInvocation ai = component.getProxy().getInvocation();
189:                ActionContext ac = ai.getInvocationContext();
190:                assertEquals(0, ac.getParameters().size());
191:            }
192:
193:            public void testNoNameDefined() throws Exception {
194:                ActionTag tag = new ActionTag();
195:                tag.setPageContext(pageContext);
196:                tag.setNamespace("");
197:                tag.setName(null);
198:                tag.setExecuteResult(false);
199:
200:                try {
201:                    tag.doStartTag();
202:                    tag.doEndTag();
203:                    fail("Should have thrown RuntimeException");
204:                } catch (RuntimeException e) {
205:                    assertEquals(
206:                            "tag 'actioncomponent', field 'name': Action name is required. Example: updatePerson",
207:                            e.getMessage());
208:                }
209:            }
210:
211:            public void testUnknownNameDefined() throws Exception {
212:                ActionTag tag = new ActionTag();
213:                tag.setPageContext(pageContext);
214:                tag.setNamespace("");
215:                tag.setName("UNKNOWN_NAME");
216:                tag.setExecuteResult(false);
217:
218:                tag.doStartTag();
219:                tag.doEndTag();
220:                // will just log it to ERROR but we run th code to test that it works somehow
221:            }
222:
223:            public void testActionMethodWithExecuteResult() throws Exception {
224:                ActionTag tag = new ActionTag();
225:                tag.setPageContext(pageContext);
226:                tag.setNamespace("");
227:                tag.setName("testActionTagAction!input");
228:                tag.setExecuteResult(true);
229:
230:                tag.doStartTag();
231:
232:                // tag clear components on doEndTag
233:                ActionComponent component = (ActionComponent) tag
234:                        .getComponent();
235:
236:                tag.doEndTag();
237:
238:                TestActionTagResult result = (TestActionTagResult) component
239:                        .getProxy().getInvocation().getResult();
240:
241:                assertTrue(stack.getContext().containsKey(
242:                        ServletActionContext.PAGE_CONTEXT));
243:                assertTrue(stack.getContext().get(
244:                        ServletActionContext.PAGE_CONTEXT) instanceof  PageContext);
245:                assertTrue(result.isExecuted());
246:            }
247:
248:            protected void setUp() throws Exception {
249:                super .setUp();
250:
251:                ConfigurationManager.clearConfigurationProviders();
252:                ConfigurationManager
253:                        .addConfigurationProvider(new TestConfigurationProvider());
254:                ConfigurationManager.getConfiguration().reload();
255:
256:                ActionContext actionContext = new ActionContext(context);
257:                actionContext.setValueStack(stack);
258:                ActionContext.setContext(actionContext);
259:            }
260:
261:            protected void tearDown() throws Exception {
262:                ConfigurationManager.destroyConfiguration();
263:
264:                OgnlValueStack stack = new OgnlValueStack();
265:                ActionContext.setContext(new ActionContext(stack.getContext()));
266:                super.tearDown();
267:            }
268:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.