001: /*
002: * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/TestHeaderElement.java,v 1.7 2004/02/22 18:08:49 olegk Exp $
003: * $Revision: 480424 $
004: * $Date: 2006-11-29 06:56:49 +0100 (Wed, 29 Nov 2006) $
005: * ====================================================================
006: *
007: * Licensed to the Apache Software Foundation (ASF) under one or more
008: * contributor license agreements. See the NOTICE file distributed with
009: * this work for additional information regarding copyright ownership.
010: * The ASF licenses this file to You under the Apache License, Version 2.0
011: * (the "License"); you may not use this file except in compliance with
012: * 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, software
017: * distributed under the License is distributed on an "AS IS" BASIS,
018: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
019: * See the License for the specific language governing permissions and
020: * limitations under the License.
021: * ====================================================================
022: *
023: * This software consists of voluntary contributions made by many
024: * individuals on behalf of the Apache Software Foundation. For more
025: * information on the Apache Software Foundation, please see
026: * <http://www.apache.org/>.
027: *
028: * [Additional notices, if required by prior licensing conditions]
029: *
030: */
031:
032: package org.apache.commons.httpclient;
033:
034: import junit.framework.*;
035:
036: /**
037: * Simple tests for {@link HeaderElement}.
038: *
039: * @author Rodney Waldhoff
040: * @author <a href="mailto:bcholmes@interlog.com">B.C. Holmes</a>
041: * @author <a href="mailto:jericho@thinkfree.com">Park, Sung-Gu</a>
042: * @author <a href="mailto:oleg@ural.ru">oleg Kalnichevski</a>
043: * @version $Id: TestHeaderElement.java 480424 2006-11-29 05:56:49Z bayard $
044: */
045: public class TestHeaderElement extends TestNVP {
046:
047: // ------------------------------------------------------------ Constructor
048: public TestHeaderElement(String testName) {
049: super (testName);
050: }
051:
052: // ------------------------------------------------------------------- Main
053: public static void main(String args[]) {
054: String[] testCaseName = { TestHeaderElement.class.getName() };
055: junit.textui.TestRunner.main(testCaseName);
056: }
057:
058: // ------------------------------------------------------- TestCase Methods
059:
060: public static Test suite() {
061: return new TestSuite(TestHeaderElement.class);
062: }
063:
064: // ------------------------------------------------------ Protected Methods
065:
066: protected NameValuePair makePair() {
067: return new HeaderElement();
068: }
069:
070: protected NameValuePair makePair(String name, String value) {
071: return new HeaderElement(name, value);
072: }
073:
074: // ----------------------------------------------------------- Test Methods
075:
076: public void testOldMain() throws Exception {
077: // this is derived from the old main method in HeaderElement
078: String headerValue = "name1 = value1; name2; name3=\"value3\" , name4=value4; "
079: + "name5=value5, name6= ; name7 = value7; name8 = \" value8\"";
080: HeaderElement[] elements = HeaderElement
081: .parseElements(headerValue);
082: // there are 3 elements
083: assertEquals(3, elements.length);
084: // 1st element
085: assertEquals("name1", elements[0].getName());
086: assertEquals("value1", elements[0].getValue());
087: // 1st element has 2 getParameters()
088: assertEquals(2, elements[0].getParameters().length);
089: assertEquals("name2", elements[0].getParameters()[0].getName());
090: assertEquals(null, elements[0].getParameters()[0].getValue());
091: assertEquals("name3", elements[0].getParameters()[1].getName());
092: assertEquals("value3", elements[0].getParameters()[1]
093: .getValue());
094: // 2nd element
095: assertEquals("name4", elements[1].getName());
096: assertEquals("value4", elements[1].getValue());
097: // 2nd element has 1 parameter
098: assertEquals(1, elements[1].getParameters().length);
099: assertEquals("name5", elements[1].getParameters()[0].getName());
100: assertEquals("value5", elements[1].getParameters()[0]
101: .getValue());
102: // 3rd element
103: assertEquals("name6", elements[2].getName());
104: assertEquals("", elements[2].getValue());
105: // 3rd element has 2 getParameters()
106: assertEquals(2, elements[2].getParameters().length);
107: assertEquals("name7", elements[2].getParameters()[0].getName());
108: assertEquals("value7", elements[2].getParameters()[0]
109: .getValue());
110: assertEquals("name8", elements[2].getParameters()[1].getName());
111: assertEquals(" value8", elements[2].getParameters()[1]
112: .getValue());
113: }
114:
115: public void testFringeCase1() throws Exception {
116: String headerValue = "name1 = value1,";
117: HeaderElement[] elements = HeaderElement
118: .parseElements(headerValue);
119: assertEquals("Number of elements", 1, elements.length);
120: }
121:
122: public void testFringeCase2() throws Exception {
123: String headerValue = "name1 = value1, ";
124: HeaderElement[] elements = HeaderElement
125: .parseElements(headerValue);
126: assertEquals("Number of elements", 1, elements.length);
127: }
128:
129: public void testFringeCase3() throws Exception {
130: String headerValue = ",, ,, ,";
131: HeaderElement[] elements = HeaderElement
132: .parseElements(headerValue);
133: assertEquals("Number of elements", 0, elements.length);
134: }
135: }
|