-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathParseTest.java
More file actions
110 lines (96 loc) · 3.55 KB
/
Copy pathParseTest.java
File metadata and controls
110 lines (96 loc) · 3.55 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
* Copyright (c) 2011-2020 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*/
package io.vertx.tests.parsing;
import io.vertx.httpproxy.impl.CacheControl;
import org.junit.Assert;
import org.junit.Test;
/**
* @author <a href="mailto:julien@julienviet.com">Julien Viet</a>
*/
public class ParseTest {
@Test
public void testParseCacheControlMaxAge() {
CacheControl control = new CacheControl();
Assert.assertEquals(123, control.parse("max-age=123").maxAge());
Assert.assertEquals(-1, control.parse("").maxAge());
}
@Test
public void testParseCacheControlPublic() {
CacheControl control = new CacheControl();
Assert.assertFalse(control.parse("max-age=123").isPublic());
Assert.assertTrue(control.parse("public").isPublic());
}
@Test
public void testCommaSplit(){
CacheControl control = new CacheControl();
Assert.assertTrue(control.parse("max-age=123,public,no-cache").isPublic());
Assert.assertEquals(control.parse("max-age=123,public,no-cache").maxAge(), 123);
Assert.assertEquals(control.parse("max-age=12121212").maxAge(), 12121212);
}
@Test
public void testSpaceSplit(){
CacheControl control = new CacheControl();
Assert.assertTrue(control.parse("max-age=123 public no-cache").isPublic());
Assert.assertEquals(control.parse("max-age=123 public no-cache").maxAge(), 123);
Assert.assertEquals(control.parse("max-age=12121212").maxAge(), 12121212);
}
@Test
public void testCommaAndSpaceSplit(){
CacheControl control = new CacheControl();
Assert.assertTrue(control.parse("max-age=123, public, no-cache").isPublic());
Assert.assertEquals(control.parse("max-age=123, public, no-cache").maxAge(), 123);
Assert.assertEquals(control.parse("max-age=12121212").maxAge(), 12121212);
}
@Test
public void testCaseInsensitiveParsing() {
CacheControl control = new CacheControl();
CacheControl parsed = control.parse("MaX-AgE=999, PuBLic");
Assert.assertTrue(parsed.isPublic());
Assert.assertEquals(999, parsed.maxAge());
}
@Test
public void testExtraSpacesAndCommas() {
CacheControl control = new CacheControl();
CacheControl parsed = control.parse(" , max-age=45 , , public ");
Assert.assertTrue(parsed.isPublic());
Assert.assertEquals(45, parsed.maxAge());
}
/*
@Test
public void testCommaSplit() {
assertCommaSplit("foo", "foo");
assertCommaSplit(" foo", "foo");
assertCommaSplit("foo ", "foo");
failCommaSplit("foo,", "foo");
failCommaSplit(",foo");
failCommaSplit("foo bar");
// assertCommaSplit("foo,bar", "foo", "bar");
// assertCommaSplit("foo ,bar", "foo", "bar");
// assertCommaSplit("foo, bar", "foo", "bar");
// assertCommaSplit("foo,bar ", "foo", "bar");
}
private void assertCommaSplit(String header, String... expected) {
LinkedList<String> list = new LinkedList<>();
ParseUtils.commaSplit(header, list::add);
assertEquals(Arrays.asList(expected), list);
}
private void failCommaSplit(String header, String... expected) {
LinkedList<String> list = new LinkedList<>();
try {
ParseUtils.commaSplit(header, list::add);
} catch (IllegalStateException e) {
assertEquals(Arrays.asList(expected), list);
return;
}
fail();
}
*/
}