Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/apache/http/impl/TestBasicRequest.java


1   /*
2    * $HeadURL: https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpcore/tags/4.0-alpha2/src/test/org/apache/http/impl/TestBasicRequest.java $
3    * $Revision: 292248 $
4    * $Date: 2005-09-28 20:45:35 +0200 (Wed, 28 Sep 2005) $
5    * ====================================================================
6    *
7    *  Copyright 2002-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   */
28  
29  package org.apache.http.impl;
30  
31  import junit.framework.Test;
32  import junit.framework.TestCase;
33  import junit.framework.TestSuite;
34  
35  import org.apache.http.HttpRequest;
36  import org.apache.http.HttpVersion;
37  import org.apache.http.RequestLine;
38  import org.apache.http.message.BasicHttpRequest;
39  import org.apache.http.params.HttpProtocolParams;
40  
41  public class TestBasicRequest extends TestCase {
42  
43      public TestBasicRequest(String testName) {
44          super(testName);
45      }
46  
47      // ------------------------------------------------------- TestCase Methods
48  
49      public static Test suite() {
50          return new TestSuite(TestBasicRequest.class);
51      }
52  
53      // ------------------------------------------------------------------- Main
54      public static void main(String args[]) {
55          String[] testCaseName = { TestBasicRequest.class.getName() };
56          junit.textui.TestRunner.main(testCaseName);
57      }
58  
59      public void testConstructor() throws Exception {
60          new BasicHttpRequest("GET", "/stuff");
61          new BasicHttpRequest(new RequestLine("GET", "/stuff", HttpVersion.HTTP_1_1));
62          try {
63              new BasicHttpRequest(null, "/stuff");
64              fail("IllegalArgumentException should have been thrown");
65          } catch (IllegalArgumentException ex) {
66              // expected
67          }
68          try {
69              new BasicHttpRequest("GET", null);
70              fail("IllegalArgumentException should have been thrown");
71          } catch (IllegalArgumentException ex) {
72              // expected
73          }
74      }
75  
76      public void testRequestLine() throws Exception {
77          HttpRequest request = new BasicHttpRequest("GET", "/stuff");
78          request.getParams().setParameter(
79                  HttpProtocolParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_0);
80          assertEquals("GET", request.getRequestLine().getMethod());
81          assertEquals("/stuff", request.getRequestLine().getUri());
82          assertEquals(HttpVersion.HTTP_1_0, request.getRequestLine().getHttpVersion());
83      }
84  
85      public void testRequestLine2() throws Exception {
86          HttpRequest request = new BasicHttpRequest(
87                  new RequestLine("GET", "/stuff", HttpVersion.HTTP_1_0));
88          assertEquals("GET", request.getRequestLine().getMethod());
89          assertEquals("/stuff", request.getRequestLine().getUri());
90          assertEquals(HttpVersion.HTTP_1_0, request.getRequestLine().getHttpVersion());
91      }
92  
93  }
94