1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 package org.apache.commons.httpclient;
32
33 import junit.framework.Test;
34 import junit.framework.TestCase;
35 import junit.framework.TestSuite;
36
37 import org.apache.commons.httpclient.methods.GetMethod;
38
39 /***
40 *
41 * Unit tests for {@link org.apache.commons.httpclient.HttpMethod}
42 * constructors that take URLs. These tests do not require any network
43 * connection or web app.
44 *
45 * @author Marc A. Saegesser
46 * @version $Id: TestHttpUrlMethod.java,v 1.5.2.1 2004/02/22 18:21:16 olegk Exp $
47 */
48 public class TestHttpUrlMethod extends TestCase {
49
50
51 public TestHttpUrlMethod(String testName) {
52 super(testName);
53 }
54
55
56 public static void main(String args[]) {
57 String[] testCaseName = { TestHttpUrlMethod.class.getName() };
58 junit.textui.TestRunner.main(testCaseName);
59 }
60
61
62
63 public static Test suite() {
64 return new TestSuite(TestHttpUrlMethod.class);
65 }
66
67
68
69
70
71
72 public void testUrlGetMethodWithPathQuery() {
73 GetMethod method = new GetMethod("http://www.fubar.com/path1/path2?query=string");
74 try {
75 assertEquals(
76 "Get URL",
77 "http://www.fubar.com/path1/path2?query=string",
78 method.getURI().toString()
79 );
80 } catch ( URIException e ) {
81 fail( "trouble getting URI: " + e );
82 }
83 assertEquals("Get Path", "/path1/path2", method.getPath());
84 assertEquals("Get query string", "query=string", method.getQueryString());
85
86 }
87
88 public void testUrlGetMethodWithPath() {
89 GetMethod method = new GetMethod("http://www.fubar.com/path1/path2");
90 try {
91 assertEquals(
92 "Get URL",
93 "http://www.fubar.com/path1/path2",
94 method.getURI().toString()
95 );
96 } catch ( URIException e ) {
97 fail( "trouble getting URI: " + e );
98 }
99 assertEquals("Get Path", "/path1/path2", method.getPath());
100 assertEquals("Get query string", null, method.getQueryString());
101
102 }
103
104 public void testUrlGetMethod() {
105 GetMethod method = new GetMethod("http://www.fubar.com/");
106 try {
107 assertEquals(
108 "Get URL",
109 "http://www.fubar.com/",
110 method.getURI().toString()
111 );
112 } catch ( URIException e ) {
113 fail( "trouble getting URI: " + e );
114 }
115 assertEquals("Get Path", "/", method.getPath());
116 assertEquals("Get query string", null, method.getQueryString());
117
118 }
119
120
121 public void testUrlGetMethodWithInvalidProtocol() {
122 try
123 {
124 GetMethod method = new GetMethod("crap://www.fubar.com/");
125 fail("The use of invalid protocol must have resulted in an IllegalStateException");
126 }
127 catch(IllegalStateException e)
128 {
129
130 }
131 }
132 }