Source Code Cross Referenced for MockLink.java in  » Web-Framework » rife-1.6.1 » com » uwyn » rife » test » 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 » rife 1.6.1 » com.uwyn.rife.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003:         * Distributed under the terms of either:
004:         * - the common development and distribution license (CDDL), v1.0; or
005:         * - the GNU Lesser General Public License, v2.1 or later
006:         * $Id: MockLink.java 3634 2007-01-08 21:42:24Z gbevin $
007:         */
008:        package com.uwyn.rife.test;
009:
010:        import com.uwyn.rife.engine.RequestMethod;
011:        import java.util.Collection;
012:        import java.util.LinkedHashMap;
013:        import java.util.Map;
014:        import org.w3c.dom.Node;
015:
016:        /**
017:         * Corresponds to a link in a HTML document after it has been parsed with
018:         * {@link ParsedHtml#parse}.
019:         * 
020:         * @author Geert Bevin (gbevin[remove] at uwyn dot com)
021:         * @version $Revision: 3634 $
022:         * @since 1.1
023:         */
024:        public class MockLink {
025:            private MockResponse mResponse;
026:            private Node mNode;
027:            private String mText;
028:            private Map<String, String[]> mParameters;
029:
030:            MockLink(MockResponse response, Node node) {
031:                assert node != null;
032:
033:                mResponse = response;
034:                mNode = node;
035:                mText = mNode.getTextContent();
036:
037:                mParameters = MockConversation.extractParameters(getHref());
038:                if (null == mParameters) {
039:                    mParameters = new LinkedHashMap<String, String[]>();
040:                }
041:            }
042:
043:            /**
044:             * Retrieves the DOM XML node that this link corresponds to.
045:             * 
046:             * @return the corresponding DOM XML node
047:             * @since 1.0
048:             */
049:            public Node getNode() {
050:                return mNode;
051:            }
052:
053:            /**
054:             * Creates a new {@link MockRequest} that contains the parameters this
055:             * link.
056:             * 
057:             * @return the created <code>MockRequest</code>
058:             * @since 1.0
059:             */
060:            public MockRequest getRequest() {
061:                return new MockRequest().method(RequestMethod.GET);
062:            }
063:
064:            /**
065:             * Click this link with its current parameters and returns the response.
066:             * 
067:             * @return the resulting {@link MockResponse}
068:             * @since 1.0
069:             */
070:            public MockResponse click() {
071:                return mResponse.getMockConversation().doRequest(getHref(),
072:                        getRequest());
073:            }
074:
075:            private String getAttribute(String attributeName) {
076:                return ParsedHtml.getNodeAttribute(mNode, attributeName, null);
077:            }
078:
079:            /**
080:             * Retrieves all the parameters of this link.
081:             * 
082:             * @return a <code>Map</code> of the parameters with the names as the keys
083:             * and their value arrays as the values
084:             * @see #getParameterNames
085:             * @see #hasParameter
086:             * @see #getParameterValue
087:             * @see #getParameterValues
088:             * @since 1.1
089:             */
090:            public Map<String, String[]> getParameters() {
091:                return mParameters;
092:            }
093:
094:            /**
095:             * Retrieves all the parameter names of this link.
096:             * 
097:             * @return a <code>Collection</code> of the parameter names
098:             * @see #getParameters
099:             * @see #hasParameter
100:             * @see #getParameterValue
101:             * @see #getParameterValues
102:             * @since 1.1
103:             */
104:            public Collection<String> getParameterNames() {
105:                return mParameters.keySet();
106:            }
107:
108:            /**
109:             * Checks whether a named parameter is present in this link.
110:             * 
111:             * @param name the name of the parameter to check
112:             * @return <code>true</code> if the parameter is present; or
113:             * <p><code>false</code> otherwise
114:             * @see #getParameters
115:             * @see #getParameterNames
116:             * @see #getParameterValue
117:             * @see #getParameterValues
118:             * @since 1.1
119:             */
120:            public boolean hasParameter(String name) {
121:                return mParameters.containsKey(name);
122:            }
123:
124:            /**
125:             * Retrieves the first value of a parameter in this link.
126:             * 
127:             * @param name the name of the parameter
128:             * @return the first value of the parameter; or
129:             * <p><code>null</code> if no such parameter could be found
130:             * @see #getParameters
131:             * @see #getParameterNames
132:             * @see #hasParameter
133:             * @see #getParameterValues
134:             * @since 1.1
135:             */
136:            public String getParameterValue(String name) {
137:                String[] values = getParameterValues(name);
138:                if (null == values || 0 == values.length) {
139:                    return null;
140:                }
141:
142:                return values[0];
143:            }
144:
145:            /**
146:             * Retrieves the values of a parameter in this link.
147:             * 
148:             * @param name the name of the parameter
149:             * @return the values of the parameter; or
150:             * <p><code>null</code> if no such parameter could be found
151:             * @see #getParameters
152:             * @see #getParameterNames
153:             * @see #hasParameter
154:             * @see #getParameterValue
155:             * @since 1.1
156:             */
157:            public String[] getParameterValues(String name) {
158:                return mParameters.get(name);
159:            }
160:
161:            /**
162:             * Retrieves the content of this link's <code>id</code> attribute.
163:             * 
164:             * @return the content of the <code>id</code> attribute; or
165:             * <p>null if no such attribute could be found
166:             * @since 1.0
167:             */
168:            public String getId() {
169:                return getAttribute("id");
170:            }
171:
172:            /**
173:             * Retrieves the content of this link's <code>class</code> attribute.
174:             * 
175:             * @return the content of the <code>class</code> attribute; or
176:             * <p>null if no such attribute could be found
177:             * @since 1.0
178:             */
179:            public String getClassName() {
180:                return getAttribute("class");
181:            }
182:
183:            /**
184:             * Retrieves the content of this link's <code>title</code> attribute.
185:             * 
186:             * @return the content of the <code>title</code> attribute; or
187:             * <p>null if no such attribute could be found
188:             * @since 1.0
189:             */
190:            public String getTitle() {
191:                return getAttribute("title");
192:            }
193:
194:            /**
195:             * Retrieves the content of this link's <code>href</code> attribute.
196:             * 
197:             * @return the content of the <code>href</code> attribute; or
198:             * <p>null if no such attribute could be found
199:             * @since 1.0
200:             */
201:            public String getHref() {
202:                return getAttribute("href");
203:            }
204:
205:            /**
206:             * Retrieves the content of this link's <code>target</code> attribute.
207:             * 
208:             * @return the content of the <code>target</code> attribute; or
209:             * <p>null if no such attribute could be found
210:             * @since 1.0
211:             */
212:            public String getTarget() {
213:                return getAttribute("target");
214:            }
215:
216:            /**
217:             * Retrieves the content of this link's <code>name</code> attribute.
218:             * 
219:             * @return the content of the <code>name</code> attribute; or
220:             * <p>null if no such attribute could be found
221:             * @since 1.0
222:             */
223:            public String getName() {
224:                return getAttribute("name");
225:            }
226:
227:            /**
228:             * Retrieves the text that this links surrounds.
229:             * 
230:             * @return the surrounded text
231:             * @since 1.0
232:             */
233:            public String getText() {
234:                return mText;
235:            }
236:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.