2
* $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestHttpUrlMethod.java,v 1.5.2.1 2004/02/22 18:21:16 olegk Exp $
4
* $Date: 2004/02/22 18:21:16 $
5
* ====================================================================
7
* Copyright 1999-2004 The Apache Software Foundation
9
* Licensed under the Apache License, Version 2.0 (the "License");
10
* you may not use this file except in compliance with the License.
11
* You may obtain a copy of the License at
13
* http://www.apache.org/licenses/LICENSE-2.0
15
* Unless required by applicable law or agreed to in writing, software
16
* distributed under the License is distributed on an "AS IS" BASIS,
17
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
* See the License for the specific language governing permissions and
19
* limitations under the License.
20
* ====================================================================
22
* This software consists of voluntary contributions made by many
23
* individuals on behalf of the Apache Software Foundation. For more
24
* information on the Apache Software Foundation, please see
25
* <http://www.apache.org/>.
27
* [Additional notices, if required by prior licensing conditions]
31
package org.apache.commons.httpclient;
33
import junit.framework.Test;
34
import junit.framework.TestCase;
35
import junit.framework.TestSuite;
37
import org.apache.commons.httpclient.methods.GetMethod;
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.
45
* @author Marc A. Saegesser
46
* @version $Id: TestHttpUrlMethod.java,v 1.5.2.1 2004/02/22 18:21:16 olegk Exp $
48
public class TestHttpUrlMethod extends TestCase {
50
// ------------------------------------------------------------ Constructor
51
public TestHttpUrlMethod(String testName) {
55
// ------------------------------------------------------------------- Main
56
public static void main(String args[]) {
57
String[] testCaseName = { TestHttpUrlMethod.class.getName() };
58
junit.textui.TestRunner.main(testCaseName);
61
// ------------------------------------------------------- TestCase Methods
63
public static Test suite() {
64
return new TestSuite(TestHttpUrlMethod.class);
68
// ----------------------------------------------------------- Test Methods
72
public void testUrlGetMethodWithPathQuery() {
73
GetMethod method = new GetMethod("http://www.fubar.com/path1/path2?query=string");
77
"http://www.fubar.com/path1/path2?query=string",
78
method.getURI().toString()
80
} catch ( URIException e ) {
81
fail( "trouble getting URI: " + e );
83
assertEquals("Get Path", "/path1/path2", method.getPath());
84
assertEquals("Get query string", "query=string", method.getQueryString());
88
public void testUrlGetMethodWithPath() {
89
GetMethod method = new GetMethod("http://www.fubar.com/path1/path2");
93
"http://www.fubar.com/path1/path2",
94
method.getURI().toString()
96
} catch ( URIException e ) {
97
fail( "trouble getting URI: " + e );
99
assertEquals("Get Path", "/path1/path2", method.getPath());
100
assertEquals("Get query string", null, method.getQueryString());
104
public void testUrlGetMethod() {
105
GetMethod method = new GetMethod("http://www.fubar.com/");
109
"http://www.fubar.com/",
110
method.getURI().toString()
112
} catch ( URIException e ) {
113
fail( "trouble getting URI: " + e );
115
assertEquals("Get Path", "/", method.getPath());
116
assertEquals("Get query string", null, method.getQueryString());
121
public void testUrlGetMethodWithInvalidProtocol() {
124
GetMethod method = new GetMethod("crap://www.fubar.com/");
125
fail("The use of invalid protocol must have resulted in an IllegalStateException");
127
catch(IllegalStateException e)