1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 package org.apache.commons.httpclient;
33
34 import junit.framework.*;
35
36 /***
37 * Simple tests for {@link HeaderElement}.
38 *
39 * @author Rodney Waldhoff
40 * @author <a href="mailto:bcholmes@interlog.com">B.C. Holmes</a>
41 * @author <a href="mailto:jericho@thinkfree.com">Park, Sung-Gu</a>
42 * @author <a href="mailto:oleg@ural.ru">oleg Kalnichevski</a>
43 * @version $Id: TestHeaderElement.java 608014 2008-01-02 05:48:53Z rolandw $
44 */
45 public class TestHeaderElement extends TestNVP {
46
47
48 public TestHeaderElement(String testName) {
49 super(testName);
50 }
51
52
53 public static void main(String args[]) {
54 String[] testCaseName = { TestHeaderElement.class.getName() };
55 junit.textui.TestRunner.main(testCaseName);
56 }
57
58
59
60 public static Test suite() {
61 return new TestSuite(TestHeaderElement.class);
62 }
63
64
65
66 protected NameValuePair makePair() {
67 return new HeaderElement();
68 }
69
70 protected NameValuePair makePair(String name, String value) {
71 return new HeaderElement(name,value);
72 }
73
74
75
76
77 public void testOldMain() throws Exception {
78
79 String headerValue = "name1 = value1; name2; name3=\"value3\" , name4=value4; " +
80 "name5=value5, name6= ; name7 = value7; name8 = \" value8\"";
81 HeaderElement[] elements = HeaderElement.parseElements(headerValue);
82
83 assertEquals(3,elements.length);
84
85 assertEquals("name1",elements[0].getName());
86 assertEquals("value1",elements[0].getValue());
87
88 assertEquals(2,elements[0].getParameters().length);
89 assertEquals("name2",elements[0].getParameters()[0].getName());
90 assertEquals(null, elements[0].getParameters()[0].getValue());
91 assertEquals("name3",elements[0].getParameters()[1].getName());
92 assertEquals("value3",elements[0].getParameters()[1].getValue());
93
94 assertEquals("name4",elements[1].getName());
95 assertEquals("value4",elements[1].getValue());
96
97 assertEquals(1,elements[1].getParameters().length);
98 assertEquals("name5",elements[1].getParameters()[0].getName());
99 assertEquals("value5",elements[1].getParameters()[0].getValue());
100
101 assertEquals("name6",elements[2].getName());
102 assertEquals("",elements[2].getValue());
103
104 assertEquals(2,elements[2].getParameters().length);
105 assertEquals("name7",elements[2].getParameters()[0].getName());
106 assertEquals("value7",elements[2].getParameters()[0].getValue());
107 assertEquals("name8",elements[2].getParameters()[1].getName());
108 assertEquals(" value8",elements[2].getParameters()[1].getValue());
109 }
110
111 public void testFringeCase1() throws Exception {
112 String headerValue = "name1 = value1,";
113 HeaderElement[] elements = HeaderElement.parseElements(headerValue);
114 assertEquals("Number of elements", 1, elements.length);
115 }
116
117
118 public void testFringeCase2() throws Exception {
119 String headerValue = "name1 = value1, ";
120 HeaderElement[] elements = HeaderElement.parseElements(headerValue);
121 assertEquals("Number of elements", 1, elements.length);
122 }
123
124
125 public void testFringeCase3() throws Exception {
126 String headerValue = ",, ,, ,";
127 HeaderElement[] elements = HeaderElement.parseElements(headerValue);
128 assertEquals("Number of elements", 0, elements.length);
129 }
130 }