1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package org.xwiki.velocity.tools; |
22 |
|
|
23 |
|
import java.util.Arrays; |
24 |
|
import java.util.Collections; |
25 |
|
import java.util.Map; |
26 |
|
|
27 |
|
import org.junit.Test; |
28 |
|
|
29 |
|
import static org.junit.Assert.*; |
30 |
|
|
31 |
|
|
32 |
|
@link |
33 |
|
|
34 |
|
@version |
35 |
|
@since |
36 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (21) |
Complexity: 5 |
Complexity Density: 0.31 |
|
37 |
|
public class URLToolTest |
38 |
|
{ |
39 |
|
private URLTool tool = new URLTool(); |
40 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
41 |
1 |
@Test... |
42 |
|
public void testSimpleUrlParse() |
43 |
|
{ |
44 |
1 |
Map<String, ?> query = tool.parseQuery("a=b%26c"); |
45 |
1 |
assertEquals("should have one parameter", Collections.singleton("a"), query.keySet()); |
46 |
1 |
assertEquals("should have one parameter value", Collections.singletonList("b&c"), query.get("a")); |
47 |
|
} |
48 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
49 |
1 |
@Test... |
50 |
|
public void testUrlParseMultipleValues() |
51 |
|
{ |
52 |
1 |
Map<String, ?> query = tool.parseQuery("a=b+c&a=b%3Dc&ab=a+%26+b"); |
53 |
1 |
assertEquals("should have two parameter", 2, query.size()); |
54 |
1 |
assertEquals("should have one parameter value for ab", Collections.singletonList("a & b"), query.get("ab")); |
55 |
1 |
assertEquals("should have two parameter values for a", Arrays.asList(new String[] {"b c", "b=c"}), |
56 |
|
query.get("a")); |
57 |
|
} |
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
59 |
1 |
@Test... |
60 |
|
public void testInvalidUrlParse() |
61 |
|
{ |
62 |
1 |
Map<String, ?> query = tool.parseQuery("a=b ' onclick='foo"); |
63 |
1 |
assertEquals("should have one parameter", Collections.singleton("a"), query.keySet()); |
64 |
1 |
assertEquals("should have one parameter", Collections.singletonList("b ' onclick='foo"), query.get("a")); |
65 |
|
} |
66 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
67 |
1 |
@Test... |
68 |
|
public void testHandleNull() |
69 |
|
{ |
70 |
1 |
Map<String, ?> query = tool.parseQuery(null); |
71 |
1 |
assertNotNull("null query results in empty map", query); |
72 |
1 |
assertTrue("null query results in empty map", query.isEmpty()); |
73 |
|
} |
74 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
75 |
1 |
@Test... |
76 |
|
public void preserveParameterOrder() |
77 |
|
{ |
78 |
1 |
EscapeTool escapeTool = new EscapeTool(); |
79 |
1 |
String queryString = "x=5&x=4&r=3&a=2"; |
80 |
1 |
assertEquals(queryString, escapeTool.url(tool.parseQuery(queryString))); |
81 |
|
} |
82 |
|
} |