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.util.URIUtil;
38
39 /***
40 *
41 * Unit tests for {@link URIUtil}. These tests care currently quite limited
42 * and should be expanded to test more functionality.
43 *
44 * @author Marc A. Saegesser
45 * @version $Id: TestURIUtil.java 155418 2005-02-26 13:01:52Z dirkv $
46 */
47 public class TestURIUtil extends TestCase {
48
49 URITestCase pathTests[] = {new URITestCase("http://www.server.com/path1/path2", "/path1/path2"),
50 new URITestCase("http://www.server.com/path1/path2/", "/path1/path2/"),
51 new URITestCase("http://www.server.com/path1/path2?query=string", "/path1/path2"),
52 new URITestCase("http://www.server.com/path1/path2/?query=string", "/path1/path2/"),
53 new URITestCase("www.noscheme.com/path1/path2", "/path1/path2"),
54 new URITestCase("www.noscheme.com/path1/path2#anchor?query=string", "/path1/path2"),
55 new URITestCase("/noscheme/nohost/path", "/noscheme/nohost/path"),
56 new URITestCase("http://www.server.com", "/"),
57 new URITestCase("https://www.server.com:443/ssl/path", "/ssl/path"),
58 new URITestCase("http://www.server.com:8080/path/with/port", "/path/with/port"),
59 new URITestCase("http://www.server.com/path1/path2?query1=string?1&query2=string2", "/path1/path2")};
60
61 URITestCase queryTests[] = {new URITestCase("http://www.server.com/path1/path2", null),
62 new URITestCase("http://www.server.com/path1/path2?query=string", "query=string"),
63 new URITestCase("http://www.server.com/path1/path2/?query=string", "query=string"),
64 new URITestCase("www.noscheme.com/path1/path2#anchor?query=string", "query=string"),
65 new URITestCase("/noscheme/nohost/path?query1=string1&query2=string2", "query1=string1&query2=string2"),
66 new URITestCase("https://www.server.com:443/ssl/path?query1=string1&query2=string2", "query1=string1&query2=string2"),
67 new URITestCase("http://www.server.com:8080/path/with/port?query1=string1&query2=string2", "query1=string1&query2=string2"),
68 new URITestCase("http://www.server.com/path1/path2?query1=string?1&query2=string2", "query1=string?1&query2=string2")};
69
70
71
72
73 public TestURIUtil(String testName) {
74 super(testName);
75 }
76
77
78 public static void main(String args[]) {
79 String[] testCaseName = { TestURIUtil.class.getName() };
80 junit.textui.TestRunner.main(testCaseName);
81 }
82
83
84
85 public static Test suite() {
86 return new TestSuite(TestURIUtil.class);
87 }
88
89
90
91 public void testGetPath()
92 {
93 String testValue = "";
94 String expectedResult = "";
95
96 for(int i=0;i<pathTests.length;i++){
97 testValue = pathTests[i].getTestValue();
98 expectedResult = pathTests[i].getExpectedResult();
99 assertEquals("Path test", expectedResult, URIUtil.getPath(testValue));
100 }
101 }
102
103 public void testGetQueryString()
104 {
105 String testValue = "";
106 String expectedResult = "";
107
108 for(int i=0;i<queryTests.length;i++){
109 testValue = queryTests[i].getTestValue();
110 expectedResult = queryTests[i].getExpectedResult();
111 assertEquals("Path test", expectedResult, URIUtil.getQuery(testValue));
112 }
113 }
114
115 private class URITestCase{
116 private String testValue;
117 private String expectedResult;
118
119 public URITestCase(String testValue, String expectedResult){
120 this.testValue = testValue;
121 this.expectedResult = expectedResult;
122 }
123
124 public String getTestValue(){
125 return testValue;
126 }
127
128 public String getExpectedResult(){
129 return expectedResult;
130 }
131 }
132 }