/
RouteEntryTest.java
114 lines (82 loc) · 3.64 KB
/
RouteEntryTest.java
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package spark.route;
import org.junit.Test;
import spark.utils.SparkUtils;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class RouteEntryTest {
@Test
public void testMatches_BeforeAndAllPaths() {
RouteEntry entry = new RouteEntry();
entry.httpMethod = HttpMethod.before;
entry.path = SparkUtils.ALL_PATHS;
assertTrue("Should return true because HTTP method is \"Before\", the methods of route and match request match," +
" and the path provided is same as ALL_PATHS (+/*paths)",
entry.matches(HttpMethod.before, SparkUtils.ALL_PATHS));
}
@Test
public void testMatches_AfterAndAllPaths() {
RouteEntry entry = new RouteEntry();
entry.httpMethod = HttpMethod.after;
entry.path = SparkUtils.ALL_PATHS;
assertTrue("Should return true because HTTP method is \"After\", the methods of route and match request match," +
" and the path provided is same as ALL_PATHS (+/*paths)",
entry.matches(HttpMethod.after, SparkUtils.ALL_PATHS));
}
@Test
public void testMatches_NotAllPathsAndDidNotMatchHttpMethod() {
RouteEntry entry = new RouteEntry();
entry.httpMethod = HttpMethod.post;
entry.path = "/test";
assertFalse("Should return false because path names did not match",
entry.matches(HttpMethod.get, "/path"));
}
@Test
public void testMatches_RouteDoesNotEndWithSlash() {
RouteEntry entry = new RouteEntry();
entry.httpMethod = HttpMethod.get;
entry.path = "/test";
assertFalse("Should return false because route path does not end with a slash, does not end with " +
"a wildcard, and the route pah supplied ends with a slash ",
entry.matches(HttpMethod.get, "/test/"));
}
@Test
public void testMatches_PathDoesNotEndInSlash() {
RouteEntry entry = new RouteEntry();
entry.httpMethod = HttpMethod.get;
entry.path = "/test/";
assertFalse("Should return false because route path ends with a slash while path supplied as parameter does" +
"not end with a slash", entry.matches(HttpMethod.get, "/test"));
}
@Test
public void testMatches_MatchingPaths() {
RouteEntry entry = new RouteEntry();
entry.httpMethod = HttpMethod.get;
entry.path = "/test/";
assertTrue("Should return true because route path and path is exactly the same",
entry.matches(HttpMethod.get, "/test/"));
}
@Test
public void testMatches_WithWildcardOnEntryPath() {
RouteEntry entry = new RouteEntry();
entry.httpMethod = HttpMethod.get;
entry.path = "/test/*";
assertTrue("Should return true because path specified is covered by the route path wildcard",
entry.matches(HttpMethod.get, "/test/me"));
}
@Test
public void testMatches_PathsDoNotMatch() {
RouteEntry entry = new RouteEntry();
entry.httpMethod = HttpMethod.get;
entry.path = "/test/me";
assertFalse("Should return false because path does not match route path",
entry.matches(HttpMethod.get, "/test/other"));
}
@Test
public void testMatches_longRoutePathWildcard() {
RouteEntry entry = new RouteEntry();
entry.httpMethod = HttpMethod.get;
entry.path = "/test/this/resource/*";
assertTrue("Should return true because path specified is covered by the route path wildcard",
entry.matches(HttpMethod.get, "/test/this/resource/child/id"));
}
}