001: /*
002: * $HeadURL: https://svn.apache.org/repos/asf/httpcomponents/httpcore/tags/4.0-beta1/module-main/src/test/java/org/apache/http/message/TestHeader.java $
003: * $Revision: 604625 $
004: * $Date: 2007-12-16 15:11:11 +0100 (Sun, 16 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.message;
033:
034: import junit.framework.Test;
035: import junit.framework.TestCase;
036: import junit.framework.TestSuite;
037:
038: import org.apache.http.Header;
039: import org.apache.http.HeaderElement;
040:
041: /**
042: * Unit tests for {@link Header}.
043: *
044: * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
045: */
046: public class TestHeader extends TestCase {
047:
048: public TestHeader(String testName) {
049: super (testName);
050: }
051:
052: public static void main(String args[]) {
053: String[] testCaseName = { TestHeader.class.getName() };
054: junit.textui.TestRunner.main(testCaseName);
055: }
056:
057: public static Test suite() {
058: return new TestSuite(TestHeader.class);
059: }
060:
061: public void testBasicConstructor() {
062: Header header = new BasicHeader("name", "value");
063: assertEquals("name", header.getName());
064: assertEquals("value", header.getValue());
065: }
066:
067: public void testBasicConstructorNullValue() {
068: Header header = new BasicHeader("name", null);
069: assertEquals("name", header.getName());
070: assertEquals(null, header.getValue());
071: }
072:
073: public void testInvalidName() {
074: try {
075: new BasicHeader(null, null);
076: fail("IllegalArgumentException should have been thrown");
077: } catch (IllegalArgumentException ex) {
078: //expected
079: }
080: }
081:
082: public void testToString() {
083: Header header1 = new BasicHeader("name1", "value1");
084: assertEquals("name1: value1", header1.toString());
085: Header header2 = new BasicHeader("name2", null);
086: assertEquals("name2: ", header2.toString());
087: }
088:
089: public void testHeaderElements() {
090: Header header = new BasicHeader("name",
091: "element1 = value1, element2; param1 = value1, element3");
092: HeaderElement[] elements = header.getElements();
093: assertNotNull(elements);
094: assertEquals(3, elements.length);
095: assertEquals("element1", elements[0].getName());
096: assertEquals("value1", elements[0].getValue());
097: assertEquals("element2", elements[1].getName());
098: assertEquals(null, elements[1].getValue());
099: assertEquals("element3", elements[2].getName());
100: assertEquals(null, elements[2].getValue());
101: assertEquals(1, elements[1].getParameters().length);
102:
103: header = new BasicHeader("name", null);
104: elements = header.getElements();
105: assertNotNull(elements);
106: assertEquals(0, elements.length);
107: }
108:
109: public void testCloning() throws Exception {
110: BasicHeader orig = new BasicHeader("name1", "value1");
111: BasicHeader clone = (BasicHeader) orig.clone();
112: assertEquals(orig.getName(), clone.getName());
113: assertEquals(orig.getValue(), clone.getValue());
114: }
115:
116: }
|