001: /*
002: * $HeadURL: https://svn.apache.org/repos/asf/httpcomponents/httpcore/tags/4.0-beta1/module-main/src/test/java/org/apache/http/message/TestStatusLine.java $
003: * $Revision: 604625 $
004: * $Date: 2007-12-16 15:11:11 +0100 (Sun, 16 Dec 2007) $
005: * ====================================================================
006: * Licensed to the Apache Software Foundation (ASF) under one
007: * or more contributor license agreements. See the NOTICE file
008: * distributed with this work for additional information
009: * regarding copyright ownership. The ASF licenses this file
010: * to you under the Apache License, Version 2.0 (the
011: * "License"); you may not use this file except in compliance
012: * with 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,
017: * software distributed under the License is distributed on an
018: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
019: * KIND, either express or implied. See the License for the
020: * specific language governing permissions and limitations
021: * under the License.
022: * ====================================================================
023: *
024: * This software consists of voluntary contributions made by many
025: * individuals on behalf of the Apache Software Foundation. For more
026: * information on the Apache Software Foundation, please see
027: * <http://www.apache.org/>.
028: *
029: */
030:
031: package org.apache.http.message;
032:
033: import junit.framework.Test;
034: import junit.framework.TestCase;
035: import junit.framework.TestSuite;
036:
037: import org.apache.http.HttpStatus;
038: import org.apache.http.HttpVersion;
039: import org.apache.http.StatusLine;
040:
041: /**
042: * Simple tests for {@link StatusLine}.
043: *
044: * @author <a href="mailto:jsdever@apache.org">Jeff Dever</a>
045: *
046: * @version $Id: TestStatusLine.java 604625 2007-12-16 14:11:11Z olegk $
047: */
048: public class TestStatusLine extends TestCase {
049:
050: // ------------------------------------------------------------ Constructor
051: public TestStatusLine(String testName) {
052: super (testName);
053: }
054:
055: // ------------------------------------------------------------------- Main
056: public static void main(String args[]) {
057: String[] testCaseName = { TestStatusLine.class.getName() };
058: junit.textui.TestRunner.main(testCaseName);
059: }
060:
061: // ------------------------------------------------------- TestCase Methods
062:
063: public static Test suite() {
064: return new TestSuite(TestStatusLine.class);
065: }
066:
067: // ------------------------------------------------------ Protected Methods
068:
069: // ----------------------------------------------------------- Test Methods
070:
071: public void testConstructor() {
072: StatusLine statusline = new BasicStatusLine(
073: HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
074: assertEquals(HttpVersion.HTTP_1_1, statusline
075: .getProtocolVersion());
076: assertEquals(HttpStatus.SC_OK, statusline.getStatusCode());
077: assertEquals("OK", statusline.getReasonPhrase());
078: }
079:
080: public void testConstructorInvalidInput() {
081: try {
082: new BasicStatusLine(null, HttpStatus.SC_OK, "OK");
083: fail("IllegalArgumentException should have been thrown");
084: } catch (IllegalArgumentException e) { /* expected */
085: }
086: try {
087: new BasicStatusLine(HttpVersion.HTTP_1_1, -1, "OK");
088: fail("IllegalArgumentException should have been thrown");
089: } catch (IllegalArgumentException e) { /* expected */
090: }
091: }
092:
093: public void testToString() throws Exception {
094: StatusLine statusline = new BasicStatusLine(
095: HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
096: assertEquals("HTTP/1.1 200 OK", statusline.toString());
097: statusline = new BasicStatusLine(HttpVersion.HTTP_1_1,
098: HttpStatus.SC_OK, null);
099: // toString uses default formatting, hence the trailing space
100: assertEquals("HTTP/1.1 200 ", statusline.toString());
101: }
102:
103: public void testCloning() throws Exception {
104: BasicStatusLine orig = new BasicStatusLine(
105: HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
106: BasicStatusLine clone = (BasicStatusLine) orig.clone();
107: assertEquals(orig.getReasonPhrase(), clone.getReasonPhrase());
108: assertEquals(orig.getStatusCode(), clone.getStatusCode());
109: assertEquals(orig.getProtocolVersion(), clone
110: .getProtocolVersion());
111: }
112:
113: }
|