Source Code Cross Referenced for FixedURLWebRequestSource.java in  » Testing » HttpUnit » com » meterware » httpunit » 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 » Testing » HttpUnit » com.meterware.httpunit 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.meterware.httpunit;
002:
003:        /********************************************************************************************************************
004:         * $Id: FixedURLWebRequestSource.java,v 1.5 2004/07/23 01:31:04 russgold Exp $
005:         *
006:         * Copyright (c) 2002, Russell Gold
007:         *
008:         * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
009:         * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
010:         * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
011:         * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
012:         *
013:         * The above copyright notice and this permission notice shall be included in all copies or substantial portions
014:         * of the Software.
015:         *
016:         * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
017:         * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
018:         * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
019:         * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
020:         * DEALINGS IN THE SOFTWARE.
021:         *
022:         *******************************************************************************************************************/
023:        import java.util.*;
024:        import java.net.URL;
025:        import java.io.IOException;
026:
027:        import org.w3c.dom.Node;
028:
029:        /**
030:         * An implementation of web request source whose URL does not change under user action.
031:         *
032:         * @author <a href="mailto:russgold@acm.org">Russell Gold</a>
033:         **/
034:        abstract class FixedURLWebRequestSource extends WebRequestSource {
035:
036:            private static final String[] NO_VALUES = new String[0];
037:            private Map _presetParameterMap;
038:            private ArrayList _presetParameterList;
039:            private String _characterSet;
040:
041:            public FixedURLWebRequestSource(WebResponse response, Node node,
042:                    URL baseURL, String destination, FrameSelector frame,
043:                    String defaultTarget, String characterSet) {
044:                super (response, node, baseURL, destination, frame,
045:                        defaultTarget);
046:                _characterSet = characterSet;
047:            }
048:
049:            //------------------------------------------- WebRequestSource methods -------------------------------------------------
050:
051:            /**
052:             * Creates and returns a web request which will simulate clicking on this link.
053:             **/
054:            public WebRequest getRequest() {
055:                return new GetMethodWebRequest(this );
056:            }
057:
058:            /**
059:             * Returns an array containing the names of any parameters defined as part of this link's URL.
060:             **/
061:            public String[] getParameterNames() {
062:                ArrayList parameterNames = new ArrayList(
063:                        getPresetParameterMap().keySet());
064:                return (String[]) parameterNames
065:                        .toArray(new String[parameterNames.size()]);
066:            }
067:
068:            /**
069:             * Returns the multiple default values of the named parameter.
070:             **/
071:            public String[] getParameterValues(String name) {
072:                final String[] values = (String[]) getPresetParameterMap().get(
073:                        name);
074:                return values == null ? NO_VALUES : values;
075:            }
076:
077:            protected void addPresetParameter(String name, String value) {
078:                _presetParameterMap.put(name, HttpUnitUtils.withNewValue(
079:                        (String[]) _presetParameterMap.get(name), value));
080:                _presetParameterList.add(new PresetParameter(name, value));
081:            }
082:
083:            protected String getEmptyParameterValue() {
084:                return "";
085:            }
086:
087:            protected void setDestination(String destination) {
088:                super .setDestination(destination);
089:                _presetParameterList = null;
090:                _presetParameterMap = null;
091:            }
092:
093:            //------------------------------------------- ParameterHolder methods --------------------------------------------------
094:
095:            /**
096:             * Specifies the position at which an image button (if any) was clicked.
097:             **/
098:            void selectImageButtonPosition(SubmitButton imageButton, int x,
099:                    int y) {
100:                throw new IllegalNonFormParametersRequest();
101:            }
102:
103:            /**
104:             * Iterates through the fixed, predefined parameters in this holder, recording them in the supplied parameter processor.\
105:             * These parameters always go on the URL, no matter what encoding method is used.
106:             **/
107:
108:            void recordPredefinedParameters(ParameterProcessor processor)
109:                    throws IOException {
110:            }
111:
112:            /**
113:             * Iterates through the parameters in this holder, recording them in the supplied parameter processor.
114:             **/
115:            void recordParameters(ParameterProcessor processor)
116:                    throws IOException {
117:                Iterator i = getPresetParameterList().iterator();
118:                while (i.hasNext()) {
119:                    PresetParameter o = (PresetParameter) i.next();
120:                    processor.addParameter(o.getName(), o.getValue(),
121:                            getCharacterSet());
122:                }
123:            }
124:
125:            /**
126:             * Removes a parameter name from this collection.
127:             **/
128:            void removeParameter(String name) {
129:                throw new IllegalNonFormParametersRequest();
130:            }
131:
132:            /**
133:             * Sets the value of a parameter in a web request.
134:             **/
135:            void setParameter(String name, String value) {
136:                setParameter(name, new String[] { value });
137:            }
138:
139:            /**
140:             * Sets the multiple values of a parameter in a web request.
141:             **/
142:            void setParameter(String name, String[] values) {
143:                if (values == null) {
144:                    throw new IllegalArgumentException(
145:                            "May not supply a null argument array to setParameter()");
146:                } else if (!getPresetParameterMap().containsKey(name)) {
147:                    throw new IllegalNonFormParametersRequest();
148:                } else if (!equals(getParameterValues(name), values)) {
149:                    throw new IllegalNonFormParametersRequest();
150:                }
151:            }
152:
153:            String getCharacterSet() {
154:                return _characterSet;
155:            }
156:
157:            private boolean equals(String[] left, String[] right) {
158:                if (left.length != right.length)
159:                    return false;
160:                List rightValues = Arrays.asList(right);
161:                for (int i = 0; i < left.length; i++) {
162:                    if (!rightValues.contains(left[i]))
163:                        return false;
164:                }
165:                return true;
166:            }
167:
168:            /**
169:             * Sets the multiple values of a file upload parameter in a web request.
170:             **/
171:            void setParameter(String name, UploadFileSpec[] files) {
172:                throw new IllegalNonFormParametersRequest();
173:            }
174:
175:            /**
176:             * Returns true if the specified parameter is a file field.
177:             **/
178:            boolean isFileParameter(String name) {
179:                return false;
180:            }
181:
182:            boolean isSubmitAsMime() {
183:                return false;
184:            }
185:
186:            void setSubmitAsMime(boolean mimeEncoded) {
187:                throw new IllegalStateException(
188:                        "May not change the encoding for a validated request created from a link");
189:            }
190:
191:            private Map getPresetParameterMap() {
192:                if (_presetParameterMap == null)
193:                    loadPresetParameters();
194:                return _presetParameterMap;
195:            }
196:
197:            private ArrayList getPresetParameterList() {
198:                if (_presetParameterList == null)
199:                    loadPresetParameters();
200:                return _presetParameterList;
201:            }
202:
203:            private void loadPresetParameters() {
204:                _presetParameterMap = new HashMap();
205:                _presetParameterList = new ArrayList();
206:                loadDestinationParameters();
207:            }
208:
209:        }
210:
211:        class PresetParameter {
212:            private String _name;
213:            private String _value;
214:
215:            public PresetParameter(String name, String value) {
216:                _name = name;
217:                _value = value;
218:            }
219:
220:            public String getName() {
221:                return _name;
222:            }
223:
224:            public String getValue() {
225:                return _value;
226:            }
227:        }
228:
229:        class IllegalNonFormParametersRequest extends
230:                IllegalRequestParameterException {
231:
232:            public IllegalNonFormParametersRequest() {
233:            }
234:
235:            public String getMessage() {
236:                return "May not modify parameters for a request not derived from a form with parameter checking enabled.";
237:            }
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.