Source Code Cross Referenced for RequestBuilderTest.java in  » Ajax » GWT » com » google » gwt » http » client » 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 » Ajax » GWT » com.google.gwt.http.client 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2007 Google Inc.
003:         * 
004:         * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005:         * use this file except in compliance with the License. You may obtain a copy of
006:         * the License at
007:         * 
008:         * http://www.apache.org/licenses/LICENSE-2.0
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012:         * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013:         * License for the specific language governing permissions and limitations under
014:         * the License.
015:         */
016:        package com.google.gwt.http.client;
017:
018:        import com.google.gwt.core.client.GWT;
019:        import com.google.gwt.junit.client.GWTTestCase;
020:
021:        /**
022:         * Test cases for the {@link RequestBuilder} class.
023:         */
024:        public class RequestBuilderTest extends GWTTestCase {
025:            private static final int TEST_FINISH_DELAY = 10000;
026:
027:            private static String getTestBaseURL() {
028:                return GWT.getModuleBaseURL() + "testRequestBuilder/";
029:            }
030:
031:            @Override
032:            public String getModuleName() {
033:                return "com.google.gwt.http.RequestBuilderTest";
034:            }
035:
036:            /**
037:             * Test method for
038:             * {@link com.google.gwt.http.client.RequestBuilder#RequestBuilder(java.lang.String, java.lang.String)}.
039:             * <p>
040:             * NOTE: When running this test against Internet Explorer, the security
041:             * settings of IE affect this test. The assumption is that the "Access Data
042:             * Sources Across Domains" setting is set to "Disabled". This is the standard
043:             * setting for the "Internet" zone, which models the case of a user's browser
044:             * sending a request to a foreign website. However, if you are running the
045:             * unit tests against a machine running the GWT app which falls into your
046:             * "Trusted Sites" or "Local Network" content zone, this setting's value is
047:             * different. You will have to change the setting to "Disabled" in these zones
048:             * for this test to pass.
049:             * <p>
050:             * Test Cases:
051:             * <ul>
052:             * <li>httpMethod == null
053:             * <li>httpMethod == ""
054:             * <li>url == null
055:             * <li>url == ""
056:             * <li>url == "www.freebsd.org" - violates same source
057:             * </ul>
058:             */
059:            public void testRequestBuilderStringString()
060:                    throws RequestException {
061:                try {
062:                    new RequestBuilder((RequestBuilder.Method) null, null);
063:                    fail("NullPointerException should have been thrown for construction with null method.");
064:                } catch (NullPointerException ex) {
065:                    // purposely ignored
066:                }
067:
068:                try {
069:                    new RequestBuilder(RequestBuilder.GET, null);
070:                    fail("NullPointerException should have been thrown for construction with null URL.");
071:                } catch (NullPointerException ex) {
072:                    // purposely ignored
073:                }
074:
075:                try {
076:                    new RequestBuilder(RequestBuilder.GET, "");
077:                    fail("IllegalArgumentException should have been throw for construction with empty URL.");
078:                } catch (IllegalArgumentException ex) {
079:                    // purposely ignored
080:                }
081:
082:                try {
083:                    RequestBuilder builder = new RequestBuilder(
084:                            RequestBuilder.GET, "http://www.freebsd.org");
085:                    builder.sendRequest(null, new RequestCallback() {
086:                        public void onError(Request request, Throwable exception) {
087:                            // should never get here
088:                            fail("HTTPRequest timed out");
089:                        }
090:
091:                        public void onResponseReceived(Request request,
092:                                Response response) {
093:                            // should never get here
094:                            fail();
095:                        }
096:                    });
097:                } catch (IllegalArgumentException ex) {
098:                    // purposely ignored
099:                } catch (RequestPermissionException ex) {
100:                    // this is the type of exception that we expect
101:                }
102:            }
103:
104:            /**
105:             * Test method for
106:             * {@link com.google.gwt.http.client.RequestBuilder#RequestBuilder(java.lang.String, java.lang.String)}. *
107:             */
108:            public void testRequestBuilderStringString_HTTPMethodRestrictionOverride() {
109:                new RequestBuilder(RequestBuilder.GET, "FOO");
110:
111:                class MyRequestBuilder extends RequestBuilder {
112:                    MyRequestBuilder(String httpMethod, String url) {
113:                        super (httpMethod, url);
114:                    }
115:                }
116:
117:                new MyRequestBuilder("HEAD", "FOO");
118:                // should reach here without any exceptions being thrown
119:            }
120:
121:            /**
122:             * Test method for
123:             * {@link com.google.gwt.http.client.RequestBuilder#sendRequest(java.lang.String, com.google.gwt.http.client.RequestCallback)}.
124:             */
125:            public void testSendRequest_GET() throws RequestException {
126:                delayTestFinish(TEST_FINISH_DELAY);
127:
128:                RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,
129:                        getTestBaseURL() + "sendRequest_GET");
130:                builder.sendRequest(null, new RequestCallback() {
131:                    public void onError(Request request, Throwable exception) {
132:                        fail();
133:                    }
134:
135:                    public void onResponseReceived(Request request,
136:                            Response response) {
137:                        assertEquals(200, response.getStatusCode());
138:                        finishTest();
139:                    }
140:                });
141:            }
142:
143:            /**
144:             * Test method for
145:             * {@link com.google.gwt.http.client.RequestBuilder#sendRequest(java.lang.String, com.google.gwt.http.client.RequestCallback)}.
146:             */
147:            public void testSendRequest_POST() throws RequestException {
148:                delayTestFinish(TEST_FINISH_DELAY);
149:
150:                RequestBuilder builder = new RequestBuilder(
151:                        RequestBuilder.POST, getTestBaseURL()
152:                                + "sendRequest_POST");
153:                builder.setHeader("Content-Type",
154:                        "application/x-www-form-urlencoded");
155:                builder.sendRequest("method=test+request",
156:                        new RequestCallback() {
157:                            public void onError(Request request,
158:                                    Throwable exception) {
159:                                fail("HTTPRequest timed out");
160:                            }
161:
162:                            public void onResponseReceived(Request request,
163:                                    Response response) {
164:                                assertEquals(200, response.getStatusCode());
165:                                finishTest();
166:                            }
167:                        });
168:            }
169:
170:            public void testSetPassword() {
171:                RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,
172:                        getTestBaseURL());
173:                try {
174:                    builder.setPassword(null);
175:                } catch (NullPointerException ex) {
176:                    // Correct behavior, exception was thrown
177:                }
178:
179:                try {
180:                    builder.setPassword("");
181:                } catch (IllegalArgumentException ex) {
182:                    // Correct behavior, exception was thrown
183:                }
184:            }
185:
186:            /**
187:             * Test method for
188:             * {@link com.google.gwt.http.client.RequestBuilder#setHeader(java.lang.String, java.lang.String)}.
189:             * 
190:             * <p>
191:             * Test Cases:
192:             * <ul>
193:             * <li>name == null
194:             * <li>name == ""
195:             * <li>value == null
196:             * <li>value == ""
197:             * </ul>
198:             */
199:            public void testSetRequestHeader() throws RequestException {
200:                RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,
201:                        getTestBaseURL() + "setRequestHeader");
202:
203:                try {
204:                    builder.setHeader(null, "bar");
205:                    fail("setRequestHeader(null, \"bar\")");
206:                } catch (NullPointerException ex) {
207:                    // purposely ignored
208:                }
209:
210:                try {
211:                    builder.setHeader("", "bar");
212:                    fail("setRequestHeader(\"\", \"bar\")");
213:                } catch (IllegalArgumentException ex) {
214:                    // purposely ignored
215:                }
216:
217:                try {
218:                    builder.setHeader("foo", null);
219:                    fail("setRequestHeader(\"foo\", null)");
220:                } catch (NullPointerException ex) {
221:                    // purposely ignored
222:                }
223:
224:                try {
225:                    builder.setHeader("foo", "");
226:                    fail("setRequestHeader(\"foo\", \"\")");
227:                } catch (IllegalArgumentException ex) {
228:                    // purposely ignored
229:                }
230:
231:                delayTestFinish(TEST_FINISH_DELAY);
232:
233:                builder = new RequestBuilder(RequestBuilder.GET,
234:                        getTestBaseURL() + "setRequestHeader");
235:                builder.setHeader("Foo", "Bar");
236:                builder.setHeader("Foo", "Bar1");
237:
238:                builder.sendRequest(null, new RequestCallback() {
239:                    public void onError(Request request, Throwable exception) {
240:                        fail("HTTPRequest timed out");
241:                    }
242:
243:                    public void onResponseReceived(Request request,
244:                            Response response) {
245:                        assertEquals(200, response.getStatusCode());
246:                        finishTest();
247:                    }
248:                });
249:            }
250:
251:            /**
252:             * Test method for
253:             * {@link com.google.gwt.http.client.RequestBuilder#setTimeoutMillis(int)}.
254:             * 
255:             * <p>
256:             * Test Cases:
257:             * <ul>
258:             * <li>Timeout greater than the server's response time
259:             * <li>Timeout is less than the server's response time
260:             * </ul>
261:             */
262:            public void testSetTimeout_noTimeout() throws RequestException {
263:                delayTestFinish(TEST_FINISH_DELAY);
264:
265:                RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,
266:                        getTestBaseURL() + "setTimeout/noTimeout");
267:                builder.setTimeoutMillis(10000);
268:                builder.sendRequest(null, new RequestCallback() {
269:                    public void onError(Request request, Throwable exception) {
270:                        fail("Test timed out");
271:                    }
272:
273:                    public void onResponseReceived(Request request,
274:                            Response response) {
275:                        assertEquals(200, response.getStatusCode());
276:                        finishTest();
277:                    }
278:                });
279:            }
280:
281:            /**
282:             * Test method for
283:             * {@link com.google.gwt.http.client.RequestBuilder#setTimeoutMillis(int)}.
284:             * 
285:             * <p>
286:             * Test Cases:
287:             * <ul>
288:             * <li>Timeout greater than the server's response time
289:             * <li>Timeout is less than the server's response time
290:             * </ul>
291:             */
292:            public void testSetTimeout_timeout() throws RequestException {
293:                delayTestFinish(TEST_FINISH_DELAY);
294:
295:                RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,
296:                        getTestBaseURL() + "setTimeout/timeout");
297:                builder.setTimeoutMillis(2000);
298:                builder.sendRequest(null, new RequestCallback() {
299:                    public void onError(Request request, Throwable exception) {
300:                        finishTest();
301:                    }
302:
303:                    public void onResponseReceived(Request request,
304:                            Response response) {
305:                        assertEquals(200, response.getStatusCode());
306:                        fail("Test did not timeout");
307:                    }
308:                });
309:            }
310:
311:            public void testSetUser() {
312:                RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,
313:                        getTestBaseURL());
314:                try {
315:                    builder.setUser(null);
316:                } catch (NullPointerException ex) {
317:                    // Correct behavior, exception was thrown
318:                }
319:
320:                try {
321:                    builder.setUser("");
322:                } catch (IllegalArgumentException ex) {
323:                    // Correct behavior, exception was thrown
324:                }
325:            }
326:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.