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


001:        /*
002:         * $Id: TestActionRedirect.java 514052 2007-03-03 02:00:37Z pbenedict $
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.action;
022:
023:        import junit.framework.AssertionFailedError;
024:        import junit.framework.ComparisonFailure;
025:        import junit.framework.TestCase;
026:        import junit.framework.TestSuite;
027:
028:        import java.util.Map;
029:
030:        /**
031:         * <p>Unit tests for the {@link ActionRedirect} class.</p>
032:         *
033:         * @version $Rev: 514052 $ $Date: 2007-03-02 20:00:37 -0600 (Fri, 02 Mar 2007) $
034:         */
035:        public class TestActionRedirect extends TestCase {
036:            public TestActionRedirect(String s) {
037:                super (s);
038:            }
039:
040:            public static TestSuite getSuite() {
041:                return new TestSuite(TestActionRedirect.class);
042:            }
043:
044:            public static void main(String[] args) {
045:                junit.textui.TestRunner runner = new junit.textui.TestRunner();
046:
047:                runner.doRun(TestActionRedirect.getSuite());
048:            }
049:
050:            // ----------------------------------------------------- Test Methods
051:
052:            /**
053:             * Check that the redirect flag is set.
054:             */
055:            public void testActionRedirectRedirectFlag() {
056:                ActionRedirect ar = new ActionRedirect("/path.do");
057:
058:                assertTrue("Redirect flag should be set to true.", ar
059:                        .getRedirect());
060:            }
061:
062:            /**
063:             * Test all addParameter methods accepting different data types.
064:             */
065:            public void testActionRedirectAddParameter() {
066:                ActionRedirect ar = new ActionRedirect("/path.do");
067:
068:                ar.addParameter("st", "test");
069:                ar.addParameter("obj", new StringBuffer("someString"));
070:
071:                assertTrue("Incorrect path",
072:                        ar.getPath().indexOf("/path.do") == 0);
073:                assertHasParameter(ar.parameterValues, "st", "test");
074:                assertHasParameter(ar.parameterValues, "obj", "someString");
075:            }
076:
077:            /**
078:             * Test redirect with anchor.
079:             */
080:            public void testActionRedirectWithAnchor() {
081:                ActionRedirect ar = new ActionRedirect("/path.do");
082:
083:                ar.addParameter("st", "test");
084:                ar.setAnchor("foo");
085:
086:                assertTrue("Incorrect path", "/path.do?st=test#foo".equals(ar
087:                        .getPath()));
088:            }
089:
090:            /**
091:             * Test adding parameters with the same name.
092:             */
093:            public void testActionRedirectAddSameNameParameter() {
094:                ActionRedirect ar = new ActionRedirect("/path.do");
095:
096:                ar.addParameter("param", "param1");
097:                ar.addParameter("param", "param2");
098:                ar.addParameter("param", new StringBuffer("someString"));
099:
100:                assertTrue("Incorrect path",
101:                        ar.getPath().indexOf("/path.do") == 0);
102:                assertHasParameter(ar.parameterValues, "param", "param1");
103:                assertHasParameter(ar.parameterValues, "param", "param2");
104:                assertHasParameter(ar.parameterValues, "param", "someString");
105:                assertEquals("Incorrect number of parameters", 3,
106:                        countParameters(ar.parameterValues, "param"));
107:            }
108:
109:            /**
110:             * Test creating an ActionRedirect which copies its configuration from an
111:             * existing ActionForward (except for the "redirect" property).
112:             */
113:            public void testActionRedirectFromExistingForward() {
114:                ActionForward forward = new ActionForward(
115:                        "/path.do?param=param1");
116:                forward.setRedirect(false);
117:                forward.setProperty("key", "value");
118:
119:                ActionRedirect ar = new ActionRedirect(forward);
120:
121:                ar.addParameter("param", "param2");
122:                ar.addParameter("object1", new StringBuffer("someString"));
123:
124:                assertTrue("Incorrect path",
125:                        ar.getPath().indexOf("/path.do") == 0);
126:                assertHasParameter(ar.parameterValues, "param", "param2");
127:                assertHasParameter(ar.parameterValues, "object1", "someString");
128:                assertEquals("Incorrect original path.", forward.getPath(), ar
129:                        .getOriginalPath());
130:                assertEquals("Incorrect or missing property", "value", ar
131:                        .getProperty("key"));
132:                assertTrue("Original had redirect to false", ar.getRedirect());
133:            }
134:
135:            /**
136:             * Assert that the given parameters contains an entry for
137:             * <code>paramValue</code> under the <code>paramName</code> key. <p/>
138:             *
139:             * @param parameters the map of parameters to check into
140:             * @param paramName  the key of the value to be checked
141:             * @param paramValue the value to check for
142:             */
143:            static void assertHasParameter(Map parameters, String paramName,
144:                    String paramValue) {
145:                Object value = parameters.get(paramName);
146:
147:                if (value == null) {
148:                    throw new AssertionFailedError("Parameter [" + paramName
149:                            + "] not found");
150:                }
151:
152:                if (value instanceof  String) {
153:                    if (!paramValue.equals(value)) {
154:                        throw new ComparisonFailure("Incorrect value found",
155:                                paramValue, (String) value);
156:                    }
157:                } else if (value instanceof  String[]) {
158:                    // see if our value is among those in the array
159:                    String[] values = (String[]) value;
160:
161:                    for (int i = 0; i < values.length; i++) {
162:                        if (paramValue.equals(values[i])) {
163:                            return;
164:                        }
165:                    }
166:
167:                    throw new AssertionFailedError(
168:                            "Expected value not found for parameter ["
169:                                    + paramName + "]");
170:                } else {
171:                    // can't recognize the value
172:                    throw new AssertionFailedError(
173:                            "Unexpected type found as parameter value for ["
174:                                    + paramName + "]");
175:                }
176:            }
177:
178:            /**
179:             * Determine the number of values that are available for a specific
180:             * parameter. <p/>
181:             *
182:             * @param parameters the map of parameters to check into
183:             * @param paramName  the key of the value(s) to count
184:             * @return the number of values for the specified parameter
185:             */
186:            static int countParameters(Map parameters, String paramName) {
187:                Object value = parameters.get(paramName);
188:
189:                if (value == null) {
190:                    return 0;
191:                }
192:
193:                if (value instanceof  String) {
194:                    return 1;
195:                } else if (value instanceof  String[]) {
196:                    String[] values = (String[]) value;
197:
198:                    return values.length;
199:                } else {
200:                    // can't recognize the value
201:                    throw new AssertionFailedError(
202:                            "Unexpected type found as parameter value for ["
203:                                    + paramName + "]");
204:                }
205:            }
206:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.