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 package org.apache.http.impl.cookie;
29
30 import org.apache.http.HeaderElement;
31 import org.apache.http.NameValuePair;
32 import org.apache.http.message.ParserCursor;
33 import org.apache.http.util.CharArrayBuffer;
34 import org.junit.Assert;
35 import org.junit.Test;
36
37
38
39
40 public class TestNetscapeDraftHeaderParser {
41
42 @Test
43 public void testNetscapeCookieParsing() throws Exception {
44 final NetscapeDraftHeaderParser parser = NetscapeDraftHeaderParser.DEFAULT;
45
46 String s = "name = value; test; test1 = stuff,with,commas ;" +
47 " test2 = \"stuff, stuff\"; test3=\"stuff";
48 CharArrayBuffer buffer = new CharArrayBuffer(16);
49 buffer.append(s);
50 ParserCursor cursor = new ParserCursor(0, s.length());
51
52 HeaderElement he = parser.parseHeader(buffer, cursor);
53 Assert.assertEquals("name", he.getName());
54 Assert.assertEquals("value", he.getValue());
55 final NameValuePair[] params = he.getParameters();
56 Assert.assertEquals("test", params[0].getName());
57 Assert.assertEquals(null, params[0].getValue());
58 Assert.assertEquals("test1", params[1].getName());
59 Assert.assertEquals("stuff,with,commas", params[1].getValue());
60 Assert.assertEquals("test2", params[2].getName());
61 Assert.assertEquals("\"stuff, stuff\"", params[2].getValue());
62 Assert.assertEquals("test3", params[3].getName());
63 Assert.assertEquals("\"stuff", params[3].getValue());
64 Assert.assertEquals(s.length(), cursor.getPos());
65 Assert.assertTrue(cursor.atEnd());
66
67 s = " ";
68 buffer = new CharArrayBuffer(16);
69 buffer.append(s);
70 cursor = new ParserCursor(0, s.length());
71 he = parser.parseHeader(buffer, cursor);
72 Assert.assertEquals("", he.getName());
73 Assert.assertEquals(null, he.getValue());
74 }
75
76 }