KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > httpclient > TestHeaderElement


1 /*
2  * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestHeaderElement.java,v 1.5.2.1 2004/02/22 18:21:16 olegk Exp $
3  * $Revision: 1.5.2.1 $
4  * $Date: 2004/02/22 18:21:16 $
5  * ====================================================================
6  *
7  * Copyright 1999-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  * [Additional notices, if required by prior licensing conditions]
28  *
29  */

30
31 package org.apache.commons.httpclient;
32
33 import junit.framework.*;
34
35 /**
36  * Simple tests for {@link HeaderElement}.
37  *
38  * @author Rodney Waldhoff
39  * @author <a HREF="mailto:bcholmes@interlog.com">B.C. Holmes</a>
40  * @author <a HREF="mailto:jericho@thinkfree.com">Park, Sung-Gu</a>
41  * @version $Id: TestHeaderElement.java,v 1.5.2.1 2004/02/22 18:21:16 olegk Exp $
42  */

43 public class TestHeaderElement extends TestNVP {
44
45     // ------------------------------------------------------------ Constructor
46
public TestHeaderElement(String JavaDoc testName) {
47         super(testName);
48     }
49
50     // ------------------------------------------------------------------- Main
51
public static void main(String JavaDoc args[]) {
52         String JavaDoc[] testCaseName = { TestHeaderElement.class.getName() };
53         junit.textui.TestRunner.main(testCaseName);
54     }
55
56     // ------------------------------------------------------- TestCase Methods
57

58     public static Test suite() {
59         return new TestSuite(TestHeaderElement.class);
60     }
61
62     // ------------------------------------------------------ Protected Methods
63

64     protected NameValuePair makePair() {
65         return new HeaderElement();
66     }
67
68     protected NameValuePair makePair(String JavaDoc name, String JavaDoc value) {
69         return new HeaderElement(name,value);
70     }
71
72
73     // ----------------------------------------------------------- Test Methods
74

75     public void testOldMain() throws Exception JavaDoc {
76         // this is derived from the old main method in HeaderElement
77
String JavaDoc headerValue = "name1 = value1; name2; name3=\"value3\" , name4=value4; " +
78             "name5=value5, name6= ; name7 = value7; name8 = \" value8\"";
79         HeaderElement[] elements = HeaderElement.parse(headerValue);
80         // there are 3 elements
81
assertEquals(3,elements.length);
82         // 1st element
83
assertEquals("name1",elements[0].getName());
84         assertEquals("value1",elements[0].getValue());
85         // 1st element has 2 getParameters()
86
assertEquals(2,elements[0].getParameters().length);
87         assertEquals("name2",elements[0].getParameters()[0].getName());
88         assertTrue(null == elements[0].getParameters()[0].getValue());
89         assertEquals("name3",elements[0].getParameters()[1].getName());
90         assertEquals("value3",elements[0].getParameters()[1].getValue());
91         // 2nd element
92
assertEquals("name4",elements[1].getName());
93         assertEquals("value4",elements[1].getValue());
94         // 2nd element has 1 parameter
95
assertEquals(1,elements[1].getParameters().length);
96         assertEquals("name5",elements[1].getParameters()[0].getName());
97         assertEquals("value5",elements[1].getParameters()[0].getValue());
98         // 3rd element
99
assertEquals("name6",elements[2].getName());
100         assertTrue(null == elements[2].getValue());
101         // 3rd element has 2 getParameters()
102
assertEquals(2,elements[2].getParameters().length);
103         assertEquals("name7",elements[2].getParameters()[0].getName());
104         assertEquals("value7",elements[2].getParameters()[0].getValue());
105         assertEquals("name8",elements[2].getParameters()[1].getName());
106         assertEquals(" value8",elements[2].getParameters()[1].getValue());
107     }
108 }
109
Popular Tags