source: josm/trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/RequestHandlerTest.java@ 8509

Last change on this file since 8509 was 8509, checked in by Don-vip, 9 years ago

fix many checkstyle violations

File size: 2.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io.remotecontrol.handler;
3
4import static org.hamcrest.CoreMatchers.is;
5import static org.junit.Assert.assertThat;
6
7import java.util.Collections;
8import java.util.HashMap;
9import java.util.Map;
10
11import org.junit.Test;
12import org.openstreetmap.josm.io.remotecontrol.PermissionPrefWithDefault;
13
14public class RequestHandlerTest {
15
16 Map<String, String> getRequestParameter(String url) {
17 final RequestHandler req = new RequestHandler() {
18 @Override
19 protected void validateRequest() throws RequestHandlerBadRequestException {
20 }
21
22 @Override
23 protected void handleRequest() throws RequestHandlerErrorException, RequestHandlerBadRequestException {
24 }
25
26 @Override
27 public String getPermissionMessage() {
28 return null;
29 }
30
31 @Override
32 public PermissionPrefWithDefault getPermissionPref() {
33 return null;
34 }
35
36 @Override
37 public String[] getMandatoryParams() {
38 return new String[0];
39 }
40 };
41 req.setUrl(url);
42 return req.args;
43 }
44
45
46 @Test
47 public void testRequestParameter1() {
48 final Map<String, String> expected = new HashMap<>();
49 expected.put("query", "a");
50 expected.put("b", "=c");
51 assertThat(getRequestParameter("http://example.com/?query=a&b==c"),
52 is(expected));
53 }
54
55 @Test
56 public void testRequestParameter12() {
57 assertThat(getRequestParameter("http://example.com/?query=a%26b==c"),
58 is(Collections.singletonMap("query", "a&b==c")));
59 }
60
61 @Test
62 public void testRequestParameter3() {
63 assertThat(getRequestParameter("http://example.com/blue+light%20blue?blue%2Blight+blue").keySet(),
64 is((Collections.singleton("blue+light blue"))));
65 }
66
67 /**
68 * @see <a href="http://blog.lunatech.com/2009/02/03/what-every-web-developer-must-know-about-url-encoding">
69 * What every web developer must know about URL encoding</a>
70 */
71 @Test
72 public void testRequestParameter4() {
73 assertThat(getRequestParameter(
74 "http://example.com/:@-._~!$&'()*+,=;:@-._~!$&'()*+,=:@-._~!$&'()*+,==?/?:@-._~!$'()*+,;=/?:@-._~!$'()*+,;==#/?:@-._~!$&'()*+,;="),
75 is(Collections.singletonMap("/?:@-._~!$'()* ,;", "/?:@-._~!$'()* ,;==")));
76 }
77
78 @Test
79 public void testRequestParameter5() {
80 final Map<String, String> expected = new HashMap<>();
81 expected.put("space", " ");
82 expected.put("tab", "\t");
83 assertThat(getRequestParameter("http://example.com/?space=%20&tab=%09"),
84 is(expected));
85 }
86}
Note: See TracBrowser for help on using the repository browser.