MCPcopy Create free account
hub / github.com/jetlang/remoting / HttpRequestTest

Class HttpRequestTest

src/test/java/org/jetlang/web/HttpRequestTest.java:15–104  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13import static org.junit.Assert.fail;
14
15public class HttpRequestTest {
16
17 @Test
18 public void parseUriQueryParams() {
19 String uri = "/path?param=1&param=2&other=with+space";
20 KeyValueList stringListMap = HttpRequest.splitQuery(URI.create(uri));
21 assertEquals(stringListMap.toString(), 3, stringListMap.size());
22 List<String> param = stringListMap.getAll("param");
23 assertEquals(2, param.size());
24 assertEquals("1", param.get(0));
25 assertEquals("2", param.get(1));
26
27 List<String> other = stringListMap.getAll("other");
28 assertEquals(1, other.size());
29 assertEquals("with space", other.get(0));
30 }
31
32 @Test
33 public void empty() {
34 String uri = "/path";
35 KeyValueList stringListMap = HttpRequest.splitQuery(URI.create(uri));
36 assertEquals(stringListMap.toString(), 0, stringListMap.size());
37 }
38
39 @Test
40 public void parseEncoded() {
41 String uri = "/keyvaluepair?type=thrift&Key=ENABLD+ZC%2bStuff+BF&Value=";
42 URI url = URI.create(uri);
43 assertEquals("type=thrift&Key=ENABLD+ZC%2bStuff+BF&Value=", url.getRawQuery());
44 KeyValueList stringListMap = HttpRequest.splitQuery(url);
45 assertEquals(stringListMap.toString(), 3, stringListMap.size());
46 assertEquals("thrift", stringListMap.get("type"));
47 assertEquals("ENABLD ZC+Stuff BF", stringListMap.get("Key"));
48 assertTrue(stringListMap.contains("Value"));
49 assertNull(stringListMap.get("Value"));
50 }
51
52 @Test
53 public void emptyWithQuestionMark() {
54 String uri = "/path?";
55 KeyValueList stringListMap = HttpRequest.splitQuery(URI.create(uri));
56 assertEquals(stringListMap.toString(), 0, stringListMap.size());
57 }
58
59 @Test
60 public void testGettingBodyWithEncoding() {
61 HttpRequest req = new HttpRequest("POST", "/path", "HTTP/1.1", null);
62 req.add("Content-Type", "application/x-www-form-urlencoded ; charset=UTF-8");
63 Charset charset = Charset.forName("UTF-8");
64 req.content = "Hello".getBytes(charset);
65 assertEquals(charset, req.getContentCharset(true));
66 assertEquals("Hello", req.getContentAsString(true));
67 }
68
69
70 @Test
71 public void testGettingBodyWithBadEncoding() {
72 HttpRequest req = new HttpRequest("POST", "/path", "HTTP/1.1", null);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…