001: /*
002: * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/TestURIUtil.java,v 1.6 2004/02/22 18:08:50 olegk Exp $
003: * $Revision: 480424 $
004: * $Date: 2006-11-29 06:56:49 +0100 (Wed, 29 Nov 2006) $
005: * ====================================================================
006: *
007: * Licensed to the Apache Software Foundation (ASF) under one or more
008: * contributor license agreements. See the NOTICE file distributed with
009: * this work for additional information regarding copyright ownership.
010: * The ASF licenses this file to You under the Apache License, Version 2.0
011: * (the "License"); you may not use this file except in compliance with
012: * the License. You may obtain a copy of the License at
013: *
014: * http://www.apache.org/licenses/LICENSE-2.0
015: *
016: * Unless required by applicable law or agreed to in writing, software
017: * distributed under the License is distributed on an "AS IS" BASIS,
018: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
019: * See the License for the specific language governing permissions and
020: * limitations under the License.
021: * ====================================================================
022: *
023: * This software consists of voluntary contributions made by many
024: * individuals on behalf of the Apache Software Foundation. For more
025: * information on the Apache Software Foundation, please see
026: * <http://www.apache.org/>.
027: *
028: * [Additional notices, if required by prior licensing conditions]
029: *
030: */
031:
032: package org.apache.commons.httpclient;
033:
034: import junit.framework.Test;
035: import junit.framework.TestCase;
036: import junit.framework.TestSuite;
037:
038: import org.apache.commons.httpclient.util.URIUtil;
039:
040: /**
041: *
042: * Unit tests for {@link URIUtil}. These tests care currently quite limited
043: * and should be expanded to test more functionality.
044: *
045: * @author Marc A. Saegesser
046: * @version $Id: TestURIUtil.java 480424 2006-11-29 05:56:49Z bayard $
047: */
048: public class TestURIUtil extends TestCase {
049: // ----------------------------------------------------- Instance Variables
050: URITestCase pathTests[] = {
051: new URITestCase("http://www.server.com/path1/path2",
052: "/path1/path2"),
053: new URITestCase("http://www.server.com/path1/path2/",
054: "/path1/path2/"),
055: new URITestCase(
056: "http://www.server.com/path1/path2?query=string",
057: "/path1/path2"),
058: new URITestCase(
059: "http://www.server.com/path1/path2/?query=string",
060: "/path1/path2/"),
061: new URITestCase("www.noscheme.com/path1/path2",
062: "/path1/path2"),
063: new URITestCase(
064: "www.noscheme.com/path1/path2#anchor?query=string",
065: "/path1/path2"),
066: new URITestCase("/noscheme/nohost/path",
067: "/noscheme/nohost/path"),
068: new URITestCase("http://www.server.com", "/"),
069: new URITestCase("https://www.server.com:443/ssl/path",
070: "/ssl/path"),
071: new URITestCase(
072: "http://www.server.com:8080/path/with/port",
073: "/path/with/port"),
074: new URITestCase(
075: "http://www.server.com/path1/path2?query1=string?1&query2=string2",
076: "/path1/path2") };
077:
078: URITestCase queryTests[] = {
079: new URITestCase("http://www.server.com/path1/path2", null),
080: new URITestCase(
081: "http://www.server.com/path1/path2?query=string",
082: "query=string"),
083: new URITestCase(
084: "http://www.server.com/path1/path2/?query=string",
085: "query=string"),
086: new URITestCase(
087: "www.noscheme.com/path1/path2#anchor?query=string",
088: "query=string"),
089: new URITestCase(
090: "/noscheme/nohost/path?query1=string1&query2=string2",
091: "query1=string1&query2=string2"),
092: new URITestCase(
093: "https://www.server.com:443/ssl/path?query1=string1&query2=string2",
094: "query1=string1&query2=string2"),
095: new URITestCase(
096: "http://www.server.com:8080/path/with/port?query1=string1&query2=string2",
097: "query1=string1&query2=string2"),
098: new URITestCase(
099: "http://www.server.com/path1/path2?query1=string?1&query2=string2",
100: "query1=string?1&query2=string2") };
101:
102: // ------------------------------------------------------------ Constructor
103: public TestURIUtil(String testName) {
104: super (testName);
105: }
106:
107: // ------------------------------------------------------------------- Main
108: public static void main(String args[]) {
109: String[] testCaseName = { TestURIUtil.class.getName() };
110: junit.textui.TestRunner.main(testCaseName);
111: }
112:
113: // ------------------------------------------------------- TestCase Methods
114:
115: public static Test suite() {
116: return new TestSuite(TestURIUtil.class);
117: }
118:
119: // ----------------------------------------------------------- Test Methods
120: public void testGetPath() {
121: String testValue = "";
122: String expectedResult = "";
123:
124: for (int i = 0; i < pathTests.length; i++) {
125: testValue = pathTests[i].getTestValue();
126: expectedResult = pathTests[i].getExpectedResult();
127: assertEquals("Path test", expectedResult, URIUtil
128: .getPath(testValue));
129: }
130: }
131:
132: public void testGetQueryString() {
133: String testValue = "";
134: String expectedResult = "";
135:
136: for (int i = 0; i < queryTests.length; i++) {
137: testValue = queryTests[i].getTestValue();
138: expectedResult = queryTests[i].getExpectedResult();
139: assertEquals("Path test", expectedResult, URIUtil
140: .getQuery(testValue));
141: }
142: }
143:
144: private class URITestCase {
145: private String testValue;
146: private String expectedResult;
147:
148: public URITestCase(String testValue, String expectedResult) {
149: this .testValue = testValue;
150: this .expectedResult = expectedResult;
151: }
152:
153: public String getTestValue() {
154: return testValue;
155: }
156:
157: public String getExpectedResult() {
158: return expectedResult;
159: }
160: }
161: }
|