Repository navigation
Expand file tree
/
Copy pathHttpRequestUtilsTest.java
More file actions
73 lines (59 loc) · 2.48 KB
/
Copy pathHttpRequestUtilsTest.java
File metadata and controls
73 lines (59 loc) · 2.48 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
package util;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import java.util.Map;
import org.junit.Test;
import util.HttpRequestUtils.Pair;
public class HttpRequestUtilsTest {
@Test
public void parseQueryString() {
String queryString = "userId=javajigi";
Map<String, String> parameters = HttpRequestUtils.parseQueryString(queryString);
assertThat(parameters.get("userId"), is("javajigi"));
assertThat(parameters.get("password"), is(nullValue()));
queryString = "userId=javajigi&password=password2";
parameters = HttpRequestUtils.parseQueryString(queryString);
assertThat(parameters.get("userId"), is("javajigi"));
assertThat(parameters.get("password"), is("password2"));
}
@Test
public void parseQueryString_null() {
Map<String, String> parameters = HttpRequestUtils.parseQueryString(null);
assertThat(parameters.isEmpty(), is(true));
parameters = HttpRequestUtils.parseQueryString("");
assertThat(parameters.isEmpty(), is(true));
parameters = HttpRequestUtils.parseQueryString(" ");
assertThat(parameters.isEmpty(), is(true));
}
@Test
public void parseQueryString_invalid() {
String queryString = "userId=javajigi&password";
Map<String, String> parameters = HttpRequestUtils.parseQueryString(queryString);
assertThat(parameters.get("userId"), is("javajigi"));
assertThat(parameters.get("password"), is(nullValue()));
}
@Test
public void parseCookies() {
String cookies = "logined=true; JSessionId=1234";
Map<String, String> parameters = HttpRequestUtils.parseCookies(cookies);
assertThat(parameters.get("logined"), is("true"));
assertThat(parameters.get("JSessionId"), is("1234"));
assertThat(parameters.get("session"), is(nullValue()));
}
@Test
public void getKeyValue() throws Exception {
Pair pair = HttpRequestUtils.getKeyValue("userId=javajigi", "=");
assertThat(pair, is(new Pair("userId", "javajigi")));
}
@Test
public void getKeyValue_invalid() throws Exception {
Pair pair = HttpRequestUtils.getKeyValue("userId", "=");
assertThat(pair, is(nullValue()));
}
@Test
public void parseHeader() throws Exception {
String header = "Content-Length: 59";
Pair pair = HttpRequestUtils.parseHeader(header);
assertThat(pair, is(new Pair("Content-Length", "59")));
}
}