~ubuntu-branches/ubuntu/lucid/commons-httpclient/lucid

« back to all changes in this revision

Viewing changes to src/test/org/apache/commons/httpclient/TestHttpUrlMethod.java

  • Committer: Bazaar Package Importer
  • Author(s): Barry Hawkins
  • Date: 2005-11-25 13:12:23 UTC
  • Revision ID: james.westby@ubuntu.com-20051125131223-2g7eyo21pqgrohpo
Tags: upstream-2.0.2
ImportĀ upstreamĀ versionĀ 2.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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 $
 
3
 * $Revision: 1.5.2.1 $
 
4
 * $Date: 2004/02/22 18:21:16 $
 
5
 * ====================================================================
 
6
 *
 
7
 *  Copyright 1999-2004 The Apache Software Foundation
 
8
 *
 
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
 
12
 *
 
13
 *      http://www.apache.org/licenses/LICENSE-2.0
 
14
 *
 
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
 * ====================================================================
 
21
 *
 
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/>.
 
26
 *
 
27
 * [Additional notices, if required by prior licensing conditions]
 
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
    // ------------------------------------------------------------ Constructor
 
51
    public TestHttpUrlMethod(String testName) {
 
52
        super(testName);
 
53
    }
 
54
 
 
55
    // ------------------------------------------------------------------- Main
 
56
    public static void main(String args[]) {
 
57
        String[] testCaseName = { TestHttpUrlMethod.class.getName() };
 
58
        junit.textui.TestRunner.main(testCaseName);
 
59
    }
 
60
 
 
61
    // ------------------------------------------------------- TestCase Methods
 
62
 
 
63
    public static Test suite() {
 
64
        return new TestSuite(TestHttpUrlMethod.class);
 
65
    }
 
66
 
 
67
 
 
68
    // ----------------------------------------------------------- Test Methods
 
69
 
 
70
    // Test constructors
 
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
            //expected exception
 
130
        }
 
131
    }
 
132
}