1 /*
2 * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestURIUtil.java,v 1.5 2003/01/23 22:48:27 jsdever Exp $
3 * $Revision: 1.5 $
4 * $Date: 2003/01/23 22:48:27 $
5 * ====================================================================
6 *
7 * The Apache Software License, Version 1.1
8 *
9 * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
10 * reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 *
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 *
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in
21 * the documentation and/or other materials provided with the
22 * distribution.
23 *
24 * 3. The end-user documentation included with the redistribution, if
25 * any, must include the following acknowlegement:
26 * "This product includes software developed by the
27 * Apache Software Foundation (http://www.apache.org/)."
28 * Alternately, this acknowlegement may appear in the software itself,
29 * if and wherever such third-party acknowlegements normally appear.
30 *
31 * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
32 * Foundation" must not be used to endorse or promote products derived
33 * from this software without prior written permission. For written
34 * permission, please contact apache@apache.org.
35 *
36 * 5. Products derived from this software may not be called "Apache"
37 * nor may "Apache" appear in their names without prior written
38 * permission of the Apache Group.
39 *
40 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
41 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
42 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
43 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
44 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
46 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
47 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
48 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
49 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
50 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 * ====================================================================
53 *
54 * This software consists of voluntary contributions made by many
55 * individuals on behalf of the Apache Software Foundation. For more
56 * information on the Apache Software Foundation, please see
57 * <http://www.apache.org/>.
58 *
59 * [Additional notices, if required by prior licensing conditions]
60 *
61 */
62
63 package org.apache.commons.httpclient;
64
65 import junit.framework.Test;
66 import junit.framework.TestCase;
67 import junit.framework.TestSuite;
68
69 import org.apache.commons.httpclient.util.URIUtil;
70
71 /***
72 *
73 * Unit tests for {@link URIUtil}. These tests care currently quite limited
74 * and should be expanded to test more functionality.
75 *
76 * @author Marc A. Saegesser
77 * @version $Id: TestURIUtil.java,v 1.5 2003/01/23 22:48:27 jsdever Exp $
78 */
79 public class TestURIUtil extends TestCase {
80 // ----------------------------------------------------- Instance Variables
81 URITestCase pathTests[] = {new URITestCase("http://www.server.com/path1/path2", "/path1/path2"),
82 new URITestCase("http://www.server.com/path1/path2/", "/path1/path2/"),
83 new URITestCase("http://www.server.com/path1/path2?query=string", "/path1/path2"),
84 new URITestCase("http://www.server.com/path1/path2/?query=string", "/path1/path2/"),
85 new URITestCase("www.noscheme.com/path1/path2", "/path1/path2"),
86 new URITestCase("www.noscheme.com/path1/path2#anchor?query=string", "/path1/path2"),
87 new URITestCase("/noscheme/nohost/path", "/noscheme/nohost/path"),
88 new URITestCase("http://www.server.com", "/"),
89 new URITestCase("https://www.server.com:443/ssl/path", "/ssl/path"),
90 new URITestCase("http://www.server.com:8080/path/with/port", "/path/with/port"),
91 new URITestCase("http://www.server.com/path1/path2?query1=string?1&query2=string2", "/path1/path2")};
92
93 URITestCase queryTests[] = {new URITestCase("http://www.server.com/path1/path2", null),
94 new URITestCase("http://www.server.com/path1/path2?query=string", "query=string"),
95 new URITestCase("http://www.server.com/path1/path2/?query=string", "query=string"),
96 new URITestCase("www.noscheme.com/path1/path2#anchor?query=string", "query=string"),
97 new URITestCase("/noscheme/nohost/path?query1=string1&query2=string2", "query1=string1&query2=string2"),
98 new URITestCase("https://www.server.com:443/ssl/path?query1=string1&query2=string2", "query1=string1&query2=string2"),
99 new URITestCase("http://www.server.com:8080/path/with/port?query1=string1&query2=string2", "query1=string1&query2=string2"),
100 new URITestCase("http://www.server.com/path1/path2?query1=string?1&query2=string2", "query1=string?1&query2=string2")};
101
102
103
104 // ------------------------------------------------------------ Constructor
105 public TestURIUtil(String testName) {
106 super(testName);
107 }
108
109 // ------------------------------------------------------------------- Main
110 public static void main(String args[]) {
111 String[] testCaseName = { TestURIUtil.class.getName() };
112 junit.textui.TestRunner.main(testCaseName);
113 }
114
115 // ------------------------------------------------------- TestCase Methods
116
117 public static Test suite() {
118 return new TestSuite(TestURIUtil.class);
119 }
120
121
122 // ----------------------------------------------------------- Test Methods
123 public void testGetPath()
124 {
125 String testValue = "";
126 String expectedResult = "";
127
128 for(int i=0;i<pathTests.length;i++){
129 testValue = pathTests[i].getTestValue();
130 expectedResult = pathTests[i].getExpectedResult();
131 assertEquals("Path test", expectedResult, URIUtil.getPath(testValue));
132 }
133 }
134
135 public void testGetQueryString()
136 {
137 String testValue = "";
138 String expectedResult = "";
139
140 for(int i=0;i<queryTests.length;i++){
141 testValue = queryTests[i].getTestValue();
142 expectedResult = queryTests[i].getExpectedResult();
143 assertEquals("Path test", expectedResult, URIUtil.getQuery(testValue));
144 }
145 }
146
147 private class URITestCase{
148 private String testValue;
149 private String expectedResult;
150
151 public URITestCase(String testValue, String expectedResult){
152 this.testValue = testValue;
153 this.expectedResult = expectedResult;
154 }
155
156 public String getTestValue(){
157 return testValue;
158 }
159
160 public String getExpectedResult(){
161 return expectedResult;
162 }
163 }
164 }
This page was automatically generated by Maven