001: /*
002: * $HeadURL: https://svn.apache.org/repos/asf/httpcomponents/httpcore/tags/4.0-beta1/module-main/src/test/java/org/apache/http/TestHttpVersion.java $
003: * $Revision: 604514 $
004: * $Date: 2007-12-15 21:49:40 +0100 (Sat, 15 Dec 2007) $
005: *
006: * ====================================================================
007: * Licensed to the Apache Software Foundation (ASF) under one
008: * or more contributor license agreements. See the NOTICE file
009: * distributed with this work for additional information
010: * regarding copyright ownership. The ASF licenses this file
011: * to you under the Apache License, Version 2.0 (the
012: * "License"); you may not use this file except in compliance
013: * with the License. You may obtain a copy of the License at
014: *
015: * http://www.apache.org/licenses/LICENSE-2.0
016: *
017: * Unless required by applicable law or agreed to in writing,
018: * software distributed under the License is distributed on an
019: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
020: * KIND, either express or implied. See the License for the
021: * specific language governing permissions and limitations
022: * under the License.
023: * ====================================================================
024: *
025: * This software consists of voluntary contributions made by many
026: * individuals on behalf of the Apache Software Foundation. For more
027: * information on the Apache Software Foundation, please see
028: * <http://www.apache.org/>.
029: *
030: */
031:
032: package org.apache.http;
033:
034: import junit.framework.Test;
035: import junit.framework.TestCase;
036: import junit.framework.TestSuite;
037:
038: /**
039: * Test cases for HTTP version class
040: *
041: * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
042: */
043: public class TestHttpVersion extends TestCase {
044:
045: // ------------------------------------------------------------ Constructor
046:
047: public TestHttpVersion(String name) {
048: super (name);
049: }
050:
051: // ------------------------------------------------------- TestCase Methods
052:
053: public static Test suite() {
054: return new TestSuite(TestHttpVersion.class);
055: }
056:
057: // ------------------------------------------------------------------ Tests
058:
059: public void testHttpVersionInvalidConstructorInput()
060: throws Exception {
061: try {
062: new HttpVersion(-1, -1);
063: fail("IllegalArgumentException should have been thrown");
064: } catch (IllegalArgumentException e) {
065: // expected
066: }
067: try {
068: new HttpVersion(0, -1);
069: fail("IllegalArgumentException should have been thrown");
070: } catch (IllegalArgumentException e) {
071: // expected
072: }
073: }
074:
075: public void testHttpVersionEquality() throws Exception {
076: HttpVersion ver1 = new HttpVersion(1, 1);
077: HttpVersion ver2 = new HttpVersion(1, 1);
078:
079: assertEquals(ver1.hashCode(), ver2.hashCode());
080: assertTrue(ver1.equals(ver1));
081: assertTrue(ver1.equals(ver2));
082: assertTrue(ver1.equals((Object) ver1));
083: assertTrue(ver1.equals((Object) ver2));
084:
085: assertFalse(ver1.equals(new Float(1.1)));
086:
087: assertTrue((new HttpVersion(0, 9)).equals(HttpVersion.HTTP_0_9));
088: assertTrue((new HttpVersion(1, 0)).equals(HttpVersion.HTTP_1_0));
089: assertTrue((new HttpVersion(1, 1)).equals(HttpVersion.HTTP_1_1));
090: assertFalse((new HttpVersion(1, 1))
091: .equals(HttpVersion.HTTP_1_0));
092:
093: assertTrue((new ProtocolVersion("HTTP", 0, 9))
094: .equals(HttpVersion.HTTP_0_9));
095: assertTrue((new ProtocolVersion("HTTP", 1, 0))
096: .equals(HttpVersion.HTTP_1_0));
097: assertTrue((new ProtocolVersion("HTTP", 1, 1))
098: .equals(HttpVersion.HTTP_1_1));
099: assertFalse((new ProtocolVersion("http", 1, 1))
100: .equals(HttpVersion.HTTP_1_1));
101:
102: assertTrue(HttpVersion.HTTP_0_9.equals(new ProtocolVersion(
103: "HTTP", 0, 9)));
104: assertTrue(HttpVersion.HTTP_1_0.equals(new ProtocolVersion(
105: "HTTP", 1, 0)));
106: assertTrue(HttpVersion.HTTP_1_1.equals(new ProtocolVersion(
107: "HTTP", 1, 1)));
108: assertFalse(HttpVersion.HTTP_1_1.equals(new ProtocolVersion(
109: "http", 1, 1)));
110: }
111:
112: public void testHttpVersionComparison() {
113: assertTrue(HttpVersion.HTTP_0_9
114: .lessEquals(HttpVersion.HTTP_1_1));
115: assertTrue(HttpVersion.HTTP_0_9
116: .greaterEquals(HttpVersion.HTTP_0_9));
117: assertFalse(HttpVersion.HTTP_0_9
118: .greaterEquals(HttpVersion.HTTP_1_0));
119:
120: assertTrue(HttpVersion.HTTP_1_0
121: .compareToVersion(HttpVersion.HTTP_1_1) < 0);
122: assertTrue(HttpVersion.HTTP_1_0
123: .compareToVersion(HttpVersion.HTTP_0_9) > 0);
124: assertTrue(HttpVersion.HTTP_1_0
125: .compareToVersion(HttpVersion.HTTP_1_0) == 0);
126: }
127:
128: public void testCloning() throws Exception {
129: HttpVersion orig = HttpVersion.HTTP_1_1;
130: HttpVersion clone = (HttpVersion) orig.clone();
131: assertEquals(orig, clone);
132: }
133:
134: }
|