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
|
package com.vaadin.client;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import com.vaadin.client.ApplicationConnection;
public class ApplicationConnectionTestURLGeneration {
private static final String[] URIS = new String[] {
"http://demo.vaadin.com/", //
"https://demo.vaadin.com/",
"http://demo.vaadin.com/foo",
"http://demo.vaadin.com/foo?f",
"http://demo.vaadin.com/foo?f=1",
"http://demo.vaadin.com:1234/foo?a",
"http://demo.vaadin.com:1234/foo#frag?fakeparam",
// Jetspeed
"http://localhost:8080/jetspeed/portal/_ns:Z3RlbXBsYXRlLXRvcDJfX3BhZ2UtdGVtcGxhdGVfX2RwLTFfX1AtMTJjNTRkYjdlYjUtMTAwMDJ8YzB8ZDF8aVVJREx8Zg__",
// Liferay generated url
"http://vaadin.com/directory?p_p_id=Directory_WAR_Directory&p_p_lifecycle=2&p_p_state=normal&p_p_mode=view&p_p_resource_id=UIDL&p_p_cacheability=cacheLevelPage&p_p_col_id=row-1&p_p_col_count=1",
};
private static final String[] URIS_WITH_ABCD_PARAM = new String[] {
"http://demo.vaadin.com/?a=b&c=d",
"https://demo.vaadin.com/?a=b&c=d",
"http://demo.vaadin.com/foo?a=b&c=d",
"http://demo.vaadin.com/foo?f&a=b&c=d",
"http://demo.vaadin.com/foo?f=1&a=b&c=d",
"http://demo.vaadin.com:1234/foo?a&a=b&c=d",
"http://demo.vaadin.com:1234/foo?a=b&c=d#frag?fakeparam",
"http://localhost:8080/jetspeed/portal/_ns:Z3RlbXBsYXRlLXRvcDJfX3BhZ2UtdGVtcGxhdGVfX2RwLTFfX1AtMTJjNTRkYjdlYjUtMTAwMDJ8YzB8ZDF8aVVJREx8Zg__?a=b&c=d",
"http://vaadin.com/directory?p_p_id=Directory_WAR_Directory&p_p_lifecycle=2&p_p_state=normal&p_p_mode=view&p_p_resource_id=UIDL&p_p_cacheability=cacheLevelPage&p_p_col_id=row-1&p_p_col_count=1&a=b&c=d",
};
private static final String[] URIS_WITH_ABCD_PARAM_AND_FRAGMENT = new String[] {
"http://demo.vaadin.com/?a=b&c=d#fragment",
"https://demo.vaadin.com/?a=b&c=d#fragment",
"http://demo.vaadin.com/foo?a=b&c=d#fragment",
"http://demo.vaadin.com/foo?f&a=b&c=d#fragment",
"http://demo.vaadin.com/foo?f=1&a=b&c=d#fragment",
"http://demo.vaadin.com:1234/foo?a&a=b&c=d#fragment",
"",
"http://localhost:8080/jetspeed/portal/_ns:Z3RlbXBsYXRlLXRvcDJfX3BhZ2UtdGVtcGxhdGVfX2RwLTFfX1AtMTJjNTRkYjdlYjUtMTAwMDJ8YzB8ZDF8aVVJREx8Zg__?a=b&c=d#fragment",
"http://vaadin.com/directory?p_p_id=Directory_WAR_Directory&p_p_lifecycle=2&p_p_state=normal&p_p_mode=view&p_p_resource_id=UIDL&p_p_cacheability=cacheLevelPage&p_p_col_id=row-1&p_p_col_count=1&a=b&c=d#fragment",
};
@Test
public void testParameterAdding() {
for (int i = 0; i < URIS.length; i++) {
// Adding nothing
assertEquals(URIS[i],
ApplicationConnection.addGetParameters(URIS[i], ""));
// Adding a=b&c=d
assertEquals(URIS_WITH_ABCD_PARAM[i],
ApplicationConnection.addGetParameters(URIS[i], "a=b&c=d"));
// Fragments
if (URIS_WITH_ABCD_PARAM_AND_FRAGMENT[i].length() > 0) {
assertEquals(
URIS_WITH_ABCD_PARAM_AND_FRAGMENT[i],
ApplicationConnection.addGetParameters(URIS[i]
+ "#fragment", "a=b&c=d"));
// Empty fragment
assertEquals(URIS_WITH_ABCD_PARAM_AND_FRAGMENT[i].replace(
"#fragment", "#"),
ApplicationConnection.addGetParameters(URIS[i] + "#",
"a=b&c=d"));
}
}
}
}
|